diff options
Diffstat (limited to 'spec/frontend/import_entities/import_groups/graphql/services/local_storage_cache_spec.js')
-rw-r--r-- | spec/frontend/import_entities/import_groups/graphql/services/local_storage_cache_spec.js | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/spec/frontend/import_entities/import_groups/graphql/services/local_storage_cache_spec.js b/spec/frontend/import_entities/import_groups/graphql/services/local_storage_cache_spec.js new file mode 100644 index 00000000000..b44a2767ad8 --- /dev/null +++ b/spec/frontend/import_entities/import_groups/graphql/services/local_storage_cache_spec.js @@ -0,0 +1,61 @@ +import { + KEY, + LocalStorageCache, +} from '~/import_entities/import_groups/graphql/services/local_storage_cache'; + +describe('Local storage cache', () => { + let cache; + let storage; + + beforeEach(() => { + storage = { + getItem: jest.fn(), + setItem: jest.fn(), + }; + + cache = new LocalStorageCache({ storage }); + }); + + describe('storage management', () => { + const IMPORT_URL = 'http://fake.url'; + + it('loads state from storage on creation', () => { + expect(storage.getItem).toHaveBeenCalledWith(KEY); + }); + + it('saves to storage when set is called', () => { + const STORAGE_CONTENT = { fake: 'content ' }; + cache.set(IMPORT_URL, STORAGE_CONTENT); + expect(storage.setItem).toHaveBeenCalledWith( + KEY, + JSON.stringify({ [IMPORT_URL]: STORAGE_CONTENT }), + ); + }); + + it('updates status by job id', () => { + const CHANGED_STATUS = 'changed'; + const JOB_ID = 2; + + cache.set(IMPORT_URL, { + progress: { + id: JOB_ID, + status: 'original', + }, + }); + + cache.updateStatusByJobId(JOB_ID, CHANGED_STATUS); + + expect(storage.setItem).toHaveBeenCalledWith( + KEY, + JSON.stringify({ + [IMPORT_URL]: { + progress: { + id: JOB_ID, + status: CHANGED_STATUS, + }, + }, + }), + ); + }); + }); +}); |