diff options
Diffstat (limited to 'spec/frontend/clusters_list/store/actions_spec.js')
-rw-r--r-- | spec/frontend/clusters_list/store/actions_spec.js | 63 |
1 files changed, 53 insertions, 10 deletions
diff --git a/spec/frontend/clusters_list/store/actions_spec.js b/spec/frontend/clusters_list/store/actions_spec.js index 74e351a3704..c8556350747 100644 --- a/spec/frontend/clusters_list/store/actions_spec.js +++ b/spec/frontend/clusters_list/store/actions_spec.js @@ -13,6 +13,28 @@ import * as Sentry from '@sentry/browser'; jest.mock('~/flash.js'); describe('Clusters store actions', () => { + let captureException; + + describe('reportSentryError', () => { + beforeEach(() => { + captureException = jest.spyOn(Sentry, 'captureException'); + }); + + afterEach(() => { + captureException.mockRestore(); + }); + + it('should report sentry error', done => { + const sentryError = new Error('New Sentry Error'); + const tag = 'sentryErrorTag'; + + testAction(actions.reportSentryError, { error: sentryError, tag }, {}, [], [], () => { + expect(captureException).toHaveBeenCalledWith(sentryError); + done(); + }); + }); + }); + describe('fetchClusters', () => { let mock; @@ -48,8 +70,9 @@ describe('Clusters store actions', () => { { endpoint: apiData.endpoint }, {}, [ + { type: types.SET_LOADING_NODES, payload: true }, { type: types.SET_CLUSTERS_DATA, payload: { data: apiData, paginationInformation } }, - { type: types.SET_LOADING_STATE, payload: false }, + { type: types.SET_LOADING_CLUSTERS, payload: false }, ], [], () => done(), @@ -63,8 +86,20 @@ describe('Clusters store actions', () => { actions.fetchClusters, { endpoint: apiData.endpoint }, {}, - [{ type: types.SET_LOADING_STATE, payload: false }], - [], + [ + { type: types.SET_LOADING_NODES, payload: true }, + { type: types.SET_LOADING_CLUSTERS, payload: false }, + { type: types.SET_LOADING_NODES, payload: false }, + ], + [ + { + type: 'reportSentryError', + payload: { + error: new Error('Request failed with status code 400'), + tag: 'fetchClustersErrorCallback', + }, + }, + ], () => { expect(flashError).toHaveBeenCalledWith(expect.stringMatching('error')); done(); @@ -73,7 +108,6 @@ describe('Clusters store actions', () => { }); describe('multiple api requests', () => { - let captureException; let pollRequest; let pollStop; @@ -81,7 +115,6 @@ describe('Clusters store actions', () => { const pollHeaders = { 'poll-interval': pollInterval, ...headers }; beforeEach(() => { - captureException = jest.spyOn(Sentry, 'captureException'); pollRequest = jest.spyOn(Poll.prototype, 'makeRequest'); pollStop = jest.spyOn(Poll.prototype, 'stop'); @@ -89,7 +122,6 @@ describe('Clusters store actions', () => { }); afterEach(() => { - captureException.mockRestore(); pollRequest.mockRestore(); pollStop.mockRestore(); }); @@ -100,8 +132,9 @@ describe('Clusters store actions', () => { { endpoint: apiData.endpoint }, {}, [ + { type: types.SET_LOADING_NODES, payload: true }, { type: types.SET_CLUSTERS_DATA, payload: { data: apiData, paginationInformation } }, - { type: types.SET_LOADING_STATE, payload: false }, + { type: types.SET_LOADING_CLUSTERS, payload: false }, ], [], () => { @@ -149,17 +182,27 @@ describe('Clusters store actions', () => { { endpoint: apiData.endpoint }, {}, [ + { type: types.SET_LOADING_NODES, payload: true }, { type: types.SET_CLUSTERS_DATA, payload: { data: badApiResponse, paginationInformation }, }, - { type: types.SET_LOADING_STATE, payload: false }, + { type: types.SET_LOADING_CLUSTERS, payload: false }, + { type: types.SET_LOADING_CLUSTERS, payload: false }, + { type: types.SET_LOADING_NODES, payload: false }, + ], + [ + { + type: 'reportSentryError', + payload: { + error: new Error('clusters.every is not a function'), + tag: 'fetchClustersSuccessCallback', + }, + }, ], - [], () => { expect(pollRequest).toHaveBeenCalledTimes(1); expect(pollStop).toHaveBeenCalledTimes(1); - expect(captureException).toHaveBeenCalledTimes(1); done(); }, ); |