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

75 lines
2.1 KiB
JavaScript
Raw Normal View History

2021-03-11 19:13:27 +05:30
import * as types from '~/search/store/mutation_types';
2021-01-29 00:20:46 +05:30
import mutations from '~/search/store/mutations';
import createState from '~/search/store/state';
2021-02-22 17:27:13 +05:30
import { MOCK_QUERY, MOCK_GROUPS, MOCK_PROJECTS } from '../mock_data';
2021-01-29 00:20:46 +05:30
describe('Global Search Store Mutations', () => {
let state;
beforeEach(() => {
state = createState({ query: MOCK_QUERY });
});
describe('REQUEST_GROUPS', () => {
it('sets fetchingGroups to true', () => {
mutations[types.REQUEST_GROUPS](state);
expect(state.fetchingGroups).toBe(true);
});
});
describe('RECEIVE_GROUPS_SUCCESS', () => {
it('sets fetchingGroups to false and sets groups', () => {
mutations[types.RECEIVE_GROUPS_SUCCESS](state, MOCK_GROUPS);
expect(state.fetchingGroups).toBe(false);
expect(state.groups).toBe(MOCK_GROUPS);
});
});
describe('RECEIVE_GROUPS_ERROR', () => {
it('sets fetchingGroups to false and clears groups', () => {
mutations[types.RECEIVE_GROUPS_ERROR](state);
expect(state.fetchingGroups).toBe(false);
expect(state.groups).toEqual([]);
});
});
2021-02-22 17:27:13 +05:30
describe('REQUEST_PROJECTS', () => {
it('sets fetchingProjects to true', () => {
mutations[types.REQUEST_PROJECTS](state);
expect(state.fetchingProjects).toBe(true);
});
});
describe('RECEIVE_PROJECTS_SUCCESS', () => {
it('sets fetchingProjects to false and sets projects', () => {
mutations[types.RECEIVE_PROJECTS_SUCCESS](state, MOCK_PROJECTS);
expect(state.fetchingProjects).toBe(false);
expect(state.projects).toBe(MOCK_PROJECTS);
});
});
describe('RECEIVE_PROJECTS_ERROR', () => {
it('sets fetchingProjects to false and clears projects', () => {
mutations[types.RECEIVE_PROJECTS_ERROR](state);
expect(state.fetchingProjects).toBe(false);
expect(state.projects).toEqual([]);
});
});
2021-01-29 00:20:46 +05:30
describe('SET_QUERY', () => {
const payload = { key: 'key1', value: 'value1' };
it('sets query key to value', () => {
mutations[types.SET_QUERY](state, payload);
expect(state.query[payload.key]).toBe(payload.value);
});
});
});