mirror of
https://github.com/iconify/iconify.git
synced 2025-01-26 08:38:30 +00:00
Support ES modules in core package, switch tests to Jest and Jasmine
This commit is contained in:
parent
cd4a1f70dd
commit
e6951fef7c
@ -3,7 +3,7 @@ module.exports = {
|
||||
browser: true,
|
||||
es6: true,
|
||||
node: true,
|
||||
mocha: true,
|
||||
jasmine: true,
|
||||
},
|
||||
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
|
||||
globals: {
|
||||
@ -11,12 +11,7 @@ module.exports = {
|
||||
SharedArrayBuffer: 'readonly',
|
||||
},
|
||||
parser: '@typescript-eslint/parser',
|
||||
parserOptions: {
|
||||
ecmaVersion: 2018,
|
||||
sourceType: 'module',
|
||||
project: __dirname + '/tsconfig-base.json',
|
||||
},
|
||||
plugins: ['@typescript-eslint'],
|
||||
plugins: ['@typescript-eslint', 'jasmine'],
|
||||
rules: {
|
||||
'no-mixed-spaces-and-tabs': ['off'],
|
||||
'no-unused-vars': ['off'],
|
||||
@ -24,7 +19,7 @@ module.exports = {
|
||||
},
|
||||
overrides: [
|
||||
{
|
||||
files: ['src/**/*.ts', 'tests/**/*.ts'],
|
||||
files: ['src/**/*.ts', 'tests/*.ts'],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
6
packages/core/.gitignore
vendored
6
packages/core/.gitignore
vendored
@ -1,6 +1,10 @@
|
||||
.idea
|
||||
.DS_Store
|
||||
*.map
|
||||
node_modules
|
||||
imports-test.mjs
|
||||
npm-debug.log
|
||||
yarn.lock
|
||||
tsconfig.tsbuildinfo
|
||||
tests-compiled
|
||||
lib
|
||||
tests-compiled
|
||||
|
@ -1,8 +1,13 @@
|
||||
.idea
|
||||
.vscode
|
||||
.DS_Store
|
||||
tsconfig.json
|
||||
*.map
|
||||
node_modules
|
||||
imports-test.mjs
|
||||
npm-debug.log
|
||||
yarn.lock
|
||||
tsconfig.tsbuildinfo
|
||||
src
|
||||
spec
|
||||
tests
|
||||
tests-compiled
|
||||
src
|
||||
|
7
packages/core/jest.config.js
Normal file
7
packages/core/jest.config.js
Normal file
@ -0,0 +1,7 @@
|
||||
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
|
||||
module.exports = {
|
||||
verbose: true,
|
||||
preset: 'ts-jest',
|
||||
testEnvironment: 'node',
|
||||
testMatch: ['**/tests/**/*-test.ts'],
|
||||
};
|
6758
packages/core/package-lock.json
generated
6758
packages/core/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -12,16 +12,16 @@
|
||||
"directory": "packages/core"
|
||||
},
|
||||
"scripts": {
|
||||
"clean": "rimraf lib tests-compiled",
|
||||
"lint": "eslint {src,tests}/**/*.ts",
|
||||
"clean": "rimraf lib tests-compiled tsconfig.tsbuildinfo",
|
||||
"lint": "eslint src/**/*.ts",
|
||||
"prebuild": "npm run lint && npm run clean",
|
||||
"build": "node build",
|
||||
"build:source": "tsc --project src/tsconfig.json",
|
||||
"build:tests": "tsc --project tests/tsconfig.json",
|
||||
"test": "mocha tests-compiled/*/*-test.js",
|
||||
"pretest": "npm run build && npm run build:tests"
|
||||
"test:jest": "jest --runInBand",
|
||||
"test:jasmine": "cross-env NODE_OPTIONS=--experimental-vm-modules npx jasmine",
|
||||
"test": "npm run test:jest && npm run test:jasmine"
|
||||
},
|
||||
"exports": {
|
||||
"./*": "./*",
|
||||
"./lib/api/callbacks": {
|
||||
"require": "./lib/api/callbacks.js",
|
||||
"import": "./lib/api/callbacks.mjs"
|
||||
@ -66,10 +66,6 @@
|
||||
"require": "./lib/browser-storage/functions.js",
|
||||
"import": "./lib/browser-storage/functions.mjs"
|
||||
},
|
||||
"./lib/browser-storage/": {
|
||||
"require": "./lib/browser-storage/index.js",
|
||||
"import": "./lib/browser-storage/index.mjs"
|
||||
},
|
||||
"./lib/browser-storage": {
|
||||
"require": "./lib/browser-storage/index.js",
|
||||
"import": "./lib/browser-storage/index.mjs"
|
||||
@ -104,22 +100,23 @@
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"@iconify/api-redundancy": "^1.0.0",
|
||||
"@iconify/types": "^1.0.6",
|
||||
"@iconify/utils": "^1.0.6",
|
||||
"@iconify/api-redundancy": "^1.0.1",
|
||||
"@iconify/types": "^1.0.7",
|
||||
"@iconify/utils": "^1.0.8",
|
||||
"cross-fetch": "^3.1.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@iconify/library-builder": "^1.0.2",
|
||||
"@types/chai": "^4.2.18",
|
||||
"@types/mocha": "^8.2.2",
|
||||
"@types/jest": "^27.0.2",
|
||||
"@types/node": "^15.3.0",
|
||||
"@types/request": "^2.48.5",
|
||||
"@typescript-eslint/eslint-plugin": "^4.31.1",
|
||||
"chai": "^4.3.4",
|
||||
"cross-env": "^7.0.3",
|
||||
"eslint": "^7.32.0",
|
||||
"mocha": "^8.3.2",
|
||||
"eslint-plugin-jasmine": "^4.1.2",
|
||||
"jasmine": "^3.9.0",
|
||||
"jest": "^27.2.1",
|
||||
"rimraf": "^3.0.2",
|
||||
"ts-jest": "^27.0.5",
|
||||
"typescript": "^4.4.3"
|
||||
}
|
||||
}
|
||||
|
537
packages/core/spec/api/callbacksSpec.mjs
Normal file
537
packages/core/spec/api/callbacksSpec.mjs
Normal file
@ -0,0 +1,537 @@
|
||||
import {
|
||||
callbacks,
|
||||
updateCallbacks,
|
||||
storeCallback,
|
||||
} from '@iconify/core/lib/api/callbacks';
|
||||
import { sortIcons } from '@iconify/core/lib/icon/sort';
|
||||
import { getStorage, addIconSet } from '@iconify/core/lib/storage/storage';
|
||||
|
||||
describe('Testing API callbacks', () => {
|
||||
let prefixCounter = 0;
|
||||
function nextPrefix() {
|
||||
prefixCounter++;
|
||||
return 'api-cb-test-' + (prefixCounter < 10 ? '0' : '') + prefixCounter;
|
||||
}
|
||||
|
||||
it('Simple callback', (done) => {
|
||||
const provider = 'iconify';
|
||||
const prefix = nextPrefix();
|
||||
let counter = 0;
|
||||
|
||||
const storage = getStorage(provider, prefix);
|
||||
const abort = storeCallback(
|
||||
(loaded, missing, pending, unsubscribe) => {
|
||||
expect(unsubscribe).toBe(abort);
|
||||
|
||||
counter++;
|
||||
switch (counter) {
|
||||
case 1:
|
||||
// First run - icon1 should be loaded, icon3 should be missing
|
||||
expect(loaded).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'icon1',
|
||||
},
|
||||
]);
|
||||
expect(missing).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'icon3',
|
||||
},
|
||||
]);
|
||||
expect(pending).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'icon2',
|
||||
},
|
||||
]);
|
||||
expect(callbacks[provider][prefix].length).toBe(1);
|
||||
|
||||
// Add icon2 and trigger update
|
||||
addIconSet(storage, {
|
||||
prefix: prefix,
|
||||
icons: {
|
||||
icon2: {
|
||||
body: '<g></g>',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
updateCallbacks(provider, prefix);
|
||||
return;
|
||||
|
||||
case 2:
|
||||
// Second run - icon2 should be added, completing callback
|
||||
expect(loaded).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'icon1',
|
||||
},
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'icon2',
|
||||
},
|
||||
]);
|
||||
expect(missing).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'icon3',
|
||||
},
|
||||
]);
|
||||
expect(pending).toEqual([]);
|
||||
expect(callbacks[provider][prefix].length).toBe(0);
|
||||
done();
|
||||
}
|
||||
},
|
||||
sortIcons([
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'icon1',
|
||||
},
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'icon2',
|
||||
},
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'icon3',
|
||||
},
|
||||
]),
|
||||
[
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
},
|
||||
]
|
||||
);
|
||||
|
||||
// Test callbacks
|
||||
expect(callbacks[provider][prefix].length).toBe(1);
|
||||
|
||||
// Test update - should do nothing
|
||||
updateCallbacks(provider, prefix);
|
||||
|
||||
// Wait for tick because updateCallbacks will use one
|
||||
setTimeout(() => {
|
||||
// Callback should not have been called yet
|
||||
expect(counter).toBe(0);
|
||||
|
||||
// Add few icons and run updateCallbacks
|
||||
addIconSet(storage, {
|
||||
prefix: prefix,
|
||||
icons: {
|
||||
icon1: {
|
||||
body: '<g></g>',
|
||||
},
|
||||
},
|
||||
not_found: ['icon3'],
|
||||
});
|
||||
updateCallbacks(provider, prefix);
|
||||
});
|
||||
});
|
||||
|
||||
it('Callback that should not be stored', () => {
|
||||
const provider = '';
|
||||
const prefix = nextPrefix();
|
||||
|
||||
const storage = getStorage(provider, prefix);
|
||||
addIconSet(storage, {
|
||||
prefix,
|
||||
icons: {
|
||||
icon1: {
|
||||
body: '<path d="" />',
|
||||
},
|
||||
icon2: {
|
||||
body: '<path d="" />',
|
||||
},
|
||||
},
|
||||
not_found: ['icon3'],
|
||||
});
|
||||
|
||||
storeCallback(
|
||||
() => {
|
||||
throw new Error('This code should not be executed!');
|
||||
},
|
||||
sortIcons([
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'icon1',
|
||||
},
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'icon2',
|
||||
},
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'icon3',
|
||||
},
|
||||
]),
|
||||
[
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
},
|
||||
]
|
||||
);
|
||||
|
||||
// callbacks should not have been initialised
|
||||
expect(callbacks[prefix]).toBeUndefined();
|
||||
});
|
||||
|
||||
it('Cancel callback', (done) => {
|
||||
const provider = 'foo';
|
||||
const prefix = nextPrefix();
|
||||
let counter = 0;
|
||||
|
||||
const storage = getStorage(provider, prefix);
|
||||
const abort = storeCallback(
|
||||
(loaded, missing, pending, unsubscribe) => {
|
||||
expect(unsubscribe).toBe(abort);
|
||||
|
||||
counter++;
|
||||
expect(counter).toBe(1);
|
||||
|
||||
// First run - icon1 should be loaded, icon3 should be missing
|
||||
expect(loaded).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'icon1',
|
||||
},
|
||||
]);
|
||||
expect(missing).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'icon3',
|
||||
},
|
||||
]);
|
||||
expect(pending).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'icon2',
|
||||
},
|
||||
]);
|
||||
expect(callbacks[provider][prefix].length).toBe(1);
|
||||
|
||||
// Add icon2 and trigger update
|
||||
addIconSet(storage, {
|
||||
prefix: prefix,
|
||||
icons: {
|
||||
icon2: {
|
||||
body: '<g></g>',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
updateCallbacks(provider, prefix);
|
||||
|
||||
// Unsubscribe and set timer to call done()
|
||||
unsubscribe();
|
||||
expect(callbacks[provider][prefix].length).toBe(0);
|
||||
setTimeout(done);
|
||||
},
|
||||
sortIcons([
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'icon1',
|
||||
},
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'icon2',
|
||||
},
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'icon3',
|
||||
},
|
||||
]),
|
||||
[
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
},
|
||||
]
|
||||
);
|
||||
|
||||
// Test callbacks
|
||||
expect(callbacks[provider][prefix].length).toBe(1);
|
||||
|
||||
// Test update - should do nothing
|
||||
updateCallbacks(provider, prefix);
|
||||
|
||||
// Wait for tick because updateCallbacks will use one
|
||||
setTimeout(() => {
|
||||
// Callback should not have been called yet
|
||||
expect(counter).toBe(0);
|
||||
|
||||
// Add few icons and run updateCallbacks
|
||||
addIconSet(storage, {
|
||||
prefix: prefix,
|
||||
icons: {
|
||||
icon1: {
|
||||
body: '<g></g>',
|
||||
},
|
||||
},
|
||||
not_found: ['icon3'],
|
||||
});
|
||||
updateCallbacks(provider, prefix);
|
||||
});
|
||||
});
|
||||
|
||||
it('Multiple prefixes', (done) => {
|
||||
const provider = '';
|
||||
const prefix1 = nextPrefix();
|
||||
const prefix2 = nextPrefix();
|
||||
let counter = 0;
|
||||
|
||||
const storage1 = getStorage(provider, prefix1);
|
||||
const storage2 = getStorage(provider, prefix2);
|
||||
|
||||
const abort = storeCallback(
|
||||
(loaded, missing, pending, unsubscribe) => {
|
||||
expect(unsubscribe).toBe(abort);
|
||||
|
||||
counter++;
|
||||
switch (counter) {
|
||||
case 1:
|
||||
// First run - icon1 should be loaded, icon3 should be missing
|
||||
expect(loaded).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix: prefix1,
|
||||
name: 'icon1',
|
||||
},
|
||||
]);
|
||||
expect(missing).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix: prefix1,
|
||||
name: 'icon3',
|
||||
},
|
||||
]);
|
||||
expect(pending).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix: prefix2,
|
||||
name: 'icon2',
|
||||
},
|
||||
]);
|
||||
expect(callbacks[provider][prefix1].length).toBe(0);
|
||||
expect(callbacks[provider][prefix2].length).toBe(1);
|
||||
|
||||
// Add icon2 and trigger update
|
||||
addIconSet(storage2, {
|
||||
prefix: prefix2,
|
||||
icons: {
|
||||
icon2: {
|
||||
body: '<g></g>',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
updateCallbacks(provider, prefix2);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
// Second run - icon2 should be loaded
|
||||
expect(callbacks[provider][prefix1].length).toBe(0);
|
||||
expect(callbacks[provider][prefix2].length).toBe(0);
|
||||
done();
|
||||
break;
|
||||
|
||||
default:
|
||||
done('Callback was called ' + counter + ' times.');
|
||||
}
|
||||
},
|
||||
sortIcons([
|
||||
{
|
||||
provider,
|
||||
prefix: prefix1,
|
||||
name: 'icon1',
|
||||
},
|
||||
{
|
||||
provider,
|
||||
prefix: prefix2,
|
||||
name: 'icon2',
|
||||
},
|
||||
{
|
||||
provider,
|
||||
prefix: prefix1,
|
||||
name: 'icon3',
|
||||
},
|
||||
]),
|
||||
[
|
||||
{ provider, prefix: prefix1 },
|
||||
{ provider, prefix: prefix2 },
|
||||
]
|
||||
);
|
||||
|
||||
// Test callbacks
|
||||
expect(callbacks[provider][prefix1].length).toBe(1);
|
||||
expect(callbacks[provider][prefix2].length).toBe(1);
|
||||
|
||||
// Test update - should do nothing
|
||||
updateCallbacks(provider, prefix1);
|
||||
|
||||
// Wait for tick because updateCallbacks will use one
|
||||
setTimeout(() => {
|
||||
// Callback should not have been called yet
|
||||
expect(counter).toBe(0);
|
||||
|
||||
// Add few icons and run updateCallbacks
|
||||
addIconSet(storage1, {
|
||||
prefix: prefix1,
|
||||
icons: {
|
||||
icon1: {
|
||||
body: '<g></g>',
|
||||
},
|
||||
},
|
||||
not_found: ['icon3'],
|
||||
});
|
||||
updateCallbacks(provider, prefix1);
|
||||
});
|
||||
});
|
||||
|
||||
it('Multiple providers', (done) => {
|
||||
const provider1 = nextPrefix();
|
||||
const provider2 = nextPrefix();
|
||||
const prefix1 = nextPrefix();
|
||||
const prefix2 = nextPrefix();
|
||||
let counter = 0;
|
||||
|
||||
const storage1 = getStorage(provider1, prefix1);
|
||||
const storage2 = getStorage(provider2, prefix2);
|
||||
|
||||
const abort = storeCallback(
|
||||
(loaded, missing, pending, unsubscribe) => {
|
||||
expect(unsubscribe).toBe(abort);
|
||||
|
||||
counter++;
|
||||
switch (counter) {
|
||||
case 1:
|
||||
// First run - icon1 should be loaded, icon3 should be missing
|
||||
expect(loaded).toEqual([
|
||||
{
|
||||
provider: provider1,
|
||||
prefix: prefix1,
|
||||
name: 'icon1',
|
||||
},
|
||||
]);
|
||||
expect(missing).toEqual([
|
||||
{
|
||||
provider: provider1,
|
||||
prefix: prefix1,
|
||||
name: 'icon3',
|
||||
},
|
||||
]);
|
||||
expect(pending).toEqual([
|
||||
{
|
||||
provider: provider2,
|
||||
prefix: prefix2,
|
||||
name: 'icon2',
|
||||
},
|
||||
]);
|
||||
expect(callbacks[provider1][prefix1].length).toBe(0);
|
||||
expect(callbacks[provider2][prefix2].length).toBe(1);
|
||||
|
||||
// Make sure providers/prefixes aren't mixed
|
||||
expect(callbacks[provider1][prefix2]).toBeUndefined();
|
||||
expect(callbacks[provider2][prefix1]).toBeUndefined();
|
||||
|
||||
// Add icon2 and trigger update
|
||||
addIconSet(storage2, {
|
||||
prefix: prefix2,
|
||||
icons: {
|
||||
icon2: {
|
||||
body: '<g></g>',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
updateCallbacks(provider2, prefix2);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
// Second run - icon2 should be loaded
|
||||
expect(callbacks[provider1][prefix1].length).toBe(0);
|
||||
expect(callbacks[provider2][prefix2].length).toBe(0);
|
||||
|
||||
// Make sure providers/prefixes aren't mixed
|
||||
expect(callbacks[provider1][prefix2]).toBeUndefined();
|
||||
expect(callbacks[provider2][prefix1]).toBeUndefined();
|
||||
|
||||
done();
|
||||
break;
|
||||
|
||||
default:
|
||||
done('Callback was called ' + counter + ' times.');
|
||||
}
|
||||
},
|
||||
sortIcons([
|
||||
{
|
||||
provider: provider1,
|
||||
prefix: prefix1,
|
||||
name: 'icon1',
|
||||
},
|
||||
{
|
||||
provider: provider2,
|
||||
prefix: prefix2,
|
||||
name: 'icon2',
|
||||
},
|
||||
{
|
||||
provider: provider1,
|
||||
prefix: prefix1,
|
||||
name: 'icon3',
|
||||
},
|
||||
]),
|
||||
[
|
||||
{ provider: provider1, prefix: prefix1 },
|
||||
{ provider: provider2, prefix: prefix2 },
|
||||
]
|
||||
);
|
||||
|
||||
// Test callbacks
|
||||
expect(callbacks[provider1][prefix1].length).toBe(1);
|
||||
expect(callbacks[provider2][prefix2].length).toBe(1);
|
||||
|
||||
expect(callbacks[provider1][prefix2]).toBeUndefined();
|
||||
expect(callbacks[provider2][prefix1]).toBeUndefined();
|
||||
|
||||
// Test update - should do nothing
|
||||
updateCallbacks(provider1, prefix1);
|
||||
|
||||
// Wait for tick because updateCallbacks will use one
|
||||
setTimeout(() => {
|
||||
// Callback should not have been called yet
|
||||
expect(counter).toBe(0);
|
||||
|
||||
// Add few icons and run updateCallbacks
|
||||
addIconSet(storage1, {
|
||||
prefix: prefix1,
|
||||
icons: {
|
||||
icon1: {
|
||||
body: '<g></g>',
|
||||
},
|
||||
},
|
||||
not_found: ['icon3'],
|
||||
});
|
||||
updateCallbacks(provider1, prefix1);
|
||||
});
|
||||
});
|
||||
});
|
82
packages/core/spec/api/fetchSpec.mjs
Normal file
82
packages/core/spec/api/fetchSpec.mjs
Normal file
@ -0,0 +1,82 @@
|
||||
import crossFetch from 'cross-fetch';
|
||||
import { sendAPIQuery } from '@iconify/core/lib/api/query';
|
||||
import { setAPIModule } from '@iconify/core/lib/api/modules';
|
||||
import { fetchAPIModule, setFetch } from '@iconify/core/lib/api/modules/fetch';
|
||||
import { setAPIConfig } from '@iconify/core/lib/api/config';
|
||||
import { mockAPIModule } from '@iconify/core/lib/api/modules/mock';
|
||||
|
||||
describe('Testing live API with fetch', () => {
|
||||
let counter = 0;
|
||||
function nextProvider() {
|
||||
return 'fetch-' + counter++;
|
||||
}
|
||||
|
||||
const host = 'https://api.iconify.design';
|
||||
|
||||
// Set fetch module
|
||||
beforeEach(() => {
|
||||
setFetch(crossFetch);
|
||||
setAPIModule('', fetchAPIModule);
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
setAPIModule('', mockAPIModule);
|
||||
});
|
||||
|
||||
it('Missing API configuration', (done) => {
|
||||
const provider = nextProvider();
|
||||
sendAPIQuery(
|
||||
provider,
|
||||
{
|
||||
type: 'custom',
|
||||
provider,
|
||||
uri: '/collections',
|
||||
},
|
||||
(data, error) => {
|
||||
expect(error).toBe(424);
|
||||
expect(data).toBeUndefined();
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('Custom request with provider', (done) => {
|
||||
const provider = nextProvider();
|
||||
expect(
|
||||
setAPIConfig(provider, {
|
||||
resources: [host],
|
||||
})
|
||||
).toBe(true);
|
||||
|
||||
sendAPIQuery(
|
||||
provider,
|
||||
{
|
||||
type: 'custom',
|
||||
provider,
|
||||
uri: '/collections',
|
||||
},
|
||||
(data, error) => {
|
||||
expect(error).toBeUndefined();
|
||||
expect(typeof data).toBe('object');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('Custom request with host', (done) => {
|
||||
sendAPIQuery(
|
||||
{
|
||||
resources: [host],
|
||||
},
|
||||
{
|
||||
type: 'custom',
|
||||
uri: '/collections',
|
||||
},
|
||||
(data, error) => {
|
||||
expect(error).toBeUndefined();
|
||||
expect(typeof data).toBe('object');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
651
packages/core/spec/api/loadingSpec.mjs
Normal file
651
packages/core/spec/api/loadingSpec.mjs
Normal file
@ -0,0 +1,651 @@
|
||||
import { setAPIConfig } from '@iconify/core/lib/api/config';
|
||||
import { setAPIModule } from '@iconify/core/lib/api/modules';
|
||||
import { loadIcons, isPending } from '@iconify/core/lib/api/icons';
|
||||
|
||||
describe('Testing API loadIcons', () => {
|
||||
let prefixCounter = 0;
|
||||
function nextPrefix() {
|
||||
prefixCounter++;
|
||||
return (
|
||||
'api-load-test-' + (prefixCounter < 10 ? '0' : '') + prefixCounter
|
||||
);
|
||||
}
|
||||
|
||||
it('Loading few icons', (done) => {
|
||||
const provider = nextPrefix();
|
||||
const prefix = nextPrefix();
|
||||
let asyncCounter = 0;
|
||||
|
||||
// Set config
|
||||
setAPIConfig(provider, {
|
||||
resources: ['https://api1.local', 'https://api2.local'],
|
||||
});
|
||||
|
||||
// Icon loader
|
||||
const prepareQuery = (provider, prefix, icons) => {
|
||||
const item = {
|
||||
type: 'icons',
|
||||
provider,
|
||||
prefix,
|
||||
icons,
|
||||
};
|
||||
|
||||
// This callback should be called first
|
||||
expect(asyncCounter).toBe(1);
|
||||
asyncCounter++;
|
||||
|
||||
// Test input and return as one item
|
||||
const expected = {
|
||||
type: 'icons',
|
||||
provider,
|
||||
prefix,
|
||||
icons: ['icon1', 'icon2'],
|
||||
};
|
||||
expect(item).toEqual(expected);
|
||||
|
||||
return [item];
|
||||
};
|
||||
|
||||
const sendQuery = (host, params, item) => {
|
||||
// This callback should be called after prepareQuery
|
||||
expect(asyncCounter).toBe(2);
|
||||
asyncCounter++;
|
||||
|
||||
expect(params.type).toBe('icons');
|
||||
|
||||
// Test input
|
||||
expect(host).toBe('https://api1.local');
|
||||
const expected = {
|
||||
type: 'icons',
|
||||
provider,
|
||||
prefix,
|
||||
icons: ['icon1', 'icon2'],
|
||||
};
|
||||
expect(params).toEqual(expected);
|
||||
|
||||
// Send data
|
||||
item.done({
|
||||
prefix,
|
||||
icons: {
|
||||
icon1: {
|
||||
body: '<path d="" />',
|
||||
},
|
||||
icon2: {
|
||||
body: '<path d="" />',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// Counter should not have increased after status.done() call becuse parsing result should be done on next tick
|
||||
expect(asyncCounter).toBe(3);
|
||||
};
|
||||
|
||||
setAPIModule(provider, {
|
||||
prepare: prepareQuery,
|
||||
send: sendQuery,
|
||||
});
|
||||
|
||||
// Load icons
|
||||
loadIcons(
|
||||
[
|
||||
// as icon
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'icon1',
|
||||
},
|
||||
// as string
|
||||
provider + ':' + prefix + ':icon2',
|
||||
],
|
||||
(loaded, missing, pending) => {
|
||||
// This callback should be called last
|
||||
expect(asyncCounter).toBe(3);
|
||||
asyncCounter++;
|
||||
|
||||
expect(loaded).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'icon1',
|
||||
},
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'icon2',
|
||||
},
|
||||
]);
|
||||
expect(missing).toEqual([]);
|
||||
expect(pending).toEqual([]);
|
||||
|
||||
expect(
|
||||
isPending({
|
||||
provider,
|
||||
prefix,
|
||||
name: 'icon1',
|
||||
})
|
||||
).toBe(false);
|
||||
expect(isPending({ provider, prefix, name: 'icon3' })).toBe(
|
||||
false
|
||||
);
|
||||
|
||||
done();
|
||||
}
|
||||
);
|
||||
|
||||
// Test isPending
|
||||
expect(isPending({ provider, prefix, name: 'icon1' })).toBe(true);
|
||||
expect(isPending({ provider, prefix, name: 'icon3' })).toBe(false);
|
||||
|
||||
// Make sure asyncCounter wasn't increased because loading shoud happen on next tick
|
||||
expect(asyncCounter).toBe(0);
|
||||
asyncCounter++;
|
||||
});
|
||||
|
||||
it('Split results', (done) => {
|
||||
const provider = nextPrefix();
|
||||
const prefix = nextPrefix();
|
||||
|
||||
// Set config
|
||||
setAPIConfig(provider, {
|
||||
resources: ['https://api1.local', 'https://api2.local'],
|
||||
});
|
||||
|
||||
// Icon loader
|
||||
const prepareQuery = (provider, prefix, icons) => {
|
||||
// Split all icons in multiple queries, one icon per query
|
||||
const results = [];
|
||||
icons.forEach((icon) => {
|
||||
const item = {
|
||||
type: 'icons',
|
||||
provider,
|
||||
prefix,
|
||||
icons: [icon],
|
||||
};
|
||||
results.push(item);
|
||||
});
|
||||
|
||||
expect(results.length).toBe(2);
|
||||
|
||||
return results;
|
||||
};
|
||||
|
||||
let queryCounter = 0;
|
||||
const sendQuery = (host, params, item) => {
|
||||
// Test input
|
||||
expect(host).toBe('https://api1.local');
|
||||
|
||||
expect(params.type).toBe('icons');
|
||||
if (params.type !== 'icons') {
|
||||
return;
|
||||
}
|
||||
|
||||
// Icon names should match queryCounter: 'icon1' on first run, 'icon2' on second run
|
||||
queryCounter++;
|
||||
const expected = {
|
||||
type: 'icons',
|
||||
provider,
|
||||
prefix,
|
||||
icons: ['icon' + queryCounter],
|
||||
};
|
||||
expect(params).toEqual(expected);
|
||||
|
||||
// Send only requested icons
|
||||
const icons = Object.create(null);
|
||||
params.icons.forEach((icon) => {
|
||||
icons[icon] = {
|
||||
body: '<path d="" />',
|
||||
};
|
||||
});
|
||||
item.done({
|
||||
prefix,
|
||||
icons,
|
||||
// Test mismatched provider: should be ignored because provider name is not affected by actual API response
|
||||
provider: nextPrefix(),
|
||||
});
|
||||
};
|
||||
|
||||
setAPIModule(provider, {
|
||||
prepare: prepareQuery,
|
||||
send: sendQuery,
|
||||
});
|
||||
|
||||
// Load icons
|
||||
let callbackCalled = false;
|
||||
loadIcons(
|
||||
[
|
||||
provider + ':' + prefix + ':icon1',
|
||||
provider + ':' + prefix + ':icon2',
|
||||
],
|
||||
(loaded, missing, pending) => {
|
||||
// Callback should be called only once because results should be sent in same tick
|
||||
expect(callbackCalled).toBe(false);
|
||||
callbackCalled = true;
|
||||
|
||||
// Test data
|
||||
expect(loaded).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'icon1',
|
||||
},
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'icon2',
|
||||
},
|
||||
]);
|
||||
expect(missing).toEqual([]);
|
||||
expect(pending).toEqual([]);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('Fail on default host', (done) => {
|
||||
const provider = nextPrefix();
|
||||
const prefix = nextPrefix();
|
||||
|
||||
// Set config
|
||||
setAPIConfig(provider, {
|
||||
resources: ['https://api1.local', 'https://api2.local'],
|
||||
rotate: 100, // 100ms to speed up test
|
||||
});
|
||||
|
||||
// Icon loader
|
||||
const prepareQuery = (provider, prefix, icons) => {
|
||||
const item = {
|
||||
type: 'icons',
|
||||
provider,
|
||||
prefix,
|
||||
icons,
|
||||
};
|
||||
return [item];
|
||||
};
|
||||
|
||||
let queryCounter = 0;
|
||||
const sendQuery = (host, params, item) => {
|
||||
queryCounter++;
|
||||
params;
|
||||
switch (queryCounter) {
|
||||
case 1:
|
||||
// First call on api1
|
||||
expect(host).toBe('https://api1.local');
|
||||
|
||||
// Do nothing - fake failed response
|
||||
break;
|
||||
|
||||
case 2:
|
||||
// First call on api2
|
||||
expect(host).toBe('https://api2.local');
|
||||
|
||||
// Return result
|
||||
item.done({
|
||||
prefix,
|
||||
icons: {
|
||||
icon1: {
|
||||
body: '<path d="" />',
|
||||
},
|
||||
icon2: {
|
||||
body: '<path d="" />',
|
||||
},
|
||||
},
|
||||
});
|
||||
break;
|
||||
|
||||
default:
|
||||
done(
|
||||
`Unexpected additional call to sendQuery for host ${host}.`
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
setAPIModule(provider, {
|
||||
prepare: prepareQuery,
|
||||
send: sendQuery,
|
||||
});
|
||||
|
||||
// Load icons
|
||||
let callbackCalled = false;
|
||||
loadIcons(
|
||||
[
|
||||
provider + ':' + prefix + ':icon1',
|
||||
provider + ':' + prefix + ':icon2',
|
||||
],
|
||||
(loaded, missing, pending) => {
|
||||
// Callback should be called only once
|
||||
expect(callbackCalled).toBe(false);
|
||||
callbackCalled = true;
|
||||
|
||||
// Test data
|
||||
expect(loaded).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'icon1',
|
||||
},
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'icon2',
|
||||
},
|
||||
]);
|
||||
expect(missing).toEqual([]);
|
||||
expect(pending).toEqual([]);
|
||||
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('Fail on default host, multiple queries', (done) => {
|
||||
const provider = nextPrefix();
|
||||
const prefix = nextPrefix();
|
||||
|
||||
// Set config
|
||||
setAPIConfig(provider, {
|
||||
resources: ['https://api1.local', 'https://api2.local'],
|
||||
rotate: 100, // 100ms to speed up test
|
||||
});
|
||||
|
||||
// Icon loader
|
||||
const prepareQuery = (provider, prefix, icons) => {
|
||||
const item = {
|
||||
type: 'icons',
|
||||
provider,
|
||||
prefix,
|
||||
icons,
|
||||
};
|
||||
return [item];
|
||||
};
|
||||
|
||||
let queryCounter = 0;
|
||||
const sendQuery = (host, params, item) => {
|
||||
queryCounter++;
|
||||
|
||||
expect(params.type).toBe('icons');
|
||||
if (params.type !== 'icons') {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (queryCounter) {
|
||||
case 1:
|
||||
// First call on api1
|
||||
expect(params.icons).toEqual(['icon1', 'icon2']);
|
||||
expect(host).toBe('https://api1.local');
|
||||
|
||||
// Do nothing - fake failed response
|
||||
break;
|
||||
|
||||
case 2:
|
||||
// First call on api2
|
||||
expect(params.icons).toEqual(['icon1', 'icon2']);
|
||||
expect(host).toBe('https://api2.local');
|
||||
|
||||
// Return result
|
||||
item.done({
|
||||
prefix,
|
||||
icons: {
|
||||
icon1: {
|
||||
body: '<path d="" />',
|
||||
},
|
||||
icon2: {
|
||||
body: '<path d="" />',
|
||||
},
|
||||
},
|
||||
});
|
||||
break;
|
||||
|
||||
case 3:
|
||||
// Second call, should have api2 as default
|
||||
expect(params.icons).toEqual(['icon3', 'icon4']);
|
||||
expect(host).toBe('https://api2.local');
|
||||
|
||||
// Return result
|
||||
item.done({
|
||||
prefix,
|
||||
icons: {
|
||||
icon3: {
|
||||
body: '<path d="" />',
|
||||
},
|
||||
icon4: {
|
||||
body: '<path d="" />',
|
||||
},
|
||||
},
|
||||
});
|
||||
break;
|
||||
|
||||
default:
|
||||
done(
|
||||
`Unexpected additional call to sendQuery for host ${host}.`
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
setAPIModule(provider, {
|
||||
prepare: prepareQuery,
|
||||
send: sendQuery,
|
||||
});
|
||||
|
||||
// Load icons
|
||||
let callbackCalled = false;
|
||||
loadIcons(
|
||||
[
|
||||
provider + ':' + prefix + ':icon1',
|
||||
provider + ':' + prefix + ':icon2',
|
||||
],
|
||||
(loaded, missing, pending) => {
|
||||
// Callback should be called only once
|
||||
expect(callbackCalled).toBe(false);
|
||||
callbackCalled = true;
|
||||
|
||||
// Test data
|
||||
expect(loaded).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'icon1',
|
||||
},
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'icon2',
|
||||
},
|
||||
]);
|
||||
expect(missing).toEqual([]);
|
||||
expect(pending).toEqual([]);
|
||||
|
||||
// Send another query on next tick
|
||||
setTimeout(() => {
|
||||
let callbackCalled = false;
|
||||
loadIcons(
|
||||
[
|
||||
provider + ':' + prefix + ':icon3',
|
||||
provider + ':' + prefix + ':icon4',
|
||||
],
|
||||
(loaded, missing, pending) => {
|
||||
// Callback should be called only once
|
||||
expect(callbackCalled).toBe(false);
|
||||
callbackCalled = true;
|
||||
|
||||
// Test data
|
||||
expect(loaded).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'icon3',
|
||||
},
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'icon4',
|
||||
},
|
||||
]);
|
||||
expect(missing).toEqual([]);
|
||||
expect(pending).toEqual([]);
|
||||
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('Fail on default host, multiple queries with different prefixes', (done) => {
|
||||
const provider = nextPrefix();
|
||||
const prefix = nextPrefix();
|
||||
const prefix2 = nextPrefix();
|
||||
|
||||
// Set config
|
||||
setAPIConfig(provider, {
|
||||
resources: ['https://api1.local', 'https://api2.local'],
|
||||
rotate: 100, // 100ms to speed up test
|
||||
});
|
||||
|
||||
// Icon loader
|
||||
const prepareQuery = (provider, prefix, icons) => {
|
||||
const item = {
|
||||
type: 'icons',
|
||||
provider,
|
||||
prefix,
|
||||
icons,
|
||||
};
|
||||
return [item];
|
||||
};
|
||||
|
||||
let queryCounter = 0;
|
||||
const sendQuery = (host, params, item) => {
|
||||
queryCounter++;
|
||||
|
||||
expect(params.type).toBe('icons');
|
||||
if (params.type !== 'icons') {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (queryCounter) {
|
||||
case 1:
|
||||
// First call on api1
|
||||
expect(params.prefix).toBe(prefix);
|
||||
expect(params.icons).toEqual(['icon1', 'icon2']);
|
||||
expect(host).toBe('https://api1.local');
|
||||
|
||||
// Do nothing - fake failed response
|
||||
break;
|
||||
|
||||
case 2:
|
||||
// First call on api2
|
||||
expect(params.prefix).toBe(prefix);
|
||||
expect(params.icons).toEqual(['icon1', 'icon2']);
|
||||
expect(host).toBe('https://api2.local');
|
||||
|
||||
// Return result
|
||||
item.done({
|
||||
prefix: params.prefix,
|
||||
icons: {
|
||||
icon1: {
|
||||
body: '<path d="" />',
|
||||
},
|
||||
icon2: {
|
||||
body: '<path d="" />',
|
||||
},
|
||||
},
|
||||
});
|
||||
break;
|
||||
|
||||
case 3:
|
||||
// Second call, should have api2 as default
|
||||
expect(params.prefix).toBe(prefix2);
|
||||
expect(params.icons).toEqual(['icon2', 'icon4']);
|
||||
expect(host).toBe('https://api2.local');
|
||||
|
||||
// Return result
|
||||
item.done({
|
||||
prefix: params.prefix,
|
||||
icons: {
|
||||
icon2: {
|
||||
body: '<path d="" />',
|
||||
},
|
||||
icon4: {
|
||||
body: '<path d="" />',
|
||||
},
|
||||
},
|
||||
});
|
||||
break;
|
||||
|
||||
default:
|
||||
done(
|
||||
`Unexpected additional call to sendQuery for host ${host}.`
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
setAPIModule(provider, {
|
||||
prepare: prepareQuery,
|
||||
send: sendQuery,
|
||||
});
|
||||
|
||||
// Load icons
|
||||
let callbackCalled = false;
|
||||
loadIcons(
|
||||
[
|
||||
provider + ':' + prefix + ':icon1',
|
||||
provider + ':' + prefix + ':icon2',
|
||||
],
|
||||
(loaded, missing, pending) => {
|
||||
// Callback should be called only once
|
||||
expect(callbackCalled).toBe(false);
|
||||
callbackCalled = true;
|
||||
|
||||
// Test data
|
||||
expect(loaded).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'icon1',
|
||||
},
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'icon2',
|
||||
},
|
||||
]);
|
||||
expect(missing).toEqual([]);
|
||||
expect(pending).toEqual([]);
|
||||
|
||||
// Send another query on next tick for different prefix that shares configuration
|
||||
setTimeout(() => {
|
||||
let callbackCalled = false;
|
||||
loadIcons(
|
||||
[
|
||||
provider + ':' + prefix2 + ':icon2',
|
||||
provider + ':' + prefix2 + ':icon4',
|
||||
],
|
||||
(loaded, missing, pending) => {
|
||||
// Callback should be called only once
|
||||
expect(callbackCalled).toBe(false);
|
||||
callbackCalled = true;
|
||||
|
||||
// Test data
|
||||
expect(loaded).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix: prefix2,
|
||||
name: 'icon2',
|
||||
},
|
||||
{
|
||||
provider,
|
||||
prefix: prefix2,
|
||||
name: 'icon4',
|
||||
},
|
||||
]);
|
||||
expect(missing).toEqual([]);
|
||||
expect(pending).toEqual([]);
|
||||
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
32
packages/core/spec/api/mergeParamsSpec.mjs
Normal file
32
packages/core/spec/api/mergeParamsSpec.mjs
Normal file
@ -0,0 +1,32 @@
|
||||
import { mergeParams } from '@iconify/core/lib/api/params';
|
||||
|
||||
describe('Testing mergeParams', () => {
|
||||
it('mergeParams()', () => {
|
||||
// Nothing
|
||||
expect(mergeParams('/foo', {})).toBe('/foo');
|
||||
|
||||
// Simple variables
|
||||
expect(
|
||||
mergeParams('/foo', {
|
||||
foo: 1,
|
||||
bar: 'baz',
|
||||
baz: true,
|
||||
})
|
||||
).toBe('/foo?foo=1&bar=baz&baz=true');
|
||||
|
||||
// More parameters to existing query
|
||||
expect(
|
||||
mergeParams('/foo?bar=baz', {
|
||||
foo: false,
|
||||
})
|
||||
).toBe('/foo?bar=baz&foo=false');
|
||||
|
||||
// Escaping characters
|
||||
expect(
|
||||
mergeParams('/foo', {
|
||||
'2&2': '1=1',
|
||||
'3 z': '?3',
|
||||
})
|
||||
).toBe('/foo?2%262=1%3D1&3%20z=%3F3');
|
||||
});
|
||||
});
|
165
packages/core/spec/api/mockPrepareSpec.mjs
Normal file
165
packages/core/spec/api/mockPrepareSpec.mjs
Normal file
@ -0,0 +1,165 @@
|
||||
import {
|
||||
mockAPIModule,
|
||||
mockAPIData,
|
||||
iconsStorage,
|
||||
} from '@iconify/core/lib/api/modules/mock';
|
||||
|
||||
describe('Testing mock API module prepare function', () => {
|
||||
let prefixCounter = 0;
|
||||
function nextPrefix() {
|
||||
prefixCounter++;
|
||||
return (
|
||||
'api-mock-prepare-' +
|
||||
(prefixCounter < 10 ? '0' : '') +
|
||||
prefixCounter
|
||||
);
|
||||
}
|
||||
|
||||
const prepare = mockAPIModule.prepare;
|
||||
|
||||
it('Setting data for all icons', () => {
|
||||
const provider = nextPrefix();
|
||||
const prefix = nextPrefix();
|
||||
|
||||
const item = {
|
||||
type: 'icons',
|
||||
provider,
|
||||
prefix,
|
||||
response: 404,
|
||||
};
|
||||
mockAPIData(item);
|
||||
|
||||
// Make sure item is stored correctly
|
||||
expect(typeof iconsStorage[provider]).toBe('object');
|
||||
expect(iconsStorage[provider][prefix]).toEqual([item]);
|
||||
|
||||
// Find item for icons
|
||||
const result = prepare(provider, prefix, ['foo', 'bar', 'baz']);
|
||||
expect(result).toEqual([
|
||||
{
|
||||
type: 'icons',
|
||||
provider,
|
||||
prefix,
|
||||
icons: ['foo', 'bar', 'baz'],
|
||||
index: 0,
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('Setting multiple entries', () => {
|
||||
const provider = nextPrefix();
|
||||
const prefix = nextPrefix();
|
||||
|
||||
const item1 = {
|
||||
type: 'icons',
|
||||
provider,
|
||||
prefix,
|
||||
response: 404,
|
||||
icons: ['foo', 'bar'],
|
||||
};
|
||||
const item2 = {
|
||||
type: 'icons',
|
||||
provider,
|
||||
prefix,
|
||||
response: 404,
|
||||
icons: 'baz',
|
||||
};
|
||||
const item3 = {
|
||||
type: 'icons',
|
||||
provider,
|
||||
prefix,
|
||||
response: {
|
||||
prefix,
|
||||
icons: {
|
||||
test10: {
|
||||
body: '<g />',
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
mockAPIData(item1);
|
||||
mockAPIData(item2);
|
||||
mockAPIData(item3);
|
||||
|
||||
// Make sure item is stored correctly
|
||||
expect(typeof iconsStorage[provider]).toBe('object');
|
||||
expect(iconsStorage[provider][prefix]).toEqual([item1, item2, item3]);
|
||||
|
||||
// Find items for icons
|
||||
const result = prepare(provider, prefix, [
|
||||
'foo',
|
||||
'baz',
|
||||
'bar',
|
||||
'test1',
|
||||
'test10',
|
||||
'test2',
|
||||
]);
|
||||
expect(result).toEqual([
|
||||
// Unknown icons first
|
||||
{
|
||||
type: 'icons',
|
||||
provider,
|
||||
prefix,
|
||||
icons: ['test1', 'test2'],
|
||||
},
|
||||
{
|
||||
type: 'icons',
|
||||
provider,
|
||||
prefix,
|
||||
icons: ['foo', 'bar'],
|
||||
index: 0,
|
||||
},
|
||||
{
|
||||
type: 'icons',
|
||||
provider,
|
||||
prefix,
|
||||
icons: ['baz'],
|
||||
index: 1,
|
||||
},
|
||||
{
|
||||
type: 'icons',
|
||||
provider,
|
||||
prefix,
|
||||
icons: ['test10'],
|
||||
index: 2,
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('Without catch-all query', () => {
|
||||
const provider = nextPrefix();
|
||||
const prefix = nextPrefix();
|
||||
|
||||
const item = {
|
||||
type: 'icons',
|
||||
provider,
|
||||
prefix,
|
||||
response: 404,
|
||||
icons: ['foo'],
|
||||
};
|
||||
mockAPIData(item);
|
||||
|
||||
// Make sure item is stored correctly
|
||||
expect(typeof iconsStorage[provider]).toBe('object');
|
||||
expect(iconsStorage[provider][prefix]).toEqual([item]);
|
||||
|
||||
// Find item for icons
|
||||
const result = prepare(provider, prefix, ['foo', 'bar', 'baz']);
|
||||
expect(result).toEqual([
|
||||
// Missing icons first
|
||||
{
|
||||
type: 'icons',
|
||||
provider,
|
||||
prefix,
|
||||
icons: ['bar', 'baz'],
|
||||
},
|
||||
{
|
||||
type: 'icons',
|
||||
provider,
|
||||
prefix,
|
||||
icons: ['foo'],
|
||||
index: 0,
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
354
packages/core/spec/api/mockSpec.mjs
Normal file
354
packages/core/spec/api/mockSpec.mjs
Normal file
@ -0,0 +1,354 @@
|
||||
import { setAPIConfig } from '@iconify/core/lib/api/config';
|
||||
import { setAPIModule } from '@iconify/core/lib/api/modules';
|
||||
import { loadIcons } from '@iconify/core/lib/api/icons';
|
||||
import { mockAPIModule, mockAPIData } from '@iconify/core/lib/api/modules/mock';
|
||||
import { getStorage, iconExists } from '@iconify/core/lib/storage/storage';
|
||||
import { sendAPIQuery } from '@iconify/core/lib/api/query';
|
||||
|
||||
describe('Testing mock API module', () => {
|
||||
let prefixCounter = 0;
|
||||
function nextPrefix() {
|
||||
prefixCounter++;
|
||||
return 'api-mock-' + (prefixCounter < 10 ? '0' : '') + prefixCounter;
|
||||
}
|
||||
|
||||
// Set API module for provider
|
||||
const provider = nextPrefix();
|
||||
|
||||
beforeEach(() => {
|
||||
setAPIConfig(provider, {
|
||||
resources: ['https://api1.local'],
|
||||
});
|
||||
setAPIModule(provider, mockAPIModule);
|
||||
});
|
||||
|
||||
// Tests
|
||||
it('404 response', (done) => {
|
||||
const prefix = nextPrefix();
|
||||
|
||||
mockAPIData({
|
||||
type: 'icons',
|
||||
provider,
|
||||
prefix,
|
||||
icons: ['test1', 'test2'],
|
||||
response: 404,
|
||||
});
|
||||
|
||||
let isSync = true;
|
||||
|
||||
loadIcons(
|
||||
[
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'test1',
|
||||
},
|
||||
],
|
||||
(loaded, missing, pending) => {
|
||||
expect(isSync).toBe(false);
|
||||
expect(loaded).toEqual([]);
|
||||
expect(pending).toEqual([]);
|
||||
expect(missing).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'test1',
|
||||
},
|
||||
]);
|
||||
done();
|
||||
}
|
||||
);
|
||||
|
||||
isSync = false;
|
||||
});
|
||||
|
||||
it('Load few icons', (done) => {
|
||||
const prefix = nextPrefix();
|
||||
|
||||
mockAPIData({
|
||||
type: 'icons',
|
||||
provider,
|
||||
prefix,
|
||||
response: {
|
||||
prefix,
|
||||
icons: {
|
||||
test10: {
|
||||
body: '<g />',
|
||||
},
|
||||
test11: {
|
||||
body: '<g />',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
mockAPIData({
|
||||
type: 'icons',
|
||||
provider,
|
||||
prefix,
|
||||
response: {
|
||||
prefix,
|
||||
icons: {
|
||||
test20: {
|
||||
body: '<g />',
|
||||
},
|
||||
test21: {
|
||||
body: '<g />',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
let isSync = true;
|
||||
|
||||
loadIcons(
|
||||
[
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'test10',
|
||||
},
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'test20',
|
||||
},
|
||||
],
|
||||
(loaded, missing, pending) => {
|
||||
expect(isSync).toBe(false);
|
||||
// All icons should have been loaded because API waits one tick before sending response, during which both queries are processed
|
||||
expect(loaded).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'test10',
|
||||
},
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'test20',
|
||||
},
|
||||
]);
|
||||
expect(pending).toEqual([]);
|
||||
expect(missing).toEqual([]);
|
||||
done();
|
||||
}
|
||||
);
|
||||
|
||||
isSync = false;
|
||||
});
|
||||
|
||||
it('Load in batches and testing delay', (done) => {
|
||||
const prefix = nextPrefix();
|
||||
let next;
|
||||
|
||||
mockAPIData({
|
||||
type: 'icons',
|
||||
provider,
|
||||
prefix,
|
||||
response: {
|
||||
prefix,
|
||||
icons: {
|
||||
test10: {
|
||||
body: '<g />',
|
||||
},
|
||||
test11: {
|
||||
body: '<g />',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
mockAPIData({
|
||||
type: 'icons',
|
||||
provider,
|
||||
prefix,
|
||||
response: {
|
||||
prefix,
|
||||
icons: {
|
||||
test20: {
|
||||
body: '<g />',
|
||||
},
|
||||
test21: {
|
||||
body: '<g />',
|
||||
},
|
||||
},
|
||||
},
|
||||
delay: (callback) => {
|
||||
next = callback;
|
||||
},
|
||||
});
|
||||
|
||||
let callbackCounter = 0;
|
||||
|
||||
loadIcons(
|
||||
[
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'test10',
|
||||
},
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'test20',
|
||||
},
|
||||
],
|
||||
(loaded, missing, pending) => {
|
||||
callbackCounter++;
|
||||
switch (callbackCounter) {
|
||||
case 1:
|
||||
// First load: only 'test10'
|
||||
expect(loaded).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'test10',
|
||||
},
|
||||
]);
|
||||
expect(pending).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'test20',
|
||||
},
|
||||
]);
|
||||
|
||||
// Send second response
|
||||
expect(typeof next).toBe('function');
|
||||
next();
|
||||
break;
|
||||
|
||||
case 2:
|
||||
// All icons should have been loaded
|
||||
expect(loaded).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'test10',
|
||||
},
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'test20',
|
||||
},
|
||||
]);
|
||||
expect(missing).toEqual([]);
|
||||
done();
|
||||
break;
|
||||
|
||||
default:
|
||||
done('Callback was called more times than expected');
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
// This is useful for testing component where loadIcons() cannot be accessed
|
||||
it('Using timer in callback for second test', (done) => {
|
||||
const prefix = nextPrefix();
|
||||
const name = 'test1';
|
||||
|
||||
// Mock data
|
||||
mockAPIData({
|
||||
type: 'icons',
|
||||
provider,
|
||||
prefix,
|
||||
response: {
|
||||
prefix,
|
||||
icons: {
|
||||
[name]: {
|
||||
body: '<g />',
|
||||
},
|
||||
},
|
||||
},
|
||||
delay: (next) => {
|
||||
// Icon should not be loaded yet
|
||||
const storage = getStorage(provider, prefix);
|
||||
expect(iconExists(storage, name)).toBe(false);
|
||||
|
||||
// Set data
|
||||
next();
|
||||
|
||||
// Icon should be loaded now
|
||||
expect(iconExists(storage, name)).toBe(true);
|
||||
|
||||
done();
|
||||
},
|
||||
});
|
||||
|
||||
// Load icons
|
||||
loadIcons([
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name,
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('Custom query', (done) => {
|
||||
mockAPIData({
|
||||
type: 'custom',
|
||||
provider,
|
||||
uri: '/test',
|
||||
response: {
|
||||
foo: true,
|
||||
},
|
||||
});
|
||||
|
||||
let isSync = true;
|
||||
|
||||
sendAPIQuery(
|
||||
provider,
|
||||
{
|
||||
type: 'custom',
|
||||
provider,
|
||||
uri: '/test',
|
||||
},
|
||||
(data, error) => {
|
||||
expect(error).toBeUndefined();
|
||||
expect(data).toEqual({
|
||||
foo: true,
|
||||
});
|
||||
expect(isSync).toBe(false);
|
||||
done();
|
||||
}
|
||||
);
|
||||
|
||||
isSync = false;
|
||||
});
|
||||
|
||||
it('Custom query with host', (done) => {
|
||||
const host = 'http://' + nextPrefix();
|
||||
setAPIModule(host, mockAPIModule);
|
||||
mockAPIData({
|
||||
type: 'host',
|
||||
host,
|
||||
uri: '/test',
|
||||
response: {
|
||||
foo: 2,
|
||||
},
|
||||
});
|
||||
|
||||
let isSync = true;
|
||||
|
||||
sendAPIQuery(
|
||||
{
|
||||
resources: [host],
|
||||
},
|
||||
{
|
||||
type: 'custom',
|
||||
uri: '/test',
|
||||
},
|
||||
(data, error) => {
|
||||
expect(error).toBeUndefined();
|
||||
expect(data).toEqual({
|
||||
foo: 2,
|
||||
});
|
||||
expect(isSync).toBe(false);
|
||||
done();
|
||||
}
|
||||
);
|
||||
|
||||
isSync = false;
|
||||
});
|
||||
});
|
60
packages/core/spec/api/modulesSpec.mjs
Normal file
60
packages/core/spec/api/modulesSpec.mjs
Normal file
@ -0,0 +1,60 @@
|
||||
import { setAPIConfig, getAPIConfig } from '@iconify/core/lib/api/config';
|
||||
import { setAPIModule, getAPIModule } from '@iconify/core/lib/api/modules';
|
||||
|
||||
describe('Testing API modules', () => {
|
||||
let prefixCounter = 0;
|
||||
function nextPrefix() {
|
||||
prefixCounter++;
|
||||
return (
|
||||
'api-mod-test-' + (prefixCounter < 10 ? '0' : '') + prefixCounter
|
||||
);
|
||||
}
|
||||
|
||||
const prepareQuery = (provider, prefix, icons) => {
|
||||
const item = {
|
||||
type: 'icons',
|
||||
provider,
|
||||
prefix,
|
||||
icons,
|
||||
};
|
||||
return [item];
|
||||
};
|
||||
|
||||
const sendQuery = () => {
|
||||
throw new Error('Unexpected API call');
|
||||
};
|
||||
|
||||
it('Empty module', () => {
|
||||
const provider = nextPrefix();
|
||||
|
||||
// Set config
|
||||
setAPIConfig(provider, {
|
||||
resources: ['https://localhost:3000'],
|
||||
maxURL: 500,
|
||||
});
|
||||
|
||||
// Set fake module
|
||||
setAPIModule(provider, {
|
||||
prepare: prepareQuery,
|
||||
send: sendQuery,
|
||||
});
|
||||
|
||||
// Get config
|
||||
const config = getAPIConfig(provider);
|
||||
expect(config).not.toBeUndefined();
|
||||
|
||||
// Check setAPIConfig
|
||||
expect(config.resources).toEqual(['https://localhost:3000']);
|
||||
|
||||
// Check getAPIModule()
|
||||
const item = getAPIModule(provider);
|
||||
expect(item).not.toBeUndefined();
|
||||
expect(item.prepare).toBe(prepareQuery);
|
||||
expect(item.send).toBe(sendQuery);
|
||||
|
||||
// Get module for different provider to make sure it is different
|
||||
const provider2 = nextPrefix();
|
||||
const item2 = getAPIModule(provider2);
|
||||
expect(item2).not.toBe(item);
|
||||
});
|
||||
});
|
85
packages/core/spec/api/simpleNamesSpec.mjs
Normal file
85
packages/core/spec/api/simpleNamesSpec.mjs
Normal file
@ -0,0 +1,85 @@
|
||||
import { setAPIModule } from '@iconify/core/lib/api/modules';
|
||||
import { loadIcons } from '@iconify/core/lib/api/icons';
|
||||
import { mockAPIModule, mockAPIData } from '@iconify/core/lib/api/modules/mock';
|
||||
import { allowSimpleNames } from '@iconify/core/lib/storage/functions';
|
||||
|
||||
describe('Testing simple names with API module', () => {
|
||||
// Set API config and allow simple names
|
||||
beforeEach(() => {
|
||||
allowSimpleNames(true);
|
||||
setAPIModule('', mockAPIModule);
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
allowSimpleNames(false);
|
||||
});
|
||||
|
||||
it('Loading icons without prefix', (done) => {
|
||||
mockAPIData({
|
||||
type: 'icons',
|
||||
provider: '',
|
||||
prefix: '',
|
||||
response: {
|
||||
prefix: '',
|
||||
icons: {
|
||||
test100: {
|
||||
body: '<g />',
|
||||
},
|
||||
test101: {
|
||||
body: '<g />',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
mockAPIData({
|
||||
type: 'icons',
|
||||
provider: '',
|
||||
prefix: 'test200',
|
||||
response: {
|
||||
prefix: 'test200',
|
||||
icons: {
|
||||
foo: {
|
||||
body: '<g />',
|
||||
},
|
||||
bar: {
|
||||
body: '<g />',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
loadIcons(
|
||||
[
|
||||
{
|
||||
provider: '',
|
||||
prefix: '',
|
||||
name: 'test100',
|
||||
},
|
||||
{
|
||||
provider: '',
|
||||
prefix: 'test200',
|
||||
name: 'foo',
|
||||
},
|
||||
],
|
||||
(loaded, missing, pending) => {
|
||||
// 'test100' should be missing because it does not have a prefix
|
||||
expect(loaded).toEqual([
|
||||
{
|
||||
provider: '',
|
||||
prefix: 'test200',
|
||||
name: 'foo',
|
||||
},
|
||||
]);
|
||||
expect(pending).toEqual([]);
|
||||
expect(missing).toEqual([
|
||||
{
|
||||
provider: '',
|
||||
prefix: '',
|
||||
name: 'test100',
|
||||
},
|
||||
]);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
272
packages/core/spec/basic/storageSpec.mjs
Normal file
272
packages/core/spec/basic/storageSpec.mjs
Normal file
@ -0,0 +1,272 @@
|
||||
import {
|
||||
newStorage,
|
||||
addIcon,
|
||||
iconExists,
|
||||
getIcon,
|
||||
addIconSet,
|
||||
getStorage,
|
||||
listIcons,
|
||||
} from '@iconify/core/lib/storage/storage';
|
||||
|
||||
describe('Testing storage', () => {
|
||||
it('Adding icon', () => {
|
||||
const storage = newStorage('', 'foo');
|
||||
|
||||
// Add one icon
|
||||
addIcon(storage, 'test', {
|
||||
body: '<path d="" />',
|
||||
width: 20,
|
||||
height: 16,
|
||||
});
|
||||
addIcon(storage, 'not-really-missing', {
|
||||
body: '<path d="" />',
|
||||
width: 24,
|
||||
height: 24,
|
||||
});
|
||||
|
||||
// Add another icon with reserved keyword as name
|
||||
addIcon(storage, 'constructor', {
|
||||
body: '<g></g>',
|
||||
width: 24,
|
||||
height: 24,
|
||||
rotate: 1,
|
||||
});
|
||||
|
||||
// Mark 'not-really-missing' as missing
|
||||
storage.missing['not-really-missing'] = Date.now();
|
||||
|
||||
// Add invalid icon
|
||||
addIcon(storage, 'invalid', {});
|
||||
|
||||
// Should not include 'invalid'
|
||||
expect(Object.keys(storage.icons)).toEqual([
|
||||
'test',
|
||||
'not-really-missing',
|
||||
'constructor',
|
||||
]);
|
||||
|
||||
// Test iconExists
|
||||
expect(iconExists(storage, 'test')).toBe(true);
|
||||
expect(iconExists(storage, 'constructor')).toBe(true);
|
||||
expect(iconExists(storage, 'invalid')).toBe(false);
|
||||
expect(iconExists(storage, 'missing')).toBe(false);
|
||||
expect(iconExists(storage, 'not-really-missing')).toBe(true);
|
||||
|
||||
// Test getIcon
|
||||
let expected = {
|
||||
body: '<path d="" />',
|
||||
width: 20,
|
||||
height: 16,
|
||||
top: 0,
|
||||
left: 0,
|
||||
hFlip: false,
|
||||
vFlip: false,
|
||||
rotate: 0,
|
||||
};
|
||||
const icon = getIcon(storage, 'test');
|
||||
expect(icon).toEqual(expected);
|
||||
|
||||
// Test icon mutation
|
||||
let thrown = false;
|
||||
try {
|
||||
icon.width = 12;
|
||||
} catch (err) {
|
||||
thrown = true;
|
||||
}
|
||||
expect(thrown).toBe(true);
|
||||
|
||||
expected = {
|
||||
body: '<g></g>',
|
||||
width: 24,
|
||||
height: 24,
|
||||
top: 0,
|
||||
left: 0,
|
||||
hFlip: false,
|
||||
vFlip: false,
|
||||
rotate: 1,
|
||||
};
|
||||
expect(getIcon(storage, 'constructor')).toEqual(expected);
|
||||
|
||||
expect(getIcon(storage, 'invalid')).toBeNull();
|
||||
expect(getIcon(storage, 'missing')).toBeNull();
|
||||
});
|
||||
|
||||
it('Adding simple icon set', () => {
|
||||
const storage = newStorage('', 'foo');
|
||||
|
||||
// Add two icons
|
||||
expect(
|
||||
addIconSet(storage, {
|
||||
prefix: 'foo',
|
||||
icons: {
|
||||
icon1: {
|
||||
body: '<path d="icon1" />',
|
||||
width: 20,
|
||||
},
|
||||
icon2: {
|
||||
body: '<path d="icon2" />',
|
||||
width: 24,
|
||||
},
|
||||
},
|
||||
height: 24,
|
||||
})
|
||||
).toBe(true);
|
||||
|
||||
expect(Object.keys(storage.icons)).toEqual(['icon1', 'icon2']);
|
||||
|
||||
// Test iconExists
|
||||
expect(iconExists(storage, 'icon1')).toBe(true);
|
||||
expect(iconExists(storage, 'icon2')).toBe(true);
|
||||
expect(iconExists(storage, 'invalid')).toBe(false);
|
||||
expect(iconExists(storage, 'missing')).toBe(false);
|
||||
|
||||
// Test getIcon
|
||||
let expected = {
|
||||
body: '<path d="icon1" />',
|
||||
width: 20,
|
||||
height: 24,
|
||||
top: 0,
|
||||
left: 0,
|
||||
hFlip: false,
|
||||
vFlip: false,
|
||||
rotate: 0,
|
||||
};
|
||||
expect(getIcon(storage, 'icon1')).toEqual(expected);
|
||||
expected = {
|
||||
body: '<path d="icon2" />',
|
||||
width: 24,
|
||||
height: 24,
|
||||
top: 0,
|
||||
left: 0,
|
||||
hFlip: false,
|
||||
vFlip: false,
|
||||
rotate: 0,
|
||||
};
|
||||
expect(getIcon(storage, 'icon2')).toEqual(expected);
|
||||
expect(getIcon(storage, 'invalid')).toBeNull();
|
||||
expect(getIcon(storage, 'missing')).toBeNull();
|
||||
});
|
||||
|
||||
it('Icon set with aliases that use transformations', () => {
|
||||
const storage = newStorage('iconify', 'arty-animated');
|
||||
const iconBody =
|
||||
'<g stroke="currentColor" stroke-width="16" stroke-linecap="round" stroke-linejoin="round" fill="none" fill-rule="evenodd"><path d="M40 64l48-48" class="animation-delay-0 animation-duration-10 animate-stroke stroke-length-102"/><path d="M40 64l48 48" class="animation-delay-0 animation-duration-10 animate-stroke stroke-length-102"/></g>';
|
||||
|
||||
expect(
|
||||
addIconSet(storage, {
|
||||
prefix: 'arty-animated',
|
||||
icons: {
|
||||
'16-chevron-left': {
|
||||
body: iconBody,
|
||||
},
|
||||
},
|
||||
aliases: {
|
||||
'16-chevron-right': {
|
||||
parent: '16-chevron-left',
|
||||
hFlip: true,
|
||||
},
|
||||
},
|
||||
width: 128,
|
||||
height: 128,
|
||||
})
|
||||
).toBe(true);
|
||||
|
||||
expect(Object.keys(storage.icons)).toEqual([
|
||||
'16-chevron-left',
|
||||
'16-chevron-right',
|
||||
]);
|
||||
|
||||
// Test icon
|
||||
let expected = {
|
||||
body: iconBody,
|
||||
width: 128,
|
||||
height: 128,
|
||||
top: 0,
|
||||
left: 0,
|
||||
hFlip: false,
|
||||
vFlip: false,
|
||||
rotate: 0,
|
||||
};
|
||||
expect(getIcon(storage, '16-chevron-left')).toEqual(expected);
|
||||
|
||||
// Test alias
|
||||
expected = {
|
||||
body: iconBody,
|
||||
width: 128,
|
||||
height: 128,
|
||||
top: 0,
|
||||
left: 0,
|
||||
hFlip: true,
|
||||
vFlip: false,
|
||||
rotate: 0,
|
||||
};
|
||||
expect(getIcon(storage, '16-chevron-right')).toEqual(expected);
|
||||
});
|
||||
|
||||
it('List icons in a global storage', () => {
|
||||
const provider = 'test-provider';
|
||||
const prefix = 'global-storage-test';
|
||||
const storage1 = getStorage('', prefix);
|
||||
const storage2 = getStorage(provider, prefix);
|
||||
|
||||
// List icons
|
||||
expect(listIcons('', prefix)).toEqual([]);
|
||||
expect(listIcons(provider, prefix)).toEqual([]);
|
||||
|
||||
// Add one icon without provider
|
||||
addIcon(storage1, 'test', {
|
||||
body: '<path d="" />',
|
||||
width: 20,
|
||||
height: 16,
|
||||
});
|
||||
|
||||
// List icons
|
||||
expect(listIcons('', prefix)).toEqual([prefix + ':test']);
|
||||
expect(listIcons(provider, prefix)).toEqual([]);
|
||||
|
||||
// Add icon set without provider
|
||||
expect(
|
||||
addIconSet(storage1, {
|
||||
prefix,
|
||||
icons: {
|
||||
'16-chevron-left': {
|
||||
body: '<path d="" />',
|
||||
},
|
||||
},
|
||||
aliases: {
|
||||
'16-chevron-right': {
|
||||
parent: '16-chevron-left',
|
||||
hFlip: true,
|
||||
},
|
||||
},
|
||||
width: 128,
|
||||
height: 128,
|
||||
})
|
||||
).toBe(true);
|
||||
|
||||
// List icons
|
||||
expect(listIcons('', prefix)).toEqual([
|
||||
prefix + ':test',
|
||||
prefix + ':16-chevron-left',
|
||||
prefix + ':16-chevron-right',
|
||||
]);
|
||||
expect(listIcons(provider, prefix)).toEqual([]);
|
||||
|
||||
// Add one icon with provider
|
||||
addIcon(storage2, 'test2', {
|
||||
body: '<path d="" />',
|
||||
width: 20,
|
||||
height: 16,
|
||||
});
|
||||
|
||||
// List icons
|
||||
expect(listIcons('', prefix)).toEqual([
|
||||
prefix + ':test',
|
||||
prefix + ':16-chevron-left',
|
||||
prefix + ':16-chevron-right',
|
||||
]);
|
||||
expect(listIcons(provider, prefix)).toEqual([
|
||||
'@' + provider + ':' + prefix + ':test2',
|
||||
]);
|
||||
});
|
||||
});
|
219
packages/core/spec/cache/basicSpec.mjs
vendored
Normal file
219
packages/core/spec/cache/basicSpec.mjs
vendored
Normal file
@ -0,0 +1,219 @@
|
||||
import { count, config, loadCache } from '@iconify/core/lib/browser-storage';
|
||||
import {
|
||||
nextPrefix,
|
||||
createCache,
|
||||
reset,
|
||||
cachePrefix,
|
||||
cacheVersion,
|
||||
versionKey,
|
||||
countKey,
|
||||
} from './fakeCache.mjs';
|
||||
|
||||
describe('Testing mocked localStorage', () => {
|
||||
const provider = '';
|
||||
|
||||
it('No usable cache', () => {
|
||||
reset({});
|
||||
|
||||
// Config before tests
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: true,
|
||||
});
|
||||
expect(count).toEqual({
|
||||
local: 0,
|
||||
session: 0,
|
||||
});
|
||||
|
||||
// Attempt to load
|
||||
loadCache();
|
||||
|
||||
// Everything should be disabled
|
||||
expect(config).toEqual({
|
||||
local: false,
|
||||
session: false,
|
||||
});
|
||||
|
||||
// Nothing should have loaded
|
||||
expect(count).toEqual({
|
||||
local: 0,
|
||||
session: 0,
|
||||
});
|
||||
});
|
||||
|
||||
it('Empty localStorage', () => {
|
||||
reset({
|
||||
localStorage: createCache(),
|
||||
});
|
||||
|
||||
// Config before tests
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: true,
|
||||
});
|
||||
expect(count).toEqual({
|
||||
local: 0,
|
||||
session: 0,
|
||||
});
|
||||
|
||||
// Attempt to load
|
||||
loadCache();
|
||||
|
||||
// sessionStorage should be disabled
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: false,
|
||||
});
|
||||
|
||||
// Nothing should have loaded
|
||||
expect(count).toEqual({
|
||||
local: 0,
|
||||
session: 0,
|
||||
});
|
||||
});
|
||||
|
||||
it('Restricted localStorage', () => {
|
||||
const prefix = nextPrefix();
|
||||
const cache = createCache();
|
||||
|
||||
// Add one item
|
||||
cache.setItem(versionKey, cacheVersion);
|
||||
cache.setItem(countKey, '1');
|
||||
cache.setItem(
|
||||
cachePrefix + '0',
|
||||
JSON.stringify({
|
||||
cached: Date.now(),
|
||||
provider,
|
||||
data: {
|
||||
prefix: prefix,
|
||||
icons: {
|
||||
foo: {
|
||||
body: '<g></g>',
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
// Prevent reading and writing
|
||||
cache.canRead = false;
|
||||
cache.canWrite = false;
|
||||
|
||||
// Set cache and test it
|
||||
reset({
|
||||
localStorage: cache,
|
||||
sessionStorage: cache,
|
||||
});
|
||||
|
||||
// Config before tests
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: true,
|
||||
});
|
||||
expect(count).toEqual({
|
||||
local: 0,
|
||||
session: 0,
|
||||
});
|
||||
|
||||
// Attempt to load
|
||||
loadCache();
|
||||
|
||||
// Everything should be disabled because read-only mock throws errors
|
||||
expect(config).toEqual({
|
||||
local: false,
|
||||
session: false,
|
||||
});
|
||||
|
||||
// Nothing should have loaded
|
||||
expect(count).toEqual({
|
||||
local: 0,
|
||||
session: 0,
|
||||
});
|
||||
});
|
||||
|
||||
it('localStorage with one item', () => {
|
||||
const prefix = nextPrefix();
|
||||
const cache = createCache();
|
||||
|
||||
// Add one icon set
|
||||
cache.setItem(versionKey, cacheVersion);
|
||||
cache.setItem(countKey, '1');
|
||||
cache.setItem(
|
||||
cachePrefix + '0',
|
||||
JSON.stringify({
|
||||
cached: Date.now(),
|
||||
provider,
|
||||
data: {
|
||||
prefix: prefix,
|
||||
icons: {
|
||||
foo: {
|
||||
body: '<g></g>',
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
// Set cache and test it
|
||||
reset({
|
||||
localStorage: cache,
|
||||
});
|
||||
|
||||
// Config before tests
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: true,
|
||||
});
|
||||
expect(count).toEqual({
|
||||
local: 0,
|
||||
session: 0,
|
||||
});
|
||||
|
||||
// Attempt to load
|
||||
loadCache();
|
||||
|
||||
// sessionStorage should be disabled
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: false,
|
||||
});
|
||||
|
||||
// One item should be in localStorage
|
||||
expect(count).toEqual({
|
||||
local: 1,
|
||||
session: 0,
|
||||
});
|
||||
});
|
||||
|
||||
it('localStorage and sessionStorage', () => {
|
||||
reset({
|
||||
localStorage: createCache(),
|
||||
sessionStorage: createCache(),
|
||||
});
|
||||
|
||||
// Config before tests
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: true,
|
||||
});
|
||||
expect(count).toEqual({
|
||||
local: 0,
|
||||
session: 0,
|
||||
});
|
||||
|
||||
// Attempt to load
|
||||
loadCache();
|
||||
|
||||
// Everything should be working
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: true,
|
||||
});
|
||||
|
||||
// Empty storage
|
||||
expect(count).toEqual({
|
||||
local: 0,
|
||||
session: 0,
|
||||
});
|
||||
});
|
||||
});
|
119
packages/core/spec/cache/fakeCache.mjs
vendored
Normal file
119
packages/core/spec/cache/fakeCache.mjs
vendored
Normal file
@ -0,0 +1,119 @@
|
||||
import {
|
||||
mock,
|
||||
count,
|
||||
config,
|
||||
emptyList,
|
||||
} from '@iconify/core/lib/browser-storage';
|
||||
|
||||
/**
|
||||
* Get next icon set prefix for testing
|
||||
*/
|
||||
let prefixCounter = 0;
|
||||
export function nextPrefix() {
|
||||
return 'fake-storage-' + prefixCounter++;
|
||||
}
|
||||
|
||||
// Cache version. Bump when structure changes
|
||||
export const cacheVersion = 'iconify2';
|
||||
|
||||
// Cache keys
|
||||
export const cachePrefix = 'iconify';
|
||||
export const countKey = cachePrefix + '-count';
|
||||
export const versionKey = cachePrefix + '-version';
|
||||
|
||||
/**
|
||||
* Cache expiration
|
||||
*/
|
||||
export const hour = 3600000;
|
||||
export const cacheExpiration = 168; // In hours
|
||||
|
||||
/**
|
||||
* Storage class
|
||||
*/
|
||||
export class Storage {
|
||||
canRead = true;
|
||||
canWrite = true;
|
||||
items = Object.create(null);
|
||||
|
||||
/**
|
||||
* Get number of items
|
||||
*/
|
||||
get length() {
|
||||
if (!this.canRead) {
|
||||
throw new Error('Restricted storage');
|
||||
}
|
||||
return Object.keys(this.items).length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get item
|
||||
*
|
||||
* @param name
|
||||
*/
|
||||
getItem(name) {
|
||||
if (!this.canRead) {
|
||||
throw new Error('Restricted storage');
|
||||
}
|
||||
return this.items[name] === void 0 ? null : this.items[name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set item
|
||||
*
|
||||
* @param name
|
||||
* @param value
|
||||
*/
|
||||
setItem(name, value) {
|
||||
if (!this.canWrite) {
|
||||
throw new Error('Read-only storage');
|
||||
}
|
||||
this.items[name] = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove item
|
||||
*
|
||||
* @param name
|
||||
*/
|
||||
removeItem(name) {
|
||||
if (!this.canWrite) {
|
||||
throw new Error('Read-only storage');
|
||||
}
|
||||
delete this.items[name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear everything
|
||||
*/
|
||||
clear() {
|
||||
if (!this.canWrite) {
|
||||
throw new Error('Read-only storage');
|
||||
}
|
||||
this.items = Object.create(null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create fake storage, assign localStorage type
|
||||
*/
|
||||
export function createCache() {
|
||||
return new Storage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset test
|
||||
*
|
||||
* @param fakeWindow
|
||||
*/
|
||||
export function reset(fakeWindow) {
|
||||
// Replace window
|
||||
mock(fakeWindow);
|
||||
|
||||
// Reset all data
|
||||
for (const key in config) {
|
||||
const attr = key;
|
||||
config[attr] = true;
|
||||
count[attr] = 0;
|
||||
emptyList[attr] = [];
|
||||
}
|
||||
}
|
491
packages/core/spec/cache/loadingSpec.mjs
vendored
Normal file
491
packages/core/spec/cache/loadingSpec.mjs
vendored
Normal file
@ -0,0 +1,491 @@
|
||||
import {
|
||||
loadCache,
|
||||
count,
|
||||
config,
|
||||
emptyList,
|
||||
} from '@iconify/core/lib/browser-storage';
|
||||
import { getStorage, iconExists } from '@iconify/core/lib/storage/storage';
|
||||
import {
|
||||
nextPrefix,
|
||||
createCache,
|
||||
reset,
|
||||
cachePrefix,
|
||||
cacheVersion,
|
||||
versionKey,
|
||||
countKey,
|
||||
hour,
|
||||
cacheExpiration,
|
||||
} from './fakeCache.mjs';
|
||||
|
||||
describe('Testing loading from localStorage', () => {
|
||||
const provider = '';
|
||||
|
||||
it('Valid icon set', () => {
|
||||
const prefix = nextPrefix();
|
||||
const cache = createCache();
|
||||
|
||||
// Add one icon set
|
||||
cache.setItem(versionKey, cacheVersion);
|
||||
cache.setItem(countKey, '1');
|
||||
|
||||
const item = {
|
||||
cached: Math.floor(Date.now() / hour),
|
||||
provider,
|
||||
data: {
|
||||
prefix: prefix,
|
||||
icons: {
|
||||
foo: {
|
||||
body: '<g></g>',
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
cache.setItem(cachePrefix + '0', JSON.stringify(item));
|
||||
|
||||
// Set cache
|
||||
reset({
|
||||
localStorage: cache,
|
||||
});
|
||||
|
||||
// Check icon storage
|
||||
const icons = getStorage(provider, prefix);
|
||||
expect(iconExists(icons, 'foo')).toBe(false);
|
||||
|
||||
// Load localStorage
|
||||
loadCache();
|
||||
|
||||
// Icon should exist now
|
||||
expect(iconExists(icons, 'foo')).toBe(true);
|
||||
|
||||
// Check data
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: false,
|
||||
});
|
||||
expect(count).toEqual({
|
||||
local: 1,
|
||||
session: 0,
|
||||
});
|
||||
expect(emptyList).toEqual({
|
||||
local: [],
|
||||
session: [],
|
||||
});
|
||||
});
|
||||
|
||||
it('Different provider', () => {
|
||||
const provider = nextPrefix();
|
||||
const prefix = nextPrefix();
|
||||
const cache = createCache();
|
||||
|
||||
// Add one icon set
|
||||
cache.setItem(versionKey, cacheVersion);
|
||||
cache.setItem(countKey, '1');
|
||||
|
||||
const item = {
|
||||
cached: Math.floor(Date.now() / hour),
|
||||
provider,
|
||||
data: {
|
||||
prefix: prefix,
|
||||
icons: {
|
||||
foo: {
|
||||
body: '<g></g>',
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
cache.setItem(cachePrefix + '0', JSON.stringify(item));
|
||||
|
||||
// Set cache
|
||||
reset({
|
||||
localStorage: cache,
|
||||
});
|
||||
|
||||
// Check icon storage
|
||||
const icons = getStorage(provider, prefix);
|
||||
expect(iconExists(icons, 'foo')).toBe(false);
|
||||
|
||||
// Check default provider
|
||||
const icons2 = getStorage('', prefix);
|
||||
expect(iconExists(icons2, 'foo')).toBe(false);
|
||||
|
||||
// Load localStorage
|
||||
loadCache();
|
||||
|
||||
// Icon should exist now
|
||||
expect(iconExists(icons, 'foo')).toBe(true);
|
||||
expect(iconExists(icons2, 'foo')).toBe(false);
|
||||
|
||||
// Check data
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: false,
|
||||
});
|
||||
expect(count).toEqual({
|
||||
local: 1,
|
||||
session: 0,
|
||||
});
|
||||
expect(emptyList).toEqual({
|
||||
local: [],
|
||||
session: [],
|
||||
});
|
||||
});
|
||||
|
||||
it('Expired icon set', () => {
|
||||
const prefix = nextPrefix();
|
||||
const cache = createCache();
|
||||
|
||||
// Add one icon set
|
||||
cache.setItem(versionKey, cacheVersion);
|
||||
cache.setItem(countKey, '1');
|
||||
|
||||
const item = {
|
||||
// Expiration date
|
||||
cached: Math.floor(Date.now() / hour) - cacheExpiration - 1,
|
||||
provider,
|
||||
data: {
|
||||
prefix: prefix,
|
||||
icons: {
|
||||
foo: {
|
||||
body: '<g></g>',
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
cache.setItem(cachePrefix + '0', JSON.stringify(item));
|
||||
|
||||
// Set cache
|
||||
reset({
|
||||
localStorage: cache,
|
||||
});
|
||||
|
||||
// Check icon storage
|
||||
const icons = getStorage(provider, prefix);
|
||||
expect(iconExists(icons, 'foo')).toBe(false);
|
||||
|
||||
// Load localStorage
|
||||
loadCache();
|
||||
|
||||
// Icon should not have loaded
|
||||
expect(iconExists(icons, 'foo')).toBe(false);
|
||||
|
||||
// Check data
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: false,
|
||||
});
|
||||
expect(count).toEqual({
|
||||
local: 0,
|
||||
session: 0,
|
||||
});
|
||||
expect(emptyList).toEqual({
|
||||
local: [],
|
||||
session: [],
|
||||
});
|
||||
});
|
||||
|
||||
it('Bad icon set', () => {
|
||||
const prefix = nextPrefix();
|
||||
const cache = createCache();
|
||||
|
||||
// Add one icon set
|
||||
cache.setItem(versionKey, cacheVersion);
|
||||
cache.setItem(countKey, '1');
|
||||
cache.setItem(
|
||||
cachePrefix + '0',
|
||||
JSON.stringify({
|
||||
cached: Math.floor(Date.now() / hour),
|
||||
provider,
|
||||
data: {
|
||||
prefix: prefix,
|
||||
icons: {
|
||||
foo: {
|
||||
// Missing 'body' property
|
||||
width: 20,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
// Set cache
|
||||
reset({
|
||||
localStorage: cache,
|
||||
});
|
||||
|
||||
// Check icon storage
|
||||
const icons = getStorage(provider, prefix);
|
||||
expect(iconExists(icons, 'foo')).toBe(false);
|
||||
|
||||
// Load localStorage
|
||||
loadCache();
|
||||
|
||||
// Icon should not have loaded
|
||||
expect(iconExists(icons, 'foo')).toBe(false);
|
||||
|
||||
// Check data
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: false,
|
||||
});
|
||||
expect(count).toEqual({
|
||||
local: 0,
|
||||
session: 0,
|
||||
});
|
||||
expect(emptyList).toEqual({
|
||||
local: [],
|
||||
session: [],
|
||||
});
|
||||
});
|
||||
|
||||
it('Wrong counter', () => {
|
||||
const prefix = nextPrefix();
|
||||
const cache = createCache();
|
||||
|
||||
// Add one icon set
|
||||
cache.setItem(versionKey, cacheVersion);
|
||||
cache.setItem(countKey, '0'); // Should be at least "1"
|
||||
|
||||
const item = {
|
||||
cached: Math.floor(Date.now() / hour),
|
||||
provider,
|
||||
data: {
|
||||
prefix: prefix,
|
||||
icons: {
|
||||
foo: {
|
||||
body: '<g></g>',
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
cache.setItem(cachePrefix + '0', JSON.stringify(item));
|
||||
|
||||
// Set cache
|
||||
reset({
|
||||
localStorage: cache,
|
||||
});
|
||||
|
||||
// Check icon storage
|
||||
const icons = getStorage(provider, prefix);
|
||||
expect(iconExists(icons, 'foo')).toBe(false);
|
||||
|
||||
// Load localStorage
|
||||
loadCache();
|
||||
|
||||
// Icon should not have loaded
|
||||
expect(iconExists(icons, 'foo')).toBe(false);
|
||||
|
||||
// Check data
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: false,
|
||||
});
|
||||
expect(count).toEqual({
|
||||
local: 0,
|
||||
session: 0,
|
||||
});
|
||||
expect(emptyList).toEqual({
|
||||
local: [],
|
||||
session: [],
|
||||
});
|
||||
});
|
||||
|
||||
it('Missing entries at the end', () => {
|
||||
const prefix = nextPrefix();
|
||||
const cache = createCache();
|
||||
|
||||
// Add one icon set
|
||||
cache.setItem(versionKey, cacheVersion);
|
||||
cache.setItem(countKey, '5');
|
||||
|
||||
const item = {
|
||||
cached: Math.floor(Date.now() / hour),
|
||||
provider,
|
||||
data: {
|
||||
prefix: prefix,
|
||||
icons: {
|
||||
foo: {
|
||||
body: '<g></g>',
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
cache.setItem(cachePrefix + '0', JSON.stringify(item));
|
||||
|
||||
// Set cache
|
||||
reset({
|
||||
localStorage: cache,
|
||||
});
|
||||
|
||||
// Check icon storage
|
||||
const icons = getStorage(provider, prefix);
|
||||
expect(iconExists(icons, 'foo')).toBe(false);
|
||||
|
||||
// Load localStorage
|
||||
loadCache();
|
||||
|
||||
// Icon should exist now
|
||||
expect(iconExists(icons, 'foo')).toBe(true);
|
||||
|
||||
// Check data
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: false,
|
||||
});
|
||||
expect(count).toEqual({
|
||||
local: 1,
|
||||
session: 0,
|
||||
});
|
||||
expect(emptyList).toEqual({
|
||||
local: [],
|
||||
session: [],
|
||||
});
|
||||
});
|
||||
|
||||
it('Missing entries', () => {
|
||||
const prefix = nextPrefix();
|
||||
const cache = createCache();
|
||||
|
||||
// Add two icon sets
|
||||
cache.setItem(versionKey, cacheVersion);
|
||||
cache.setItem(countKey, '5');
|
||||
|
||||
// Missing: 0, 2, 3
|
||||
const item1 = {
|
||||
cached: Math.floor(Date.now() / hour),
|
||||
provider,
|
||||
data: {
|
||||
prefix: prefix,
|
||||
icons: {
|
||||
foo1: {
|
||||
body: '<g></g>',
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const item4 = {
|
||||
cached: Math.floor(Date.now() / hour),
|
||||
provider,
|
||||
data: {
|
||||
prefix: prefix,
|
||||
icons: {
|
||||
foo4: {
|
||||
body: '<g></g>',
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
cache.setItem(cachePrefix + '1', JSON.stringify(item1));
|
||||
cache.setItem(cachePrefix + '4', JSON.stringify(item4));
|
||||
|
||||
// Set cache
|
||||
reset({
|
||||
localStorage: cache,
|
||||
});
|
||||
|
||||
// Check icon storage
|
||||
const icons = getStorage(provider, prefix);
|
||||
expect(iconExists(icons, 'foo1')).toBe(false);
|
||||
expect(iconExists(icons, 'foo4')).toBe(false);
|
||||
|
||||
// Load localStorage
|
||||
loadCache();
|
||||
|
||||
// Icons should exist now
|
||||
expect(iconExists(icons, 'foo1')).toBe(true);
|
||||
expect(iconExists(icons, 'foo4')).toBe(true);
|
||||
|
||||
// Check data
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: false,
|
||||
});
|
||||
expect(count).toEqual({
|
||||
local: 5,
|
||||
session: 0,
|
||||
});
|
||||
expect(emptyList).toEqual({
|
||||
local: [3, 2, 0], // reserse order
|
||||
session: [],
|
||||
});
|
||||
});
|
||||
|
||||
it('Using both storage options', () => {
|
||||
const prefix = nextPrefix();
|
||||
const cache1 = createCache();
|
||||
const cache2 = createCache();
|
||||
|
||||
// Add few icon sets
|
||||
cache1.setItem(versionKey, cacheVersion);
|
||||
cache2.setItem(versionKey, cacheVersion);
|
||||
|
||||
cache1.setItem(countKey, '6');
|
||||
cache2.setItem(countKey, '3');
|
||||
|
||||
// Create 5 items
|
||||
const icons = [];
|
||||
const items = [];
|
||||
|
||||
for (let i = 0; i < 6; i++) {
|
||||
const icon = {
|
||||
prefix: prefix,
|
||||
icons: {
|
||||
['foo' + i]: {
|
||||
body: '<g></g>',
|
||||
},
|
||||
},
|
||||
};
|
||||
const item = {
|
||||
cached: Math.floor(Date.now() / hour),
|
||||
provider,
|
||||
data: icon,
|
||||
};
|
||||
icons.push(icon);
|
||||
items.push(item);
|
||||
}
|
||||
|
||||
// Add items 1,3,5 to localStorage
|
||||
[1, 3, 5].forEach((index) => {
|
||||
cache1.setItem(cachePrefix + index, JSON.stringify(items[index]));
|
||||
});
|
||||
|
||||
// Add items 0 and 2 to sessionStorage
|
||||
[0, 2].forEach((index) => {
|
||||
cache2.setItem(cachePrefix + index, JSON.stringify(items[index]));
|
||||
});
|
||||
|
||||
// Set cache
|
||||
reset({
|
||||
localStorage: cache1,
|
||||
sessionStorage: cache2,
|
||||
});
|
||||
|
||||
// Check icon storage
|
||||
const iconsStorage = getStorage(provider, prefix);
|
||||
for (let i = 0; i < 6; i++) {
|
||||
expect(iconExists(iconsStorage, 'foo' + i)).toBe(false);
|
||||
}
|
||||
|
||||
// Load localStorage
|
||||
loadCache();
|
||||
|
||||
// Icons should exist now, except for number 4
|
||||
for (let i = 0; i < 6; i++) {
|
||||
expect(iconExists(iconsStorage, 'foo' + i)).toBe(i !== 4);
|
||||
}
|
||||
|
||||
// Check data
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: true,
|
||||
});
|
||||
expect(count).toEqual({
|
||||
local: 6,
|
||||
session: 3,
|
||||
});
|
||||
expect(emptyList).toEqual({
|
||||
local: [4, 2, 0],
|
||||
session: [1],
|
||||
});
|
||||
});
|
||||
});
|
660
packages/core/spec/cache/savingSpec.mjs
vendored
Normal file
660
packages/core/spec/cache/savingSpec.mjs
vendored
Normal file
@ -0,0 +1,660 @@
|
||||
import {
|
||||
loadCache,
|
||||
storeCache,
|
||||
count,
|
||||
config,
|
||||
emptyList,
|
||||
} from '@iconify/core/lib/browser-storage';
|
||||
import { getStorage, iconExists } from '@iconify/core/lib/storage/storage';
|
||||
import {
|
||||
nextPrefix,
|
||||
createCache,
|
||||
reset,
|
||||
cachePrefix,
|
||||
cacheVersion,
|
||||
versionKey,
|
||||
countKey,
|
||||
hour,
|
||||
cacheExpiration,
|
||||
} from './fakeCache.mjs';
|
||||
|
||||
describe('Testing saving to localStorage', () => {
|
||||
const provider = '';
|
||||
|
||||
it('One icon set', () => {
|
||||
const prefix = nextPrefix();
|
||||
const cache = createCache();
|
||||
|
||||
// Add one icon set
|
||||
const icon = {
|
||||
prefix: prefix,
|
||||
icons: {
|
||||
foo: {
|
||||
body: '<g></g>',
|
||||
},
|
||||
},
|
||||
};
|
||||
const item = {
|
||||
cached: Math.floor(Date.now() / hour),
|
||||
provider,
|
||||
data: icon,
|
||||
};
|
||||
|
||||
// Set cache
|
||||
reset({
|
||||
localStorage: cache,
|
||||
});
|
||||
|
||||
// Check icon storage
|
||||
const icons = getStorage(provider, prefix);
|
||||
expect(iconExists(icons, 'foo')).toBe(false);
|
||||
|
||||
// Save item
|
||||
storeCache(provider, icon);
|
||||
|
||||
// Storing in cache should not add item to storage
|
||||
expect(iconExists(icons, 'foo')).toBe(false);
|
||||
|
||||
// Check data that should have been updated because storeCache()
|
||||
// should call load function before first execution
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: false,
|
||||
});
|
||||
expect(count).toEqual({
|
||||
local: 1,
|
||||
session: 0,
|
||||
});
|
||||
expect(emptyList).toEqual({
|
||||
local: [],
|
||||
session: [],
|
||||
});
|
||||
|
||||
// Check cache
|
||||
expect(cache.getItem(cachePrefix + '0')).toBe(JSON.stringify(item));
|
||||
expect(cache.getItem(countKey)).toBe('1');
|
||||
expect(cache.getItem(versionKey)).toBe(cacheVersion);
|
||||
});
|
||||
|
||||
it('Multiple icon sets', () => {
|
||||
const prefix = nextPrefix();
|
||||
const cache = createCache();
|
||||
|
||||
// Add icon sets
|
||||
const icon0 = {
|
||||
prefix: prefix,
|
||||
icons: {
|
||||
foo0: {
|
||||
body: '<g></g>',
|
||||
},
|
||||
},
|
||||
};
|
||||
const item0 = {
|
||||
cached: Math.floor(Date.now() / hour),
|
||||
provider,
|
||||
data: icon0,
|
||||
};
|
||||
const icon1 = {
|
||||
prefix: prefix,
|
||||
icons: {
|
||||
foo: {
|
||||
body: '<g></g>',
|
||||
},
|
||||
},
|
||||
};
|
||||
const item1 = {
|
||||
cached: Math.floor(Date.now() / hour),
|
||||
provider,
|
||||
data: icon1,
|
||||
};
|
||||
|
||||
// Set cache
|
||||
reset({
|
||||
localStorage: cache,
|
||||
});
|
||||
|
||||
// Save items
|
||||
storeCache(provider, icon0);
|
||||
storeCache(provider, icon1);
|
||||
|
||||
// Check data that should have been updated because storeCache()
|
||||
// should call load function before first execution
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: false,
|
||||
});
|
||||
expect(count).toEqual({
|
||||
local: 2,
|
||||
session: 0,
|
||||
});
|
||||
expect(emptyList).toEqual({
|
||||
local: [],
|
||||
session: [],
|
||||
});
|
||||
|
||||
// Check cache
|
||||
expect(cache.getItem(cachePrefix + '0')).toBe(JSON.stringify(item0));
|
||||
expect(cache.getItem(cachePrefix + '1')).toBe(JSON.stringify(item1));
|
||||
expect(cache.getItem(countKey)).toBe('2');
|
||||
expect(cache.getItem(versionKey)).toBe(cacheVersion);
|
||||
});
|
||||
|
||||
it('Adding icon set on unused spot', () => {
|
||||
const prefix = nextPrefix();
|
||||
const cache = createCache();
|
||||
|
||||
// Add icon sets
|
||||
const icon0 = {
|
||||
prefix: prefix,
|
||||
icons: {
|
||||
foo0: {
|
||||
body: '<g></g>',
|
||||
},
|
||||
},
|
||||
};
|
||||
const item0 = {
|
||||
cached: Math.floor(Date.now() / hour),
|
||||
provider,
|
||||
data: icon0,
|
||||
};
|
||||
const icon1 = {
|
||||
prefix: prefix,
|
||||
icons: {
|
||||
foo: {
|
||||
body: '<g></g>',
|
||||
},
|
||||
},
|
||||
};
|
||||
const item1 = {
|
||||
cached: Math.floor(Date.now() / hour),
|
||||
provider,
|
||||
data: icon1,
|
||||
};
|
||||
|
||||
// Add item
|
||||
cache.setItem(versionKey, cacheVersion);
|
||||
cache.setItem(countKey, '2');
|
||||
cache.setItem(cachePrefix + '1', JSON.stringify(item1));
|
||||
|
||||
// Set cache
|
||||
reset({
|
||||
localStorage: cache,
|
||||
});
|
||||
|
||||
// Load data
|
||||
loadCache();
|
||||
|
||||
// Check data
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: false,
|
||||
});
|
||||
expect(count).toEqual({
|
||||
local: 2,
|
||||
session: 0,
|
||||
});
|
||||
expect(emptyList).toEqual({
|
||||
local: [0],
|
||||
session: [],
|
||||
});
|
||||
|
||||
// Save items
|
||||
storeCache(provider, icon0);
|
||||
|
||||
// Check data
|
||||
expect(count).toEqual({
|
||||
local: 2,
|
||||
session: 0,
|
||||
});
|
||||
expect(emptyList).toEqual({
|
||||
local: [],
|
||||
session: [],
|
||||
});
|
||||
|
||||
// Check cache
|
||||
expect(cache.getItem(cachePrefix + '0')).toBe(JSON.stringify(item0));
|
||||
expect(cache.getItem(cachePrefix + '1')).toBe(JSON.stringify(item1));
|
||||
expect(cache.getItem(countKey)).toBe('2');
|
||||
expect(cache.getItem(versionKey)).toBe(cacheVersion);
|
||||
});
|
||||
|
||||
it('Adding multiple icon sets to existing data', () => {
|
||||
const prefix = nextPrefix();
|
||||
const cache = createCache();
|
||||
|
||||
// Add icon sets
|
||||
const icons = [];
|
||||
const items = [];
|
||||
for (let i = 0; i < 12; i++) {
|
||||
const icon = {
|
||||
prefix: prefix,
|
||||
icons: {
|
||||
['foo' + i]: {
|
||||
body: '<g></g>',
|
||||
},
|
||||
},
|
||||
};
|
||||
const item = {
|
||||
cached: Math.floor(Date.now() / hour),
|
||||
provider,
|
||||
data: icon,
|
||||
};
|
||||
|
||||
// Make items 2 and 4 expire
|
||||
if (i === 2 || i === 4) {
|
||||
item.cached -= cacheExpiration + 1;
|
||||
}
|
||||
|
||||
// Change expiration for items 6 and 8 to almost expire
|
||||
if (i === 6 || i === 8) {
|
||||
item.cached -= cacheExpiration - 1;
|
||||
}
|
||||
|
||||
icons.push(icon);
|
||||
items.push(item);
|
||||
|
||||
// Skip items 1, 5, 9+
|
||||
if (i !== 1 && i !== 5 && i < 9) {
|
||||
cache.setItem(cachePrefix + i, JSON.stringify(item));
|
||||
}
|
||||
}
|
||||
|
||||
cache.setItem(versionKey, cacheVersion);
|
||||
cache.setItem(countKey, '10');
|
||||
|
||||
// Set cache
|
||||
reset({
|
||||
sessionStorage: cache,
|
||||
});
|
||||
|
||||
// Load data
|
||||
loadCache();
|
||||
|
||||
// Check data
|
||||
expect(config).toEqual({
|
||||
local: false,
|
||||
session: true,
|
||||
});
|
||||
expect(count).toEqual({
|
||||
local: 0,
|
||||
session: 9, // item 9 was missing
|
||||
});
|
||||
expect(emptyList).toEqual({
|
||||
local: [],
|
||||
// mix of expired and skipped items
|
||||
// reverse order, 9 should not be there because it is last item
|
||||
session: [5, 4, 2, 1],
|
||||
});
|
||||
expect(cache.getItem(countKey)).toBe('9');
|
||||
|
||||
// Check cached items
|
||||
[0, 3, 6, 7, 8].forEach((index) => {
|
||||
expect(cache.getItem(cachePrefix + index)).toBe(
|
||||
JSON.stringify(items[index])
|
||||
);
|
||||
});
|
||||
|
||||
// Check expired items - should have been deleted
|
||||
// Also check items that weren't supposed to be added
|
||||
[2, 4, 1, 5, 9, 10, 11, 12, 13].forEach((index) => {
|
||||
expect(cache.getItem(cachePrefix + index)).toBeNull();
|
||||
});
|
||||
|
||||
// Add item 5
|
||||
storeCache(provider, icons[5]);
|
||||
expect(count).toEqual({
|
||||
local: 0,
|
||||
session: 9,
|
||||
});
|
||||
expect(emptyList).toEqual({
|
||||
local: [],
|
||||
session: [4, 2, 1],
|
||||
});
|
||||
expect(cache.getItem(countKey)).toBe('9');
|
||||
|
||||
// Add items 4, 2, 1
|
||||
const list = [4, 2, 1];
|
||||
list.slice(0).forEach((index) => {
|
||||
expect(list.shift()).toBe(index);
|
||||
storeCache(provider, icons[index]);
|
||||
expect(count).toEqual({
|
||||
local: 0,
|
||||
session: 9,
|
||||
});
|
||||
expect(emptyList).toEqual({
|
||||
local: [],
|
||||
session: list,
|
||||
});
|
||||
expect(cache.getItem(countKey)).toBe('9');
|
||||
});
|
||||
|
||||
// Add item 10
|
||||
storeCache(provider, icons[10]);
|
||||
expect(count).toEqual({
|
||||
local: 0,
|
||||
session: 10,
|
||||
});
|
||||
expect(emptyList).toEqual({
|
||||
local: [],
|
||||
session: [],
|
||||
});
|
||||
expect(cache.getItem(countKey)).toBe('10');
|
||||
|
||||
// Add item 11
|
||||
storeCache(provider, icons[11]);
|
||||
expect(count).toEqual({
|
||||
local: 0,
|
||||
session: 11,
|
||||
});
|
||||
expect(emptyList).toEqual({
|
||||
local: [],
|
||||
session: [],
|
||||
});
|
||||
expect(cache.getItem(countKey)).toBe('11');
|
||||
});
|
||||
|
||||
it('Overwrite outdated data', () => {
|
||||
const prefix = nextPrefix();
|
||||
const cache = createCache();
|
||||
|
||||
// Add data in old format
|
||||
cache.setItem(versionKey, '1.0.6');
|
||||
cache.setItem(countKey, '3');
|
||||
for (let i = 0; i < 3; i++) {
|
||||
cache.setItem(
|
||||
cachePrefix + i,
|
||||
JSON.stringify({
|
||||
prefix: prefix,
|
||||
icons: {
|
||||
['foo' + i]: {
|
||||
body: '<g></g>',
|
||||
},
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
// Set cache
|
||||
reset({
|
||||
localStorage: cache,
|
||||
});
|
||||
|
||||
// Check icon storage
|
||||
const icons = getStorage(provider, prefix);
|
||||
expect(iconExists(icons, 'foo1')).toBe(false);
|
||||
|
||||
// Load cache
|
||||
loadCache();
|
||||
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: false,
|
||||
});
|
||||
expect(count).toEqual({
|
||||
local: 0,
|
||||
session: 0,
|
||||
});
|
||||
expect(emptyList).toEqual({
|
||||
local: [],
|
||||
session: [],
|
||||
});
|
||||
|
||||
// Add one icon set
|
||||
const icon = {
|
||||
prefix: prefix,
|
||||
icons: {
|
||||
foo: {
|
||||
body: '<g></g>',
|
||||
},
|
||||
},
|
||||
};
|
||||
const item = {
|
||||
cached: Math.floor(Date.now() / hour),
|
||||
provider,
|
||||
data: icon,
|
||||
};
|
||||
|
||||
// Save item
|
||||
storeCache(provider, icon);
|
||||
|
||||
// Storing in cache should not add item to storage
|
||||
expect(iconExists(icons, 'foo')).toBe(false);
|
||||
|
||||
// Check data that should have been updated because storeCache()
|
||||
// should call load function before first execution
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: false,
|
||||
});
|
||||
expect(count).toEqual({
|
||||
local: 1,
|
||||
session: 0,
|
||||
});
|
||||
expect(emptyList).toEqual({
|
||||
local: [],
|
||||
session: [],
|
||||
});
|
||||
|
||||
// Check cache
|
||||
expect(cache.getItem(cachePrefix + '0')).toBe(JSON.stringify(item));
|
||||
expect(cache.getItem(countKey)).toBe('1');
|
||||
expect(cache.getItem(versionKey)).toBe(cacheVersion);
|
||||
});
|
||||
|
||||
it('Using both storage options', () => {
|
||||
const prefix = nextPrefix();
|
||||
const cache1 = createCache();
|
||||
const cache2 = createCache();
|
||||
|
||||
// Add icon sets to localStorage
|
||||
cache1.setItem(versionKey, cacheVersion);
|
||||
cache1.setItem(countKey, '3');
|
||||
[0, 1, 2].forEach((index) => {
|
||||
const icon = {
|
||||
prefix: prefix,
|
||||
icons: {
|
||||
['foo' + index]: {
|
||||
body: '<g></g>',
|
||||
},
|
||||
},
|
||||
};
|
||||
const item = {
|
||||
cached: Math.floor(Date.now() / hour),
|
||||
provider,
|
||||
data: icon,
|
||||
};
|
||||
cache1.setItem(cachePrefix + index, JSON.stringify(item));
|
||||
});
|
||||
|
||||
// Add icon sets to sessionStorage
|
||||
cache2.setItem(versionKey, cacheVersion);
|
||||
cache2.setItem(countKey, '4');
|
||||
[0, 1, 2, 3].forEach((index) => {
|
||||
const icon = {
|
||||
prefix: prefix,
|
||||
icons: {
|
||||
['bar' + index]: {
|
||||
body: '<g></g>',
|
||||
},
|
||||
},
|
||||
};
|
||||
const item = {
|
||||
cached: Math.floor(Date.now() / hour),
|
||||
provider,
|
||||
data: icon,
|
||||
};
|
||||
cache2.setItem(cachePrefix + index, JSON.stringify(item));
|
||||
});
|
||||
|
||||
// Set cache
|
||||
reset({
|
||||
localStorage: cache1,
|
||||
sessionStorage: cache2,
|
||||
});
|
||||
|
||||
// Load data
|
||||
loadCache();
|
||||
|
||||
// Check data
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: true,
|
||||
});
|
||||
expect(count).toEqual({
|
||||
local: 3,
|
||||
session: 4,
|
||||
});
|
||||
expect(emptyList).toEqual({
|
||||
local: [],
|
||||
session: [],
|
||||
});
|
||||
|
||||
// Check icon storage
|
||||
const iconsStorage = getStorage(provider, prefix);
|
||||
for (let i = 0; i < count.local; i++) {
|
||||
expect(iconExists(iconsStorage, 'foo' + i)).toBe(true);
|
||||
}
|
||||
for (let i = 0; i < count.session; i++) {
|
||||
expect(iconExists(iconsStorage, 'bar' + i)).toBe(true);
|
||||
}
|
||||
|
||||
// Add new item to localStorage
|
||||
const icon = {
|
||||
prefix: prefix,
|
||||
icons: {
|
||||
'new-icon': {
|
||||
body: '<g></g>',
|
||||
},
|
||||
},
|
||||
};
|
||||
const item = {
|
||||
cached: Math.floor(Date.now() / hour),
|
||||
provider,
|
||||
data: icon,
|
||||
};
|
||||
storeCache(provider, icon);
|
||||
|
||||
// Check data
|
||||
expect(count).toEqual({
|
||||
local: 4, // +1
|
||||
session: 4,
|
||||
});
|
||||
expect(emptyList).toEqual({
|
||||
local: [],
|
||||
session: [],
|
||||
});
|
||||
|
||||
// Check cache
|
||||
expect(cache1.getItem(cachePrefix + '3')).toBe(JSON.stringify(item));
|
||||
});
|
||||
|
||||
it('Using both storage options, but localStorage is read only', () => {
|
||||
const prefix = nextPrefix();
|
||||
const cache1 = createCache();
|
||||
const cache2 = createCache();
|
||||
|
||||
// Add icon sets to localStorage
|
||||
cache1.setItem(versionKey, cacheVersion);
|
||||
cache1.setItem(countKey, '3');
|
||||
[0, 1, 2].forEach((index) => {
|
||||
const icon = {
|
||||
prefix: prefix,
|
||||
icons: {
|
||||
['foo' + index]: {
|
||||
body: '<g></g>',
|
||||
},
|
||||
},
|
||||
};
|
||||
const item = {
|
||||
cached: Math.floor(Date.now() / hour),
|
||||
provider,
|
||||
data: icon,
|
||||
};
|
||||
cache1.setItem(cachePrefix + index, JSON.stringify(item));
|
||||
});
|
||||
|
||||
// Add icon sets to sessionStorage
|
||||
cache2.setItem(versionKey, cacheVersion);
|
||||
cache2.setItem(countKey, '4');
|
||||
[0, 1, 2, 3].forEach((index) => {
|
||||
const icon = {
|
||||
prefix: prefix,
|
||||
icons: {
|
||||
['bar' + index]: {
|
||||
body: '<g></g>',
|
||||
},
|
||||
},
|
||||
};
|
||||
const item = {
|
||||
cached: Math.floor(Date.now() / hour),
|
||||
provider,
|
||||
data: icon,
|
||||
};
|
||||
cache2.setItem(cachePrefix + index, JSON.stringify(item));
|
||||
});
|
||||
|
||||
// Set cache
|
||||
reset({
|
||||
localStorage: cache1,
|
||||
sessionStorage: cache2,
|
||||
});
|
||||
|
||||
// Load data
|
||||
loadCache();
|
||||
|
||||
// Check data
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: true,
|
||||
});
|
||||
expect(count).toEqual({
|
||||
local: 3,
|
||||
session: 4,
|
||||
});
|
||||
expect(emptyList).toEqual({
|
||||
local: [],
|
||||
session: [],
|
||||
});
|
||||
|
||||
// Check icon storage
|
||||
const iconsStorage = getStorage(provider, prefix);
|
||||
for (let i = 0; i < count.local; i++) {
|
||||
expect(iconExists(iconsStorage, 'foo' + i)).toBe(true);
|
||||
}
|
||||
for (let i = 0; i < count.session; i++) {
|
||||
expect(iconExists(iconsStorage, 'bar' + i)).toBe(true);
|
||||
}
|
||||
|
||||
// Set localStorage to read-only
|
||||
cache1.canWrite = false;
|
||||
|
||||
// Add new item to localStorage
|
||||
const icon = {
|
||||
prefix: prefix,
|
||||
icons: {
|
||||
'new-icon': {
|
||||
body: '<g></g>',
|
||||
},
|
||||
},
|
||||
};
|
||||
const item = {
|
||||
cached: Math.floor(Date.now() / hour),
|
||||
provider,
|
||||
data: icon,
|
||||
};
|
||||
storeCache(provider, icon);
|
||||
|
||||
// Check data
|
||||
expect(count).toEqual({
|
||||
local: 3,
|
||||
session: 5,
|
||||
});
|
||||
expect(emptyList).toEqual({
|
||||
local: [],
|
||||
session: [],
|
||||
});
|
||||
|
||||
// Check cache
|
||||
expect(cache2.getItem(cachePrefix + '4')).toBe(JSON.stringify(item));
|
||||
});
|
||||
});
|
148
packages/core/spec/modules/storageSpec.mjs
Normal file
148
packages/core/spec/modules/storageSpec.mjs
Normal file
@ -0,0 +1,148 @@
|
||||
import { fullIcon } from '@iconify/utils/lib/icon';
|
||||
import {
|
||||
storageFunctions,
|
||||
allowSimpleNames,
|
||||
} from '@iconify/core/lib/storage/functions';
|
||||
|
||||
describe('Testing IconifyStorageFunctions', () => {
|
||||
let count = 0;
|
||||
|
||||
function nextProvider() {
|
||||
return 'storage-test-' + count++;
|
||||
}
|
||||
|
||||
it('Storage functions', () => {
|
||||
const provider = nextProvider();
|
||||
const testName = `@${provider}:foo:bar`;
|
||||
|
||||
// Empty
|
||||
expect(storageFunctions.iconExists(testName)).toBe(false);
|
||||
expect(storageFunctions.getIcon(testName)).toBeNull();
|
||||
expect(storageFunctions.listIcons(provider)).toEqual([]);
|
||||
|
||||
// Add and test one icon
|
||||
expect(
|
||||
storageFunctions.addIcon(testName, {
|
||||
body: '<g />',
|
||||
})
|
||||
).toBe(true);
|
||||
expect(storageFunctions.iconExists(testName)).toBe(true);
|
||||
expect(storageFunctions.listIcons(provider)).toEqual([testName]);
|
||||
});
|
||||
|
||||
it('Invalid icon name', () => {
|
||||
const testName = 'storage' + count++;
|
||||
|
||||
// Reset module
|
||||
allowSimpleNames(false);
|
||||
|
||||
// Empty
|
||||
expect(storageFunctions.iconExists(testName)).toBe(false);
|
||||
expect(storageFunctions.getIcon(testName)).toBeNull();
|
||||
|
||||
// Add and test one icon (icon should not be added)
|
||||
expect(
|
||||
storageFunctions.addIcon(testName, {
|
||||
body: '<g />',
|
||||
})
|
||||
).toBe(false);
|
||||
expect(storageFunctions.iconExists(testName)).toBe(false);
|
||||
});
|
||||
|
||||
it('Invalid icon set', () => {
|
||||
// Reset module
|
||||
allowSimpleNames(false);
|
||||
|
||||
// Icon set without prefix (should work only when simple names are allowed, tested later in this file)
|
||||
expect(
|
||||
storageFunctions.addCollection({
|
||||
prefix: '',
|
||||
icons: {
|
||||
foo: {
|
||||
body: '<g />',
|
||||
},
|
||||
},
|
||||
})
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it('Simple icon name', () => {
|
||||
const testName = 'storage' + count++;
|
||||
|
||||
// Enable empty storage
|
||||
allowSimpleNames(true);
|
||||
|
||||
// Empty
|
||||
expect(storageFunctions.iconExists(testName)).toBe(false);
|
||||
expect(storageFunctions.getIcon(testName)).toBeNull();
|
||||
|
||||
// Add and test one icon
|
||||
expect(
|
||||
storageFunctions.addIcon(testName, {
|
||||
body: '<g />',
|
||||
})
|
||||
).toBe(true);
|
||||
expect(storageFunctions.iconExists(testName)).toBe(true);
|
||||
|
||||
// Reset config after test
|
||||
allowSimpleNames(false);
|
||||
});
|
||||
|
||||
it('Collection with simple icon name', () => {
|
||||
const n = count++;
|
||||
const n2 = count++;
|
||||
let name;
|
||||
|
||||
// Enable empty storage
|
||||
allowSimpleNames(true);
|
||||
|
||||
// Add icon set
|
||||
const name1 = 'test' + n;
|
||||
const prefix2 = `prefixed${n}`;
|
||||
const name2 = `icon${n2}`;
|
||||
expect(
|
||||
storageFunctions.addCollection({
|
||||
prefix: '',
|
||||
icons: {
|
||||
[name1]: {
|
||||
body: '<g data-icon="basic-icon" />',
|
||||
},
|
||||
[`${prefix2}-${name2}`]: {
|
||||
body: '<g data-icon="prefixed-icon" />',
|
||||
},
|
||||
},
|
||||
})
|
||||
).toBe(true);
|
||||
|
||||
// Test 'test'
|
||||
name = name1;
|
||||
expect(storageFunctions.iconExists(name)).toBe(true);
|
||||
expect(storageFunctions.getIcon(name)).toEqual(
|
||||
fullIcon({
|
||||
body: '<g data-icon="basic-icon" />',
|
||||
})
|
||||
);
|
||||
|
||||
// Test prefixed icon, using ':' separator
|
||||
name = `${prefix2}:${name2}`;
|
||||
expect(storageFunctions.listIcons('', prefix2)).toEqual([name]);
|
||||
expect(storageFunctions.iconExists(name)).toBe(true);
|
||||
expect(storageFunctions.getIcon(name)).toEqual(
|
||||
fullIcon({
|
||||
body: '<g data-icon="prefixed-icon" />',
|
||||
})
|
||||
);
|
||||
|
||||
// Test prefixed icon, using '-' separator
|
||||
name = `${prefix2}-${name2}`;
|
||||
expect(storageFunctions.iconExists(name)).toBe(true);
|
||||
expect(storageFunctions.getIcon(name)).toEqual(
|
||||
fullIcon({
|
||||
body: '<g data-icon="prefixed-icon" />',
|
||||
})
|
||||
);
|
||||
|
||||
// Reset config after test
|
||||
allowSimpleNames(false);
|
||||
});
|
||||
});
|
7
packages/core/spec/support/jasmine.json
Normal file
7
packages/core/spec/support/jasmine.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"spec_dir": "spec",
|
||||
"spec_files": ["**/*[sS]pec.?(m)js"],
|
||||
"helpers": ["helpers/**/*.?(m)js"],
|
||||
"stopSpecOnExpectationFailure": false,
|
||||
"random": true
|
||||
}
|
@ -1,13 +1,13 @@
|
||||
import type { IconifyJSON } from '@iconify/types';
|
||||
import type {
|
||||
IconifyIconName,
|
||||
IconifyIconSource,
|
||||
} from '@iconify/utils/lib/icon/name';
|
||||
import type { SortedIcons } from '../icon/sort';
|
||||
import { sortIcons } from '../icon/sort';
|
||||
import { storeCallback, updateCallbacks } from './callbacks';
|
||||
import { getAPIModule } from './modules';
|
||||
import { getStorage, addIconSet } from '../storage/storage';
|
||||
import type {
|
||||
IconifyIconName,
|
||||
IconifyIconSource,
|
||||
} from '@iconify/utils/lib/icon/name';
|
||||
import { listToIcons } from '../icon/list';
|
||||
import { allowSimpleNames } from '../storage/functions';
|
||||
import { sendAPIQuery } from './query';
|
||||
|
@ -1,7 +0,0 @@
|
||||
{
|
||||
"extends": "../tsconfig-base.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "../lib",
|
||||
"rootDir": "."
|
||||
}
|
||||
}
|
@ -1,7 +1,3 @@
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars-experimental */
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import {
|
||||
callbacks,
|
||||
updateCallbacks,
|
||||
@ -25,36 +21,34 @@ describe('Testing API callbacks', () => {
|
||||
const storage = getStorage(provider, prefix);
|
||||
const abort = storeCallback(
|
||||
(loaded, missing, pending, unsubscribe) => {
|
||||
expect(unsubscribe).to.be.equal(abort);
|
||||
expect(unsubscribe).toBe(abort);
|
||||
|
||||
counter++;
|
||||
switch (counter) {
|
||||
case 1:
|
||||
// First run - icon1 should be loaded, icon3 should be missing
|
||||
expect(loaded).to.be.eql([
|
||||
expect(loaded).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'icon1',
|
||||
},
|
||||
]);
|
||||
expect(missing).to.be.eql([
|
||||
expect(missing).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'icon3',
|
||||
},
|
||||
]);
|
||||
expect(pending).to.be.eql([
|
||||
expect(pending).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'icon2',
|
||||
},
|
||||
]);
|
||||
expect(callbacks[provider][prefix].length).to.be.equal(
|
||||
1
|
||||
);
|
||||
expect(callbacks[provider][prefix].length).toBe(1);
|
||||
|
||||
// Add icon2 and trigger update
|
||||
addIconSet(storage, {
|
||||
@ -71,7 +65,7 @@ describe('Testing API callbacks', () => {
|
||||
|
||||
case 2:
|
||||
// Second run - icon2 should be added, completing callback
|
||||
expect(loaded).to.be.eql([
|
||||
expect(loaded).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
@ -83,17 +77,15 @@ describe('Testing API callbacks', () => {
|
||||
name: 'icon2',
|
||||
},
|
||||
]);
|
||||
expect(missing).to.be.eql([
|
||||
expect(missing).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'icon3',
|
||||
},
|
||||
]);
|
||||
expect(pending).to.be.eql([]);
|
||||
expect(callbacks[provider][prefix].length).to.be.equal(
|
||||
0
|
||||
);
|
||||
expect(pending).toEqual([]);
|
||||
expect(callbacks[provider][prefix].length).toBe(0);
|
||||
done();
|
||||
}
|
||||
},
|
||||
@ -123,7 +115,7 @@ describe('Testing API callbacks', () => {
|
||||
);
|
||||
|
||||
// Test callbacks
|
||||
expect(callbacks[provider][prefix].length).to.be.equal(1);
|
||||
expect(callbacks[provider][prefix].length).toBe(1);
|
||||
|
||||
// Test update - should do nothing
|
||||
updateCallbacks(provider, prefix);
|
||||
@ -131,7 +123,7 @@ describe('Testing API callbacks', () => {
|
||||
// Wait for tick because updateCallbacks will use one
|
||||
setTimeout(() => {
|
||||
// Callback should not have been called yet
|
||||
expect(counter).to.be.equal(0);
|
||||
expect(counter).toBe(0);
|
||||
|
||||
// Add few icons and run updateCallbacks
|
||||
addIconSet(storage, {
|
||||
@ -166,7 +158,7 @@ describe('Testing API callbacks', () => {
|
||||
});
|
||||
|
||||
storeCallback(
|
||||
(loaded, missing, pending, unsubscribe) => {
|
||||
() => {
|
||||
throw new Error('This code should not be executed!');
|
||||
},
|
||||
sortIcons([
|
||||
@ -195,7 +187,7 @@ describe('Testing API callbacks', () => {
|
||||
);
|
||||
|
||||
// callbacks should not have been initialised
|
||||
expect(callbacks[prefix]).to.be.equal(void 0);
|
||||
expect(callbacks[prefix]).toBeUndefined();
|
||||
});
|
||||
|
||||
it('Cancel callback', (done) => {
|
||||
@ -206,34 +198,34 @@ describe('Testing API callbacks', () => {
|
||||
const storage = getStorage(provider, prefix);
|
||||
const abort = storeCallback(
|
||||
(loaded, missing, pending, unsubscribe) => {
|
||||
expect(unsubscribe).to.be.equal(abort);
|
||||
expect(unsubscribe).toBe(abort);
|
||||
|
||||
counter++;
|
||||
expect(counter).to.be.equal(1);
|
||||
expect(counter).toBe(1);
|
||||
|
||||
// First run - icon1 should be loaded, icon3 should be missing
|
||||
expect(loaded).to.be.eql([
|
||||
expect(loaded).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'icon1',
|
||||
},
|
||||
]);
|
||||
expect(missing).to.be.eql([
|
||||
expect(missing).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'icon3',
|
||||
},
|
||||
]);
|
||||
expect(pending).to.be.eql([
|
||||
expect(pending).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'icon2',
|
||||
},
|
||||
]);
|
||||
expect(callbacks[provider][prefix].length).to.be.equal(1);
|
||||
expect(callbacks[provider][prefix].length).toBe(1);
|
||||
|
||||
// Add icon2 and trigger update
|
||||
addIconSet(storage, {
|
||||
@ -249,7 +241,7 @@ describe('Testing API callbacks', () => {
|
||||
|
||||
// Unsubscribe and set timer to call done()
|
||||
unsubscribe();
|
||||
expect(callbacks[provider][prefix].length).to.be.equal(0);
|
||||
expect(callbacks[provider][prefix].length).toBe(0);
|
||||
setTimeout(done);
|
||||
},
|
||||
sortIcons([
|
||||
@ -278,7 +270,7 @@ describe('Testing API callbacks', () => {
|
||||
);
|
||||
|
||||
// Test callbacks
|
||||
expect(callbacks[provider][prefix].length).to.be.equal(1);
|
||||
expect(callbacks[provider][prefix].length).toBe(1);
|
||||
|
||||
// Test update - should do nothing
|
||||
updateCallbacks(provider, prefix);
|
||||
@ -286,7 +278,7 @@ describe('Testing API callbacks', () => {
|
||||
// Wait for tick because updateCallbacks will use one
|
||||
setTimeout(() => {
|
||||
// Callback should not have been called yet
|
||||
expect(counter).to.be.equal(0);
|
||||
expect(counter).toBe(0);
|
||||
|
||||
// Add few icons and run updateCallbacks
|
||||
addIconSet(storage, {
|
||||
@ -313,39 +305,35 @@ describe('Testing API callbacks', () => {
|
||||
|
||||
const abort = storeCallback(
|
||||
(loaded, missing, pending, unsubscribe) => {
|
||||
expect(unsubscribe).to.be.equal(abort);
|
||||
expect(unsubscribe).toBe(abort);
|
||||
|
||||
counter++;
|
||||
switch (counter) {
|
||||
case 1:
|
||||
// First run - icon1 should be loaded, icon3 should be missing
|
||||
expect(loaded).to.be.eql([
|
||||
expect(loaded).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix: prefix1,
|
||||
name: 'icon1',
|
||||
},
|
||||
]);
|
||||
expect(missing).to.be.eql([
|
||||
expect(missing).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix: prefix1,
|
||||
name: 'icon3',
|
||||
},
|
||||
]);
|
||||
expect(pending).to.be.eql([
|
||||
expect(pending).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix: prefix2,
|
||||
name: 'icon2',
|
||||
},
|
||||
]);
|
||||
expect(callbacks[provider][prefix1].length).to.be.equal(
|
||||
0
|
||||
);
|
||||
expect(callbacks[provider][prefix2].length).to.be.equal(
|
||||
1
|
||||
);
|
||||
expect(callbacks[provider][prefix1].length).toBe(0);
|
||||
expect(callbacks[provider][prefix2].length).toBe(1);
|
||||
|
||||
// Add icon2 and trigger update
|
||||
addIconSet(storage2, {
|
||||
@ -362,12 +350,8 @@ describe('Testing API callbacks', () => {
|
||||
|
||||
case 2:
|
||||
// Second run - icon2 should be loaded
|
||||
expect(callbacks[provider][prefix1].length).to.be.equal(
|
||||
0
|
||||
);
|
||||
expect(callbacks[provider][prefix2].length).to.be.equal(
|
||||
0
|
||||
);
|
||||
expect(callbacks[provider][prefix1].length).toBe(0);
|
||||
expect(callbacks[provider][prefix2].length).toBe(0);
|
||||
done();
|
||||
break;
|
||||
|
||||
@ -399,8 +383,8 @@ describe('Testing API callbacks', () => {
|
||||
);
|
||||
|
||||
// Test callbacks
|
||||
expect(callbacks[provider][prefix1].length).to.be.equal(1);
|
||||
expect(callbacks[provider][prefix2].length).to.be.equal(1);
|
||||
expect(callbacks[provider][prefix1].length).toBe(1);
|
||||
expect(callbacks[provider][prefix2].length).toBe(1);
|
||||
|
||||
// Test update - should do nothing
|
||||
updateCallbacks(provider, prefix1);
|
||||
@ -408,7 +392,7 @@ describe('Testing API callbacks', () => {
|
||||
// Wait for tick because updateCallbacks will use one
|
||||
setTimeout(() => {
|
||||
// Callback should not have been called yet
|
||||
expect(counter).to.be.equal(0);
|
||||
expect(counter).toBe(0);
|
||||
|
||||
// Add few icons and run updateCallbacks
|
||||
addIconSet(storage1, {
|
||||
@ -436,47 +420,39 @@ describe('Testing API callbacks', () => {
|
||||
|
||||
const abort = storeCallback(
|
||||
(loaded, missing, pending, unsubscribe) => {
|
||||
expect(unsubscribe).to.be.equal(abort);
|
||||
expect(unsubscribe).toBe(abort);
|
||||
|
||||
counter++;
|
||||
switch (counter) {
|
||||
case 1:
|
||||
// First run - icon1 should be loaded, icon3 should be missing
|
||||
expect(loaded).to.be.eql([
|
||||
expect(loaded).toEqual([
|
||||
{
|
||||
provider: provider1,
|
||||
prefix: prefix1,
|
||||
name: 'icon1',
|
||||
},
|
||||
]);
|
||||
expect(missing).to.be.eql([
|
||||
expect(missing).toEqual([
|
||||
{
|
||||
provider: provider1,
|
||||
prefix: prefix1,
|
||||
name: 'icon3',
|
||||
},
|
||||
]);
|
||||
expect(pending).to.be.eql([
|
||||
expect(pending).toEqual([
|
||||
{
|
||||
provider: provider2,
|
||||
prefix: prefix2,
|
||||
name: 'icon2',
|
||||
},
|
||||
]);
|
||||
expect(
|
||||
callbacks[provider1][prefix1].length
|
||||
).to.be.equal(0);
|
||||
expect(
|
||||
callbacks[provider2][prefix2].length
|
||||
).to.be.equal(1);
|
||||
expect(callbacks[provider1][prefix1].length).toBe(0);
|
||||
expect(callbacks[provider2][prefix2].length).toBe(1);
|
||||
|
||||
// Make sure providers/prefixes aren't mixed
|
||||
expect(callbacks[provider1][prefix2]).to.be.equal(
|
||||
void 0
|
||||
);
|
||||
expect(callbacks[provider2][prefix1]).to.be.equal(
|
||||
void 0
|
||||
);
|
||||
expect(callbacks[provider1][prefix2]).toBeUndefined();
|
||||
expect(callbacks[provider2][prefix1]).toBeUndefined();
|
||||
|
||||
// Add icon2 and trigger update
|
||||
addIconSet(storage2, {
|
||||
@ -493,20 +469,12 @@ describe('Testing API callbacks', () => {
|
||||
|
||||
case 2:
|
||||
// Second run - icon2 should be loaded
|
||||
expect(
|
||||
callbacks[provider1][prefix1].length
|
||||
).to.be.equal(0);
|
||||
expect(
|
||||
callbacks[provider2][prefix2].length
|
||||
).to.be.equal(0);
|
||||
expect(callbacks[provider1][prefix1].length).toBe(0);
|
||||
expect(callbacks[provider2][prefix2].length).toBe(0);
|
||||
|
||||
// Make sure providers/prefixes aren't mixed
|
||||
expect(callbacks[provider1][prefix2]).to.be.equal(
|
||||
void 0
|
||||
);
|
||||
expect(callbacks[provider2][prefix1]).to.be.equal(
|
||||
void 0
|
||||
);
|
||||
expect(callbacks[provider1][prefix2]).toBeUndefined();
|
||||
expect(callbacks[provider2][prefix1]).toBeUndefined();
|
||||
|
||||
done();
|
||||
break;
|
||||
@ -539,11 +507,11 @@ describe('Testing API callbacks', () => {
|
||||
);
|
||||
|
||||
// Test callbacks
|
||||
expect(callbacks[provider1][prefix1].length).to.be.equal(1);
|
||||
expect(callbacks[provider2][prefix2].length).to.be.equal(1);
|
||||
expect(callbacks[provider1][prefix1].length).toBe(1);
|
||||
expect(callbacks[provider2][prefix2].length).toBe(1);
|
||||
|
||||
expect(callbacks[provider1][prefix2]).to.be.equal(void 0);
|
||||
expect(callbacks[provider2][prefix1]).to.be.equal(void 0);
|
||||
expect(callbacks[provider1][prefix2]).toBeUndefined();
|
||||
expect(callbacks[provider2][prefix1]).toBeUndefined();
|
||||
|
||||
// Test update - should do nothing
|
||||
updateCallbacks(provider1, prefix1);
|
||||
@ -551,7 +519,7 @@ describe('Testing API callbacks', () => {
|
||||
// Wait for tick because updateCallbacks will use one
|
||||
setTimeout(() => {
|
||||
// Callback should not have been called yet
|
||||
expect(counter).to.be.equal(0);
|
||||
expect(counter).toBe(0);
|
||||
|
||||
// Add few icons and run updateCallbacks
|
||||
addIconSet(storage1, {
|
@ -1,7 +1,3 @@
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars-experimental */
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import crossFetch from 'cross-fetch';
|
||||
import { sendAPIQuery } from '../../lib/api/query';
|
||||
import { setAPIModule } from '../../lib/api/modules';
|
||||
@ -18,12 +14,12 @@ describe('Testing live API with fetch', () => {
|
||||
const host = 'https://api.iconify.design';
|
||||
|
||||
// Set fetch module
|
||||
before(() => {
|
||||
beforeEach(() => {
|
||||
setFetch(crossFetch);
|
||||
setAPIModule('', fetchAPIModule);
|
||||
});
|
||||
|
||||
after(() => {
|
||||
afterAll(() => {
|
||||
setAPIModule('', mockAPIModule);
|
||||
});
|
||||
|
||||
@ -37,8 +33,8 @@ describe('Testing live API with fetch', () => {
|
||||
uri: '/collections',
|
||||
},
|
||||
(data, error) => {
|
||||
expect(error).to.be.equal(424);
|
||||
expect(data).to.be.equal(void 0);
|
||||
expect(error).toBe(424);
|
||||
expect(data).toBeUndefined();
|
||||
done();
|
||||
}
|
||||
);
|
||||
@ -50,7 +46,7 @@ describe('Testing live API with fetch', () => {
|
||||
setAPIConfig(provider, {
|
||||
resources: [host],
|
||||
})
|
||||
).to.be.equal(true);
|
||||
).toBe(true);
|
||||
|
||||
sendAPIQuery(
|
||||
provider,
|
||||
@ -60,8 +56,8 @@ describe('Testing live API with fetch', () => {
|
||||
uri: '/collections',
|
||||
},
|
||||
(data, error) => {
|
||||
expect(error).to.be.equal(void 0);
|
||||
expect(typeof data).to.be.equal('object');
|
||||
expect(error).toBeUndefined();
|
||||
expect(typeof data).toBe('object');
|
||||
done();
|
||||
}
|
||||
);
|
||||
@ -77,8 +73,8 @@ describe('Testing live API with fetch', () => {
|
||||
uri: '/collections',
|
||||
},
|
||||
(data, error) => {
|
||||
expect(error).to.be.equal(void 0);
|
||||
expect(typeof data).to.be.equal('object');
|
||||
expect(error).toBeUndefined();
|
||||
expect(typeof data).toBe('object');
|
||||
done();
|
||||
}
|
||||
);
|
@ -1,7 +1,3 @@
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars-experimental */
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import type { PendingQueryItem } from '@iconify/api-redundancy';
|
||||
import { setAPIConfig } from '../../lib/api/config';
|
||||
import type {
|
||||
@ -44,7 +40,7 @@ describe('Testing API loadIcons', () => {
|
||||
};
|
||||
|
||||
// This callback should be called first
|
||||
expect(asyncCounter).to.be.equal(1);
|
||||
expect(asyncCounter).toBe(1);
|
||||
asyncCounter++;
|
||||
|
||||
// Test input and return as one item
|
||||
@ -54,7 +50,7 @@ describe('Testing API loadIcons', () => {
|
||||
prefix,
|
||||
icons: ['icon1', 'icon2'],
|
||||
};
|
||||
expect(item).to.be.eql(expected);
|
||||
expect(item).toEqual(expected);
|
||||
|
||||
return [item];
|
||||
};
|
||||
@ -65,20 +61,20 @@ describe('Testing API loadIcons', () => {
|
||||
item: PendingQueryItem
|
||||
): void => {
|
||||
// This callback should be called after prepareQuery
|
||||
expect(asyncCounter).to.be.equal(2);
|
||||
expect(asyncCounter).toBe(2);
|
||||
asyncCounter++;
|
||||
|
||||
expect(params.type).to.be.equal('icons');
|
||||
expect(params.type).toBe('icons');
|
||||
|
||||
// Test input
|
||||
expect(host).to.be.equal('https://api1.local');
|
||||
expect(host).toBe('https://api1.local');
|
||||
const expected: IconifyAPIQueryParams = {
|
||||
type: 'icons',
|
||||
provider,
|
||||
prefix,
|
||||
icons: ['icon1', 'icon2'],
|
||||
};
|
||||
expect(params).to.be.eql(expected);
|
||||
expect(params).toEqual(expected);
|
||||
|
||||
// Send data
|
||||
item.done({
|
||||
@ -94,7 +90,7 @@ describe('Testing API loadIcons', () => {
|
||||
});
|
||||
|
||||
// Counter should not have increased after status.done() call becuse parsing result should be done on next tick
|
||||
expect(asyncCounter).to.be.equal(3);
|
||||
expect(asyncCounter).toBe(3);
|
||||
};
|
||||
|
||||
setAPIModule(provider, {
|
||||
@ -114,12 +110,12 @@ describe('Testing API loadIcons', () => {
|
||||
// as string
|
||||
provider + ':' + prefix + ':icon2',
|
||||
],
|
||||
(loaded, missing, pending, unsubscribe) => {
|
||||
(loaded, missing, pending) => {
|
||||
// This callback should be called last
|
||||
expect(asyncCounter).to.be.equal(3);
|
||||
expect(asyncCounter).toBe(3);
|
||||
asyncCounter++;
|
||||
|
||||
expect(loaded).to.be.eql([
|
||||
expect(loaded).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
@ -131,8 +127,8 @@ describe('Testing API loadIcons', () => {
|
||||
name: 'icon2',
|
||||
},
|
||||
]);
|
||||
expect(missing).to.be.eql([]);
|
||||
expect(pending).to.be.eql([]);
|
||||
expect(missing).toEqual([]);
|
||||
expect(pending).toEqual([]);
|
||||
|
||||
expect(
|
||||
isPending({
|
||||
@ -140,25 +136,21 @@ describe('Testing API loadIcons', () => {
|
||||
prefix,
|
||||
name: 'icon1',
|
||||
})
|
||||
).to.be.equal(false);
|
||||
expect(
|
||||
isPending({ provider, prefix, name: 'icon3' })
|
||||
).to.be.equal(false);
|
||||
).toBe(false);
|
||||
expect(isPending({ provider, prefix, name: 'icon3' })).toBe(
|
||||
false
|
||||
);
|
||||
|
||||
done();
|
||||
}
|
||||
);
|
||||
|
||||
// Test isPending
|
||||
expect(isPending({ provider, prefix, name: 'icon1' })).to.be.equal(
|
||||
true
|
||||
);
|
||||
expect(isPending({ provider, prefix, name: 'icon3' })).to.be.equal(
|
||||
false
|
||||
);
|
||||
expect(isPending({ provider, prefix, name: 'icon1' })).toBe(true);
|
||||
expect(isPending({ provider, prefix, name: 'icon3' })).toBe(false);
|
||||
|
||||
// Make sure asyncCounter wasn't increased because loading shoud happen on next tick
|
||||
expect(asyncCounter).to.be.equal(0);
|
||||
expect(asyncCounter).toBe(0);
|
||||
asyncCounter++;
|
||||
});
|
||||
|
||||
@ -189,7 +181,7 @@ describe('Testing API loadIcons', () => {
|
||||
results.push(item);
|
||||
});
|
||||
|
||||
expect(results.length).to.be.equal(2);
|
||||
expect(results.length).toBe(2);
|
||||
|
||||
return results;
|
||||
};
|
||||
@ -201,9 +193,9 @@ describe('Testing API loadIcons', () => {
|
||||
item: PendingQueryItem
|
||||
): void => {
|
||||
// Test input
|
||||
expect(host).to.be.equal('https://api1.local');
|
||||
expect(host).toBe('https://api1.local');
|
||||
|
||||
expect(params.type).to.be.equal('icons');
|
||||
expect(params.type).toBe('icons');
|
||||
if (params.type !== 'icons') {
|
||||
return;
|
||||
}
|
||||
@ -216,7 +208,7 @@ describe('Testing API loadIcons', () => {
|
||||
prefix,
|
||||
icons: ['icon' + queryCounter],
|
||||
};
|
||||
expect(params).to.be.eql(expected);
|
||||
expect(params).toEqual(expected);
|
||||
|
||||
// Send only requested icons
|
||||
const icons = Object.create(null);
|
||||
@ -245,13 +237,13 @@ describe('Testing API loadIcons', () => {
|
||||
provider + ':' + prefix + ':icon1',
|
||||
provider + ':' + prefix + ':icon2',
|
||||
],
|
||||
(loaded, missing, pending, unsubscribe) => {
|
||||
(loaded, missing, pending) => {
|
||||
// Callback should be called only once because results should be sent in same tick
|
||||
expect(callbackCalled).to.be.equal(false);
|
||||
expect(callbackCalled).toBe(false);
|
||||
callbackCalled = true;
|
||||
|
||||
// Test data
|
||||
expect(loaded).to.be.eql([
|
||||
expect(loaded).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
@ -263,8 +255,8 @@ describe('Testing API loadIcons', () => {
|
||||
name: 'icon2',
|
||||
},
|
||||
]);
|
||||
expect(missing).to.be.eql([]);
|
||||
expect(pending).to.be.eql([]);
|
||||
expect(missing).toEqual([]);
|
||||
expect(pending).toEqual([]);
|
||||
done();
|
||||
}
|
||||
);
|
||||
@ -302,17 +294,18 @@ describe('Testing API loadIcons', () => {
|
||||
item: PendingQueryItem
|
||||
): void => {
|
||||
queryCounter++;
|
||||
params;
|
||||
switch (queryCounter) {
|
||||
case 1:
|
||||
// First call on api1
|
||||
expect(host).to.be.equal('https://api1.local');
|
||||
expect(host).toBe('https://api1.local');
|
||||
|
||||
// Do nothing - fake failed response
|
||||
break;
|
||||
|
||||
case 2:
|
||||
// First call on api2
|
||||
expect(host).to.be.equal('https://api2.local');
|
||||
expect(host).toBe('https://api2.local');
|
||||
|
||||
// Return result
|
||||
item.done({
|
||||
@ -347,13 +340,13 @@ describe('Testing API loadIcons', () => {
|
||||
provider + ':' + prefix + ':icon1',
|
||||
provider + ':' + prefix + ':icon2',
|
||||
],
|
||||
(loaded, missing, pending, unsubscribe) => {
|
||||
(loaded, missing, pending) => {
|
||||
// Callback should be called only once
|
||||
expect(callbackCalled).to.be.equal(false);
|
||||
expect(callbackCalled).toBe(false);
|
||||
callbackCalled = true;
|
||||
|
||||
// Test data
|
||||
expect(loaded).to.be.eql([
|
||||
expect(loaded).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
@ -365,8 +358,8 @@ describe('Testing API loadIcons', () => {
|
||||
name: 'icon2',
|
||||
},
|
||||
]);
|
||||
expect(missing).to.be.eql([]);
|
||||
expect(pending).to.be.eql([]);
|
||||
expect(missing).toEqual([]);
|
||||
expect(pending).toEqual([]);
|
||||
|
||||
done();
|
||||
}
|
||||
@ -406,7 +399,7 @@ describe('Testing API loadIcons', () => {
|
||||
): void => {
|
||||
queryCounter++;
|
||||
|
||||
expect(params.type).to.be.equal('icons');
|
||||
expect(params.type).toBe('icons');
|
||||
if (params.type !== 'icons') {
|
||||
return;
|
||||
}
|
||||
@ -414,16 +407,16 @@ describe('Testing API loadIcons', () => {
|
||||
switch (queryCounter) {
|
||||
case 1:
|
||||
// First call on api1
|
||||
expect(params.icons).to.be.eql(['icon1', 'icon2']);
|
||||
expect(host).to.be.equal('https://api1.local');
|
||||
expect(params.icons).toEqual(['icon1', 'icon2']);
|
||||
expect(host).toBe('https://api1.local');
|
||||
|
||||
// Do nothing - fake failed response
|
||||
break;
|
||||
|
||||
case 2:
|
||||
// First call on api2
|
||||
expect(params.icons).to.be.eql(['icon1', 'icon2']);
|
||||
expect(host).to.be.equal('https://api2.local');
|
||||
expect(params.icons).toEqual(['icon1', 'icon2']);
|
||||
expect(host).toBe('https://api2.local');
|
||||
|
||||
// Return result
|
||||
item.done({
|
||||
@ -441,8 +434,8 @@ describe('Testing API loadIcons', () => {
|
||||
|
||||
case 3:
|
||||
// Second call, should have api2 as default
|
||||
expect(params.icons).to.be.eql(['icon3', 'icon4']);
|
||||
expect(host).to.be.equal('https://api2.local');
|
||||
expect(params.icons).toEqual(['icon3', 'icon4']);
|
||||
expect(host).toBe('https://api2.local');
|
||||
|
||||
// Return result
|
||||
item.done({
|
||||
@ -477,13 +470,13 @@ describe('Testing API loadIcons', () => {
|
||||
provider + ':' + prefix + ':icon1',
|
||||
provider + ':' + prefix + ':icon2',
|
||||
],
|
||||
(loaded, missing, pending, unsubscribe) => {
|
||||
(loaded, missing, pending) => {
|
||||
// Callback should be called only once
|
||||
expect(callbackCalled).to.be.equal(false);
|
||||
expect(callbackCalled).toBe(false);
|
||||
callbackCalled = true;
|
||||
|
||||
// Test data
|
||||
expect(loaded).to.be.eql([
|
||||
expect(loaded).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
@ -495,8 +488,8 @@ describe('Testing API loadIcons', () => {
|
||||
name: 'icon2',
|
||||
},
|
||||
]);
|
||||
expect(missing).to.be.eql([]);
|
||||
expect(pending).to.be.eql([]);
|
||||
expect(missing).toEqual([]);
|
||||
expect(pending).toEqual([]);
|
||||
|
||||
// Send another query on next tick
|
||||
setTimeout(() => {
|
||||
@ -506,13 +499,13 @@ describe('Testing API loadIcons', () => {
|
||||
provider + ':' + prefix + ':icon3',
|
||||
provider + ':' + prefix + ':icon4',
|
||||
],
|
||||
(loaded, missing, pending, unsubscribe) => {
|
||||
(loaded, missing, pending) => {
|
||||
// Callback should be called only once
|
||||
expect(callbackCalled).to.be.equal(false);
|
||||
expect(callbackCalled).toBe(false);
|
||||
callbackCalled = true;
|
||||
|
||||
// Test data
|
||||
expect(loaded).to.be.eql([
|
||||
expect(loaded).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
@ -524,8 +517,8 @@ describe('Testing API loadIcons', () => {
|
||||
name: 'icon4',
|
||||
},
|
||||
]);
|
||||
expect(missing).to.be.eql([]);
|
||||
expect(pending).to.be.eql([]);
|
||||
expect(missing).toEqual([]);
|
||||
expect(pending).toEqual([]);
|
||||
|
||||
done();
|
||||
}
|
||||
@ -569,7 +562,7 @@ describe('Testing API loadIcons', () => {
|
||||
): void => {
|
||||
queryCounter++;
|
||||
|
||||
expect(params.type).to.be.equal('icons');
|
||||
expect(params.type).toBe('icons');
|
||||
if (params.type !== 'icons') {
|
||||
return;
|
||||
}
|
||||
@ -577,18 +570,18 @@ describe('Testing API loadIcons', () => {
|
||||
switch (queryCounter) {
|
||||
case 1:
|
||||
// First call on api1
|
||||
expect(params.prefix).to.be.equal(prefix);
|
||||
expect(params.icons).to.be.eql(['icon1', 'icon2']);
|
||||
expect(host).to.be.equal('https://api1.local');
|
||||
expect(params.prefix).toBe(prefix);
|
||||
expect(params.icons).toEqual(['icon1', 'icon2']);
|
||||
expect(host).toBe('https://api1.local');
|
||||
|
||||
// Do nothing - fake failed response
|
||||
break;
|
||||
|
||||
case 2:
|
||||
// First call on api2
|
||||
expect(params.prefix).to.be.equal(prefix);
|
||||
expect(params.icons).to.be.eql(['icon1', 'icon2']);
|
||||
expect(host).to.be.equal('https://api2.local');
|
||||
expect(params.prefix).toBe(prefix);
|
||||
expect(params.icons).toEqual(['icon1', 'icon2']);
|
||||
expect(host).toBe('https://api2.local');
|
||||
|
||||
// Return result
|
||||
item.done({
|
||||
@ -606,9 +599,9 @@ describe('Testing API loadIcons', () => {
|
||||
|
||||
case 3:
|
||||
// Second call, should have api2 as default
|
||||
expect(params.prefix).to.be.equal(prefix2);
|
||||
expect(params.icons).to.be.eql(['icon2', 'icon4']);
|
||||
expect(host).to.be.equal('https://api2.local');
|
||||
expect(params.prefix).toBe(prefix2);
|
||||
expect(params.icons).toEqual(['icon2', 'icon4']);
|
||||
expect(host).toBe('https://api2.local');
|
||||
|
||||
// Return result
|
||||
item.done({
|
||||
@ -643,13 +636,13 @@ describe('Testing API loadIcons', () => {
|
||||
provider + ':' + prefix + ':icon1',
|
||||
provider + ':' + prefix + ':icon2',
|
||||
],
|
||||
(loaded, missing, pending, unsubscribe) => {
|
||||
(loaded, missing, pending) => {
|
||||
// Callback should be called only once
|
||||
expect(callbackCalled).to.be.equal(false);
|
||||
expect(callbackCalled).toBe(false);
|
||||
callbackCalled = true;
|
||||
|
||||
// Test data
|
||||
expect(loaded).to.be.eql([
|
||||
expect(loaded).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
@ -661,8 +654,8 @@ describe('Testing API loadIcons', () => {
|
||||
name: 'icon2',
|
||||
},
|
||||
]);
|
||||
expect(missing).to.be.eql([]);
|
||||
expect(pending).to.be.eql([]);
|
||||
expect(missing).toEqual([]);
|
||||
expect(pending).toEqual([]);
|
||||
|
||||
// Send another query on next tick for different prefix that shares configuration
|
||||
setTimeout(() => {
|
||||
@ -672,13 +665,13 @@ describe('Testing API loadIcons', () => {
|
||||
provider + ':' + prefix2 + ':icon2',
|
||||
provider + ':' + prefix2 + ':icon4',
|
||||
],
|
||||
(loaded, missing, pending, unsubscribe) => {
|
||||
(loaded, missing, pending) => {
|
||||
// Callback should be called only once
|
||||
expect(callbackCalled).to.be.equal(false);
|
||||
expect(callbackCalled).toBe(false);
|
||||
callbackCalled = true;
|
||||
|
||||
// Test data
|
||||
expect(loaded).to.be.eql([
|
||||
expect(loaded).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix: prefix2,
|
||||
@ -690,8 +683,8 @@ describe('Testing API loadIcons', () => {
|
||||
name: 'icon4',
|
||||
},
|
||||
]);
|
||||
expect(missing).to.be.eql([]);
|
||||
expect(pending).to.be.eql([]);
|
||||
expect(missing).toEqual([]);
|
||||
expect(pending).toEqual([]);
|
||||
|
||||
done();
|
||||
}
|
@ -1,11 +1,9 @@
|
||||
import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import { mergeParams } from '../../lib/api/params';
|
||||
|
||||
describe('Testing mergeParams', () => {
|
||||
it('mergeParams()', () => {
|
||||
// Nothing
|
||||
expect(mergeParams('/foo', {})).to.be.equal('/foo');
|
||||
expect(mergeParams('/foo', {})).toBe('/foo');
|
||||
|
||||
// Simple variables
|
||||
expect(
|
||||
@ -14,14 +12,14 @@ describe('Testing mergeParams', () => {
|
||||
bar: 'baz',
|
||||
baz: true,
|
||||
})
|
||||
).to.be.equal('/foo?foo=1&bar=baz&baz=true');
|
||||
).toBe('/foo?foo=1&bar=baz&baz=true');
|
||||
|
||||
// More parameters to existing query
|
||||
expect(
|
||||
mergeParams('/foo?bar=baz', {
|
||||
foo: false,
|
||||
})
|
||||
).to.be.equal('/foo?bar=baz&foo=false');
|
||||
).toBe('/foo?bar=baz&foo=false');
|
||||
|
||||
// Escaping characters
|
||||
expect(
|
||||
@ -29,6 +27,6 @@ describe('Testing mergeParams', () => {
|
||||
'2&2': '1=1',
|
||||
'3 z': '?3',
|
||||
})
|
||||
).to.be.equal('/foo?2%262=1%3D1&3%20z=%3F3');
|
||||
).toBe('/foo?2%262=1%3D1&3%20z=%3F3');
|
||||
});
|
||||
});
|
@ -1,7 +1,3 @@
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars-experimental */
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import type { IconifyMockAPI } from '../../lib/api/modules/mock';
|
||||
import {
|
||||
mockAPIModule,
|
||||
@ -35,12 +31,12 @@ describe('Testing mock API module prepare function', () => {
|
||||
mockAPIData(item);
|
||||
|
||||
// Make sure item is stored correctly
|
||||
expect(typeof iconsStorage[provider]).to.be.equal('object');
|
||||
expect(iconsStorage[provider][prefix]).to.be.eql([item]);
|
||||
expect(typeof iconsStorage[provider]).toBe('object');
|
||||
expect(iconsStorage[provider][prefix]).toEqual([item]);
|
||||
|
||||
// Find item for icons
|
||||
const result = prepare(provider, prefix, ['foo', 'bar', 'baz']);
|
||||
expect(result).to.be.eql([
|
||||
expect(result).toEqual([
|
||||
{
|
||||
type: 'icons',
|
||||
provider,
|
||||
@ -87,8 +83,8 @@ describe('Testing mock API module prepare function', () => {
|
||||
mockAPIData(item3);
|
||||
|
||||
// Make sure item is stored correctly
|
||||
expect(typeof iconsStorage[provider]).to.be.equal('object');
|
||||
expect(iconsStorage[provider][prefix]).to.be.eql([item1, item2, item3]);
|
||||
expect(typeof iconsStorage[provider]).toBe('object');
|
||||
expect(iconsStorage[provider][prefix]).toEqual([item1, item2, item3]);
|
||||
|
||||
// Find items for icons
|
||||
const result = prepare(provider, prefix, [
|
||||
@ -99,7 +95,7 @@ describe('Testing mock API module prepare function', () => {
|
||||
'test10',
|
||||
'test2',
|
||||
]);
|
||||
expect(result).to.be.eql([
|
||||
expect(result).toEqual([
|
||||
// Unknown icons first
|
||||
{
|
||||
type: 'icons',
|
||||
@ -145,12 +141,12 @@ describe('Testing mock API module prepare function', () => {
|
||||
mockAPIData(item);
|
||||
|
||||
// Make sure item is stored correctly
|
||||
expect(typeof iconsStorage[provider]).to.be.equal('object');
|
||||
expect(iconsStorage[provider][prefix]).to.be.eql([item]);
|
||||
expect(typeof iconsStorage[provider]).toBe('object');
|
||||
expect(iconsStorage[provider][prefix]).toEqual([item]);
|
||||
|
||||
// Find item for icons
|
||||
const result = prepare(provider, prefix, ['foo', 'bar', 'baz']);
|
||||
expect(result).to.be.eql([
|
||||
expect(result).toEqual([
|
||||
// Missing icons first
|
||||
{
|
||||
type: 'icons',
|
@ -1,7 +1,3 @@
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars-experimental */
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import { setAPIConfig } from '../../lib/api/config';
|
||||
import { setAPIModule } from '../../lib/api/modules';
|
||||
import { loadIcons } from '../../lib/api/icons';
|
||||
@ -20,7 +16,7 @@ describe('Testing mock API module', () => {
|
||||
// Set API module for provider
|
||||
const provider = nextPrefix();
|
||||
|
||||
before(() => {
|
||||
beforeEach(() => {
|
||||
setAPIConfig(provider, {
|
||||
resources: ['https://api1.local'],
|
||||
});
|
||||
@ -50,10 +46,10 @@ describe('Testing mock API module', () => {
|
||||
},
|
||||
],
|
||||
(loaded, missing, pending) => {
|
||||
expect(isSync).to.be.equal(false);
|
||||
expect(loaded).to.be.eql([]);
|
||||
expect(pending).to.be.eql([]);
|
||||
expect(missing).to.be.eql([
|
||||
expect(isSync).toBe(false);
|
||||
expect(loaded).toEqual([]);
|
||||
expect(pending).toEqual([]);
|
||||
expect(missing).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
@ -119,9 +115,9 @@ describe('Testing mock API module', () => {
|
||||
},
|
||||
],
|
||||
(loaded, missing, pending) => {
|
||||
expect(isSync).to.be.equal(false);
|
||||
expect(isSync).toBe(false);
|
||||
// All icons should have been loaded because API waits one tick before sending response, during which both queries are processed
|
||||
expect(loaded).to.be.eql([
|
||||
expect(loaded).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
@ -133,8 +129,8 @@ describe('Testing mock API module', () => {
|
||||
name: 'test20',
|
||||
},
|
||||
]);
|
||||
expect(pending).to.be.eql([]);
|
||||
expect(missing).to.be.eql([]);
|
||||
expect(pending).toEqual([]);
|
||||
expect(missing).toEqual([]);
|
||||
done();
|
||||
}
|
||||
);
|
||||
@ -202,14 +198,14 @@ describe('Testing mock API module', () => {
|
||||
switch (callbackCounter) {
|
||||
case 1:
|
||||
// First load: only 'test10'
|
||||
expect(loaded).to.be.eql([
|
||||
expect(loaded).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
name: 'test10',
|
||||
},
|
||||
]);
|
||||
expect(pending).to.be.eql([
|
||||
expect(pending).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
@ -218,14 +214,14 @@ describe('Testing mock API module', () => {
|
||||
]);
|
||||
|
||||
// Send second response
|
||||
expect(typeof next).to.be.equal('function');
|
||||
expect(typeof next).toBe('function');
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
next!();
|
||||
break;
|
||||
|
||||
case 2:
|
||||
// All icons should have been loaded
|
||||
expect(loaded).to.be.eql([
|
||||
expect(loaded).toEqual([
|
||||
{
|
||||
provider,
|
||||
prefix,
|
||||
@ -237,7 +233,7 @@ describe('Testing mock API module', () => {
|
||||
name: 'test20',
|
||||
},
|
||||
]);
|
||||
expect(missing).to.be.eql([]);
|
||||
expect(missing).toEqual([]);
|
||||
done();
|
||||
break;
|
||||
|
||||
@ -269,13 +265,13 @@ describe('Testing mock API module', () => {
|
||||
delay: (next) => {
|
||||
// Icon should not be loaded yet
|
||||
const storage = getStorage(provider, prefix);
|
||||
expect(iconExists(storage, name)).to.be.equal(false);
|
||||
expect(iconExists(storage, name)).toBe(false);
|
||||
|
||||
// Set data
|
||||
next();
|
||||
|
||||
// Icon should be loaded now
|
||||
expect(iconExists(storage, name)).to.be.equal(true);
|
||||
expect(iconExists(storage, name)).toBe(true);
|
||||
|
||||
done();
|
||||
},
|
||||
@ -311,11 +307,11 @@ describe('Testing mock API module', () => {
|
||||
uri: '/test',
|
||||
},
|
||||
(data, error) => {
|
||||
expect(error).to.be.equal(void 0);
|
||||
expect(data).to.be.eql({
|
||||
expect(error).toBeUndefined();
|
||||
expect(data).toEqual({
|
||||
foo: true,
|
||||
});
|
||||
expect(isSync).to.be.equal(false);
|
||||
expect(isSync).toBe(false);
|
||||
done();
|
||||
}
|
||||
);
|
||||
@ -346,11 +342,11 @@ describe('Testing mock API module', () => {
|
||||
uri: '/test',
|
||||
},
|
||||
(data, error) => {
|
||||
expect(error).to.be.equal(void 0);
|
||||
expect(data).to.be.eql({
|
||||
expect(error).toBeUndefined();
|
||||
expect(data).toEqual({
|
||||
foo: 2,
|
||||
});
|
||||
expect(isSync).to.be.equal(false);
|
||||
expect(isSync).toBe(false);
|
||||
done();
|
||||
}
|
||||
);
|
@ -1,13 +1,7 @@
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars-experimental */
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import type { PendingQueryItem } from '@iconify/api-redundancy';
|
||||
import type { IconifyAPIConfig } from '../../lib/api/config';
|
||||
import { setAPIConfig, getAPIConfig } from '../../lib/api/config';
|
||||
import type {
|
||||
IconifyAPIIconsQueryParams,
|
||||
IconifyAPIQueryParams,
|
||||
IconifyAPIModule,
|
||||
} from '../../lib/api/modules';
|
||||
import { setAPIModule, getAPIModule } from '../../lib/api/modules';
|
||||
@ -35,11 +29,7 @@ describe('Testing API modules', () => {
|
||||
return [item];
|
||||
};
|
||||
|
||||
const sendQuery = (
|
||||
host: string,
|
||||
params: IconifyAPIQueryParams,
|
||||
item: PendingQueryItem
|
||||
): void => {
|
||||
const sendQuery = (): void => {
|
||||
throw new Error('Unexpected API call');
|
||||
};
|
||||
|
||||
@ -60,20 +50,20 @@ describe('Testing API modules', () => {
|
||||
|
||||
// Get config
|
||||
const config = getAPIConfig(provider) as IconifyAPIConfig;
|
||||
expect(config).to.not.be.equal(void 0);
|
||||
expect(config).not.toBeUndefined();
|
||||
|
||||
// Check setAPIConfig
|
||||
expect(config.resources).to.be.eql(['https://localhost:3000']);
|
||||
expect(config.resources).toEqual(['https://localhost:3000']);
|
||||
|
||||
// Check getAPIModule()
|
||||
const item = getAPIModule(provider) as IconifyAPIModule;
|
||||
expect(item).to.not.be.equal(void 0);
|
||||
expect(item.prepare).to.be.equal(prepareQuery);
|
||||
expect(item.send).to.be.equal(sendQuery);
|
||||
expect(item).not.toBeUndefined();
|
||||
expect(item.prepare).toBe(prepareQuery);
|
||||
expect(item.send).toBe(sendQuery);
|
||||
|
||||
// Get module for different provider to make sure it is empty
|
||||
// Get module for different provider to make sure it is different
|
||||
const provider2 = nextPrefix();
|
||||
const item2 = getAPIModule(provider2);
|
||||
expect(item2).to.be.equal(void 0);
|
||||
expect(item2).not.toBe(item);
|
||||
});
|
||||
});
|
@ -1,7 +1,3 @@
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars-experimental */
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import { setAPIModule } from '../../lib/api/modules';
|
||||
import { loadIcons } from '../../lib/api/icons';
|
||||
import { mockAPIModule, mockAPIData } from '../../lib/api/modules/mock';
|
||||
@ -9,12 +5,12 @@ import { allowSimpleNames } from '../../lib/storage/functions';
|
||||
|
||||
describe('Testing simple names with API module', () => {
|
||||
// Set API config and allow simple names
|
||||
before(() => {
|
||||
beforeEach(() => {
|
||||
allowSimpleNames(true);
|
||||
setAPIModule('', mockAPIModule);
|
||||
});
|
||||
|
||||
after(() => {
|
||||
afterAll(() => {
|
||||
allowSimpleNames(false);
|
||||
});
|
||||
|
||||
@ -67,15 +63,15 @@ describe('Testing simple names with API module', () => {
|
||||
],
|
||||
(loaded, missing, pending) => {
|
||||
// 'test100' should be missing because it does not have a prefix
|
||||
expect(loaded).to.be.eql([
|
||||
expect(loaded).toEqual([
|
||||
{
|
||||
provider: '',
|
||||
prefix: 'test200',
|
||||
name: 'foo',
|
||||
},
|
||||
]);
|
||||
expect(pending).to.be.eql([]);
|
||||
expect(missing).to.be.eql([
|
||||
expect(pending).toEqual([]);
|
||||
expect(missing).toEqual([
|
||||
{
|
||||
provider: '',
|
||||
prefix: '',
|
@ -1,6 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
||||
import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import {
|
||||
newStorage,
|
||||
addIcon,
|
||||
@ -43,18 +41,18 @@ describe('Testing storage', () => {
|
||||
addIcon(storage, 'invalid', {} as unknown as IconifyIcon);
|
||||
|
||||
// Should not include 'invalid'
|
||||
expect(Object.keys(storage.icons)).to.be.eql([
|
||||
expect(Object.keys(storage.icons)).toEqual([
|
||||
'test',
|
||||
'not-really-missing',
|
||||
'constructor',
|
||||
]);
|
||||
|
||||
// Test iconExists
|
||||
expect(iconExists(storage, 'test')).to.be.equal(true);
|
||||
expect(iconExists(storage, 'constructor')).to.be.equal(true);
|
||||
expect(iconExists(storage, 'invalid')).to.be.equal(false);
|
||||
expect(iconExists(storage, 'missing')).to.be.equal(false);
|
||||
expect(iconExists(storage, 'not-really-missing')).to.be.equal(true);
|
||||
expect(iconExists(storage, 'test')).toBe(true);
|
||||
expect(iconExists(storage, 'constructor')).toBe(true);
|
||||
expect(iconExists(storage, 'invalid')).toBe(false);
|
||||
expect(iconExists(storage, 'missing')).toBe(false);
|
||||
expect(iconExists(storage, 'not-really-missing')).toBe(true);
|
||||
|
||||
// Test getIcon
|
||||
let expected: FullIconifyIcon = {
|
||||
@ -68,7 +66,7 @@ describe('Testing storage', () => {
|
||||
rotate: 0,
|
||||
};
|
||||
const icon = getIcon(storage, 'test');
|
||||
expect(icon).to.be.eql(expected);
|
||||
expect(icon).toEqual(expected);
|
||||
|
||||
// Test icon mutation
|
||||
let thrown = false;
|
||||
@ -78,7 +76,7 @@ describe('Testing storage', () => {
|
||||
} catch (err) {
|
||||
thrown = true;
|
||||
}
|
||||
expect(thrown).to.be.equal(true);
|
||||
expect(thrown).toBe(true);
|
||||
|
||||
expected = {
|
||||
body: '<g></g>',
|
||||
@ -90,10 +88,10 @@ describe('Testing storage', () => {
|
||||
vFlip: false,
|
||||
rotate: 1,
|
||||
};
|
||||
expect(getIcon(storage, 'constructor')).to.be.eql(expected);
|
||||
expect(getIcon(storage, 'constructor')).toEqual(expected);
|
||||
|
||||
expect(getIcon(storage, 'invalid')).to.be.equal(null);
|
||||
expect(getIcon(storage, 'missing')).to.be.equal(null);
|
||||
expect(getIcon(storage, 'invalid')).toBeNull();
|
||||
expect(getIcon(storage, 'missing')).toBeNull();
|
||||
});
|
||||
|
||||
it('Adding simple icon set', () => {
|
||||
@ -115,15 +113,15 @@ describe('Testing storage', () => {
|
||||
},
|
||||
height: 24,
|
||||
})
|
||||
).to.be.equal(true);
|
||||
).toBe(true);
|
||||
|
||||
expect(Object.keys(storage.icons)).to.be.eql(['icon1', 'icon2']);
|
||||
expect(Object.keys(storage.icons)).toEqual(['icon1', 'icon2']);
|
||||
|
||||
// Test iconExists
|
||||
expect(iconExists(storage, 'icon1')).to.be.equal(true);
|
||||
expect(iconExists(storage, 'icon2')).to.be.equal(true);
|
||||
expect(iconExists(storage, 'invalid')).to.be.equal(false);
|
||||
expect(iconExists(storage, 'missing')).to.be.equal(false);
|
||||
expect(iconExists(storage, 'icon1')).toBe(true);
|
||||
expect(iconExists(storage, 'icon2')).toBe(true);
|
||||
expect(iconExists(storage, 'invalid')).toBe(false);
|
||||
expect(iconExists(storage, 'missing')).toBe(false);
|
||||
|
||||
// Test getIcon
|
||||
let expected: FullIconifyIcon = {
|
||||
@ -136,7 +134,7 @@ describe('Testing storage', () => {
|
||||
vFlip: false,
|
||||
rotate: 0,
|
||||
};
|
||||
expect(getIcon(storage, 'icon1')).to.be.eql(expected);
|
||||
expect(getIcon(storage, 'icon1')).toEqual(expected);
|
||||
expected = {
|
||||
body: '<path d="icon2" />',
|
||||
width: 24,
|
||||
@ -147,9 +145,9 @@ describe('Testing storage', () => {
|
||||
vFlip: false,
|
||||
rotate: 0,
|
||||
};
|
||||
expect(getIcon(storage, 'icon2')).to.be.eql(expected);
|
||||
expect(getIcon(storage, 'invalid')).to.be.equal(null);
|
||||
expect(getIcon(storage, 'missing')).to.be.equal(null);
|
||||
expect(getIcon(storage, 'icon2')).toEqual(expected);
|
||||
expect(getIcon(storage, 'invalid')).toBeNull();
|
||||
expect(getIcon(storage, 'missing')).toBeNull();
|
||||
});
|
||||
|
||||
it('Icon set with aliases that use transformations', () => {
|
||||
@ -174,9 +172,9 @@ describe('Testing storage', () => {
|
||||
width: 128,
|
||||
height: 128,
|
||||
})
|
||||
).to.be.equal(true);
|
||||
).toBe(true);
|
||||
|
||||
expect(Object.keys(storage.icons)).to.be.eql([
|
||||
expect(Object.keys(storage.icons)).toEqual([
|
||||
'16-chevron-left',
|
||||
'16-chevron-right',
|
||||
]);
|
||||
@ -192,7 +190,7 @@ describe('Testing storage', () => {
|
||||
vFlip: false,
|
||||
rotate: 0,
|
||||
};
|
||||
expect(getIcon(storage, '16-chevron-left')).to.be.eql(expected);
|
||||
expect(getIcon(storage, '16-chevron-left')).toEqual(expected);
|
||||
|
||||
// Test alias
|
||||
expected = {
|
||||
@ -205,7 +203,7 @@ describe('Testing storage', () => {
|
||||
vFlip: false,
|
||||
rotate: 0,
|
||||
};
|
||||
expect(getIcon(storage, '16-chevron-right')).to.be.eql(expected);
|
||||
expect(getIcon(storage, '16-chevron-right')).toEqual(expected);
|
||||
});
|
||||
|
||||
it('List icons in a global storage', () => {
|
||||
@ -215,8 +213,8 @@ describe('Testing storage', () => {
|
||||
const storage2 = getStorage(provider, prefix);
|
||||
|
||||
// List icons
|
||||
expect(listIcons('', prefix)).to.be.eql([]);
|
||||
expect(listIcons(provider, prefix)).to.be.eql([]);
|
||||
expect(listIcons('', prefix)).toEqual([]);
|
||||
expect(listIcons(provider, prefix)).toEqual([]);
|
||||
|
||||
// Add one icon without provider
|
||||
addIcon(storage1, 'test', {
|
||||
@ -226,8 +224,8 @@ describe('Testing storage', () => {
|
||||
});
|
||||
|
||||
// List icons
|
||||
expect(listIcons('', prefix)).to.be.eql([prefix + ':test']);
|
||||
expect(listIcons(provider, prefix)).to.be.eql([]);
|
||||
expect(listIcons('', prefix)).toEqual([prefix + ':test']);
|
||||
expect(listIcons(provider, prefix)).toEqual([]);
|
||||
|
||||
// Add icon set without provider
|
||||
expect(
|
||||
@ -247,15 +245,15 @@ describe('Testing storage', () => {
|
||||
width: 128,
|
||||
height: 128,
|
||||
})
|
||||
).to.be.equal(true);
|
||||
).toBe(true);
|
||||
|
||||
// List icons
|
||||
expect(listIcons('', prefix)).to.be.eql([
|
||||
expect(listIcons('', prefix)).toEqual([
|
||||
prefix + ':test',
|
||||
prefix + ':16-chevron-left',
|
||||
prefix + ':16-chevron-right',
|
||||
]);
|
||||
expect(listIcons(provider, prefix)).to.be.eql([]);
|
||||
expect(listIcons(provider, prefix)).toEqual([]);
|
||||
|
||||
// Add one icon with provider
|
||||
addIcon(storage2, 'test2', {
|
||||
@ -265,12 +263,12 @@ describe('Testing storage', () => {
|
||||
});
|
||||
|
||||
// List icons
|
||||
expect(listIcons('', prefix)).to.be.eql([
|
||||
expect(listIcons('', prefix)).toEqual([
|
||||
prefix + ':test',
|
||||
prefix + ':16-chevron-left',
|
||||
prefix + ':16-chevron-right',
|
||||
]);
|
||||
expect(listIcons(provider, prefix)).to.be.eql([
|
||||
expect(listIcons(provider, prefix)).toEqual([
|
||||
'@' + provider + ':' + prefix + ':test2',
|
||||
]);
|
||||
});
|
@ -1,6 +1,4 @@
|
||||
import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import { count, config, loadCache } from '../../lib/browser-storage/';
|
||||
import { count, config, loadCache } from '../../lib/browser-storage';
|
||||
import {
|
||||
nextPrefix,
|
||||
createCache,
|
||||
@ -18,11 +16,11 @@ describe('Testing mocked localStorage', () => {
|
||||
reset({});
|
||||
|
||||
// Config before tests
|
||||
expect(config).to.be.eql({
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: true,
|
||||
});
|
||||
expect(count).to.be.eql({
|
||||
expect(count).toEqual({
|
||||
local: 0,
|
||||
session: 0,
|
||||
});
|
||||
@ -31,13 +29,13 @@ describe('Testing mocked localStorage', () => {
|
||||
loadCache();
|
||||
|
||||
// Everything should be disabled
|
||||
expect(config).to.be.eql({
|
||||
expect(config).toEqual({
|
||||
local: false,
|
||||
session: false,
|
||||
});
|
||||
|
||||
// Nothing should have loaded
|
||||
expect(count).to.be.eql({
|
||||
expect(count).toEqual({
|
||||
local: 0,
|
||||
session: 0,
|
||||
});
|
||||
@ -49,11 +47,11 @@ describe('Testing mocked localStorage', () => {
|
||||
});
|
||||
|
||||
// Config before tests
|
||||
expect(config).to.be.eql({
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: true,
|
||||
});
|
||||
expect(count).to.be.eql({
|
||||
expect(count).toEqual({
|
||||
local: 0,
|
||||
session: 0,
|
||||
});
|
||||
@ -62,13 +60,13 @@ describe('Testing mocked localStorage', () => {
|
||||
loadCache();
|
||||
|
||||
// sessionStorage should be disabled
|
||||
expect(config).to.be.eql({
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: false,
|
||||
});
|
||||
|
||||
// Nothing should have loaded
|
||||
expect(count).to.be.eql({
|
||||
expect(count).toEqual({
|
||||
local: 0,
|
||||
session: 0,
|
||||
});
|
||||
@ -108,11 +106,11 @@ describe('Testing mocked localStorage', () => {
|
||||
});
|
||||
|
||||
// Config before tests
|
||||
expect(config).to.be.eql({
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: true,
|
||||
});
|
||||
expect(count).to.be.eql({
|
||||
expect(count).toEqual({
|
||||
local: 0,
|
||||
session: 0,
|
||||
});
|
||||
@ -121,13 +119,13 @@ describe('Testing mocked localStorage', () => {
|
||||
loadCache();
|
||||
|
||||
// Everything should be disabled because read-only mock throws errors
|
||||
expect(config).to.be.eql({
|
||||
expect(config).toEqual({
|
||||
local: false,
|
||||
session: false,
|
||||
});
|
||||
|
||||
// Nothing should have loaded
|
||||
expect(count).to.be.eql({
|
||||
expect(count).toEqual({
|
||||
local: 0,
|
||||
session: 0,
|
||||
});
|
||||
@ -162,11 +160,11 @@ describe('Testing mocked localStorage', () => {
|
||||
});
|
||||
|
||||
// Config before tests
|
||||
expect(config).to.be.eql({
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: true,
|
||||
});
|
||||
expect(count).to.be.eql({
|
||||
expect(count).toEqual({
|
||||
local: 0,
|
||||
session: 0,
|
||||
});
|
||||
@ -175,13 +173,13 @@ describe('Testing mocked localStorage', () => {
|
||||
loadCache();
|
||||
|
||||
// sessionStorage should be disabled
|
||||
expect(config).to.be.eql({
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: false,
|
||||
});
|
||||
|
||||
// One item should be in localStorage
|
||||
expect(count).to.be.eql({
|
||||
expect(count).toEqual({
|
||||
local: 1,
|
||||
session: 0,
|
||||
});
|
||||
@ -194,11 +192,11 @@ describe('Testing mocked localStorage', () => {
|
||||
});
|
||||
|
||||
// Config before tests
|
||||
expect(config).to.be.eql({
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: true,
|
||||
});
|
||||
expect(count).to.be.eql({
|
||||
expect(count).toEqual({
|
||||
local: 0,
|
||||
session: 0,
|
||||
});
|
||||
@ -207,13 +205,13 @@ describe('Testing mocked localStorage', () => {
|
||||
loadCache();
|
||||
|
||||
// Everything should be working
|
||||
expect(config).to.be.eql({
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: true,
|
||||
});
|
||||
|
||||
// Empty storage
|
||||
expect(count).to.be.eql({
|
||||
expect(count).toEqual({
|
||||
local: 0,
|
||||
session: 0,
|
||||
});
|
@ -1,4 +1,4 @@
|
||||
import { mock, count, config, emptyList } from '../../lib/browser-storage/';
|
||||
import { mock, count, config, emptyList } from '../../lib/browser-storage';
|
||||
|
||||
/**
|
||||
* Get next icon set prefix for testing
|
||||
@ -92,7 +92,7 @@ export class Storage {
|
||||
* Create fake storage, assign localStorage type
|
||||
*/
|
||||
export function createCache(): typeof localStorage {
|
||||
return (new Storage() as unknown) as typeof localStorage;
|
||||
return new Storage() as unknown as typeof localStorage;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -106,7 +106,7 @@ export function reset(fakeWindow: Record<string, typeof localStorage>): void {
|
||||
|
||||
// Reset all data
|
||||
for (const key in config) {
|
||||
const attr = (key as unknown) as keyof typeof config;
|
||||
const attr = key as unknown as keyof typeof config;
|
||||
config[attr] = true;
|
||||
count[attr] = 0;
|
||||
emptyList[attr] = [];
|
@ -1,13 +1,6 @@
|
||||
import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import type { IconifyJSON } from '@iconify/types';
|
||||
import type { StoredItem } from '../../lib/browser-storage/';
|
||||
import {
|
||||
loadCache,
|
||||
count,
|
||||
config,
|
||||
emptyList,
|
||||
} from '../../lib/browser-storage/';
|
||||
import type { StoredItem } from '../../lib/browser-storage';
|
||||
import { loadCache, count, config, emptyList } from '../../lib/browser-storage';
|
||||
import { getStorage, iconExists } from '../../lib/storage/storage';
|
||||
import {
|
||||
nextPrefix,
|
||||
@ -53,24 +46,24 @@ describe('Testing loading from localStorage', () => {
|
||||
|
||||
// Check icon storage
|
||||
const icons = getStorage(provider, prefix);
|
||||
expect(iconExists(icons, 'foo')).to.be.equal(false);
|
||||
expect(iconExists(icons, 'foo')).toBe(false);
|
||||
|
||||
// Load localStorage
|
||||
loadCache();
|
||||
|
||||
// Icon should exist now
|
||||
expect(iconExists(icons, 'foo')).to.be.equal(true);
|
||||
expect(iconExists(icons, 'foo')).toBe(true);
|
||||
|
||||
// Check data
|
||||
expect(config).to.be.eql({
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: false,
|
||||
});
|
||||
expect(count).to.be.eql({
|
||||
expect(count).toEqual({
|
||||
local: 1,
|
||||
session: 0,
|
||||
});
|
||||
expect(emptyList).to.be.eql({
|
||||
expect(emptyList).toEqual({
|
||||
local: [],
|
||||
session: [],
|
||||
});
|
||||
@ -106,29 +99,29 @@ describe('Testing loading from localStorage', () => {
|
||||
|
||||
// Check icon storage
|
||||
const icons = getStorage(provider, prefix);
|
||||
expect(iconExists(icons, 'foo')).to.be.equal(false);
|
||||
expect(iconExists(icons, 'foo')).toBe(false);
|
||||
|
||||
// Check default provider
|
||||
const icons2 = getStorage('', prefix);
|
||||
expect(iconExists(icons2, 'foo')).to.be.equal(false);
|
||||
expect(iconExists(icons2, 'foo')).toBe(false);
|
||||
|
||||
// Load localStorage
|
||||
loadCache();
|
||||
|
||||
// Icon should exist now
|
||||
expect(iconExists(icons, 'foo')).to.be.equal(true);
|
||||
expect(iconExists(icons2, 'foo')).to.be.equal(false);
|
||||
expect(iconExists(icons, 'foo')).toBe(true);
|
||||
expect(iconExists(icons2, 'foo')).toBe(false);
|
||||
|
||||
// Check data
|
||||
expect(config).to.be.eql({
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: false,
|
||||
});
|
||||
expect(count).to.be.eql({
|
||||
expect(count).toEqual({
|
||||
local: 1,
|
||||
session: 0,
|
||||
});
|
||||
expect(emptyList).to.be.eql({
|
||||
expect(emptyList).toEqual({
|
||||
local: [],
|
||||
session: [],
|
||||
});
|
||||
@ -164,24 +157,24 @@ describe('Testing loading from localStorage', () => {
|
||||
|
||||
// Check icon storage
|
||||
const icons = getStorage(provider, prefix);
|
||||
expect(iconExists(icons, 'foo')).to.be.equal(false);
|
||||
expect(iconExists(icons, 'foo')).toBe(false);
|
||||
|
||||
// Load localStorage
|
||||
loadCache();
|
||||
|
||||
// Icon should not have loaded
|
||||
expect(iconExists(icons, 'foo')).to.be.equal(false);
|
||||
expect(iconExists(icons, 'foo')).toBe(false);
|
||||
|
||||
// Check data
|
||||
expect(config).to.be.eql({
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: false,
|
||||
});
|
||||
expect(count).to.be.eql({
|
||||
expect(count).toEqual({
|
||||
local: 0,
|
||||
session: 0,
|
||||
});
|
||||
expect(emptyList).to.be.eql({
|
||||
expect(emptyList).toEqual({
|
||||
local: [],
|
||||
session: [],
|
||||
});
|
||||
@ -218,24 +211,24 @@ describe('Testing loading from localStorage', () => {
|
||||
|
||||
// Check icon storage
|
||||
const icons = getStorage(provider, prefix);
|
||||
expect(iconExists(icons, 'foo')).to.be.equal(false);
|
||||
expect(iconExists(icons, 'foo')).toBe(false);
|
||||
|
||||
// Load localStorage
|
||||
loadCache();
|
||||
|
||||
// Icon should not have loaded
|
||||
expect(iconExists(icons, 'foo')).to.be.equal(false);
|
||||
expect(iconExists(icons, 'foo')).toBe(false);
|
||||
|
||||
// Check data
|
||||
expect(config).to.be.eql({
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: false,
|
||||
});
|
||||
expect(count).to.be.eql({
|
||||
expect(count).toEqual({
|
||||
local: 0,
|
||||
session: 0,
|
||||
});
|
||||
expect(emptyList).to.be.eql({
|
||||
expect(emptyList).toEqual({
|
||||
local: [],
|
||||
session: [],
|
||||
});
|
||||
@ -270,24 +263,24 @@ describe('Testing loading from localStorage', () => {
|
||||
|
||||
// Check icon storage
|
||||
const icons = getStorage(provider, prefix);
|
||||
expect(iconExists(icons, 'foo')).to.be.equal(false);
|
||||
expect(iconExists(icons, 'foo')).toBe(false);
|
||||
|
||||
// Load localStorage
|
||||
loadCache();
|
||||
|
||||
// Icon should not have loaded
|
||||
expect(iconExists(icons, 'foo')).to.be.equal(false);
|
||||
expect(iconExists(icons, 'foo')).toBe(false);
|
||||
|
||||
// Check data
|
||||
expect(config).to.be.eql({
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: false,
|
||||
});
|
||||
expect(count).to.be.eql({
|
||||
expect(count).toEqual({
|
||||
local: 0,
|
||||
session: 0,
|
||||
});
|
||||
expect(emptyList).to.be.eql({
|
||||
expect(emptyList).toEqual({
|
||||
local: [],
|
||||
session: [],
|
||||
});
|
||||
@ -322,24 +315,24 @@ describe('Testing loading from localStorage', () => {
|
||||
|
||||
// Check icon storage
|
||||
const icons = getStorage(provider, prefix);
|
||||
expect(iconExists(icons, 'foo')).to.be.equal(false);
|
||||
expect(iconExists(icons, 'foo')).toBe(false);
|
||||
|
||||
// Load localStorage
|
||||
loadCache();
|
||||
|
||||
// Icon should exist now
|
||||
expect(iconExists(icons, 'foo')).to.be.equal(true);
|
||||
expect(iconExists(icons, 'foo')).toBe(true);
|
||||
|
||||
// Check data
|
||||
expect(config).to.be.eql({
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: false,
|
||||
});
|
||||
expect(count).to.be.eql({
|
||||
expect(count).toEqual({
|
||||
local: 1,
|
||||
session: 0,
|
||||
});
|
||||
expect(emptyList).to.be.eql({
|
||||
expect(emptyList).toEqual({
|
||||
local: [],
|
||||
session: [],
|
||||
});
|
||||
@ -389,26 +382,26 @@ describe('Testing loading from localStorage', () => {
|
||||
|
||||
// Check icon storage
|
||||
const icons = getStorage(provider, prefix);
|
||||
expect(iconExists(icons, 'foo1')).to.be.equal(false);
|
||||
expect(iconExists(icons, 'foo4')).to.be.equal(false);
|
||||
expect(iconExists(icons, 'foo1')).toBe(false);
|
||||
expect(iconExists(icons, 'foo4')).toBe(false);
|
||||
|
||||
// Load localStorage
|
||||
loadCache();
|
||||
|
||||
// Icons should exist now
|
||||
expect(iconExists(icons, 'foo1')).to.be.equal(true);
|
||||
expect(iconExists(icons, 'foo4')).to.be.equal(true);
|
||||
expect(iconExists(icons, 'foo1')).toBe(true);
|
||||
expect(iconExists(icons, 'foo4')).toBe(true);
|
||||
|
||||
// Check data
|
||||
expect(config).to.be.eql({
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: false,
|
||||
});
|
||||
expect(count).to.be.eql({
|
||||
expect(count).toEqual({
|
||||
local: 5,
|
||||
session: 0,
|
||||
});
|
||||
expect(emptyList).to.be.eql({
|
||||
expect(emptyList).toEqual({
|
||||
local: [3, 2, 0], // reserse order
|
||||
session: [],
|
||||
});
|
||||
@ -467,10 +460,7 @@ describe('Testing loading from localStorage', () => {
|
||||
// Check icon storage
|
||||
const iconsStorage = getStorage(provider, prefix);
|
||||
for (let i = 0; i < 6; i++) {
|
||||
expect(iconExists(iconsStorage, 'foo' + i)).to.be.equal(
|
||||
false,
|
||||
`Icon ${i} should not exist yet`
|
||||
);
|
||||
expect(iconExists(iconsStorage, 'foo' + i)).toBe(false);
|
||||
}
|
||||
|
||||
// Load localStorage
|
||||
@ -478,22 +468,19 @@ describe('Testing loading from localStorage', () => {
|
||||
|
||||
// Icons should exist now, except for number 4
|
||||
for (let i = 0; i < 6; i++) {
|
||||
expect(iconExists(iconsStorage, 'foo' + i)).to.be.equal(
|
||||
i !== 4,
|
||||
`Icon ${i} failed loading test`
|
||||
);
|
||||
expect(iconExists(iconsStorage, 'foo' + i)).toBe(i !== 4);
|
||||
}
|
||||
|
||||
// Check data
|
||||
expect(config).to.be.eql({
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: true,
|
||||
});
|
||||
expect(count).to.be.eql({
|
||||
expect(count).toEqual({
|
||||
local: 6,
|
||||
session: 3,
|
||||
});
|
||||
expect(emptyList).to.be.eql({
|
||||
expect(emptyList).toEqual({
|
||||
local: [4, 2, 0],
|
||||
session: [1],
|
||||
});
|
@ -1,14 +1,12 @@
|
||||
import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import type { IconifyJSON } from '@iconify/types';
|
||||
import type { StoredItem } from '../../lib/browser-storage/';
|
||||
import type { StoredItem } from '../../lib/browser-storage';
|
||||
import {
|
||||
loadCache,
|
||||
storeCache,
|
||||
count,
|
||||
config,
|
||||
emptyList,
|
||||
} from '../../lib/browser-storage/';
|
||||
} from '../../lib/browser-storage';
|
||||
import { getStorage, iconExists } from '../../lib/storage/storage';
|
||||
import {
|
||||
nextPrefix,
|
||||
@ -51,35 +49,33 @@ describe('Testing saving to localStorage', () => {
|
||||
|
||||
// Check icon storage
|
||||
const icons = getStorage(provider, prefix);
|
||||
expect(iconExists(icons, 'foo')).to.be.equal(false);
|
||||
expect(iconExists(icons, 'foo')).toBe(false);
|
||||
|
||||
// Save item
|
||||
storeCache(provider, icon);
|
||||
|
||||
// Storing in cache should not add item to storage
|
||||
expect(iconExists(icons, 'foo')).to.be.equal(false);
|
||||
expect(iconExists(icons, 'foo')).toBe(false);
|
||||
|
||||
// Check data that should have been updated because storeCache()
|
||||
// should call load function before first execution
|
||||
expect(config).to.be.eql({
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: false,
|
||||
});
|
||||
expect(count).to.be.eql({
|
||||
expect(count).toEqual({
|
||||
local: 1,
|
||||
session: 0,
|
||||
});
|
||||
expect(emptyList).to.be.eql({
|
||||
expect(emptyList).toEqual({
|
||||
local: [],
|
||||
session: [],
|
||||
});
|
||||
|
||||
// Check cache
|
||||
expect(cache.getItem(cachePrefix + '0')).to.be.equal(
|
||||
JSON.stringify(item)
|
||||
);
|
||||
expect(cache.getItem(countKey)).to.be.equal('1');
|
||||
expect(cache.getItem(versionKey)).to.be.equal(cacheVersion);
|
||||
expect(cache.getItem(cachePrefix + '0')).toBe(JSON.stringify(item));
|
||||
expect(cache.getItem(countKey)).toBe('1');
|
||||
expect(cache.getItem(versionKey)).toBe(cacheVersion);
|
||||
});
|
||||
|
||||
it('Multiple icon sets', () => {
|
||||
@ -125,28 +121,24 @@ describe('Testing saving to localStorage', () => {
|
||||
|
||||
// Check data that should have been updated because storeCache()
|
||||
// should call load function before first execution
|
||||
expect(config).to.be.eql({
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: false,
|
||||
});
|
||||
expect(count).to.be.eql({
|
||||
expect(count).toEqual({
|
||||
local: 2,
|
||||
session: 0,
|
||||
});
|
||||
expect(emptyList).to.be.eql({
|
||||
expect(emptyList).toEqual({
|
||||
local: [],
|
||||
session: [],
|
||||
});
|
||||
|
||||
// Check cache
|
||||
expect(cache.getItem(cachePrefix + '0')).to.be.equal(
|
||||
JSON.stringify(item0)
|
||||
);
|
||||
expect(cache.getItem(cachePrefix + '1')).to.be.equal(
|
||||
JSON.stringify(item1)
|
||||
);
|
||||
expect(cache.getItem(countKey)).to.be.equal('2');
|
||||
expect(cache.getItem(versionKey)).to.be.equal(cacheVersion);
|
||||
expect(cache.getItem(cachePrefix + '0')).toBe(JSON.stringify(item0));
|
||||
expect(cache.getItem(cachePrefix + '1')).toBe(JSON.stringify(item1));
|
||||
expect(cache.getItem(countKey)).toBe('2');
|
||||
expect(cache.getItem(versionKey)).toBe(cacheVersion);
|
||||
});
|
||||
|
||||
it('Adding icon set on unused spot', () => {
|
||||
@ -195,15 +187,15 @@ describe('Testing saving to localStorage', () => {
|
||||
loadCache();
|
||||
|
||||
// Check data
|
||||
expect(config).to.be.eql({
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: false,
|
||||
});
|
||||
expect(count).to.be.eql({
|
||||
expect(count).toEqual({
|
||||
local: 2,
|
||||
session: 0,
|
||||
});
|
||||
expect(emptyList).to.be.eql({
|
||||
expect(emptyList).toEqual({
|
||||
local: [0],
|
||||
session: [],
|
||||
});
|
||||
@ -212,24 +204,20 @@ describe('Testing saving to localStorage', () => {
|
||||
storeCache(provider, icon0);
|
||||
|
||||
// Check data
|
||||
expect(count).to.be.eql({
|
||||
expect(count).toEqual({
|
||||
local: 2,
|
||||
session: 0,
|
||||
});
|
||||
expect(emptyList).to.be.eql({
|
||||
expect(emptyList).toEqual({
|
||||
local: [],
|
||||
session: [],
|
||||
});
|
||||
|
||||
// Check cache
|
||||
expect(cache.getItem(cachePrefix + '0')).to.be.equal(
|
||||
JSON.stringify(item0)
|
||||
);
|
||||
expect(cache.getItem(cachePrefix + '1')).to.be.equal(
|
||||
JSON.stringify(item1)
|
||||
);
|
||||
expect(cache.getItem(countKey)).to.be.equal('2');
|
||||
expect(cache.getItem(versionKey)).to.be.equal(cacheVersion);
|
||||
expect(cache.getItem(cachePrefix + '0')).toBe(JSON.stringify(item0));
|
||||
expect(cache.getItem(cachePrefix + '1')).toBe(JSON.stringify(item1));
|
||||
expect(cache.getItem(countKey)).toBe('2');
|
||||
expect(cache.getItem(versionKey)).toBe(cacheVersion);
|
||||
});
|
||||
|
||||
it('Adding multiple icon sets to existing data', () => {
|
||||
@ -285,90 +273,86 @@ describe('Testing saving to localStorage', () => {
|
||||
loadCache();
|
||||
|
||||
// Check data
|
||||
expect(config).to.be.eql({
|
||||
expect(config).toEqual({
|
||||
local: false,
|
||||
session: true,
|
||||
});
|
||||
expect(count).to.be.eql({
|
||||
expect(count).toEqual({
|
||||
local: 0,
|
||||
session: 9, // item 9 was missing
|
||||
});
|
||||
expect(emptyList).to.be.eql({
|
||||
expect(emptyList).toEqual({
|
||||
local: [],
|
||||
// mix of expired and skipped items
|
||||
// reverse order, 9 should not be there because it is last item
|
||||
session: [5, 4, 2, 1],
|
||||
});
|
||||
expect(cache.getItem(countKey)).to.be.equal('9');
|
||||
expect(cache.getItem(countKey)).toBe('9');
|
||||
|
||||
// Check cached items
|
||||
[0, 3, 6, 7, 8].forEach((index) => {
|
||||
expect(cache.getItem(cachePrefix + index)).to.be.equal(
|
||||
JSON.stringify(items[index]),
|
||||
`Checking item ${index}`
|
||||
expect(cache.getItem(cachePrefix + index)).toBe(
|
||||
JSON.stringify(items[index])
|
||||
);
|
||||
});
|
||||
|
||||
// Check expired items - should have been deleted
|
||||
// Also check items that weren't supposed to be added
|
||||
[2, 4, 1, 5, 9, 10, 11, 12, 13].forEach((index) => {
|
||||
expect(cache.getItem(cachePrefix + index)).to.be.equal(
|
||||
null,
|
||||
`Checking item ${index}`
|
||||
);
|
||||
expect(cache.getItem(cachePrefix + index)).toBeNull();
|
||||
});
|
||||
|
||||
// Add item 5
|
||||
storeCache(provider, icons[5]);
|
||||
expect(count).to.be.eql({
|
||||
expect(count).toEqual({
|
||||
local: 0,
|
||||
session: 9,
|
||||
});
|
||||
expect(emptyList).to.be.eql({
|
||||
expect(emptyList).toEqual({
|
||||
local: [],
|
||||
session: [4, 2, 1],
|
||||
});
|
||||
expect(cache.getItem(countKey)).to.be.equal('9');
|
||||
expect(cache.getItem(countKey)).toBe('9');
|
||||
|
||||
// Add items 4, 2, 1
|
||||
const list = [4, 2, 1];
|
||||
list.slice(0).forEach((index) => {
|
||||
expect(list.shift()).to.be.equal(index);
|
||||
expect(list.shift()).toBe(index);
|
||||
storeCache(provider, icons[index]);
|
||||
expect(count).to.be.eql({
|
||||
expect(count).toEqual({
|
||||
local: 0,
|
||||
session: 9,
|
||||
});
|
||||
expect(emptyList).to.be.eql({
|
||||
expect(emptyList).toEqual({
|
||||
local: [],
|
||||
session: list,
|
||||
});
|
||||
expect(cache.getItem(countKey)).to.be.equal('9');
|
||||
expect(cache.getItem(countKey)).toBe('9');
|
||||
});
|
||||
|
||||
// Add item 10
|
||||
storeCache(provider, icons[10]);
|
||||
expect(count).to.be.eql({
|
||||
expect(count).toEqual({
|
||||
local: 0,
|
||||
session: 10,
|
||||
});
|
||||
expect(emptyList).to.be.eql({
|
||||
expect(emptyList).toEqual({
|
||||
local: [],
|
||||
session: [],
|
||||
});
|
||||
expect(cache.getItem(countKey)).to.be.equal('10');
|
||||
expect(cache.getItem(countKey)).toBe('10');
|
||||
|
||||
// Add item 11
|
||||
storeCache(provider, icons[11]);
|
||||
expect(count).to.be.eql({
|
||||
expect(count).toEqual({
|
||||
local: 0,
|
||||
session: 11,
|
||||
});
|
||||
expect(emptyList).to.be.eql({
|
||||
expect(emptyList).toEqual({
|
||||
local: [],
|
||||
session: [],
|
||||
});
|
||||
expect(cache.getItem(countKey)).to.be.equal('11');
|
||||
expect(cache.getItem(countKey)).toBe('11');
|
||||
});
|
||||
|
||||
it('Overwrite outdated data', () => {
|
||||
@ -399,20 +383,20 @@ describe('Testing saving to localStorage', () => {
|
||||
|
||||
// Check icon storage
|
||||
const icons = getStorage(provider, prefix);
|
||||
expect(iconExists(icons, 'foo1')).to.be.equal(false);
|
||||
expect(iconExists(icons, 'foo1')).toBe(false);
|
||||
|
||||
// Load cache
|
||||
loadCache();
|
||||
|
||||
expect(config).to.be.eql({
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: false,
|
||||
});
|
||||
expect(count).to.be.eql({
|
||||
expect(count).toEqual({
|
||||
local: 0,
|
||||
session: 0,
|
||||
});
|
||||
expect(emptyList).to.be.eql({
|
||||
expect(emptyList).toEqual({
|
||||
local: [],
|
||||
session: [],
|
||||
});
|
||||
@ -436,29 +420,27 @@ describe('Testing saving to localStorage', () => {
|
||||
storeCache(provider, icon);
|
||||
|
||||
// Storing in cache should not add item to storage
|
||||
expect(iconExists(icons, 'foo')).to.be.equal(false);
|
||||
expect(iconExists(icons, 'foo')).toBe(false);
|
||||
|
||||
// Check data that should have been updated because storeCache()
|
||||
// should call load function before first execution
|
||||
expect(config).to.be.eql({
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: false,
|
||||
});
|
||||
expect(count).to.be.eql({
|
||||
expect(count).toEqual({
|
||||
local: 1,
|
||||
session: 0,
|
||||
});
|
||||
expect(emptyList).to.be.eql({
|
||||
expect(emptyList).toEqual({
|
||||
local: [],
|
||||
session: [],
|
||||
});
|
||||
|
||||
// Check cache
|
||||
expect(cache.getItem(cachePrefix + '0')).to.be.equal(
|
||||
JSON.stringify(item)
|
||||
);
|
||||
expect(cache.getItem(countKey)).to.be.equal('1');
|
||||
expect(cache.getItem(versionKey)).to.be.equal(cacheVersion);
|
||||
expect(cache.getItem(cachePrefix + '0')).toBe(JSON.stringify(item));
|
||||
expect(cache.getItem(countKey)).toBe('1');
|
||||
expect(cache.getItem(versionKey)).toBe(cacheVersion);
|
||||
});
|
||||
|
||||
it('Using both storage options', () => {
|
||||
@ -516,15 +498,15 @@ describe('Testing saving to localStorage', () => {
|
||||
loadCache();
|
||||
|
||||
// Check data
|
||||
expect(config).to.be.eql({
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: true,
|
||||
});
|
||||
expect(count).to.be.eql({
|
||||
expect(count).toEqual({
|
||||
local: 3,
|
||||
session: 4,
|
||||
});
|
||||
expect(emptyList).to.be.eql({
|
||||
expect(emptyList).toEqual({
|
||||
local: [],
|
||||
session: [],
|
||||
});
|
||||
@ -532,16 +514,10 @@ describe('Testing saving to localStorage', () => {
|
||||
// Check icon storage
|
||||
const iconsStorage = getStorage(provider, prefix);
|
||||
for (let i = 0; i < count.local; i++) {
|
||||
expect(iconExists(iconsStorage, 'foo' + i)).to.be.equal(
|
||||
true,
|
||||
`Icon foo${i} should have loaded`
|
||||
);
|
||||
expect(iconExists(iconsStorage, 'foo' + i)).toBe(true);
|
||||
}
|
||||
for (let i = 0; i < count.session; i++) {
|
||||
expect(iconExists(iconsStorage, 'bar' + i)).to.be.equal(
|
||||
true,
|
||||
`Icon bar${i} should have loaded`
|
||||
);
|
||||
expect(iconExists(iconsStorage, 'bar' + i)).toBe(true);
|
||||
}
|
||||
|
||||
// Add new item to localStorage
|
||||
@ -561,19 +537,17 @@ describe('Testing saving to localStorage', () => {
|
||||
storeCache(provider, icon);
|
||||
|
||||
// Check data
|
||||
expect(count).to.be.eql({
|
||||
expect(count).toEqual({
|
||||
local: 4, // +1
|
||||
session: 4,
|
||||
});
|
||||
expect(emptyList).to.be.eql({
|
||||
expect(emptyList).toEqual({
|
||||
local: [],
|
||||
session: [],
|
||||
});
|
||||
|
||||
// Check cache
|
||||
expect(cache1.getItem(cachePrefix + '3')).to.be.equal(
|
||||
JSON.stringify(item)
|
||||
);
|
||||
expect(cache1.getItem(cachePrefix + '3')).toBe(JSON.stringify(item));
|
||||
});
|
||||
|
||||
it('Using both storage options, but localStorage is read only', () => {
|
||||
@ -631,15 +605,15 @@ describe('Testing saving to localStorage', () => {
|
||||
loadCache();
|
||||
|
||||
// Check data
|
||||
expect(config).to.be.eql({
|
||||
expect(config).toEqual({
|
||||
local: true,
|
||||
session: true,
|
||||
});
|
||||
expect(count).to.be.eql({
|
||||
expect(count).toEqual({
|
||||
local: 3,
|
||||
session: 4,
|
||||
});
|
||||
expect(emptyList).to.be.eql({
|
||||
expect(emptyList).toEqual({
|
||||
local: [],
|
||||
session: [],
|
||||
});
|
||||
@ -647,16 +621,10 @@ describe('Testing saving to localStorage', () => {
|
||||
// Check icon storage
|
||||
const iconsStorage = getStorage(provider, prefix);
|
||||
for (let i = 0; i < count.local; i++) {
|
||||
expect(iconExists(iconsStorage, 'foo' + i)).to.be.equal(
|
||||
true,
|
||||
`Icon foo${i} should have loaded`
|
||||
);
|
||||
expect(iconExists(iconsStorage, 'foo' + i)).toBe(true);
|
||||
}
|
||||
for (let i = 0; i < count.session; i++) {
|
||||
expect(iconExists(iconsStorage, 'bar' + i)).to.be.equal(
|
||||
true,
|
||||
`Icon bar${i} should have loaded`
|
||||
);
|
||||
expect(iconExists(iconsStorage, 'bar' + i)).toBe(true);
|
||||
}
|
||||
|
||||
// Set localStorage to read-only
|
||||
@ -679,18 +647,16 @@ describe('Testing saving to localStorage', () => {
|
||||
storeCache(provider, icon);
|
||||
|
||||
// Check data
|
||||
expect(count).to.be.eql({
|
||||
expect(count).toEqual({
|
||||
local: 3,
|
||||
session: 5,
|
||||
});
|
||||
expect(emptyList).to.be.eql({
|
||||
expect(emptyList).toEqual({
|
||||
local: [],
|
||||
session: [],
|
||||
});
|
||||
|
||||
// Check cache
|
||||
expect(cache2.getItem(cachePrefix + '4')).to.be.equal(
|
||||
JSON.stringify(item)
|
||||
);
|
||||
expect(cache2.getItem(cachePrefix + '4')).toBe(JSON.stringify(item));
|
||||
});
|
||||
});
|
@ -1,10 +1,8 @@
|
||||
import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import { fullIcon } from '@iconify/utils/lib/icon';
|
||||
import {
|
||||
storageFunctions,
|
||||
allowSimpleNames,
|
||||
} from '../../lib/storage/functions';
|
||||
import { fullIcon } from '@iconify/utils/lib/icon';
|
||||
|
||||
describe('Testing IconifyStorageFunctions', () => {
|
||||
let count = 0;
|
||||
@ -18,18 +16,18 @@ describe('Testing IconifyStorageFunctions', () => {
|
||||
const testName = `@${provider}:foo:bar`;
|
||||
|
||||
// Empty
|
||||
expect(storageFunctions.iconExists(testName)).to.be.equal(false);
|
||||
expect(storageFunctions.getIcon(testName)).to.be.equal(null);
|
||||
expect(storageFunctions.listIcons(provider)).to.be.eql([]);
|
||||
expect(storageFunctions.iconExists(testName)).toBe(false);
|
||||
expect(storageFunctions.getIcon(testName)).toBeNull();
|
||||
expect(storageFunctions.listIcons(provider)).toEqual([]);
|
||||
|
||||
// Add and test one icon
|
||||
expect(
|
||||
storageFunctions.addIcon(testName, {
|
||||
body: '<g />',
|
||||
})
|
||||
).to.be.equal(true);
|
||||
expect(storageFunctions.iconExists(testName)).to.be.equal(true);
|
||||
expect(storageFunctions.listIcons(provider)).to.be.eql([testName]);
|
||||
).toBe(true);
|
||||
expect(storageFunctions.iconExists(testName)).toBe(true);
|
||||
expect(storageFunctions.listIcons(provider)).toEqual([testName]);
|
||||
});
|
||||
|
||||
it('Invalid icon name', () => {
|
||||
@ -39,16 +37,16 @@ describe('Testing IconifyStorageFunctions', () => {
|
||||
allowSimpleNames(false);
|
||||
|
||||
// Empty
|
||||
expect(storageFunctions.iconExists(testName)).to.be.equal(false);
|
||||
expect(storageFunctions.getIcon(testName)).to.be.equal(null);
|
||||
expect(storageFunctions.iconExists(testName)).toBe(false);
|
||||
expect(storageFunctions.getIcon(testName)).toBeNull();
|
||||
|
||||
// Add and test one icon (icon should not be added)
|
||||
expect(
|
||||
storageFunctions.addIcon(testName, {
|
||||
body: '<g />',
|
||||
})
|
||||
).to.be.equal(false);
|
||||
expect(storageFunctions.iconExists(testName)).to.be.equal(false);
|
||||
).toBe(false);
|
||||
expect(storageFunctions.iconExists(testName)).toBe(false);
|
||||
});
|
||||
|
||||
it('Invalid icon set', () => {
|
||||
@ -65,7 +63,7 @@ describe('Testing IconifyStorageFunctions', () => {
|
||||
},
|
||||
},
|
||||
})
|
||||
).to.be.equal(false);
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it('Simple icon name', () => {
|
||||
@ -75,16 +73,16 @@ describe('Testing IconifyStorageFunctions', () => {
|
||||
allowSimpleNames(true);
|
||||
|
||||
// Empty
|
||||
expect(storageFunctions.iconExists(testName)).to.be.equal(false);
|
||||
expect(storageFunctions.getIcon(testName)).to.be.equal(null);
|
||||
expect(storageFunctions.iconExists(testName)).toBe(false);
|
||||
expect(storageFunctions.getIcon(testName)).toBeNull();
|
||||
|
||||
// Add and test one icon
|
||||
expect(
|
||||
storageFunctions.addIcon(testName, {
|
||||
body: '<g />',
|
||||
})
|
||||
).to.be.equal(true);
|
||||
expect(storageFunctions.iconExists(testName)).to.be.equal(true);
|
||||
).toBe(true);
|
||||
expect(storageFunctions.iconExists(testName)).toBe(true);
|
||||
|
||||
// Reset config after test
|
||||
allowSimpleNames(false);
|
||||
@ -114,12 +112,12 @@ describe('Testing IconifyStorageFunctions', () => {
|
||||
},
|
||||
},
|
||||
})
|
||||
).to.be.equal(true);
|
||||
).toBe(true);
|
||||
|
||||
// Test 'test'
|
||||
name = name1;
|
||||
expect(storageFunctions.iconExists(name)).to.be.equal(true);
|
||||
expect(storageFunctions.getIcon(name)).to.be.eql(
|
||||
expect(storageFunctions.iconExists(name)).toBe(true);
|
||||
expect(storageFunctions.getIcon(name)).toEqual(
|
||||
fullIcon({
|
||||
body: '<g data-icon="basic-icon" />',
|
||||
})
|
||||
@ -127,9 +125,9 @@ describe('Testing IconifyStorageFunctions', () => {
|
||||
|
||||
// Test prefixed icon, using ':' separator
|
||||
name = `${prefix2}:${name2}`;
|
||||
expect(storageFunctions.listIcons('', prefix2)).to.be.eql([name]);
|
||||
expect(storageFunctions.iconExists(name)).to.be.equal(true);
|
||||
expect(storageFunctions.getIcon(name)).to.be.eql(
|
||||
expect(storageFunctions.listIcons('', prefix2)).toEqual([name]);
|
||||
expect(storageFunctions.iconExists(name)).toBe(true);
|
||||
expect(storageFunctions.getIcon(name)).toEqual(
|
||||
fullIcon({
|
||||
body: '<g data-icon="prefixed-icon" />',
|
||||
})
|
||||
@ -137,8 +135,8 @@ describe('Testing IconifyStorageFunctions', () => {
|
||||
|
||||
// Test prefixed icon, using '-' separator
|
||||
name = `${prefix2}-${name2}`;
|
||||
expect(storageFunctions.iconExists(name)).to.be.equal(true);
|
||||
expect(storageFunctions.getIcon(name)).to.be.eql(
|
||||
expect(storageFunctions.iconExists(name)).toBe(true);
|
||||
expect(storageFunctions.getIcon(name)).toEqual(
|
||||
fullIcon({
|
||||
body: '<g data-icon="prefixed-icon" />',
|
||||
})
|
@ -1,8 +1,8 @@
|
||||
{
|
||||
"extends": "../tsconfig-base.json",
|
||||
"compilerOptions": {
|
||||
"types": ["node", "mocha"],
|
||||
"outDir": "../tests-compiled",
|
||||
"rootDir": "."
|
||||
"types": ["node", "jest"],
|
||||
"rootDir": ".",
|
||||
"outDir": "../tests-compiled"
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"rootDir": "./src",
|
||||
"outDir": "./lib",
|
||||
"target": "ES2019",
|
||||
"module": "commonjs",
|
||||
"module": "CommonJS",
|
||||
"declaration": true,
|
||||
"declarationMap": false,
|
||||
"sourceMap": false,
|
||||
|
@ -1,12 +1,8 @@
|
||||
{
|
||||
"files": [],
|
||||
"include": [],
|
||||
"references": [
|
||||
{
|
||||
"path": "./src/tsconfig.json"
|
||||
},
|
||||
{
|
||||
"path": "./tests/tsconfig.json"
|
||||
}
|
||||
]
|
||||
"extends": "./tsconfig-base.json",
|
||||
"include": ["src/**/*.ts", ".eslintrc.js"],
|
||||
"compilerOptions": {
|
||||
"rootDir": "./src",
|
||||
"outDir": "./lib"
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user