debian-mirror-gitlab/spec/frontend/header_search/store/actions_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

65 lines
2.1 KiB
JavaScript
Raw Normal View History

2021-11-18 22:05:49 +05:30
import MockAdapter from 'axios-mock-adapter';
2021-11-11 11:23:49 +05:30
import testAction from 'helpers/vuex_action_helper';
import * as actions from '~/header_search/store/actions';
import * as types from '~/header_search/store/mutation_types';
import createState from '~/header_search/store/state';
2021-11-18 22:05:49 +05:30
import axios from '~/lib/utils/axios_utils';
2022-01-26 12:08:38 +05:30
import { MOCK_SEARCH, MOCK_AUTOCOMPLETE_OPTIONS_RES } from '../mock_data';
2021-11-18 22:05:49 +05:30
jest.mock('~/flash');
2021-11-11 11:23:49 +05:30
describe('Header Search Store Actions', () => {
let state;
2021-11-18 22:05:49 +05:30
let mock;
2021-11-11 11:23:49 +05:30
beforeEach(() => {
state = createState({});
2021-11-18 22:05:49 +05:30
mock = new MockAdapter(axios);
2021-11-11 11:23:49 +05:30
});
afterEach(() => {
state = null;
2021-11-18 22:05:49 +05:30
mock.restore();
});
describe.each`
2022-05-07 20:08:51 +05:30
axiosMock | type | expectedMutations
${{ method: 'onGet', code: 200, res: MOCK_AUTOCOMPLETE_OPTIONS_RES }} | ${'success'} | ${[{ type: types.REQUEST_AUTOCOMPLETE }, { type: types.RECEIVE_AUTOCOMPLETE_SUCCESS, payload: MOCK_AUTOCOMPLETE_OPTIONS_RES }]}
${{ method: 'onGet', code: 500, res: null }} | ${'error'} | ${[{ type: types.REQUEST_AUTOCOMPLETE }, { type: types.RECEIVE_AUTOCOMPLETE_ERROR }]}
`('fetchAutocompleteOptions', ({ axiosMock, type, expectedMutations }) => {
2021-11-18 22:05:49 +05:30
describe(`on ${type}`, () => {
beforeEach(() => {
mock[axiosMock.method]().replyOnce(axiosMock.code, axiosMock.res);
});
it(`should dispatch the correct mutations`, () => {
return testAction({
action: actions.fetchAutocompleteOptions,
state,
expectedMutations,
2022-05-07 20:08:51 +05:30
});
2021-11-18 22:05:49 +05:30
});
});
2021-11-11 11:23:49 +05:30
});
2022-01-26 12:08:38 +05:30
describe('clearAutocomplete', () => {
it('calls the CLEAR_AUTOCOMPLETE mutation', () => {
return testAction({
action: actions.clearAutocomplete,
state,
expectedMutations: [{ type: types.CLEAR_AUTOCOMPLETE }],
});
});
});
2021-11-11 11:23:49 +05:30
describe('setSearch', () => {
it('calls the SET_SEARCH mutation', () => {
return testAction({
action: actions.setSearch,
payload: MOCK_SEARCH,
state,
expectedMutations: [{ type: types.SET_SEARCH, payload: MOCK_SEARCH }],
});
});
});
});