2022-03-31 08:07:02 +00:00
|
|
|
import { quicklyValidateIconSet } from '../lib/icon-set/validate-basic';
|
|
|
|
|
|
|
|
describe('Testing validation', () => {
|
|
|
|
test('Not object', () => {
|
|
|
|
expect(quicklyValidateIconSet(void 0)).toBe(null);
|
|
|
|
expect(quicklyValidateIconSet({})).toBe(null);
|
|
|
|
expect(quicklyValidateIconSet(null)).toBe(null);
|
|
|
|
expect(quicklyValidateIconSet([])).toBe(null);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Valid sets', () => {
|
|
|
|
expect(
|
|
|
|
quicklyValidateIconSet({
|
|
|
|
prefix: 'foo',
|
|
|
|
icons: {
|
|
|
|
bar: {
|
|
|
|
body: '<g />',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
width: 24,
|
|
|
|
height: 24,
|
|
|
|
})
|
|
|
|
).toEqual({
|
|
|
|
prefix: 'foo',
|
|
|
|
icons: {
|
|
|
|
bar: {
|
|
|
|
body: '<g />',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
width: 24,
|
|
|
|
height: 24,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(
|
|
|
|
quicklyValidateIconSet({
|
2024-11-02 07:02:07 +00:00
|
|
|
// Characters that used to be invalid
|
|
|
|
prefix: 'fòó_bār',
|
2022-03-31 08:07:02 +00:00
|
|
|
icons: {
|
2024-11-02 07:02:07 +00:00
|
|
|
// Characters that used to be invalid
|
|
|
|
bär: {
|
2022-03-31 08:07:02 +00:00
|
|
|
body: '<g />',
|
|
|
|
width: 32,
|
|
|
|
height: 32,
|
|
|
|
rotate: 0,
|
|
|
|
hFlip: false,
|
|
|
|
vFlip: true,
|
|
|
|
// Legacy property
|
|
|
|
verticalAlign: -0.14,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
aliases: {
|
2024-11-02 07:02:07 +00:00
|
|
|
// Characters that used to be invalid
|
|
|
|
Bär_Bāz: {
|
|
|
|
parent: 'bär',
|
2022-03-31 08:07:02 +00:00
|
|
|
hFlip: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
width: 24,
|
|
|
|
height: 24,
|
|
|
|
})
|
|
|
|
).toEqual({
|
2024-11-02 07:02:07 +00:00
|
|
|
prefix: 'fòó_bār',
|
2022-03-31 08:07:02 +00:00
|
|
|
icons: {
|
2024-11-02 07:02:07 +00:00
|
|
|
bär: {
|
2022-03-31 08:07:02 +00:00
|
|
|
body: '<g />',
|
|
|
|
width: 32,
|
|
|
|
height: 32,
|
|
|
|
rotate: 0,
|
|
|
|
hFlip: false,
|
|
|
|
vFlip: true,
|
|
|
|
verticalAlign: -0.14,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
aliases: {
|
2024-11-02 07:02:07 +00:00
|
|
|
Bär_Bāz: {
|
|
|
|
parent: 'bär',
|
2022-03-31 08:07:02 +00:00
|
|
|
hFlip: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
width: 24,
|
|
|
|
height: 24,
|
|
|
|
});
|
|
|
|
|
|
|
|
// Empty is allowed
|
|
|
|
expect(
|
|
|
|
quicklyValidateIconSet({
|
|
|
|
prefix: 'foo',
|
|
|
|
icons: {},
|
|
|
|
})
|
|
|
|
).toEqual({
|
|
|
|
prefix: 'foo',
|
|
|
|
icons: {},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Missing required properties', () => {
|
|
|
|
expect(
|
|
|
|
quicklyValidateIconSet({
|
|
|
|
prefix: 'foo',
|
|
|
|
})
|
|
|
|
).toBe(null);
|
|
|
|
|
|
|
|
expect(
|
|
|
|
quicklyValidateIconSet({
|
|
|
|
icons: {},
|
|
|
|
})
|
|
|
|
).toBe(null);
|
|
|
|
});
|
|
|
|
|
2024-11-02 07:02:07 +00:00
|
|
|
test('Empty icon name', () => {
|
|
|
|
expect(
|
|
|
|
quicklyValidateIconSet({
|
|
|
|
prefix: 'foo',
|
|
|
|
icons: {
|
|
|
|
'': {
|
|
|
|
body: '<g />',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
).toBe(null);
|
|
|
|
});
|
|
|
|
|
2022-03-31 08:07:02 +00:00
|
|
|
test('Invalid optional properties', () => {
|
|
|
|
expect(
|
|
|
|
quicklyValidateIconSet({
|
|
|
|
prefix: 'foo',
|
|
|
|
icons: {
|
|
|
|
icon1: {
|
|
|
|
body: '<path d="icon1" />',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
height: 24,
|
|
|
|
// Object
|
2022-06-19 14:12:26 +00:00
|
|
|
width: {
|
2022-03-31 08:07:02 +00:00
|
|
|
foo: 1,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
).toBe(null);
|
|
|
|
|
|
|
|
expect(
|
|
|
|
quicklyValidateIconSet({
|
|
|
|
prefix: 'foo',
|
|
|
|
icons: {
|
|
|
|
icon1: {
|
|
|
|
body: '<path d="icon1" />',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
height: 24,
|
|
|
|
// Object
|
2022-06-19 14:12:26 +00:00
|
|
|
left: null,
|
2022-03-31 08:07:02 +00:00
|
|
|
})
|
|
|
|
).toBe(null);
|
|
|
|
|
|
|
|
expect(
|
|
|
|
quicklyValidateIconSet({
|
|
|
|
prefix: 'foo',
|
|
|
|
icons: {
|
|
|
|
icon1: {
|
|
|
|
body: '<path d="icon1" />',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
height: 24,
|
|
|
|
// String
|
|
|
|
width: '32',
|
|
|
|
})
|
|
|
|
).toBe(null);
|
|
|
|
});
|
|
|
|
});
|