diff options
author | Stan Hu <stanhu@gmail.com> | 2019-02-23 22:00:38 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2019-02-24 08:27:53 +0300 |
commit | ec5bbd27f5b334a6e338574ebafe6b0cd39461bc (patch) | |
tree | 011d9e65d6d2c26a5538f6d1f1be73eac20ef5bd /spec/javascripts/lib | |
parent | 7e37b4e4ef2041f5c1818fdbf7de7fee91608595 (diff) |
Remove duplicate XHR request when requesting new pipeline page
When a user clicked on another page in the pipeline page, the following
would happen:
1. PipelinesService.getPipelines() would be called to fetch the new page
2. In the success handler, Poll.restart() would be called
3. This would invoke Poll.makeRequest(), which would fire off a new
request.
To fix this, we introduce a enable(), which will:
1. Update the request data accordingly
2. Clear the old timeout if necessary and start a new timer
Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/58095
Diffstat (limited to 'spec/javascripts/lib')
-rw-r--r-- | spec/javascripts/lib/utils/poll_spec.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/spec/javascripts/lib/utils/poll_spec.js b/spec/javascripts/lib/utils/poll_spec.js index d0da659c3d7..138041a349f 100644 --- a/spec/javascripts/lib/utils/poll_spec.js +++ b/spec/javascripts/lib/utils/poll_spec.js @@ -153,6 +153,36 @@ describe('Poll', () => { }); }); + describe('enable', () => { + it('should enable polling upon a response', done => { + jasmine.clock().install(); + + const Polling = new Poll({ + resource: service, + method: 'fetch', + data: { page: 1 }, + successCallback: () => {}, + }); + + Polling.enable({ + data: { page: 4 }, + response: { status: 200, headers: { 'poll-interval': 1 } }, + }); + + jasmine.clock().tick(1); + jasmine.clock().uninstall(); + + waitForAllCallsToFinish(service, 1, () => { + Polling.stop(); + + expect(service.fetch.calls.count()).toEqual(1); + expect(service.fetch).toHaveBeenCalledWith({ page: 4 }); + expect(Polling.options.data).toEqual({ page: 4 }); + done(); + }); + }); + }); + describe('restart', () => { it('should restart polling when its called', done => { mockServiceCall(service, { status: 200, headers: { 'poll-interval': 1 } }); @@ -171,6 +201,7 @@ describe('Poll', () => { }); spyOn(Polling, 'stop').and.callThrough(); + spyOn(Polling, 'enable').and.callThrough(); spyOn(Polling, 'restart').and.callThrough(); Polling.makeRequest(); @@ -181,6 +212,7 @@ describe('Poll', () => { expect(service.fetch.calls.count()).toEqual(2); expect(service.fetch).toHaveBeenCalledWith({ page: 4 }); expect(Polling.stop).toHaveBeenCalled(); + expect(Polling.enable).toHaveBeenCalled(); expect(Polling.restart).toHaveBeenCalled(); expect(Polling.options.data).toEqual({ page: 4 }); done(); |