diff options
Diffstat (limited to 'spec/frontend/clusters_list/store/actions_spec.js')
-rw-r--r-- | spec/frontend/clusters_list/store/actions_spec.js | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/spec/frontend/clusters_list/store/actions_spec.js b/spec/frontend/clusters_list/store/actions_spec.js index e903200bf1d..70766af3ec4 100644 --- a/spec/frontend/clusters_list/store/actions_spec.js +++ b/spec/frontend/clusters_list/store/actions_spec.js @@ -2,6 +2,7 @@ import MockAdapter from 'axios-mock-adapter'; import flashError from '~/flash'; import testAction from 'helpers/vuex_action_helper'; import axios from '~/lib/utils/axios_utils'; +import { apiData } from '../mock_data'; import * as types from '~/clusters_list/store/mutation_types'; import * as actions from '~/clusters_list/store/actions'; @@ -10,8 +11,6 @@ jest.mock('~/flash.js'); describe('Clusters store actions', () => { describe('fetchClusters', () => { let mock; - const endpoint = '/clusters'; - const clusters = [{ name: 'test' }]; beforeEach(() => { mock = new MockAdapter(axios); @@ -20,14 +19,29 @@ describe('Clusters store actions', () => { afterEach(() => mock.restore()); it('should commit SET_CLUSTERS_DATA with received response', done => { - mock.onGet().reply(200, clusters); + const headers = { + 'x-total': apiData.clusters.length, + 'x-per-page': 20, + 'x-page': 1, + }; + + const paginationInformation = { + nextPage: NaN, + page: 1, + perPage: 20, + previousPage: NaN, + total: apiData.clusters.length, + totalPages: NaN, + }; + + mock.onGet().reply(200, apiData, headers); testAction( actions.fetchClusters, - { endpoint }, + { endpoint: apiData.endpoint }, {}, [ - { type: types.SET_CLUSTERS_DATA, payload: clusters }, + { type: types.SET_CLUSTERS_DATA, payload: { data: apiData, paginationInformation } }, { type: types.SET_LOADING_STATE, payload: false }, ], [], @@ -38,13 +52,10 @@ describe('Clusters store actions', () => { it('should show flash on API error', done => { mock.onGet().reply(400, 'Not Found'); - testAction(actions.fetchClusters, { endpoint }, {}, [], [], () => { + testAction(actions.fetchClusters, { endpoint: apiData.endpoint }, {}, [], [], () => { expect(flashError).toHaveBeenCalledWith(expect.stringMatching('error')); done(); }); }); }); }); - -// prevent babel-plugin-rewire from generating an invalid default during karma tests -export default () => {}; |