2021-05-24 10:25:02 +00:00
|
|
|
import type { IconifyJSON } from '@iconify/types';
|
2021-09-20 20:53:49 +00:00
|
|
|
import { minifyIconSet } from '../lib/icon-set/minify';
|
2021-05-24 10:25:02 +00:00
|
|
|
|
|
|
|
describe('Testing minifying icon set', () => {
|
2021-09-20 20:53:49 +00:00
|
|
|
test('Nothing to minify', () => {
|
2021-05-24 10:25:02 +00:00
|
|
|
const item: IconifyJSON = {
|
|
|
|
prefix: 'foo',
|
|
|
|
icons: {
|
|
|
|
foo: {
|
|
|
|
body: '<g />',
|
|
|
|
width: 24,
|
|
|
|
height: 24,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const expected: IconifyJSON = {
|
|
|
|
prefix: 'foo',
|
|
|
|
icons: {
|
|
|
|
foo: {
|
|
|
|
body: '<g />',
|
|
|
|
width: 24,
|
|
|
|
height: 24,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
minifyIconSet(item);
|
2021-09-20 20:53:49 +00:00
|
|
|
expect(item).toEqual(expected);
|
2021-05-24 10:25:02 +00:00
|
|
|
});
|
|
|
|
|
2021-09-20 20:53:49 +00:00
|
|
|
test('No common values', () => {
|
2021-05-24 10:25:02 +00:00
|
|
|
const item: IconifyJSON = {
|
|
|
|
prefix: 'foo',
|
|
|
|
icons: {
|
|
|
|
'foo-24': {
|
|
|
|
body: '<g />',
|
|
|
|
width: 24,
|
|
|
|
height: 24,
|
|
|
|
},
|
|
|
|
'foo-16': {
|
|
|
|
body: '<g />',
|
|
|
|
width: 12,
|
|
|
|
height: 12,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const expected: IconifyJSON = {
|
|
|
|
prefix: 'foo',
|
|
|
|
icons: {
|
|
|
|
'foo-24': {
|
|
|
|
body: '<g />',
|
|
|
|
width: 24,
|
|
|
|
height: 24,
|
|
|
|
},
|
|
|
|
'foo-16': {
|
|
|
|
body: '<g />',
|
|
|
|
width: 12,
|
|
|
|
height: 12,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
minifyIconSet(item);
|
2021-09-20 20:53:49 +00:00
|
|
|
expect(item).toEqual(expected);
|
2021-05-24 10:25:02 +00:00
|
|
|
});
|
|
|
|
|
2021-09-20 20:53:49 +00:00
|
|
|
test('Default values', () => {
|
2021-05-24 10:25:02 +00:00
|
|
|
const item: IconifyJSON = {
|
|
|
|
prefix: 'foo',
|
|
|
|
icons: {
|
|
|
|
foo: {
|
|
|
|
body: '<g />',
|
|
|
|
width: 24,
|
|
|
|
// Height matches default
|
|
|
|
height: 16,
|
|
|
|
},
|
|
|
|
bar: {
|
|
|
|
body: '<g />',
|
|
|
|
// Width matches default
|
|
|
|
width: 16,
|
|
|
|
height: 12,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const expected: IconifyJSON = {
|
|
|
|
prefix: 'foo',
|
|
|
|
icons: {
|
|
|
|
foo: {
|
|
|
|
body: '<g />',
|
|
|
|
width: 24,
|
|
|
|
},
|
|
|
|
bar: {
|
|
|
|
body: '<g />',
|
|
|
|
height: 12,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
minifyIconSet(item);
|
2021-09-20 20:53:49 +00:00
|
|
|
expect(item).toEqual(expected);
|
2021-05-24 10:25:02 +00:00
|
|
|
});
|
|
|
|
|
2021-09-20 20:53:49 +00:00
|
|
|
test('Common value', () => {
|
2021-05-24 10:25:02 +00:00
|
|
|
const item: IconifyJSON = {
|
|
|
|
prefix: 'foo',
|
|
|
|
icons: {
|
|
|
|
// 2 icons have the same height, 2 icons have the same width
|
|
|
|
'foo-wide': {
|
|
|
|
body: '<g />',
|
|
|
|
width: 32,
|
|
|
|
height: 24,
|
|
|
|
},
|
|
|
|
'foo-square': {
|
|
|
|
body: '<g />',
|
|
|
|
width: 24,
|
|
|
|
height: 24,
|
|
|
|
},
|
|
|
|
'foo-tiny-wide': {
|
|
|
|
body: '<g />',
|
|
|
|
width: 24,
|
|
|
|
height: 16,
|
|
|
|
},
|
|
|
|
'foo-tiny-square': {
|
|
|
|
body: '<g />',
|
|
|
|
width: 16,
|
|
|
|
height: 16,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const expected: IconifyJSON = {
|
|
|
|
prefix: 'foo',
|
|
|
|
icons: {
|
|
|
|
'foo-wide': {
|
|
|
|
body: '<g />',
|
|
|
|
width: 32,
|
|
|
|
},
|
|
|
|
'foo-square': {
|
|
|
|
body: '<g />',
|
|
|
|
},
|
|
|
|
'foo-tiny-wide': {
|
|
|
|
body: '<g />',
|
|
|
|
height: 16,
|
|
|
|
},
|
|
|
|
'foo-tiny-square': {
|
|
|
|
body: '<g />',
|
|
|
|
width: 16,
|
|
|
|
height: 16,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
width: 24,
|
|
|
|
height: 24,
|
|
|
|
};
|
|
|
|
minifyIconSet(item);
|
2021-09-20 20:53:49 +00:00
|
|
|
expect(item).toEqual(expected);
|
2021-05-24 10:25:02 +00:00
|
|
|
});
|
|
|
|
|
2021-09-20 20:53:49 +00:00
|
|
|
test('Common value that matches default', () => {
|
2021-05-24 10:25:02 +00:00
|
|
|
const item: IconifyJSON = {
|
|
|
|
prefix: 'foo',
|
|
|
|
icons: {
|
|
|
|
// 2 icons have the same height of 16, which is default value
|
|
|
|
'foo-wide': {
|
|
|
|
body: '<g />',
|
|
|
|
width: 24,
|
|
|
|
height: 16,
|
|
|
|
},
|
|
|
|
'foo-square': {
|
|
|
|
body: '<g />',
|
|
|
|
width: 16,
|
|
|
|
height: 16,
|
|
|
|
},
|
|
|
|
'foo-tiny': {
|
|
|
|
body: '<g />',
|
|
|
|
width: 12,
|
|
|
|
height: 16,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const expected: IconifyJSON = {
|
|
|
|
prefix: 'foo',
|
|
|
|
icons: {
|
|
|
|
'foo-wide': {
|
|
|
|
body: '<g />',
|
|
|
|
width: 24,
|
|
|
|
},
|
|
|
|
'foo-square': {
|
|
|
|
body: '<g />',
|
|
|
|
// Should not have width because it matches default value
|
|
|
|
},
|
|
|
|
'foo-tiny': {
|
|
|
|
body: '<g />',
|
|
|
|
width: 12,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
minifyIconSet(item);
|
2021-09-20 20:53:49 +00:00
|
|
|
expect(item).toEqual(expected);
|
2021-05-24 10:25:02 +00:00
|
|
|
});
|
|
|
|
});
|