2020-04-28 09:47:35 +00:00
|
|
|
import {
|
|
|
|
callbacks,
|
|
|
|
updateCallbacks,
|
|
|
|
storeCallback,
|
|
|
|
} from '../../lib/api/callbacks';
|
|
|
|
import { sortIcons } from '../../lib/icon/sort';
|
2020-12-21 15:15:45 +00:00
|
|
|
import { getStorage, addIconSet } from '../../lib/storage/storage';
|
2020-04-28 09:47:35 +00:00
|
|
|
|
|
|
|
describe('Testing API callbacks', () => {
|
|
|
|
let prefixCounter = 0;
|
|
|
|
function nextPrefix(): string {
|
|
|
|
prefixCounter++;
|
2022-03-16 21:30:16 +00:00
|
|
|
return (
|
|
|
|
'api-cb-test-' +
|
|
|
|
(prefixCounter < 10 ? '0' : '') +
|
|
|
|
prefixCounter.toString()
|
|
|
|
);
|
2020-04-28 09:47:35 +00:00
|
|
|
}
|
|
|
|
|
2020-05-29 19:08:45 +00:00
|
|
|
it('Simple callback', (done) => {
|
|
|
|
const provider = 'iconify';
|
2020-04-28 09:47:35 +00:00
|
|
|
const prefix = nextPrefix();
|
|
|
|
let counter = 0;
|
|
|
|
|
2020-05-29 19:08:45 +00:00
|
|
|
const storage = getStorage(provider, prefix);
|
2020-04-28 09:47:35 +00:00
|
|
|
const abort = storeCallback(
|
|
|
|
(loaded, missing, pending, unsubscribe) => {
|
2021-09-23 21:27:16 +00:00
|
|
|
expect(unsubscribe).toBe(abort);
|
2020-04-28 09:47:35 +00:00
|
|
|
|
|
|
|
counter++;
|
|
|
|
switch (counter) {
|
|
|
|
case 1:
|
|
|
|
// First run - icon1 should be loaded, icon3 should be missing
|
2021-09-23 21:27:16 +00:00
|
|
|
expect(loaded).toEqual([
|
2020-04-28 09:47:35 +00:00
|
|
|
{
|
2020-05-29 19:08:45 +00:00
|
|
|
provider,
|
2020-04-28 09:47:35 +00:00
|
|
|
prefix,
|
|
|
|
name: 'icon1',
|
|
|
|
},
|
|
|
|
]);
|
2021-09-23 21:27:16 +00:00
|
|
|
expect(missing).toEqual([
|
2020-04-28 09:47:35 +00:00
|
|
|
{
|
2020-05-29 19:08:45 +00:00
|
|
|
provider,
|
2020-04-28 09:47:35 +00:00
|
|
|
prefix,
|
|
|
|
name: 'icon3',
|
|
|
|
},
|
|
|
|
]);
|
2021-09-23 21:27:16 +00:00
|
|
|
expect(pending).toEqual([
|
2020-04-28 09:47:35 +00:00
|
|
|
{
|
2020-05-29 19:08:45 +00:00
|
|
|
provider,
|
2020-04-28 09:47:35 +00:00
|
|
|
prefix,
|
|
|
|
name: 'icon2',
|
|
|
|
},
|
|
|
|
]);
|
2021-09-23 21:27:16 +00:00
|
|
|
expect(callbacks[provider][prefix].length).toBe(1);
|
2020-04-28 09:47:35 +00:00
|
|
|
|
|
|
|
// Add icon2 and trigger update
|
|
|
|
addIconSet(storage, {
|
|
|
|
prefix: prefix,
|
|
|
|
icons: {
|
|
|
|
icon2: {
|
|
|
|
body: '<g></g>',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-05-29 19:08:45 +00:00
|
|
|
updateCallbacks(provider, prefix);
|
2020-04-28 09:47:35 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
// Second run - icon2 should be added, completing callback
|
2021-09-23 21:27:16 +00:00
|
|
|
expect(loaded).toEqual([
|
2020-04-28 09:47:35 +00:00
|
|
|
{
|
2020-05-29 19:08:45 +00:00
|
|
|
provider,
|
2020-04-28 09:47:35 +00:00
|
|
|
prefix,
|
|
|
|
name: 'icon1',
|
|
|
|
},
|
|
|
|
{
|
2020-05-29 19:08:45 +00:00
|
|
|
provider,
|
2020-04-28 09:47:35 +00:00
|
|
|
prefix,
|
|
|
|
name: 'icon2',
|
|
|
|
},
|
|
|
|
]);
|
2021-09-23 21:27:16 +00:00
|
|
|
expect(missing).toEqual([
|
2020-04-28 09:47:35 +00:00
|
|
|
{
|
2020-05-29 19:08:45 +00:00
|
|
|
provider,
|
2020-04-28 09:47:35 +00:00
|
|
|
prefix,
|
|
|
|
name: 'icon3',
|
|
|
|
},
|
|
|
|
]);
|
2021-09-23 21:27:16 +00:00
|
|
|
expect(pending).toEqual([]);
|
|
|
|
expect(callbacks[provider][prefix].length).toBe(0);
|
2020-04-28 09:47:35 +00:00
|
|
|
done();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
sortIcons([
|
|
|
|
{
|
2020-05-29 19:08:45 +00:00
|
|
|
provider,
|
2020-04-28 09:47:35 +00:00
|
|
|
prefix,
|
|
|
|
name: 'icon1',
|
|
|
|
},
|
|
|
|
{
|
2020-05-29 19:08:45 +00:00
|
|
|
provider,
|
2020-04-28 09:47:35 +00:00
|
|
|
prefix,
|
|
|
|
name: 'icon2',
|
|
|
|
},
|
|
|
|
{
|
2020-05-29 19:08:45 +00:00
|
|
|
provider,
|
2020-04-28 09:47:35 +00:00
|
|
|
prefix,
|
|
|
|
name: 'icon3',
|
|
|
|
},
|
|
|
|
]),
|
2020-05-29 19:08:45 +00:00
|
|
|
[
|
|
|
|
{
|
|
|
|
provider,
|
|
|
|
prefix,
|
|
|
|
},
|
|
|
|
]
|
2020-04-28 09:47:35 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// Test callbacks
|
2021-09-23 21:27:16 +00:00
|
|
|
expect(callbacks[provider][prefix].length).toBe(1);
|
2020-04-28 09:47:35 +00:00
|
|
|
|
|
|
|
// Test update - should do nothing
|
2020-05-29 19:08:45 +00:00
|
|
|
updateCallbacks(provider, prefix);
|
2020-04-28 09:47:35 +00:00
|
|
|
|
|
|
|
// Wait for tick because updateCallbacks will use one
|
|
|
|
setTimeout(() => {
|
|
|
|
// Callback should not have been called yet
|
2021-09-23 21:27:16 +00:00
|
|
|
expect(counter).toBe(0);
|
2020-04-28 09:47:35 +00:00
|
|
|
|
|
|
|
// Add few icons and run updateCallbacks
|
|
|
|
addIconSet(storage, {
|
|
|
|
prefix: prefix,
|
|
|
|
icons: {
|
|
|
|
icon1: {
|
|
|
|
body: '<g></g>',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
not_found: ['icon3'],
|
|
|
|
});
|
2020-05-29 19:08:45 +00:00
|
|
|
updateCallbacks(provider, prefix);
|
2020-04-28 09:47:35 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Callback that should not be stored', () => {
|
2020-05-29 19:08:45 +00:00
|
|
|
const provider = '';
|
2020-04-28 09:47:35 +00:00
|
|
|
const prefix = nextPrefix();
|
|
|
|
|
2020-05-29 19:08:45 +00:00
|
|
|
const storage = getStorage(provider, prefix);
|
2020-04-28 09:47:35 +00:00
|
|
|
addIconSet(storage, {
|
|
|
|
prefix,
|
|
|
|
icons: {
|
|
|
|
icon1: {
|
|
|
|
body: '<path d="" />',
|
|
|
|
},
|
|
|
|
icon2: {
|
|
|
|
body: '<path d="" />',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
not_found: ['icon3'],
|
|
|
|
});
|
|
|
|
|
|
|
|
storeCallback(
|
2021-09-23 21:27:16 +00:00
|
|
|
() => {
|
2020-04-28 09:47:35 +00:00
|
|
|
throw new Error('This code should not be executed!');
|
|
|
|
},
|
|
|
|
sortIcons([
|
|
|
|
{
|
2020-05-29 19:08:45 +00:00
|
|
|
provider,
|
2020-04-28 09:47:35 +00:00
|
|
|
prefix,
|
|
|
|
name: 'icon1',
|
|
|
|
},
|
|
|
|
{
|
2020-05-29 19:08:45 +00:00
|
|
|
provider,
|
2020-04-28 09:47:35 +00:00
|
|
|
prefix,
|
|
|
|
name: 'icon2',
|
|
|
|
},
|
|
|
|
{
|
2020-05-29 19:08:45 +00:00
|
|
|
provider,
|
2020-04-28 09:47:35 +00:00
|
|
|
prefix,
|
|
|
|
name: 'icon3',
|
|
|
|
},
|
|
|
|
]),
|
2020-05-29 19:08:45 +00:00
|
|
|
[
|
|
|
|
{
|
|
|
|
provider,
|
|
|
|
prefix,
|
|
|
|
},
|
|
|
|
]
|
2020-04-28 09:47:35 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// callbacks should not have been initialised
|
2021-09-23 21:27:16 +00:00
|
|
|
expect(callbacks[prefix]).toBeUndefined();
|
2020-04-28 09:47:35 +00:00
|
|
|
});
|
|
|
|
|
2020-05-29 19:08:45 +00:00
|
|
|
it('Cancel callback', (done) => {
|
|
|
|
const provider = 'foo';
|
2020-04-28 09:47:35 +00:00
|
|
|
const prefix = nextPrefix();
|
|
|
|
let counter = 0;
|
|
|
|
|
2020-05-29 19:08:45 +00:00
|
|
|
const storage = getStorage(provider, prefix);
|
2020-04-28 09:47:35 +00:00
|
|
|
const abort = storeCallback(
|
|
|
|
(loaded, missing, pending, unsubscribe) => {
|
2021-09-23 21:27:16 +00:00
|
|
|
expect(unsubscribe).toBe(abort);
|
2020-04-28 09:47:35 +00:00
|
|
|
|
|
|
|
counter++;
|
2021-09-23 21:27:16 +00:00
|
|
|
expect(counter).toBe(1);
|
2020-04-28 09:47:35 +00:00
|
|
|
|
|
|
|
// First run - icon1 should be loaded, icon3 should be missing
|
2021-09-23 21:27:16 +00:00
|
|
|
expect(loaded).toEqual([
|
2020-04-28 09:47:35 +00:00
|
|
|
{
|
2020-05-29 19:08:45 +00:00
|
|
|
provider,
|
2020-04-28 09:47:35 +00:00
|
|
|
prefix,
|
|
|
|
name: 'icon1',
|
|
|
|
},
|
|
|
|
]);
|
2021-09-23 21:27:16 +00:00
|
|
|
expect(missing).toEqual([
|
2020-04-28 09:47:35 +00:00
|
|
|
{
|
2020-05-29 19:08:45 +00:00
|
|
|
provider,
|
2020-04-28 09:47:35 +00:00
|
|
|
prefix,
|
|
|
|
name: 'icon3',
|
|
|
|
},
|
|
|
|
]);
|
2021-09-23 21:27:16 +00:00
|
|
|
expect(pending).toEqual([
|
2020-04-28 09:47:35 +00:00
|
|
|
{
|
2020-05-29 19:08:45 +00:00
|
|
|
provider,
|
2020-04-28 09:47:35 +00:00
|
|
|
prefix,
|
|
|
|
name: 'icon2',
|
|
|
|
},
|
|
|
|
]);
|
2021-09-23 21:27:16 +00:00
|
|
|
expect(callbacks[provider][prefix].length).toBe(1);
|
2020-04-28 09:47:35 +00:00
|
|
|
|
|
|
|
// Add icon2 and trigger update
|
|
|
|
addIconSet(storage, {
|
|
|
|
prefix: prefix,
|
|
|
|
icons: {
|
|
|
|
icon2: {
|
|
|
|
body: '<g></g>',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-05-29 19:08:45 +00:00
|
|
|
updateCallbacks(provider, prefix);
|
2020-04-28 09:47:35 +00:00
|
|
|
|
|
|
|
// Unsubscribe and set timer to call done()
|
|
|
|
unsubscribe();
|
2021-09-23 21:27:16 +00:00
|
|
|
expect(callbacks[provider][prefix].length).toBe(0);
|
2020-04-28 09:47:35 +00:00
|
|
|
setTimeout(done);
|
|
|
|
},
|
|
|
|
sortIcons([
|
|
|
|
{
|
2020-05-29 19:08:45 +00:00
|
|
|
provider,
|
2020-04-28 09:47:35 +00:00
|
|
|
prefix,
|
|
|
|
name: 'icon1',
|
|
|
|
},
|
|
|
|
{
|
2020-05-29 19:08:45 +00:00
|
|
|
provider,
|
2020-04-28 09:47:35 +00:00
|
|
|
prefix,
|
|
|
|
name: 'icon2',
|
|
|
|
},
|
|
|
|
{
|
2020-05-29 19:08:45 +00:00
|
|
|
provider,
|
2020-04-28 09:47:35 +00:00
|
|
|
prefix,
|
|
|
|
name: 'icon3',
|
|
|
|
},
|
|
|
|
]),
|
2020-05-29 19:08:45 +00:00
|
|
|
[
|
|
|
|
{
|
|
|
|
provider,
|
|
|
|
prefix,
|
|
|
|
},
|
|
|
|
]
|
2020-04-28 09:47:35 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// Test callbacks
|
2021-09-23 21:27:16 +00:00
|
|
|
expect(callbacks[provider][prefix].length).toBe(1);
|
2020-04-28 09:47:35 +00:00
|
|
|
|
|
|
|
// Test update - should do nothing
|
2020-05-29 19:08:45 +00:00
|
|
|
updateCallbacks(provider, prefix);
|
2020-04-28 09:47:35 +00:00
|
|
|
|
|
|
|
// Wait for tick because updateCallbacks will use one
|
|
|
|
setTimeout(() => {
|
|
|
|
// Callback should not have been called yet
|
2021-09-23 21:27:16 +00:00
|
|
|
expect(counter).toBe(0);
|
2020-04-28 09:47:35 +00:00
|
|
|
|
|
|
|
// Add few icons and run updateCallbacks
|
|
|
|
addIconSet(storage, {
|
|
|
|
prefix: prefix,
|
|
|
|
icons: {
|
|
|
|
icon1: {
|
|
|
|
body: '<g></g>',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
not_found: ['icon3'],
|
|
|
|
});
|
2020-05-29 19:08:45 +00:00
|
|
|
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) => {
|
2021-09-23 21:27:16 +00:00
|
|
|
expect(unsubscribe).toBe(abort);
|
2020-05-29 19:08:45 +00:00
|
|
|
|
|
|
|
counter++;
|
|
|
|
switch (counter) {
|
|
|
|
case 1:
|
|
|
|
// First run - icon1 should be loaded, icon3 should be missing
|
2021-09-23 21:27:16 +00:00
|
|
|
expect(loaded).toEqual([
|
2020-05-29 19:08:45 +00:00
|
|
|
{
|
|
|
|
provider,
|
|
|
|
prefix: prefix1,
|
|
|
|
name: 'icon1',
|
|
|
|
},
|
|
|
|
]);
|
2021-09-23 21:27:16 +00:00
|
|
|
expect(missing).toEqual([
|
2020-05-29 19:08:45 +00:00
|
|
|
{
|
|
|
|
provider,
|
|
|
|
prefix: prefix1,
|
|
|
|
name: 'icon3',
|
|
|
|
},
|
|
|
|
]);
|
2021-09-23 21:27:16 +00:00
|
|
|
expect(pending).toEqual([
|
2020-05-29 19:08:45 +00:00
|
|
|
{
|
|
|
|
provider,
|
|
|
|
prefix: prefix2,
|
|
|
|
name: 'icon2',
|
|
|
|
},
|
|
|
|
]);
|
2021-09-23 21:27:16 +00:00
|
|
|
expect(callbacks[provider][prefix1].length).toBe(0);
|
|
|
|
expect(callbacks[provider][prefix2].length).toBe(1);
|
2020-05-29 19:08:45 +00:00
|
|
|
|
|
|
|
// 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
|
2021-09-23 21:27:16 +00:00
|
|
|
expect(callbacks[provider][prefix1].length).toBe(0);
|
|
|
|
expect(callbacks[provider][prefix2].length).toBe(0);
|
2020-05-29 19:08:45 +00:00
|
|
|
done();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2022-03-16 21:30:16 +00:00
|
|
|
done(`Callback was called ${counter} times.`);
|
2020-05-29 19:08:45 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
sortIcons([
|
|
|
|
{
|
|
|
|
provider,
|
|
|
|
prefix: prefix1,
|
|
|
|
name: 'icon1',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
provider,
|
|
|
|
prefix: prefix2,
|
|
|
|
name: 'icon2',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
provider,
|
|
|
|
prefix: prefix1,
|
|
|
|
name: 'icon3',
|
|
|
|
},
|
|
|
|
]),
|
|
|
|
[
|
|
|
|
{ provider, prefix: prefix1 },
|
|
|
|
{ provider, prefix: prefix2 },
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
// Test callbacks
|
2021-09-23 21:27:16 +00:00
|
|
|
expect(callbacks[provider][prefix1].length).toBe(1);
|
|
|
|
expect(callbacks[provider][prefix2].length).toBe(1);
|
2020-05-29 19:08:45 +00:00
|
|
|
|
|
|
|
// Test update - should do nothing
|
|
|
|
updateCallbacks(provider, prefix1);
|
|
|
|
|
|
|
|
// Wait for tick because updateCallbacks will use one
|
|
|
|
setTimeout(() => {
|
|
|
|
// Callback should not have been called yet
|
2021-09-23 21:27:16 +00:00
|
|
|
expect(counter).toBe(0);
|
2020-05-29 19:08:45 +00:00
|
|
|
|
|
|
|
// Add few icons and run updateCallbacks
|
|
|
|
addIconSet(storage1, {
|
|
|
|
prefix: prefix1,
|
|
|
|
icons: {
|
|
|
|
icon1: {
|
|
|
|
body: '<g></g>',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
not_found: ['icon3'],
|
|
|
|
});
|
|
|
|
updateCallbacks(provider, prefix1);
|
2020-04-28 09:47:35 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-05-29 19:08:45 +00:00
|
|
|
it('Multiple providers', (done) => {
|
|
|
|
const provider1 = nextPrefix();
|
|
|
|
const provider2 = nextPrefix();
|
2020-04-28 09:47:35 +00:00
|
|
|
const prefix1 = nextPrefix();
|
|
|
|
const prefix2 = nextPrefix();
|
|
|
|
let counter = 0;
|
|
|
|
|
2020-05-29 19:08:45 +00:00
|
|
|
const storage1 = getStorage(provider1, prefix1);
|
|
|
|
const storage2 = getStorage(provider2, prefix2);
|
2020-04-28 09:47:35 +00:00
|
|
|
|
|
|
|
const abort = storeCallback(
|
|
|
|
(loaded, missing, pending, unsubscribe) => {
|
2021-09-23 21:27:16 +00:00
|
|
|
expect(unsubscribe).toBe(abort);
|
2020-04-28 09:47:35 +00:00
|
|
|
|
|
|
|
counter++;
|
|
|
|
switch (counter) {
|
|
|
|
case 1:
|
|
|
|
// First run - icon1 should be loaded, icon3 should be missing
|
2021-09-23 21:27:16 +00:00
|
|
|
expect(loaded).toEqual([
|
2020-04-28 09:47:35 +00:00
|
|
|
{
|
2020-05-29 19:08:45 +00:00
|
|
|
provider: provider1,
|
2020-04-28 09:47:35 +00:00
|
|
|
prefix: prefix1,
|
|
|
|
name: 'icon1',
|
|
|
|
},
|
|
|
|
]);
|
2021-09-23 21:27:16 +00:00
|
|
|
expect(missing).toEqual([
|
2020-04-28 09:47:35 +00:00
|
|
|
{
|
2020-05-29 19:08:45 +00:00
|
|
|
provider: provider1,
|
2020-04-28 09:47:35 +00:00
|
|
|
prefix: prefix1,
|
|
|
|
name: 'icon3',
|
|
|
|
},
|
|
|
|
]);
|
2021-09-23 21:27:16 +00:00
|
|
|
expect(pending).toEqual([
|
2020-04-28 09:47:35 +00:00
|
|
|
{
|
2020-05-29 19:08:45 +00:00
|
|
|
provider: provider2,
|
2020-04-28 09:47:35 +00:00
|
|
|
prefix: prefix2,
|
|
|
|
name: 'icon2',
|
|
|
|
},
|
|
|
|
]);
|
2021-09-23 21:27:16 +00:00
|
|
|
expect(callbacks[provider1][prefix1].length).toBe(0);
|
|
|
|
expect(callbacks[provider2][prefix2].length).toBe(1);
|
2020-05-29 19:08:45 +00:00
|
|
|
|
|
|
|
// Make sure providers/prefixes aren't mixed
|
2021-09-23 21:27:16 +00:00
|
|
|
expect(callbacks[provider1][prefix2]).toBeUndefined();
|
|
|
|
expect(callbacks[provider2][prefix1]).toBeUndefined();
|
2020-04-28 09:47:35 +00:00
|
|
|
|
|
|
|
// Add icon2 and trigger update
|
|
|
|
addIconSet(storage2, {
|
|
|
|
prefix: prefix2,
|
|
|
|
icons: {
|
|
|
|
icon2: {
|
|
|
|
body: '<g></g>',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-05-29 19:08:45 +00:00
|
|
|
updateCallbacks(provider2, prefix2);
|
2020-04-28 09:47:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
// Second run - icon2 should be loaded
|
2021-09-23 21:27:16 +00:00
|
|
|
expect(callbacks[provider1][prefix1].length).toBe(0);
|
|
|
|
expect(callbacks[provider2][prefix2].length).toBe(0);
|
2020-05-29 19:08:45 +00:00
|
|
|
|
|
|
|
// Make sure providers/prefixes aren't mixed
|
2021-09-23 21:27:16 +00:00
|
|
|
expect(callbacks[provider1][prefix2]).toBeUndefined();
|
|
|
|
expect(callbacks[provider2][prefix1]).toBeUndefined();
|
2020-05-29 19:08:45 +00:00
|
|
|
|
2020-04-28 09:47:35 +00:00
|
|
|
done();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2022-03-16 21:30:16 +00:00
|
|
|
done(`Callback was called ${counter} times.`);
|
2020-04-28 09:47:35 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
sortIcons([
|
|
|
|
{
|
2020-05-29 19:08:45 +00:00
|
|
|
provider: provider1,
|
2020-04-28 09:47:35 +00:00
|
|
|
prefix: prefix1,
|
|
|
|
name: 'icon1',
|
|
|
|
},
|
|
|
|
{
|
2020-05-29 19:08:45 +00:00
|
|
|
provider: provider2,
|
2020-04-28 09:47:35 +00:00
|
|
|
prefix: prefix2,
|
|
|
|
name: 'icon2',
|
|
|
|
},
|
|
|
|
{
|
2020-05-29 19:08:45 +00:00
|
|
|
provider: provider1,
|
2020-04-28 09:47:35 +00:00
|
|
|
prefix: prefix1,
|
|
|
|
name: 'icon3',
|
|
|
|
},
|
|
|
|
]),
|
2020-05-29 19:08:45 +00:00
|
|
|
[
|
|
|
|
{ provider: provider1, prefix: prefix1 },
|
|
|
|
{ provider: provider2, prefix: prefix2 },
|
|
|
|
]
|
2020-04-28 09:47:35 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// Test callbacks
|
2021-09-23 21:27:16 +00:00
|
|
|
expect(callbacks[provider1][prefix1].length).toBe(1);
|
|
|
|
expect(callbacks[provider2][prefix2].length).toBe(1);
|
2020-05-29 19:08:45 +00:00
|
|
|
|
2021-09-23 21:27:16 +00:00
|
|
|
expect(callbacks[provider1][prefix2]).toBeUndefined();
|
|
|
|
expect(callbacks[provider2][prefix1]).toBeUndefined();
|
2020-04-28 09:47:35 +00:00
|
|
|
|
|
|
|
// Test update - should do nothing
|
2020-05-29 19:08:45 +00:00
|
|
|
updateCallbacks(provider1, prefix1);
|
2020-04-28 09:47:35 +00:00
|
|
|
|
|
|
|
// Wait for tick because updateCallbacks will use one
|
|
|
|
setTimeout(() => {
|
|
|
|
// Callback should not have been called yet
|
2021-09-23 21:27:16 +00:00
|
|
|
expect(counter).toBe(0);
|
2020-04-28 09:47:35 +00:00
|
|
|
|
|
|
|
// Add few icons and run updateCallbacks
|
|
|
|
addIconSet(storage1, {
|
|
|
|
prefix: prefix1,
|
|
|
|
icons: {
|
|
|
|
icon1: {
|
|
|
|
body: '<g></g>',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
not_found: ['icon3'],
|
|
|
|
});
|
2020-05-29 19:08:45 +00:00
|
|
|
updateCallbacks(provider1, prefix1);
|
2020-04-28 09:47:35 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|