2022-07-01 20:22:22 +00:00
|
|
|
import type { ExtendedIconifyIcon } from '@iconify/types';
|
2023-02-15 07:34:29 +00:00
|
|
|
import { parseIconSet, parseIconSetAsync } from '../lib/icon-set/parse';
|
2020-09-03 11:11:17 +00:00
|
|
|
|
|
|
|
describe('Testing parsing icon set', () => {
|
2021-09-20 20:53:49 +00:00
|
|
|
test('Simple icon set', () => {
|
2020-09-03 11:11:17 +00:00
|
|
|
// Names list
|
|
|
|
const names: string[] = ['missing', 'icon1', 'icon2'];
|
|
|
|
|
|
|
|
// Resolved data
|
2022-07-01 20:22:22 +00:00
|
|
|
const expected: Record<string, ExtendedIconifyIcon | null> = {
|
2020-09-03 11:11:17 +00:00
|
|
|
icon1: {
|
|
|
|
body: '<path d="icon1" />',
|
|
|
|
width: 20,
|
|
|
|
height: 24,
|
|
|
|
},
|
|
|
|
icon2: {
|
|
|
|
body: '<path d="icon2" />',
|
|
|
|
width: 24,
|
|
|
|
height: 24,
|
|
|
|
},
|
|
|
|
missing: null,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Do stuff
|
|
|
|
expect(
|
|
|
|
parseIconSet(
|
|
|
|
{
|
|
|
|
prefix: 'foo',
|
|
|
|
not_found: ['missing'],
|
|
|
|
icons: {
|
|
|
|
icon1: {
|
|
|
|
body: '<path d="icon1" />',
|
|
|
|
width: 20,
|
|
|
|
},
|
|
|
|
icon2: {
|
|
|
|
body: '<path d="icon2" />',
|
|
|
|
width: 24,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
height: 24,
|
|
|
|
},
|
|
|
|
(name, data) => {
|
|
|
|
// Make sure name matches
|
2021-09-20 20:53:49 +00:00
|
|
|
expect(names.length).toBeGreaterThanOrEqual(1);
|
|
|
|
expect(name).toBe(names.shift());
|
2020-09-03 11:11:17 +00:00
|
|
|
|
|
|
|
// Check icon data
|
2021-09-20 20:53:49 +00:00
|
|
|
expect(data).toEqual(expected[name]);
|
2020-09-03 11:11:17 +00:00
|
|
|
}
|
|
|
|
)
|
2021-10-12 15:19:46 +00:00
|
|
|
).toEqual(['missing', 'icon1', 'icon2']);
|
2020-09-03 11:11:17 +00:00
|
|
|
|
|
|
|
// All names should have been parsed
|
2021-09-20 20:53:49 +00:00
|
|
|
expect(names).toEqual([]);
|
2020-09-03 11:11:17 +00:00
|
|
|
});
|
|
|
|
|
2021-09-20 20:53:49 +00:00
|
|
|
test('Aliases', () => {
|
2020-09-03 11:11:17 +00:00
|
|
|
// Names list
|
2022-06-20 17:39:06 +00:00
|
|
|
let names: string[] = ['icon1', 'icon2', 'alias1', 'alias2'];
|
|
|
|
const expectedNames = names.slice(0).sort((a, b) => a.localeCompare(b));
|
2020-09-03 11:11:17 +00:00
|
|
|
|
|
|
|
// Resolved data
|
2022-07-01 20:22:22 +00:00
|
|
|
const expected: Record<string, ExtendedIconifyIcon | null> = {
|
2020-09-03 11:11:17 +00:00
|
|
|
icon1: {
|
|
|
|
body: '<path d="icon1" />',
|
|
|
|
width: 20,
|
|
|
|
height: 24,
|
|
|
|
},
|
|
|
|
icon2: {
|
|
|
|
body: '<path d="icon2" />',
|
|
|
|
width: 24,
|
|
|
|
height: 24,
|
|
|
|
vFlip: true,
|
|
|
|
rotate: 3,
|
|
|
|
},
|
|
|
|
alias1: {
|
|
|
|
body: '<path d="icon1" />',
|
|
|
|
width: 20,
|
|
|
|
height: 24,
|
|
|
|
},
|
|
|
|
alias2: {
|
|
|
|
body: '<path d="icon2" />',
|
|
|
|
width: 20,
|
|
|
|
height: 24,
|
|
|
|
hFlip: true,
|
|
|
|
vFlip: true,
|
|
|
|
rotate: 3,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
// Do stuff
|
2022-06-20 17:39:06 +00:00
|
|
|
const parsedNames = parseIconSet(
|
|
|
|
{
|
|
|
|
prefix: 'foo',
|
|
|
|
icons: {
|
|
|
|
icon1: {
|
|
|
|
body: '<path d="icon1" />',
|
|
|
|
width: 20,
|
2020-09-03 11:11:17 +00:00
|
|
|
},
|
2022-06-20 17:39:06 +00:00
|
|
|
icon2: {
|
|
|
|
body: '<path d="icon2" />',
|
|
|
|
width: 24,
|
|
|
|
vFlip: true,
|
|
|
|
rotate: 3,
|
2020-09-03 11:11:17 +00:00
|
|
|
},
|
|
|
|
},
|
2022-06-20 17:39:06 +00:00
|
|
|
aliases: {
|
|
|
|
alias1: {
|
|
|
|
parent: 'icon1',
|
|
|
|
},
|
|
|
|
alias2: {
|
|
|
|
parent: 'icon2',
|
|
|
|
hFlip: true,
|
|
|
|
width: 20,
|
|
|
|
},
|
|
|
|
// invalid alias
|
|
|
|
icon2: {
|
|
|
|
parent: 'icon1',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
height: 24,
|
|
|
|
},
|
|
|
|
(name, data) => {
|
|
|
|
// Make sure name exists in array of pending names
|
|
|
|
const index = names.indexOf(name);
|
|
|
|
expect(index).not.toBe(-1);
|
|
|
|
names = names.slice(0, index).concat(names.slice(index + 1));
|
2020-09-03 11:11:17 +00:00
|
|
|
|
2022-06-20 17:39:06 +00:00
|
|
|
// Check icon data
|
|
|
|
expect(data).toEqual(expected[name]);
|
|
|
|
}
|
|
|
|
);
|
2020-09-03 11:11:17 +00:00
|
|
|
|
2022-06-20 17:39:06 +00:00
|
|
|
// All names should have been parsed, not necessary in expected order
|
2021-09-20 20:53:49 +00:00
|
|
|
expect(names).toEqual([]);
|
2022-06-20 17:39:06 +00:00
|
|
|
parsedNames.sort((a, b) => a.localeCompare(b));
|
|
|
|
expect(parsedNames).toEqual(expectedNames);
|
2020-09-03 11:11:17 +00:00
|
|
|
});
|
|
|
|
|
2023-02-15 07:34:29 +00:00
|
|
|
test('Nested aliases', async () => {
|
2020-09-03 11:11:17 +00:00
|
|
|
// Names list
|
2022-06-20 17:39:06 +00:00
|
|
|
let names: string[] = [
|
2020-09-03 11:11:17 +00:00
|
|
|
'icon1',
|
|
|
|
'icon2',
|
|
|
|
'alias2a',
|
|
|
|
'alias2f',
|
|
|
|
'alias2z',
|
|
|
|
'alias2z3',
|
2021-10-12 14:17:51 +00:00
|
|
|
'alias2z4',
|
|
|
|
'alias2z5',
|
|
|
|
'alias2z6',
|
2022-06-20 17:00:56 +00:00
|
|
|
'alias2z7',
|
2020-09-03 11:11:17 +00:00
|
|
|
];
|
2022-06-20 17:39:06 +00:00
|
|
|
const expectedNames = names.slice(0).sort((a, b) => a.localeCompare(b));
|
2020-09-03 11:11:17 +00:00
|
|
|
|
|
|
|
// Resolved data
|
2022-07-01 20:22:22 +00:00
|
|
|
const expected: Record<string, ExtendedIconifyIcon | null> = {
|
2020-09-03 11:11:17 +00:00
|
|
|
icon1: {
|
|
|
|
body: '<path d="icon1" />',
|
|
|
|
width: 20,
|
|
|
|
height: 20,
|
|
|
|
},
|
|
|
|
icon2: {
|
|
|
|
body: '<path d="icon2" />',
|
|
|
|
width: 24,
|
|
|
|
height: 24,
|
|
|
|
hFlip: true,
|
|
|
|
rotate: 1,
|
|
|
|
},
|
|
|
|
alias2f: {
|
|
|
|
// icon2 + alias2f
|
|
|
|
body: '<path d="icon2" />',
|
|
|
|
width: 22,
|
|
|
|
height: 24,
|
|
|
|
vFlip: true,
|
|
|
|
rotate: 2,
|
|
|
|
},
|
|
|
|
alias2a: {
|
|
|
|
// icon2 + alias2f + alias2a
|
|
|
|
body: '<path d="icon2" />',
|
|
|
|
width: 20,
|
|
|
|
height: 20,
|
|
|
|
vFlip: true,
|
|
|
|
rotate: 2,
|
|
|
|
},
|
|
|
|
alias2z: {
|
|
|
|
// icon2 + alias2f + alias2z
|
|
|
|
body: '<path d="icon2" />',
|
|
|
|
width: 21,
|
|
|
|
height: 24,
|
|
|
|
vFlip: true,
|
|
|
|
rotate: 1,
|
|
|
|
},
|
|
|
|
alias2z3: {
|
|
|
|
// icon2 + alias2f + alias2z
|
|
|
|
body: '<path d="icon2" />',
|
|
|
|
width: 21,
|
|
|
|
height: 24,
|
|
|
|
vFlip: true,
|
|
|
|
rotate: 1,
|
|
|
|
},
|
2021-10-12 14:17:51 +00:00
|
|
|
alias2z4: {
|
|
|
|
// alias of alias2z3
|
|
|
|
body: '<path d="icon2" />',
|
|
|
|
width: 21,
|
|
|
|
height: 24,
|
|
|
|
vFlip: true,
|
|
|
|
rotate: 1,
|
|
|
|
},
|
|
|
|
alias2z5: {
|
|
|
|
// alias of alias2z4
|
|
|
|
body: '<path d="icon2" />',
|
|
|
|
width: 21,
|
|
|
|
height: 24,
|
|
|
|
vFlip: true,
|
|
|
|
rotate: 1,
|
|
|
|
},
|
|
|
|
alias2z6: {
|
|
|
|
// alias of alias2z5
|
|
|
|
body: '<path d="icon2" />',
|
|
|
|
width: 21,
|
|
|
|
height: 24,
|
|
|
|
vFlip: true,
|
|
|
|
rotate: 1,
|
|
|
|
},
|
2022-06-20 17:00:56 +00:00
|
|
|
alias2z7: {
|
|
|
|
// alias of alias2z6
|
|
|
|
body: '<path d="icon2" />',
|
|
|
|
width: 21,
|
|
|
|
height: 24,
|
|
|
|
vFlip: true,
|
|
|
|
rotate: 1,
|
|
|
|
},
|
2020-09-03 11:11:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Do stuff
|
2023-02-15 07:34:29 +00:00
|
|
|
const parsedNames = await parseIconSetAsync(
|
2022-06-20 17:39:06 +00:00
|
|
|
{
|
|
|
|
prefix: 'foo',
|
|
|
|
icons: {
|
|
|
|
icon1: {
|
|
|
|
body: '<path d="icon1" />',
|
|
|
|
width: 20,
|
|
|
|
height: 20,
|
2020-09-03 11:11:17 +00:00
|
|
|
},
|
2022-06-20 17:39:06 +00:00
|
|
|
icon2: {
|
|
|
|
body: '<path d="icon2" />',
|
|
|
|
width: 24,
|
|
|
|
rotate: 1,
|
|
|
|
hFlip: true,
|
2020-09-03 11:11:17 +00:00
|
|
|
},
|
|
|
|
},
|
2022-06-20 17:39:06 +00:00
|
|
|
aliases: {
|
|
|
|
alias2a: {
|
|
|
|
// Alias before parent
|
|
|
|
parent: 'alias2f',
|
|
|
|
width: 20,
|
|
|
|
height: 20,
|
|
|
|
},
|
|
|
|
alias2f: {
|
|
|
|
parent: 'icon2',
|
|
|
|
width: 22,
|
|
|
|
rotate: 1,
|
|
|
|
hFlip: true,
|
|
|
|
vFlip: true,
|
|
|
|
},
|
|
|
|
alias2z: {
|
|
|
|
// Alias after parent
|
|
|
|
parent: 'alias2f',
|
|
|
|
width: 21,
|
|
|
|
rotate: 3,
|
|
|
|
},
|
|
|
|
alias2z3: {
|
|
|
|
// 3 parents: alias2z, alias2f, icon2
|
|
|
|
parent: 'alias2z',
|
|
|
|
},
|
|
|
|
alias2z4: {
|
|
|
|
// 4 parents: alias2z3, alias2z, alias2f, icon2
|
|
|
|
parent: 'alias2z3',
|
|
|
|
},
|
|
|
|
alias2z5: {
|
|
|
|
// 5 parents: alias2z4, alias2z3, alias2z, alias2f, icon2
|
|
|
|
parent: 'alias2z4',
|
|
|
|
},
|
|
|
|
alias2z6: {
|
|
|
|
// 6 parents: alias2z5, alias2z4, alias2z3, alias2z, alias2f, icon2
|
|
|
|
parent: 'alias2z5',
|
|
|
|
},
|
|
|
|
alias2z7: {
|
|
|
|
// 7 parents: alias2z6, alias2z5, alias2z4, alias2z3, alias2z, alias2f, icon2
|
|
|
|
parent: 'alias2z6',
|
|
|
|
},
|
|
|
|
alias3: {
|
|
|
|
// invalid parent
|
|
|
|
parent: 'icon3',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
height: 24,
|
|
|
|
},
|
|
|
|
(name, data) => {
|
2023-02-15 07:34:29 +00:00
|
|
|
return new Promise((fulfill) => {
|
|
|
|
// Make sure name exists in array of pending names
|
|
|
|
const index = names.indexOf(name);
|
|
|
|
expect(index).not.toBe(-1);
|
|
|
|
names = names
|
|
|
|
.slice(0, index)
|
|
|
|
.concat(names.slice(index + 1));
|
2020-09-03 11:11:17 +00:00
|
|
|
|
2023-02-15 07:34:29 +00:00
|
|
|
// Check icon data
|
|
|
|
expect(data).toEqual(expected[name]);
|
|
|
|
|
|
|
|
fulfill(void 0);
|
|
|
|
});
|
2022-06-20 17:39:06 +00:00
|
|
|
}
|
|
|
|
);
|
2020-09-03 11:11:17 +00:00
|
|
|
|
2022-06-20 17:39:06 +00:00
|
|
|
// All names should have been parsed, not necessary in expected order
|
2021-09-20 20:53:49 +00:00
|
|
|
expect(names).toEqual([]);
|
2022-06-20 17:39:06 +00:00
|
|
|
parsedNames.sort((a, b) => a.localeCompare(b));
|
|
|
|
expect(parsedNames).toEqual(expectedNames);
|
2020-09-03 11:11:17 +00:00
|
|
|
});
|
|
|
|
});
|