mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-23 01:20:24 +03:00
Add test for TagColorsStorage
This commit is contained in:
parent
89e75653d7
commit
75fed53ba4
2 changed files with 38 additions and 2 deletions
|
@ -10,13 +10,13 @@ describe('csvjson', () => {
|
|||
];
|
||||
|
||||
describe('csvToJson', () => {
|
||||
test('parses CSVs as expected', async () => {
|
||||
it('parses CSVs as expected', async () => {
|
||||
expect(await csvToJson(csv)).toEqual(json);
|
||||
});
|
||||
});
|
||||
|
||||
describe('jsonToCsv', () => {
|
||||
test('parses JSON as expected', () => {
|
||||
it('parses JSON as expected', () => {
|
||||
expect(jsonToCsv(json)).toEqual(csv);
|
||||
});
|
||||
});
|
||||
|
|
36
test/utils/services/TagColorsStorage.test.ts
Normal file
36
test/utils/services/TagColorsStorage.test.ts
Normal file
|
@ -0,0 +1,36 @@
|
|||
import { fromPartial } from '@total-typescript/shoehorn';
|
||||
import type { LocalStorage } from '../../../src/utils/services/LocalStorage';
|
||||
import { TagColorsStorage } from '../../../src/utils/services/TagColorsStorage';
|
||||
|
||||
describe('TagColorsStorage', () => {
|
||||
const get = vi.fn();
|
||||
const set = vi.fn();
|
||||
const localStorage = fromPartial<LocalStorage>({ get, set });
|
||||
let tagColorsStorage: TagColorsStorage;
|
||||
|
||||
beforeEach(() => {
|
||||
tagColorsStorage = new TagColorsStorage(localStorage);
|
||||
});
|
||||
|
||||
describe('getTagColors', () => {
|
||||
it.each([
|
||||
[undefined, {}],
|
||||
[{ foo: 'red', var: 'green' }, { foo: 'red', var: 'green' }],
|
||||
])('returns colors from local storage', (colorsFromStorage, expectedValue) => {
|
||||
get.mockReturnValue(colorsFromStorage);
|
||||
|
||||
expect(tagColorsStorage.getTagColors()).toEqual(expectedValue);
|
||||
expect(get).toHaveBeenCalledOnce();
|
||||
});
|
||||
});
|
||||
|
||||
describe('storeTagColors', () => {
|
||||
it('stores provied colors', () => {
|
||||
const colors = { foo: 'red' };
|
||||
|
||||
tagColorsStorage.storeTagColors(colors);
|
||||
|
||||
expect(set).toHaveBeenCalledWith('colors', colors);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue