2
0
mirror of https://github.com/iconify/iconify.git synced 2024-11-09 23:00:56 +00:00

Fix broken test in utils

This commit is contained in:
Vjacheslav Trushkin 2022-07-01 22:01:49 +03:00
parent 54830793b0
commit d475c2e3a8

View File

@ -1,5 +1,5 @@
import type { IconifyIconName } from '../lib/icon/name';
import { stringToIcon, validateIcon } from '../lib/icon/name';
import { stringToIcon, validateIconName } from '../lib/icon/name';
describe('Testing icon name', () => {
test('Simple icon names', () => {
@ -12,7 +12,7 @@ describe('Testing icon name', () => {
prefix: 'fa',
name: 'home',
});
expect(validateIcon(icon)).toBe(true);
expect(validateIconName(icon)).toBe(true);
// Simple prefix:name
icon = stringToIcon('fa:arrow-left') as IconifyIconName;
@ -21,7 +21,7 @@ describe('Testing icon name', () => {
prefix: 'fa',
name: 'arrow-left',
});
expect(validateIcon(icon)).toBe(true);
expect(validateIconName(icon)).toBe(true);
// Longer prefix:name
icon = stringToIcon('mdi-light:home-outline') as IconifyIconName;
@ -30,12 +30,12 @@ describe('Testing icon name', () => {
prefix: 'mdi-light',
name: 'home-outline',
});
expect(validateIcon(icon)).toBe(true);
expect(validateIconName(icon)).toBe(true);
// Simple word without prefix
icon = stringToIcon('home');
expect(icon).toEqual(null);
expect(validateIcon(icon)).toBe(false);
expect(validateIconName(icon)).toBe(false);
// Same as above, but with empty names enabled
icon = stringToIcon('home', false, true);
@ -44,24 +44,24 @@ describe('Testing icon name', () => {
prefix: '',
name: 'home',
});
expect(validateIcon(icon)).toBe(false);
expect(validateIcon(icon, true)).toBe(true);
expect(validateIconName(icon)).toBe(false);
expect(validateIconName(icon, true)).toBe(true);
// Missing icon name
icon = stringToIcon('@iconify-home-icon');
expect(icon).toEqual(null);
expect(validateIcon(icon)).toBe(false);
expect(validateIconName(icon)).toBe(false);
// Same as above, but with empty names enabled
icon = stringToIcon('@iconify-home-icon', false, true);
expect(icon).toEqual(null);
expect(validateIcon(icon)).toBe(false);
expect(validateIcon(icon, true)).toBe(false);
expect(validateIconName(icon)).toBe(false);
expect(validateIconName(icon, true)).toBe(false);
// Underscore is not an acceptable separator
icon = stringToIcon('fa_home');
expect(icon).toEqual(null);
expect(validateIcon(icon)).toBe(false);
expect(validateIconName(icon)).toBe(false);
// Same as above, but with empty names enabled
icon = stringToIcon('fa_home', false, true);
@ -70,8 +70,8 @@ describe('Testing icon name', () => {
prefix: '',
name: 'fa_home',
});
expect(validateIcon(icon)).toBe(false);
expect(validateIcon(icon, true)).toBe(false);
expect(validateIconName(icon)).toBe(false);
expect(validateIconName(icon, true)).toBe(false);
// Invalid character '_': fail validateIcon
icon = stringToIcon('fa:home_outline') as IconifyIconName;
@ -80,12 +80,12 @@ describe('Testing icon name', () => {
prefix: 'fa',
name: 'home_outline',
});
expect(validateIcon(icon)).toBe(false);
expect(validateIconName(icon)).toBe(false);
// Too many colons: fail stringToIcon
icon = stringToIcon('mdi:light:home:outline');
expect(icon).toEqual(null);
expect(validateIcon(icon)).toBe(false);
expect(validateIconName(icon)).toBe(false);
// Upper case: fail validateIcon
icon = stringToIcon('MD:Home') as IconifyIconName;
@ -94,7 +94,7 @@ describe('Testing icon name', () => {
prefix: 'MD',
name: 'Home',
});
expect(validateIcon(icon)).toBe(false);
expect(validateIconName(icon)).toBe(false);
// Numbers: pass
icon = stringToIcon('1:foo') as IconifyIconName;
@ -103,7 +103,7 @@ describe('Testing icon name', () => {
prefix: '1',
name: 'foo',
});
expect(validateIcon(icon)).toBe(true);
expect(validateIconName(icon)).toBe(true);
// Accented letters: fail validateIcon
icon = stringToIcon('md-fõö') as IconifyIconName;
@ -112,7 +112,7 @@ describe('Testing icon name', () => {
prefix: 'md',
name: 'fõö',
});
expect(validateIcon(icon)).toBe(false);
expect(validateIconName(icon)).toBe(false);
});
it('Providers', () => {
@ -125,7 +125,7 @@ describe('Testing icon name', () => {
prefix: 'fa',
name: 'home',
});
expect(validateIcon(icon)).toBe(true);
expect(validateIconName(icon)).toBe(true);
// Simple @provider:prefix:name
icon = stringToIcon('@iconify:fa:arrow-left') as IconifyIconName;
@ -134,7 +134,7 @@ describe('Testing icon name', () => {
prefix: 'fa',
name: 'arrow-left',
});
expect(validateIcon(icon)).toBe(true);
expect(validateIconName(icon)).toBe(true);
// Longer @provider:prefix:name
icon = stringToIcon(
@ -145,7 +145,7 @@ describe('Testing icon name', () => {
prefix: 'mdi-light',
name: 'home-outline',
});
expect(validateIcon(icon)).toBe(true);
expect(validateIconName(icon)).toBe(true);
// Missing @ for provider
icon = stringToIcon(
@ -156,12 +156,12 @@ describe('Testing icon name', () => {
prefix: 'mdi-light',
name: 'home-outline',
});
expect(validateIcon(icon)).toBe(true);
expect(validateIconName(icon)).toBe(true);
// Too many colons: fail stringToIcon
icon = stringToIcon('@mdi:light:home:outline');
expect(icon).toEqual(null);
expect(validateIcon(icon)).toBe(false);
expect(validateIconName(icon)).toBe(false);
// Same as above, empty names allowed
icon = stringToIcon('@mdi:light:home:outline', false, true);
@ -174,6 +174,6 @@ describe('Testing icon name', () => {
prefix: 'home',
name: 'outline',
});
expect(validateIcon(icon)).toBe(false);
expect(validateIconName(icon)).toBe(false);
});
});