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
path: root/spec
diff options
context:
space:
mode:
authorFatih Acet <acetfatih@gmail.com>2018-07-16 15:34:46 +0300
committerFatih Acet <acetfatih@gmail.com>2018-07-18 13:55:57 +0300
commit01aa7752ef9b6bac2f9fbcf912ab4fc87c0075f1 (patch)
treee61d713da5f14ff57896e4962ddd105d9b0469b6 /spec
parentef2b2546eaae74347b0ae54b15270c50daecbc5f (diff)
Debounce Autosave callback.
Diffstat (limited to 'spec')
-rw-r--r--spec/javascripts/autosave_spec.js27
1 files changed, 18 insertions, 9 deletions
diff --git a/spec/javascripts/autosave_spec.js b/spec/javascripts/autosave_spec.js
index 38ae5b7e00c..404e1b53bf4 100644
--- a/spec/javascripts/autosave_spec.js
+++ b/spec/javascripts/autosave_spec.js
@@ -1,4 +1,5 @@
import $ from 'jquery';
+import _ from 'underscore';
import Autosave from '~/autosave';
import AccessorUtilities from '~/lib/utils/accessor';
@@ -10,12 +11,24 @@ describe('Autosave', () => {
describe('class constructor', () => {
beforeEach(() => {
spyOn(AccessorUtilities, 'isLocalStorageAccessSafe').and.returnValue(true);
+ spyOn(_, 'debounce');
+ spyOn(Autosave.prototype, 'save');
spyOn(Autosave.prototype, 'restore');
+ autosave = new Autosave(field, key);
});
- it('should set .isLocalStorageAvailable', () => {
- autosave = new Autosave(field, key);
+ it('should debounce the input handler', () => {
+ expect(_.debounce).toHaveBeenCalled();
+ expect(autosave.save).not.toHaveBeenCalled();
+
+ const [cb, timer] = _.debounce.calls.argsFor(0);
+ cb(); // execute debounced callback
+ expect(timer).toEqual(Autosave.DEBOUNCE_TIMER);
+ expect(autosave.save).toHaveBeenCalled();
+ });
+
+ it('should set .isLocalStorageAvailable', () => {
expect(AccessorUtilities.isLocalStorageAccessSafe).toHaveBeenCalled();
expect(autosave.isLocalStorageAvailable).toBe(true);
});
@@ -59,12 +72,10 @@ describe('Autosave', () => {
Autosave.prototype.restore.call(autosave);
- expect(
- field.trigger,
- ).toHaveBeenCalled();
+ expect(field.trigger).toHaveBeenCalled();
});
- it('triggers native event', (done) => {
+ it('triggers native event', done => {
autosave.field.get(0).addEventListener('change', () => {
done();
});
@@ -81,9 +92,7 @@ describe('Autosave', () => {
it('does not trigger event', () => {
spyOn(field, 'trigger').and.callThrough();
- expect(
- field.trigger,
- ).not.toHaveBeenCalled();
+ expect(field.trigger).not.toHaveBeenCalled();
});
});
});