2
0
mirror of https://github.com/iconify/iconify.git synced 2024-11-10 15:20:54 +00:00
iconify/packages/utils/tests/get-icons-test.ts

182 lines
2.9 KiB
TypeScript
Raw Normal View History

import type { IconifyJSON } from '@iconify/types';
2021-09-20 20:53:49 +00:00
import { getIcons } from '../lib/icon-set/get-icons';
describe('Testing retrieving icons from icon set', () => {
2021-09-20 20:53:49 +00:00
test('Simple icon set', () => {
const data: IconifyJSON = {
prefix: 'foo',
icons: {
bar: {
body: '<g id="bar" />',
},
baz: {
body: '<g id="baz" />',
},
foo: {
body: '<g id="foo" />',
},
},
};
// Missing icon
2021-09-20 20:53:49 +00:00
expect(getIcons(data, ['missing-icon'])).toBeNull();
2021-09-20 20:53:49 +00:00
expect(getIcons(data, ['missing-icon'], true)).toEqual({
prefix: 'foo',
icons: {},
not_found: ['missing-icon'],
});
// Icon
2021-09-20 20:53:49 +00:00
expect(getIcons(data, ['bar'])).toEqual({
prefix: 'foo',
icons: {
bar: {
body: '<g id="bar" />',
},
},
});
// Same icon multiple times
2021-09-20 20:53:49 +00:00
expect(getIcons(data, ['bar', 'bar', 'bar'])).toEqual({
prefix: 'foo',
icons: {
bar: {
body: '<g id="bar" />',
},
},
});
// Mutliple icons
2021-09-20 20:53:49 +00:00
expect(getIcons(data, ['foo', 'bar'])).toEqual({
prefix: 'foo',
icons: {
bar: {
body: '<g id="bar" />',
},
foo: {
body: '<g id="foo" />',
},
},
});
});
2021-09-20 20:53:49 +00:00
test('Aliases and characters', () => {
const data: IconifyJSON = {
prefix: 'foo',
icons: {
bar: {
body: '<g />',
},
bar2: {
body: '<g />',
},
},
aliases: {
'foo': {
parent: 'bar',
hFlip: true,
},
'foo2': {
parent: 'foo',
},
'missing-alias': {
parent: 'missing-icon',
},
},
chars: {
f00: 'bar2',
f01: 'bar',
f02: 'foo',
f03: 'foo2',
f04: 'missing-icon',
},
};
// Alias
2021-09-20 20:53:49 +00:00
expect(getIcons(data, ['foo'])).toEqual({
prefix: 'foo',
icons: {
bar: {
body: '<g />',
},
},
aliases: {
foo: {
parent: 'bar',
hFlip: true,
},
},
});
// Alias of alias
2021-09-20 20:53:49 +00:00
expect(getIcons(data, ['foo2'])).toEqual({
prefix: 'foo',
icons: {
bar: {
body: '<g />',
},
},
aliases: {
foo: {
parent: 'bar',
hFlip: true,
},
foo2: {
parent: 'foo',
},
},
});
// Bad alias
2021-09-20 20:53:49 +00:00
expect(getIcons(data, ['missing-alias'])).toBeNull();
expect(getIcons(data, ['missing-alias'], true)).toEqual({
prefix: 'foo',
icons: {},
not_found: ['missing-alias'],
});
// Character
2021-09-20 20:53:49 +00:00
expect(getIcons(data, ['f00'])).toEqual({
prefix: 'foo',
icons: {
bar2: {
body: '<g />',
},
},
aliases: {
f00: {
parent: 'bar2',
},
},
});
// Character that points to alias
2021-09-20 20:53:49 +00:00
expect(getIcons(data, ['f02'])).toEqual({
prefix: 'foo',
icons: {
bar: {
body: '<g />',
},
},
aliases: {
f02: {
parent: 'foo',
},
foo: {
parent: 'bar',
hFlip: true,
},
},
});
// Bad character
2021-09-20 20:53:49 +00:00
expect(getIcons(data, ['f04'])).toBeNull();
expect(getIcons(data, ['f04'], true)).toEqual({
prefix: 'foo',
icons: {},
not_found: ['f04'],
});
});
});