From 75fed53ba426595a9bbb100b1f7c0324e6a1e972 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 6 Aug 2023 17:11:27 +0200 Subject: [PATCH] Add test for TagColorsStorage --- test/utils/helpers/csvjson.test.ts | 4 +-- test/utils/services/TagColorsStorage.test.ts | 36 ++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 test/utils/services/TagColorsStorage.test.ts diff --git a/test/utils/helpers/csvjson.test.ts b/test/utils/helpers/csvjson.test.ts index ff924779..921b3302 100644 --- a/test/utils/helpers/csvjson.test.ts +++ b/test/utils/helpers/csvjson.test.ts @@ -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); }); }); diff --git a/test/utils/services/TagColorsStorage.test.ts b/test/utils/services/TagColorsStorage.test.ts new file mode 100644 index 00000000..abbb908a --- /dev/null +++ b/test/utils/services/TagColorsStorage.test.ts @@ -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({ 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); + }); + }); +});