Add test for TagColorsStorage

This commit is contained in:
Alejandro Celaya 2023-08-06 17:11:27 +02:00
parent 89e75653d7
commit 75fed53ba4
2 changed files with 38 additions and 2 deletions

View file

@ -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);
});
});

View 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);
});
});
});