Commit 163c8a8c authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch 'vs-migrate-issue-analytics-to-jest' into 'master'

Migrate ee/issue_analytics to jest

Closes #194292

See merge request gitlab-org/gitlab!27143
parents 6b8e175b fd12733f
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import testAction from 'spec/helpers/vuex_action_helper'; import testAction from 'helpers/vuex_action_helper';
import * as actions from 'ee/issues_analytics/stores/modules/issue_analytics/actions'; import * as actions from 'ee/issues_analytics/stores/modules/issue_analytics/actions';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
describe('Issue analytics store actions', () => { describe('Issue analytics store actions', () => {
describe('setFilters', () => { describe('setFilters', () => {
it('commits SET_FILTERS', done => { it('commits SET_FILTERS', () => {
testAction( testAction(actions.setFilters, null, null, [{ type: 'SET_FILTERS', payload: null }], []);
actions.setFilters,
null,
null,
[{ type: 'SET_FILTERS', payload: null }],
[],
done,
);
}); });
}); });
describe('setLoadingState', () => { describe('setLoadingState', () => {
it('commits SET_LOADING_STATE', done => { it('commits SET_LOADING_STATE', () => {
testAction( testAction(
actions.setLoadingState, actions.setLoadingState,
true, true,
null, null,
[{ type: 'SET_LOADING_STATE', payload: true }], [{ type: 'SET_LOADING_STATE', payload: true }],
[], [],
done,
); );
}); });
}); });
...@@ -37,8 +29,8 @@ describe('Issue analytics store actions', () => { ...@@ -37,8 +29,8 @@ describe('Issue analytics store actions', () => {
const chartData = { '2017-11': 0, '2017-12': 2 }; const chartData = { '2017-11': 0, '2017-12': 2 };
beforeEach(() => { beforeEach(() => {
dispatch = jasmine.createSpy('dispatch'); dispatch = jest.fn().mockName('dispatch');
commit = jasmine.createSpy('commit'); commit = jest.fn().mockName('commit');
mock = new MockAdapter(axios); mock = new MockAdapter(axios);
mock.onGet().reply(200, chartData); mock.onGet().reply(200, chartData);
...@@ -48,7 +40,7 @@ describe('Issue analytics store actions', () => { ...@@ -48,7 +40,7 @@ describe('Issue analytics store actions', () => {
mock.restore(); mock.restore();
}); });
it('commits SET_CHART_DATA with chart data', done => { it('commits SET_CHART_DATA with chart data', () => {
const getters = { appliedFilters: '?hello=world' }; const getters = { appliedFilters: '?hello=world' };
const context = { const context = {
dispatch, dispatch,
...@@ -56,15 +48,11 @@ describe('Issue analytics store actions', () => { ...@@ -56,15 +48,11 @@ describe('Issue analytics store actions', () => {
commit, commit,
}; };
actions return actions.fetchChartData(context, gl.TEST_HOST).then(() => {
.fetchChartData(context, gl.TEST_HOST) expect(dispatch.mock.calls[0]).toEqual(['setLoadingState', true]);
.then(() => { expect(commit).toHaveBeenCalledWith('SET_CHART_DATA', chartData);
expect(dispatch.calls.argsFor(0)).toEqual(['setLoadingState', true]); expect(dispatch.mock.calls[1]).toEqual(['setLoadingState', false]);
expect(commit).toHaveBeenCalledWith('SET_CHART_DATA', chartData); });
expect(dispatch.calls.argsFor(1)).toEqual(['setLoadingState', false]);
})
.then(done)
.catch(done.fail);
}); });
}); });
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment