2021-09-27 13:29:45 +00:00
|
|
|
/**
|
|
|
|
* @jest-environment jsdom
|
|
|
|
*/
|
2021-04-30 09:51:31 +00:00
|
|
|
import { render } from '@testing-library/svelte';
|
2021-05-14 18:39:12 +00:00
|
|
|
import Icon from '../../dist/offline';
|
2021-04-30 09:51:31 +00:00
|
|
|
|
|
|
|
const iconData = {
|
2021-05-11 20:27:13 +00:00
|
|
|
body: '<path d="M4 19h16v2H4zm5-4h11v2H9zm-5-4h16v2H4zm0-8h16v2H4zm5 4h11v2H9z" fill="currentColor"/>',
|
2021-04-30 09:51:31 +00:00
|
|
|
width: 24,
|
|
|
|
height: 32,
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('Rotation', () => {
|
|
|
|
test('number', () => {
|
|
|
|
const component = render(Icon, { icon: iconData, rotate: 1 });
|
2021-09-27 13:29:45 +00:00
|
|
|
const node = component.container.querySelector('svg')!;
|
2021-04-30 09:51:31 +00:00
|
|
|
|
|
|
|
// Find first child node
|
2021-09-27 13:29:45 +00:00
|
|
|
const child = node.childNodes[0] as SVGGElement;
|
|
|
|
expect(child.tagName).toBe('g');
|
|
|
|
expect(child.getAttribute('transform')).toBe('rotate(90 16 16)');
|
2021-04-30 09:51:31 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('string', () => {
|
|
|
|
const component = render(Icon, { icon: iconData, rotate: '180deg' });
|
2021-09-27 13:29:45 +00:00
|
|
|
const node = component.container.querySelector('svg')!;
|
2021-04-30 09:51:31 +00:00
|
|
|
|
|
|
|
// Find first child node
|
2021-09-27 13:29:45 +00:00
|
|
|
const child = node.childNodes[0] as SVGGElement;
|
|
|
|
expect(child.tagName).toBe('g');
|
|
|
|
expect(child.getAttribute('transform')).toBe('rotate(180 12 16)');
|
2021-04-30 09:51:31 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Flip', () => {
|
|
|
|
test('boolean', () => {
|
|
|
|
const component = render(Icon, { icon: iconData, hFlip: true });
|
2021-09-27 13:29:45 +00:00
|
|
|
const node = component.container.querySelector('svg')!;
|
2021-04-30 09:51:31 +00:00
|
|
|
|
|
|
|
// Find first child node
|
2021-09-27 13:29:45 +00:00
|
|
|
const child = node.childNodes[0] as SVGGElement;
|
|
|
|
expect(child.tagName).toBe('g');
|
|
|
|
expect(child.getAttribute('transform')).toBe(
|
2021-04-30 09:51:31 +00:00
|
|
|
'translate(24 0) scale(-1 1)'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('string', () => {
|
|
|
|
const component = render(Icon, { icon: iconData, flip: 'vertical' });
|
2021-09-27 13:29:45 +00:00
|
|
|
const node = component.container.querySelector('svg')!;
|
2021-04-30 09:51:31 +00:00
|
|
|
|
|
|
|
// Find first child node
|
2021-09-27 13:29:45 +00:00
|
|
|
const child = node.childNodes[0] as SVGGElement;
|
|
|
|
expect(child.tagName).toBe('g');
|
|
|
|
expect(child.getAttribute('transform')).toBe(
|
2021-04-30 09:51:31 +00:00
|
|
|
'translate(0 32) scale(1 -1)'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('string and boolean', () => {
|
|
|
|
const component = render(Icon, {
|
|
|
|
icon: iconData,
|
|
|
|
flip: 'horizontal',
|
|
|
|
vFlip: true,
|
|
|
|
});
|
2021-09-27 13:29:45 +00:00
|
|
|
const node = component.container.querySelector('svg')!;
|
2021-04-30 09:51:31 +00:00
|
|
|
|
|
|
|
// Find first child node
|
2021-09-27 13:29:45 +00:00
|
|
|
const child = node.childNodes[0] as SVGGElement;
|
|
|
|
expect(child.tagName).toBe('g');
|
2021-04-30 09:51:31 +00:00
|
|
|
// horizontal + vertical = 180deg rotation
|
2021-09-27 13:29:45 +00:00
|
|
|
expect(child.getAttribute('transform')).toBe('rotate(180 12 16)');
|
2021-04-30 09:51:31 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('string for boolean attribute', () => {
|
|
|
|
const component = render(Icon, {
|
|
|
|
icon: iconData,
|
|
|
|
hFlip: 'true',
|
|
|
|
});
|
2021-09-27 13:29:45 +00:00
|
|
|
const node = component.container.querySelector('svg')!;
|
2021-04-30 09:51:31 +00:00
|
|
|
|
|
|
|
// Find first child node
|
2021-09-27 13:29:45 +00:00
|
|
|
const child = node.childNodes[0] as SVGGElement;
|
|
|
|
expect(child.tagName).toBe('g');
|
|
|
|
expect(child.getAttribute('transform')).toBe(
|
2021-04-30 09:51:31 +00:00
|
|
|
'translate(24 0) scale(-1 1)'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('shorthand and boolean', () => {
|
2021-05-11 20:27:13 +00:00
|
|
|
// 'flip' is processed after 'hFlip' because of order of elements in object, overwriting value
|
2021-04-30 09:51:31 +00:00
|
|
|
const component = render(Icon, {
|
|
|
|
icon: iconData,
|
|
|
|
hFlip: false,
|
2021-05-11 20:27:13 +00:00
|
|
|
flip: 'horizontal',
|
2021-04-30 09:51:31 +00:00
|
|
|
});
|
2021-09-27 13:29:45 +00:00
|
|
|
const node = component.container.querySelector('svg')!;
|
2021-04-30 09:51:31 +00:00
|
|
|
|
|
|
|
// Find first child node
|
2021-09-27 13:29:45 +00:00
|
|
|
const child = node.childNodes[0] as SVGGElement;
|
|
|
|
expect(child.tagName).toBe('g');
|
|
|
|
expect(child.getAttribute('transform')).toBe(
|
2021-04-30 09:51:31 +00:00
|
|
|
'translate(24 0) scale(-1 1)'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('shorthand and boolean as string', () => {
|
|
|
|
const component = render(Icon, {
|
|
|
|
icon: iconData,
|
|
|
|
flip: 'vertical',
|
|
|
|
hFlip: true,
|
|
|
|
});
|
2021-09-27 13:29:45 +00:00
|
|
|
const node = component.container.querySelector('svg')!;
|
2021-04-30 09:51:31 +00:00
|
|
|
|
|
|
|
// Find first child node
|
2021-09-27 13:29:45 +00:00
|
|
|
const child = node.childNodes[0] as SVGGElement;
|
|
|
|
expect(child.tagName).toBe('g');
|
|
|
|
expect(child.getAttribute('transform')).toBe('rotate(180 12 16)');
|
2021-04-30 09:51:31 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('wrong case', () => {
|
|
|
|
const component = render(Icon, {
|
|
|
|
icon: iconData,
|
|
|
|
vflip: true,
|
|
|
|
});
|
2021-09-27 13:29:45 +00:00
|
|
|
const node = component.container.querySelector('svg')!;
|
2021-04-30 09:51:31 +00:00
|
|
|
|
|
|
|
// Find first child node
|
2021-09-27 13:29:45 +00:00
|
|
|
const child = node.childNodes[0] as SVGGElement;
|
|
|
|
expect(child.tagName).toBe('path');
|
2021-04-30 09:51:31 +00:00
|
|
|
});
|
|
|
|
});
|