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

172 lines
3.9 KiB
JavaScript
Raw Normal View History

2018-11-18 11:00:15 +05:30
import MockAdapter from 'axios-mock-adapter';
2020-05-24 23:13:21 +05:30
import { TEST_HOST } from 'helpers/test_constants';
2021-03-11 19:13:27 +05:30
import testAction from 'helpers/vuex_action_helper';
2018-11-18 11:00:15 +05:30
import axios from '~/lib/utils/axios_utils';
import {
setEndpoint,
requestReports,
fetchReports,
stopPolling,
clearEtagPoll,
receiveReportsSuccess,
receiveReportsError,
openModal,
2021-03-08 18:12:59 +05:30
closeModal,
2018-11-18 11:00:15 +05:30
} from '~/reports/store/actions';
import * as types from '~/reports/store/mutation_types';
2021-03-11 19:13:27 +05:30
import state from '~/reports/store/state';
2018-11-18 11:00:15 +05:30
describe('Reports Store Actions', () => {
let mockedState;
beforeEach(() => {
mockedState = state();
});
describe('setEndpoint', () => {
2021-03-08 18:12:59 +05:30
it('should commit SET_ENDPOINT mutation', (done) => {
2018-11-18 11:00:15 +05:30
testAction(
setEndpoint,
'endpoint.json',
mockedState,
[{ type: types.SET_ENDPOINT, payload: 'endpoint.json' }],
[],
done,
);
});
});
describe('requestReports', () => {
2021-03-08 18:12:59 +05:30
it('should commit REQUEST_REPORTS mutation', (done) => {
2018-11-18 11:00:15 +05:30
testAction(requestReports, null, mockedState, [{ type: types.REQUEST_REPORTS }], [], done);
});
});
describe('fetchReports', () => {
let mock;
beforeEach(() => {
mockedState.endpoint = `${TEST_HOST}/endpoint.json`;
mock = new MockAdapter(axios);
});
afterEach(() => {
mock.restore();
stopPolling();
clearEtagPoll();
});
describe('success', () => {
2021-03-08 18:12:59 +05:30
it('dispatches requestReports and receiveReportsSuccess ', (done) => {
2018-11-18 11:00:15 +05:30
mock
.onGet(`${TEST_HOST}/endpoint.json`)
.replyOnce(200, { summary: {}, suites: [{ name: 'rspec' }] });
testAction(
fetchReports,
null,
mockedState,
[],
[
{
type: 'requestReports',
},
{
payload: { data: { summary: {}, suites: [{ name: 'rspec' }] }, status: 200 },
type: 'receiveReportsSuccess',
},
],
done,
);
});
});
describe('error', () => {
beforeEach(() => {
mock.onGet(`${TEST_HOST}/endpoint.json`).reply(500);
});
2021-03-08 18:12:59 +05:30
it('dispatches requestReports and receiveReportsError ', (done) => {
2018-11-18 11:00:15 +05:30
testAction(
fetchReports,
null,
mockedState,
[],
[
{
type: 'requestReports',
},
{
type: 'receiveReportsError',
},
],
done,
);
});
});
});
describe('receiveReportsSuccess', () => {
2021-03-08 18:12:59 +05:30
it('should commit RECEIVE_REPORTS_SUCCESS mutation with 200', (done) => {
2018-11-18 11:00:15 +05:30
testAction(
receiveReportsSuccess,
{ data: { summary: {} }, status: 200 },
mockedState,
[{ type: types.RECEIVE_REPORTS_SUCCESS, payload: { summary: {} } }],
[],
done,
);
});
2021-03-08 18:12:59 +05:30
it('should not commit RECEIVE_REPORTS_SUCCESS mutation with 204', (done) => {
2018-11-18 11:00:15 +05:30
testAction(
receiveReportsSuccess,
{ data: { summary: {} }, status: 204 },
mockedState,
[],
[],
done,
);
});
});
describe('receiveReportsError', () => {
2021-03-08 18:12:59 +05:30
it('should commit RECEIVE_REPORTS_ERROR mutation', (done) => {
2018-11-18 11:00:15 +05:30
testAction(
receiveReportsError,
null,
mockedState,
[{ type: types.RECEIVE_REPORTS_ERROR }],
[],
done,
);
});
});
describe('openModal', () => {
2021-03-08 18:12:59 +05:30
it('should commit SET_ISSUE_MODAL_DATA', (done) => {
2018-11-18 11:00:15 +05:30
testAction(
openModal,
{ name: 'foo' },
mockedState,
2021-03-08 18:12:59 +05:30
[{ type: types.SET_ISSUE_MODAL_DATA, payload: { name: 'foo' } }],
2018-11-18 11:00:15 +05:30
[],
done,
);
});
});
2021-03-08 18:12:59 +05:30
describe('closeModal', () => {
it('should commit RESET_ISSUE_MODAL_DATA', (done) => {
2018-11-18 11:00:15 +05:30
testAction(
2021-03-08 18:12:59 +05:30
closeModal,
{},
2018-11-18 11:00:15 +05:30
mockedState,
2021-03-08 18:12:59 +05:30
[{ type: types.RESET_ISSUE_MODAL_DATA, payload: {} }],
2018-11-18 11:00:15 +05:30
[],
done,
);
});
});
});