Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/autosave_spec.js')
-rw-r--r--spec/frontend/autosave_spec.js44
1 files changed, 44 insertions, 0 deletions
diff --git a/spec/frontend/autosave_spec.js b/spec/frontend/autosave_spec.js
index c881e0f9794..7a9262cd004 100644
--- a/spec/frontend/autosave_spec.js
+++ b/spec/frontend/autosave_spec.js
@@ -8,6 +8,7 @@ describe('Autosave', () => {
let autosave;
const field = $('<textarea></textarea>');
+ const checkbox = $('<input type="checkbox">');
const key = 'key';
const fallbackKey = 'fallbackKey';
const lockVersionKey = 'lockVersionKey';
@@ -90,6 +91,24 @@ describe('Autosave', () => {
expect(eventHandler).toHaveBeenCalledTimes(1);
fieldElement.removeEventListener('change', eventHandler);
});
+
+ describe('if field type is checkbox', () => {
+ beforeEach(() => {
+ autosave = {
+ field: checkbox,
+ key,
+ isLocalStorageAvailable: true,
+ type: 'checkbox',
+ };
+ });
+
+ it('should restore', () => {
+ window.localStorage.setItem(key, true);
+ expect(checkbox.is(':checked')).toBe(false);
+ Autosave.prototype.restore.call(autosave);
+ expect(checkbox.is(':checked')).toBe(true);
+ });
+ });
});
describe('if field gets deleted from DOM', () => {
@@ -169,6 +188,31 @@ describe('Autosave', () => {
expect(window.localStorage.setItem).toHaveBeenCalled();
});
});
+
+ describe('if field type is checkbox', () => {
+ beforeEach(() => {
+ autosave = {
+ field: checkbox,
+ key,
+ isLocalStorageAvailable: true,
+ type: 'checkbox',
+ };
+ });
+
+ it('should save true when checkbox on', () => {
+ checkbox.prop('checked', true);
+ Autosave.prototype.save.call(autosave);
+ expect(window.localStorage.setItem).toHaveBeenCalledWith(key, true);
+ });
+
+ it('should call reset when checkbox off', () => {
+ autosave.reset = jest.fn();
+ checkbox.prop('checked', false);
+ Autosave.prototype.save.call(autosave);
+ expect(autosave.reset).toHaveBeenCalled();
+ expect(window.localStorage.setItem).not.toHaveBeenCalled();
+ });
+ });
});
describe('save with lockVersion', () => {