debian-mirror-gitlab/spec/frontend/projects/commits/store/actions_spec.js

72 lines
2 KiB
JavaScript
Raw Normal View History

2020-04-22 19:07:51 +05:30
import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
import testAction from 'helpers/vuex_action_helper';
2021-09-04 01:27:46 +05:30
import createFlash from '~/flash';
2020-04-22 19:07:51 +05:30
import actions from '~/projects/commits/store/actions';
2021-03-11 19:13:27 +05:30
import * as types from '~/projects/commits/store/mutation_types';
2020-04-22 19:07:51 +05:30
import createState from '~/projects/commits/store/state';
jest.mock('~/flash');
describe('Project commits actions', () => {
let state;
let mock;
beforeEach(() => {
state = createState();
mock = new MockAdapter(axios);
});
afterEach(() => {
mock.restore();
});
describe('setInitialData', () => {
it(`commits ${types.SET_INITIAL_DATA}`, () =>
testAction(actions.setInitialData, undefined, state, [{ type: types.SET_INITIAL_DATA }]));
});
describe('receiveAuthorsSuccess', () => {
it(`commits ${types.COMMITS_AUTHORS}`, () =>
testAction(actions.receiveAuthorsSuccess, undefined, state, [
{ type: types.COMMITS_AUTHORS },
]));
});
describe('shows a flash message when there is an error', () => {
it('creates a flash', () => {
const mockDispatchContext = { dispatch: () => {}, commit: () => {}, state };
actions.receiveAuthorsError(mockDispatchContext);
expect(createFlash).toHaveBeenCalledTimes(1);
2021-09-04 01:27:46 +05:30
expect(createFlash).toHaveBeenCalledWith({
message: 'An error occurred fetching the project authors.',
});
2020-04-22 19:07:51 +05:30
});
});
describe('fetchAuthors', () => {
it('dispatches request/receive', () => {
2020-07-28 23:09:34 +05:30
const path = '/-/autocomplete/users.json';
2020-04-22 19:07:51 +05:30
state.projectId = '8';
const data = [{ id: 1 }];
mock.onGet(path).replyOnce(200, data);
testAction(
actions.fetchAuthors,
null,
state,
[],
[{ type: 'receiveAuthorsSuccess', payload: data }],
);
});
it('dispatches request/receive on error', () => {
2020-07-28 23:09:34 +05:30
const path = '/-/autocomplete/users.json';
2020-04-22 19:07:51 +05:30
mock.onGet(path).replyOnce(500);
testAction(actions.fetchAuthors, null, state, [], [{ type: 'receiveAuthorsError' }]);
});
});
});