1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
import * as types from '~/header_search/store/mutation_types';
import mutations from '~/header_search/store/mutations';
import createState from '~/header_search/store/state';
import {
MOCK_SEARCH,
MOCK_AUTOCOMPLETE_OPTIONS_RES,
MOCK_AUTOCOMPLETE_OPTIONS,
} from '../mock_data';
describe('Header Search Store Mutations', () => {
let state;
beforeEach(() => {
state = createState({});
});
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([]);
expect(state.autocompleteError).toBe(false);
});
});
describe('RECEIVE_AUTOCOMPLETE_SUCCESS', () => {
it('sets loading to false and then formats and sets the autocompleteOptions array', () => {
mutations[types.RECEIVE_AUTOCOMPLETE_SUCCESS](state, MOCK_AUTOCOMPLETE_OPTIONS_RES);
expect(state.loading).toBe(false);
expect(state.autocompleteOptions).toStrictEqual(MOCK_AUTOCOMPLETE_OPTIONS);
expect(state.autocompleteError).toBe(false);
});
});
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([]);
expect(state.autocompleteError).toBe(true);
});
});
describe('CLEAR_AUTOCOMPLETE', () => {
it('empties autocompleteOptions array', () => {
mutations[types.CLEAR_AUTOCOMPLETE](state);
expect(state.autocompleteOptions).toStrictEqual([]);
expect(state.autocompleteError).toBe(false);
});
});
describe('SET_SEARCH', () => {
it('sets search to value', () => {
mutations[types.SET_SEARCH](state, MOCK_SEARCH);
expect(state.search).toBe(MOCK_SEARCH);
});
});
});
|