summaryrefslogtreecommitdiff
path: root/spec/frontend/autosave_spec.js
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-11-21 09:06:16 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-11-21 09:06:16 +0000
commita048261403ea7e12992ccffe704f0779235712d7 (patch)
tree59254549db6d39a4da824379a7bf354e7c8e7e67 /spec/frontend/autosave_spec.js
parent80e5134020483299c039114e76b734436f006c66 (diff)
downloadgitlab-ce-a048261403ea7e12992ccffe704f0779235712d7.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/autosave_spec.js')
-rw-r--r--spec/frontend/autosave_spec.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/spec/frontend/autosave_spec.js b/spec/frontend/autosave_spec.js
index 33d402388c9..1d73e452eb4 100644
--- a/spec/frontend/autosave_spec.js
+++ b/spec/frontend/autosave_spec.js
@@ -9,6 +9,7 @@ describe('Autosave', () => {
let autosave;
const field = $('<textarea></textarea>');
const key = 'key';
+ const fallbackKey = 'fallbackKey';
describe('class constructor', () => {
beforeEach(() => {
@@ -22,6 +23,13 @@ describe('Autosave', () => {
expect(AccessorUtilities.isLocalStorageAccessSafe).toHaveBeenCalled();
expect(autosave.isLocalStorageAvailable).toBe(true);
});
+
+ it('should set .isLocalStorageAvailable if fallbackKey is passed', () => {
+ autosave = new Autosave(field, key, fallbackKey);
+
+ expect(AccessorUtilities.isLocalStorageAccessSafe).toHaveBeenCalled();
+ expect(autosave.isLocalStorageAvailable).toBe(true);
+ });
});
describe('restore', () => {
@@ -151,4 +159,33 @@ describe('Autosave', () => {
});
});
});
+
+ describe('restore with fallbackKey', () => {
+ beforeEach(() => {
+ autosave = {
+ field,
+ key,
+ fallbackKey,
+ };
+ autosave.isLocalStorageAvailable = true;
+ });
+
+ it('should call .getItem', () => {
+ Autosave.prototype.restore.call(autosave);
+
+ expect(window.localStorage.getItem).toHaveBeenCalledWith(fallbackKey);
+ });
+
+ it('should call .setItem for key and fallbackKey', () => {
+ Autosave.prototype.save.call(autosave);
+
+ expect(window.localStorage.setItem).toHaveBeenCalledTimes(2);
+ });
+
+ it('should call .removeItem for key and fallbackKey', () => {
+ Autosave.prototype.reset.call(autosave);
+
+ expect(window.localStorage.removeItem).toHaveBeenCalledTimes(2);
+ });
+ });
});