diff options
author | Igor Drozdov <idrozdov@gitlab.com> | 2019-04-01 17:36:11 +0300 |
---|---|---|
committer | Igor Drozdov <idrozdov@gitlab.com> | 2019-04-01 17:36:11 +0300 |
commit | 04bb35a4b562fd57b14c55645bb1848a50cdef56 (patch) | |
tree | 1bd1ac2af6a5c088ac2529cdbccceeca402d3ebe /spec/frontend/lib/utils/autosave_spec.js | |
parent | ade207e575ab846f6d354aaccc1382a6e512dd0d (diff) | |
parent | b8118a65d595040bfce2d83d5e38dd63ebfedb58 (diff) | |
download | gitlab-ce-id-split-self-approval-restrictions.tar.gz |
Merge branch 'master' into id-split-self-approval-restrictionsid-split-self-approval-restrictions
Diffstat (limited to 'spec/frontend/lib/utils/autosave_spec.js')
-rw-r--r-- | spec/frontend/lib/utils/autosave_spec.js | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/spec/frontend/lib/utils/autosave_spec.js b/spec/frontend/lib/utils/autosave_spec.js new file mode 100644 index 00000000000..12e97f6cdec --- /dev/null +++ b/spec/frontend/lib/utils/autosave_spec.js @@ -0,0 +1,64 @@ +import { clearDraft, getDraft, updateDraft } from '~/lib/utils/autosave'; + +describe('autosave utils', () => { + const autosaveKey = 'dummy-autosave-key'; + const text = 'some dummy text'; + + describe('clearDraft', () => { + beforeEach(() => { + localStorage.setItem(`autosave/${autosaveKey}`, text); + }); + + afterEach(() => { + localStorage.removeItem(`autosave/${autosaveKey}`); + }); + + it('removes the draft from localStorage', () => { + clearDraft(autosaveKey); + + expect(localStorage.getItem(`autosave/${autosaveKey}`)).toBe(null); + }); + }); + + describe('getDraft', () => { + beforeEach(() => { + localStorage.setItem(`autosave/${autosaveKey}`, text); + }); + + afterEach(() => { + localStorage.removeItem(`autosave/${autosaveKey}`); + }); + + it('returns the draft from localStorage', () => { + const result = getDraft(autosaveKey); + + expect(result).toBe(text); + }); + + it('returns null if no entry exists in localStorage', () => { + localStorage.removeItem(`autosave/${autosaveKey}`); + + const result = getDraft(autosaveKey); + + expect(result).toBe(null); + }); + }); + + describe('updateDraft', () => { + beforeEach(() => { + localStorage.setItem(`autosave/${autosaveKey}`, text); + }); + + afterEach(() => { + localStorage.removeItem(`autosave/${autosaveKey}`); + }); + + it('removes the draft from localStorage', () => { + const newText = 'new text'; + + updateDraft(autosaveKey, newText); + + expect(localStorage.getItem(`autosave/${autosaveKey}`)).toBe(newText); + }); + }); +}); |