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

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

64 lines
1.9 KiB
JavaScript
Raw Normal View History

2021-11-11 11:23:49 +05:30
import * as types from '~/header_search/store/mutation_types';
import mutations from '~/header_search/store/mutations';
import createState from '~/header_search/store/state';
2022-01-26 12:08:38 +05:30
import {
MOCK_SEARCH,
MOCK_AUTOCOMPLETE_OPTIONS_RES,
MOCK_AUTOCOMPLETE_OPTIONS,
} from '../mock_data';
2021-11-11 11:23:49 +05:30
describe('Header Search Store Mutations', () => {
let state;
beforeEach(() => {
state = createState({});
});
2021-11-18 22:05:49 +05:30
describe('REQUEST_AUTOCOMPLETE', () => {
it('sets loading to true and empties autocompleteOptions array', () => {
mutations[types.REQUEST_AUTOCOMPLETE](state);
expect(state.loading).toBe(true);
expect(state.autocompleteOptions).toStrictEqual([]);
2022-05-07 20:08:51 +05:30
expect(state.autocompleteError).toBe(false);
2021-11-18 22:05:49 +05:30
});
});
describe('RECEIVE_AUTOCOMPLETE_SUCCESS', () => {
2022-01-26 12:08:38 +05:30
it('sets loading to false and then formats and sets the autocompleteOptions array', () => {
mutations[types.RECEIVE_AUTOCOMPLETE_SUCCESS](state, MOCK_AUTOCOMPLETE_OPTIONS_RES);
2021-11-18 22:05:49 +05:30
expect(state.loading).toBe(false);
expect(state.autocompleteOptions).toStrictEqual(MOCK_AUTOCOMPLETE_OPTIONS);
2022-05-07 20:08:51 +05:30
expect(state.autocompleteError).toBe(false);
2021-11-18 22:05:49 +05:30
});
});
describe('RECEIVE_AUTOCOMPLETE_ERROR', () => {
it('sets loading to false and empties autocompleteOptions array', () => {
mutations[types.RECEIVE_AUTOCOMPLETE_ERROR](state);
expect(state.loading).toBe(false);
expect(state.autocompleteOptions).toStrictEqual([]);
2022-05-07 20:08:51 +05:30
expect(state.autocompleteError).toBe(true);
2021-11-18 22:05:49 +05:30
});
});
2022-01-26 12:08:38 +05:30
describe('CLEAR_AUTOCOMPLETE', () => {
it('empties autocompleteOptions array', () => {
mutations[types.CLEAR_AUTOCOMPLETE](state);
expect(state.autocompleteOptions).toStrictEqual([]);
2022-05-07 20:08:51 +05:30
expect(state.autocompleteError).toBe(false);
2022-01-26 12:08:38 +05:30
});
});
2021-11-11 11:23:49 +05:30
describe('SET_SEARCH', () => {
it('sets search to value', () => {
mutations[types.SET_SEARCH](state, MOCK_SEARCH);
expect(state.search).toBe(MOCK_SEARCH);
});
});
});