debian-mirror-gitlab/spec/frontend/error_tracking/store/details/actions_spec.js

77 lines
2.1 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';
2020-01-01 13:55:28 +05:30
import axios from '~/lib/utils/axios_utils';
2019-12-26 22:10:19 +05:30
import createFlash from '~/flash';
import * as actions from '~/error_tracking/store/details/actions';
import * as types from '~/error_tracking/store/details/mutation_types';
2020-03-13 15:44:24 +05:30
import Poll from '~/lib/utils/poll';
let mockedAdapter;
let mockedRestart;
2019-12-26 22:10:19 +05:30
jest.mock('~/flash.js');
2020-03-13 15:44:24 +05:30
jest.mock('~/lib/utils/url_utility');
2019-12-26 22:10:19 +05:30
describe('Sentry error details store actions', () => {
beforeEach(() => {
2020-03-13 15:44:24 +05:30
mockedAdapter = new MockAdapter(axios);
2019-12-26 22:10:19 +05:30
});
afterEach(() => {
2020-03-13 15:44:24 +05:30
mockedAdapter.restore();
2019-12-26 22:10:19 +05:30
createFlash.mockClear();
2020-03-13 15:44:24 +05:30
if (mockedRestart) {
mockedRestart.mockRestore();
mockedRestart = null;
}
2019-12-26 22:10:19 +05:30
});
describe('startPollingStacktrace', () => {
const endpoint = '123/stacktrace';
it('should commit SET_ERROR with received response', done => {
const payload = { error: [1, 2, 3] };
2020-03-13 15:44:24 +05:30
mockedAdapter.onGet().reply(200, payload);
2019-12-26 22:10:19 +05:30
testAction(
actions.startPollingStacktrace,
{ endpoint },
{},
[
{ type: types.SET_STACKTRACE_DATA, payload: payload.error },
{ type: types.SET_LOADING_STACKTRACE, payload: false },
],
[],
() => {
done();
},
);
});
it('should show flash on API error', done => {
2020-03-13 15:44:24 +05:30
mockedAdapter.onGet().reply(400);
2019-12-26 22:10:19 +05:30
testAction(
actions.startPollingStacktrace,
{ endpoint },
{},
[{ type: types.SET_LOADING_STACKTRACE, payload: false }],
[],
() => {
expect(createFlash).toHaveBeenCalledTimes(1);
done();
},
);
});
2020-03-13 15:44:24 +05:30
it('should not restart polling when receiving an empty 204 response', done => {
mockedRestart = jest.spyOn(Poll.prototype, 'restart');
mockedAdapter.onGet().reply(204);
testAction(actions.startPollingStacktrace, { endpoint }, {}, [], [], () => {
mockedRestart = jest.spyOn(Poll.prototype, 'restart');
expect(mockedRestart).toHaveBeenCalledTimes(0);
done();
});
});
2019-12-26 22:10:19 +05:30
});
});