From 0f8c2334f0e57a22bf10e4485c17f856289e4fb4 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Thu, 23 Jan 2020 06:08:32 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- .../error_tracking/store/details/actions_spec.js | 43 ++++++++++++++++++---- 1 file changed, 35 insertions(+), 8 deletions(-) (limited to 'spec/frontend/error_tracking') diff --git a/spec/frontend/error_tracking/store/details/actions_spec.js b/spec/frontend/error_tracking/store/details/actions_spec.js index 129760bb705..fa37886f176 100644 --- a/spec/frontend/error_tracking/store/details/actions_spec.js +++ b/spec/frontend/error_tracking/store/details/actions_spec.js @@ -4,27 +4,33 @@ import axios from '~/lib/utils/axios_utils'; import createFlash from '~/flash'; import * as actions from '~/error_tracking/store/details/actions'; import * as types from '~/error_tracking/store/details/mutation_types'; +import Poll from '~/lib/utils/poll'; + +let mockedAdapter; +let mockedRestart; jest.mock('~/flash.js'); jest.mock('~/lib/utils/url_utility'); -let mock; - describe('Sentry error details store actions', () => { beforeEach(() => { - mock = new MockAdapter(axios); + mockedAdapter = new MockAdapter(axios); }); afterEach(() => { - mock.restore(); + mockedAdapter.restore(); createFlash.mockClear(); + if (mockedRestart) { + mockedRestart.mockRestore(); + mockedRestart = null; + } }); describe('startPollingDetails', () => { const endpoint = '123/details'; it('should commit SET_ERROR with received response', done => { const payload = { error: { id: 1 } }; - mock.onGet().reply(200, payload); + mockedAdapter.onGet().reply(200, payload); testAction( actions.startPollingDetails, { endpoint }, @@ -41,7 +47,7 @@ describe('Sentry error details store actions', () => { }); it('should show flash on API error', done => { - mock.onGet().reply(400); + mockedAdapter.onGet().reply(400); testAction( actions.startPollingDetails, @@ -55,13 +61,23 @@ describe('Sentry error details store actions', () => { }, ); }); + + it('should not restart polling when receiving an empty 204 response', done => { + mockedRestart = jest.spyOn(Poll.prototype, 'restart'); + mockedAdapter.onGet().reply(204); + + testAction(actions.startPollingDetails, { endpoint }, {}, [], [], () => { + expect(mockedRestart).toHaveBeenCalledTimes(0); + done(); + }); + }); }); describe('startPollingStacktrace', () => { const endpoint = '123/stacktrace'; it('should commit SET_ERROR with received response', done => { const payload = { error: [1, 2, 3] }; - mock.onGet().reply(200, payload); + mockedAdapter.onGet().reply(200, payload); testAction( actions.startPollingStacktrace, { endpoint }, @@ -78,7 +94,7 @@ describe('Sentry error details store actions', () => { }); it('should show flash on API error', done => { - mock.onGet().reply(400); + mockedAdapter.onGet().reply(400); testAction( actions.startPollingStacktrace, @@ -92,5 +108,16 @@ describe('Sentry error details store actions', () => { }, ); }); + + it('should not restart polling when receiving an empty 204 response', done => { + mockedRestart = jest.spyOn(Poll.prototype, 'restart'); + mockedAdapter.onGet().reply(204); + + testAction(actions.startPollingStacktrace, { endpoint }, {}, [], [], () => { + mockedRestart = jest.spyOn(Poll.prototype, 'restart'); + expect(mockedRestart).toHaveBeenCalledTimes(0); + done(); + }); + }); }); }); -- cgit v1.2.3