diff options
author | Francisco Javier López <fjlopez@gitlab.com> | 2018-04-08 13:20:05 +0300 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2018-04-08 13:20:05 +0300 |
commit | 31dd86b636a42e251e346dd5207281fda99c413f (patch) | |
tree | 2dbb1c776e595e0975de374dee7eb02b65e939da /spec/javascripts/matchers.js | |
parent | dd552d06f6e39d5e6138a33bd7c1bffb2d3dbb1d (diff) |
Projects and groups badges settings UI
Diffstat (limited to 'spec/javascripts/matchers.js')
-rw-r--r-- | spec/javascripts/matchers.js | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/spec/javascripts/matchers.js b/spec/javascripts/matchers.js new file mode 100644 index 00000000000..7cc5e753c22 --- /dev/null +++ b/spec/javascripts/matchers.js @@ -0,0 +1,35 @@ +export default { + toHaveSpriteIcon: () => ({ + compare(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')); + const matchingIcon = iconReferences.find(reference => reference.getAttribute('xlink:href').endsWith(`#${iconName}`)); + const result = { + pass: !!matchingIcon, + }; + + if (result.pass) { + result.message = `${element.outerHTML} contains the sprite icon "${iconName}"!`; + } else { + result.message = `${element.outerHTML} does not contain the sprite icon "${iconName}"!`; + + const existingIcons = iconReferences.map((reference) => { + const iconUrl = reference.getAttribute('xlink:href'); + return `"${iconUrl.replace(/^.+#/, '')}"`; + }); + if (existingIcons.length > 0) { + result.message += ` (only found ${existingIcons.join(',')})`; + } + } + + return result; + }, + }), +}; |