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

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

57 lines
1.6 KiB
JavaScript
Raw Normal View History

2019-12-26 22:10:19 +05:30
import MockAdapter from 'axios-mock-adapter';
import testAction from 'helpers/vuex_action_helper';
import * as actions from '~/contributors/stores/actions';
import * as types from '~/contributors/stores/mutation_types';
2022-11-25 23:54:43 +05:30
import { createAlert } from '~/flash';
2021-03-11 19:13:27 +05:30
import axios from '~/lib/utils/axios_utils';
2023-04-23 21:23:45 +05:30
import { HTTP_STATUS_BAD_REQUEST, HTTP_STATUS_OK } from '~/lib/utils/http_status';
2019-12-26 22:10:19 +05:30
jest.mock('~/flash.js');
describe('Contributors store actions', () => {
describe('fetchChartData', () => {
let mock;
const endpoint = '/contributors';
const chartData = { '2017-11': 0, '2017-12': 2 };
beforeEach(() => {
mock = new MockAdapter(axios);
});
2022-06-21 17:19:12 +05:30
afterEach(() => {
mock.restore();
});
it('should commit SET_CHART_DATA with received response', () => {
2023-04-23 21:23:45 +05:30
mock.onGet().reply(HTTP_STATUS_OK, chartData);
2019-12-26 22:10:19 +05:30
2022-06-21 17:19:12 +05:30
return testAction(
2019-12-26 22:10:19 +05:30
actions.fetchChartData,
{ endpoint },
{},
[
{ type: types.SET_LOADING_STATE, payload: true },
{ type: types.SET_CHART_DATA, payload: chartData },
{ type: types.SET_LOADING_STATE, payload: false },
],
[],
);
});
2022-06-21 17:19:12 +05:30
it('should show flash on API error', async () => {
2023-04-23 21:23:45 +05:30
mock.onGet().reply(HTTP_STATUS_BAD_REQUEST, 'Not Found');
2019-12-26 22:10:19 +05:30
2022-06-21 17:19:12 +05:30
await testAction(
2019-12-26 22:10:19 +05:30
actions.fetchChartData,
{ endpoint },
{},
[{ type: types.SET_LOADING_STATE, payload: true }],
[],
);
2022-11-25 23:54:43 +05:30
expect(createAlert).toHaveBeenCalledWith({
2022-06-21 17:19:12 +05:30
message: expect.stringMatching('error'),
});
2019-12-26 22:10:19 +05:30
});
});
});