mirror of
https://github.com/iconify/iconify.git
synced 2024-12-04 18:23:17 +00:00
chore(utils): test various functions with custom icon names
This commit is contained in:
parent
3ae86d5f0d
commit
7f27d10da6
@ -23,16 +23,16 @@ describe('Testing getting icon data', () => {
|
|||||||
test('Minified icon set', () => {
|
test('Minified icon set', () => {
|
||||||
const result = getIconData(
|
const result = getIconData(
|
||||||
{
|
{
|
||||||
prefix: 'foo',
|
prefix: 'test_set',
|
||||||
icons: {
|
icons: {
|
||||||
bar: {
|
test_icon: {
|
||||||
body: '<g />',
|
body: '<g />',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
width: 24,
|
width: 24,
|
||||||
height: 24,
|
height: 24,
|
||||||
},
|
},
|
||||||
'bar'
|
'test_icon'
|
||||||
);
|
);
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
body: '<g />',
|
body: '<g />',
|
||||||
@ -40,4 +40,32 @@ describe('Testing getting icon data', () => {
|
|||||||
height: 24,
|
height: 24,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Alias', () => {
|
||||||
|
const result = getIconData(
|
||||||
|
{
|
||||||
|
prefix: 'test_set',
|
||||||
|
icons: {
|
||||||
|
test_icon: {
|
||||||
|
body: '<g />',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
aliases: {
|
||||||
|
test_alias: {
|
||||||
|
parent: 'test_icon',
|
||||||
|
rotate: 2,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
width: 24,
|
||||||
|
height: 24,
|
||||||
|
},
|
||||||
|
'test_alias'
|
||||||
|
);
|
||||||
|
expect(result).toEqual({
|
||||||
|
body: '<g />',
|
||||||
|
width: 24,
|
||||||
|
height: 24,
|
||||||
|
rotate: 2,
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -70,7 +70,7 @@ describe('Testing retrieving icons from icon set', () => {
|
|||||||
bar: {
|
bar: {
|
||||||
body: '<g />',
|
body: '<g />',
|
||||||
},
|
},
|
||||||
bar2: {
|
bar_2: {
|
||||||
body: '<g />',
|
body: '<g />',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -79,7 +79,7 @@ describe('Testing retrieving icons from icon set', () => {
|
|||||||
parent: 'bar',
|
parent: 'bar',
|
||||||
hFlip: true,
|
hFlip: true,
|
||||||
},
|
},
|
||||||
'foo2': {
|
'foo_2': {
|
||||||
parent: 'foo',
|
parent: 'foo',
|
||||||
},
|
},
|
||||||
'missing-alias': {
|
'missing-alias': {
|
||||||
@ -87,10 +87,10 @@ describe('Testing retrieving icons from icon set', () => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
chars: {
|
chars: {
|
||||||
f00: 'bar2',
|
f00: 'bar_2',
|
||||||
f01: 'bar',
|
f01: 'bar',
|
||||||
f02: 'foo',
|
f02: 'foo',
|
||||||
f03: 'foo2',
|
f03: 'foo_2',
|
||||||
f04: 'missing-icon',
|
f04: 'missing-icon',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -113,7 +113,7 @@ describe('Testing retrieving icons from icon set', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Alias of alias
|
// Alias of alias
|
||||||
expect(getIcons(data, ['foo2'])).toEqual({
|
expect(getIcons(data, ['foo_2'])).toEqual({
|
||||||
prefix: 'foo',
|
prefix: 'foo',
|
||||||
lastModified,
|
lastModified,
|
||||||
icons: {
|
icons: {
|
||||||
@ -126,7 +126,7 @@ describe('Testing retrieving icons from icon set', () => {
|
|||||||
parent: 'bar',
|
parent: 'bar',
|
||||||
hFlip: true,
|
hFlip: true,
|
||||||
},
|
},
|
||||||
foo2: {
|
foo_2: {
|
||||||
parent: 'foo',
|
parent: 'foo',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -16,7 +16,7 @@ describe('Testing CSS for multiple icons', () => {
|
|||||||
'airplane': {
|
'airplane': {
|
||||||
body: '<path fill="currentColor" d="M6.428 1.151C6.708.591 7.213 0 8 0s1.292.592 1.572 1.151C9.861 1.73 10 2.431 10 3v3.691l5.17 2.585a1.5 1.5 0 0 1 .83 1.342V12a.5.5 0 0 1-.582.493l-5.507-.918l-.375 2.253l1.318 1.318A.5.5 0 0 1 10.5 16h-5a.5.5 0 0 1-.354-.854l1.319-1.318l-.376-2.253l-5.507.918A.5.5 0 0 1 0 12v-1.382a1.5 1.5 0 0 1 .83-1.342L6 6.691V3c0-.568.14-1.271.428-1.849Zm.894.448C7.111 2.02 7 2.569 7 3v4a.5.5 0 0 1-.276.447l-5.448 2.724a.5.5 0 0 0-.276.447v.792l5.418-.903a.5.5 0 0 1 .575.41l.5 3a.5.5 0 0 1-.14.437L6.708 15h2.586l-.647-.646a.5.5 0 0 1-.14-.436l.5-3a.5.5 0 0 1 .576-.411L15 11.41v-.792a.5.5 0 0 0-.276-.447L9.276 7.447A.5.5 0 0 1 9 7V3c0-.432-.11-.979-.322-1.401C8.458 1.159 8.213 1 8 1c-.213 0-.458.158-.678.599Z"/>',
|
body: '<path fill="currentColor" d="M6.428 1.151C6.708.591 7.213 0 8 0s1.292.592 1.572 1.151C9.861 1.73 10 2.431 10 3v3.691l5.17 2.585a1.5 1.5 0 0 1 .83 1.342V12a.5.5 0 0 1-.582.493l-5.507-.918l-.375 2.253l1.318 1.318A.5.5 0 0 1 10.5 16h-5a.5.5 0 0 1-.354-.854l1.319-1.318l-.376-2.253l-5.507.918A.5.5 0 0 1 0 12v-1.382a1.5 1.5 0 0 1 .83-1.342L6 6.691V3c0-.568.14-1.271.428-1.849Zm.894.448C7.111 2.02 7 2.569 7 3v4a.5.5 0 0 1-.276.447l-5.448 2.724a.5.5 0 0 0-.276.447v.792l5.418-.903a.5.5 0 0 1 .575.41l.5 3a.5.5 0 0 1-.14.437L6.708 15h2.586l-.647-.646a.5.5 0 0 1-.14-.436l.5-3a.5.5 0 0 1 .576-.411L15 11.41v-.792a.5.5 0 0 0-.276-.447L9.276 7.447A.5.5 0 0 1 9 7V3c0-.432-.11-.979-.322-1.401C8.458 1.159 8.213 1 8 1c-.213 0-.458.158-.678.599Z"/>',
|
||||||
},
|
},
|
||||||
'airplane-engines': {
|
'airplane_engines': {
|
||||||
body: '<path fill="currentColor" d="M8 0c-.787 0-1.292.592-1.572 1.151A4.347 4.347 0 0 0 6 3v3.691l-2 1V7.5a.5.5 0 0 0-.5-.5h-1a.5.5 0 0 0-.5.5v1.191l-1.17.585A1.5 1.5 0 0 0 0 10.618V12a.5.5 0 0 0 .582.493l1.631-.272l.313.937a.5.5 0 0 0 .948 0l.405-1.214l2.21-.369l.375 2.253l-1.318 1.318A.5.5 0 0 0 5.5 16h5a.5.5 0 0 0 .354-.854l-1.318-1.318l.375-2.253l2.21.369l.405 1.214a.5.5 0 0 0 .948 0l.313-.937l1.63.272A.5.5 0 0 0 16 12v-1.382a1.5 1.5 0 0 0-.83-1.342L14 8.691V7.5a.5.5 0 0 0-.5-.5h-1a.5.5 0 0 0-.5.5v.191l-2-1V3c0-.568-.14-1.271-.428-1.849C9.292.591 8.787 0 8 0ZM7 3c0-.432.11-.979.322-1.401C7.542 1.159 7.787 1 8 1c.213 0 .458.158.678.599C8.889 2.02 9 2.569 9 3v4a.5.5 0 0 0 .276.447l5.448 2.724a.5.5 0 0 1 .276.447v.792l-5.418-.903a.5.5 0 0 0-.575.41l-.5 3a.5.5 0 0 0 .14.437l.646.646H6.707l.647-.646a.5.5 0 0 0 .14-.436l-.5-3a.5.5 0 0 0-.576-.411L1 11.41v-.792a.5.5 0 0 1 .276-.447l5.448-2.724A.5.5 0 0 0 7 7V3Z"/>',
|
body: '<path fill="currentColor" d="M8 0c-.787 0-1.292.592-1.572 1.151A4.347 4.347 0 0 0 6 3v3.691l-2 1V7.5a.5.5 0 0 0-.5-.5h-1a.5.5 0 0 0-.5.5v1.191l-1.17.585A1.5 1.5 0 0 0 0 10.618V12a.5.5 0 0 0 .582.493l1.631-.272l.313.937a.5.5 0 0 0 .948 0l.405-1.214l2.21-.369l.375 2.253l-1.318 1.318A.5.5 0 0 0 5.5 16h5a.5.5 0 0 0 .354-.854l-1.318-1.318l.375-2.253l2.21.369l.405 1.214a.5.5 0 0 0 .948 0l.313-.937l1.63.272A.5.5 0 0 0 16 12v-1.382a1.5 1.5 0 0 0-.83-1.342L14 8.691V7.5a.5.5 0 0 0-.5-.5h-1a.5.5 0 0 0-.5.5v.191l-2-1V3c0-.568-.14-1.271-.428-1.849C9.292.591 8.787 0 8 0ZM7 3c0-.432.11-.979.322-1.401C7.542 1.159 7.787 1 8 1c.213 0 .458.158.678.599C8.889 2.02 9 2.569 9 3v4a.5.5 0 0 0 .276.447l5.448 2.724a.5.5 0 0 1 .276.447v.792l-5.418-.903a.5.5 0 0 0-.575.41l-.5 3a.5.5 0 0 0 .14.437l.646.646H6.707l.647-.646a.5.5 0 0 0 .14-.436l-.5-3a.5.5 0 0 0-.576-.411L1 11.41v-.792a.5.5 0 0 1 .276-.447l5.448-2.724A.5.5 0 0 0 7 7V3Z"/>',
|
||||||
},
|
},
|
||||||
'empty': {
|
'empty': {
|
||||||
@ -33,12 +33,16 @@ describe('Testing CSS for multiple icons', () => {
|
|||||||
|
|
||||||
// Detect mode: mask
|
// Detect mode: mask
|
||||||
expect(
|
expect(
|
||||||
getIconsCSS(iconSet, ['activity', '123', 'airplane', 'missing'], {
|
getIconsCSS(
|
||||||
format: 'expanded',
|
iconSet,
|
||||||
rules: {
|
['activity', '123', 'airplane_engines', 'missing'],
|
||||||
visibility: 'visible',
|
{
|
||||||
},
|
format: 'expanded',
|
||||||
})
|
rules: {
|
||||||
|
visibility: 'visible',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
).toBe(`.icon--test-prefix {
|
).toBe(`.icon--test-prefix {
|
||||||
visibility: visible;
|
visibility: visible;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
@ -61,8 +65,8 @@ describe('Testing CSS for multiple icons', () => {
|
|||||||
--svg: ${expectedURL('123')};
|
--svg: ${expectedURL('123')};
|
||||||
}
|
}
|
||||||
|
|
||||||
.icon--test-prefix--airplane {
|
.icon--test-prefix--airplane_engines {
|
||||||
--svg: ${expectedURL('airplane')};
|
--svg: ${expectedURL('airplane_engines')};
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Could not find icon: missing */
|
/* Could not find icon: missing */
|
||||||
|
@ -4,16 +4,16 @@ import { parseIconSet, parseIconSetAsync } from '../lib/icon-set/parse';
|
|||||||
describe('Testing parsing icon set', () => {
|
describe('Testing parsing icon set', () => {
|
||||||
test('Simple icon set', () => {
|
test('Simple icon set', () => {
|
||||||
// Names list
|
// Names list
|
||||||
const names: string[] = ['missing', 'icon1', 'icon2'];
|
const names: string[] = ['missing', 'icon_1', 'icon_2'];
|
||||||
|
|
||||||
// Resolved data
|
// Resolved data
|
||||||
const expected: Record<string, ExtendedIconifyIcon | null> = {
|
const expected: Record<string, ExtendedIconifyIcon | null> = {
|
||||||
icon1: {
|
icon_1: {
|
||||||
body: '<path d="icon1" />',
|
body: '<path d="icon1" />',
|
||||||
width: 20,
|
width: 20,
|
||||||
height: 24,
|
height: 24,
|
||||||
},
|
},
|
||||||
icon2: {
|
icon_2: {
|
||||||
body: '<path d="icon2" />',
|
body: '<path d="icon2" />',
|
||||||
width: 24,
|
width: 24,
|
||||||
height: 24,
|
height: 24,
|
||||||
@ -28,11 +28,11 @@ describe('Testing parsing icon set', () => {
|
|||||||
prefix: 'foo',
|
prefix: 'foo',
|
||||||
not_found: ['missing'],
|
not_found: ['missing'],
|
||||||
icons: {
|
icons: {
|
||||||
icon1: {
|
icon_1: {
|
||||||
body: '<path d="icon1" />',
|
body: '<path d="icon1" />',
|
||||||
width: 20,
|
width: 20,
|
||||||
},
|
},
|
||||||
icon2: {
|
icon_2: {
|
||||||
body: '<path d="icon2" />',
|
body: '<path d="icon2" />',
|
||||||
width: 24,
|
width: 24,
|
||||||
},
|
},
|
||||||
@ -48,7 +48,7 @@ describe('Testing parsing icon set', () => {
|
|||||||
expect(data).toEqual(expected[name]);
|
expect(data).toEqual(expected[name]);
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
).toEqual(['missing', 'icon1', 'icon2']);
|
).toEqual(['missing', 'icon_1', 'icon_2']);
|
||||||
|
|
||||||
// All names should have been parsed
|
// All names should have been parsed
|
||||||
expect(names).toEqual([]);
|
expect(names).toEqual([]);
|
||||||
|
@ -58,7 +58,9 @@ describe('Testing validating alias', () => {
|
|||||||
},
|
},
|
||||||
aliases: null,
|
aliases: null,
|
||||||
});
|
});
|
||||||
reject('Expected to throw error when aliases is null');
|
reject(
|
||||||
|
new Error('Expected to throw error when aliases is null')
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
} catch {
|
} catch {
|
||||||
//
|
//
|
||||||
@ -108,8 +110,10 @@ describe('Testing validating alias', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
reject(
|
reject(
|
||||||
'Expected to throw error when alias has missing parent, got ' +
|
new Error(
|
||||||
JSON.stringify(result)
|
'Expected to throw error when alias has missing parent, got ' +
|
||||||
|
JSON.stringify(result)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
} catch {
|
} catch {
|
||||||
@ -167,8 +171,10 @@ describe('Testing validating alias', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
reject(
|
reject(
|
||||||
'Expected to throw error when alias has missing parent, got ' +
|
new Error(
|
||||||
JSON.stringify(result)
|
'Expected to throw error when alias has missing parent, got ' +
|
||||||
|
JSON.stringify(result)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
} catch {
|
} catch {
|
||||||
@ -229,8 +235,10 @@ describe('Testing validating alias', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
reject(
|
reject(
|
||||||
'Expected to throw error when alias has missing parent, got ' +
|
new Error(
|
||||||
JSON.stringify(result)
|
'Expected to throw error when alias has missing parent, got ' +
|
||||||
|
JSON.stringify(result)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
} catch {
|
} catch {
|
||||||
@ -294,8 +302,10 @@ describe('Testing validating alias', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
reject(
|
reject(
|
||||||
'Expected to throw error when alias has missing parent, got ' +
|
new Error(
|
||||||
JSON.stringify(result)
|
'Expected to throw error when alias has missing parent, got ' +
|
||||||
|
JSON.stringify(result)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
} catch {
|
} catch {
|
||||||
|
Loading…
Reference in New Issue
Block a user