2019-10-12 21:52:04 +05:30
|
|
|
export default {
|
|
|
|
toHaveSpriteIcon: (element, iconName) => {
|
|
|
|
if (!iconName) {
|
|
|
|
throw new Error('toHaveSpriteIcon is missing iconName argument!');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(element instanceof HTMLElement)) {
|
|
|
|
throw new Error(`${element} is not a DOM element!`);
|
|
|
|
}
|
|
|
|
|
|
|
|
const iconReferences = [].slice.apply(element.querySelectorAll('svg use'));
|
2020-11-24 15:15:51 +05:30
|
|
|
const matchingIcon = iconReferences.find(
|
2021-03-08 18:12:59 +05:30
|
|
|
(reference) => reference.parentNode.getAttribute('data-testid') === `${iconName}-icon`,
|
2019-10-12 21:52:04 +05:30
|
|
|
);
|
|
|
|
|
|
|
|
const pass = Boolean(matchingIcon);
|
|
|
|
|
|
|
|
let message;
|
|
|
|
if (pass) {
|
|
|
|
message = `${element.outerHTML} contains the sprite icon "${iconName}"!`;
|
|
|
|
} else {
|
|
|
|
message = `${element.outerHTML} does not contain the sprite icon "${iconName}"!`;
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
const existingIcons = iconReferences.map((reference) => {
|
2020-11-24 15:15:51 +05:30
|
|
|
const iconUrl = reference.getAttribute('href');
|
2019-10-12 21:52:04 +05:30
|
|
|
return `"${iconUrl.replace(/^.+#/, '')}"`;
|
|
|
|
});
|
|
|
|
if (existingIcons.length > 0) {
|
|
|
|
message += ` (only found ${existingIcons.join(',')})`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
pass,
|
|
|
|
message: () => message,
|
|
|
|
};
|
|
|
|
},
|
2020-06-23 00:09:42 +05:30
|
|
|
toMatchInterpolatedText(received, match) {
|
|
|
|
let clearReceived;
|
|
|
|
let clearMatch;
|
|
|
|
|
|
|
|
try {
|
2021-03-08 18:12:59 +05:30
|
|
|
clearReceived = received.replace(/\s\s+/gm, ' ').replace(/\s\./gm, '.').trim();
|
2020-06-23 00:09:42 +05:30
|
|
|
} catch (e) {
|
|
|
|
return { actual: received, message: 'The received value is not a string', pass: false };
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
clearMatch = match.replace(/%{\w+}/gm, '').trim();
|
|
|
|
} catch (e) {
|
|
|
|
return { message: 'The comparator value is not a string', pass: false };
|
|
|
|
}
|
|
|
|
const pass = clearReceived === clearMatch;
|
|
|
|
const message = pass
|
|
|
|
? () => `
|
|
|
|
\n\n
|
|
|
|
Expected: ${this.utils.printExpected(clearReceived)}
|
|
|
|
To not equal: ${this.utils.printReceived(clearMatch)}
|
|
|
|
`
|
|
|
|
: () =>
|
|
|
|
`
|
|
|
|
\n\n
|
|
|
|
Expected: ${this.utils.printExpected(clearReceived)}
|
|
|
|
To equal: ${this.utils.printReceived(clearMatch)}
|
|
|
|
`;
|
|
|
|
|
|
|
|
return { actual: received, message, pass };
|
|
|
|
},
|
2019-10-12 21:52:04 +05:30
|
|
|
};
|