Commit 059a6af4 authored by Ezekiel Kigbo's avatar Ezekiel Kigbo

Added specs for the url_sync component

Checks that the correct url parameters
are set when data is updated
parent 422219de
......@@ -23,7 +23,7 @@ export default {
},
},
render() {
return this.$slots.default;
return null;
},
};
</script>
......@@ -17,6 +17,9 @@ import Daterange from 'ee/analytics/shared/components/daterange.vue';
import TasksByTypeChart from 'ee/analytics/cycle_analytics/components/tasks_by_type_chart.vue';
import waitForPromises from 'helpers/wait_for_promises';
import httpStatusCodes from '~/lib/utils/http_status';
import * as commonUtils from '~/lib/utils/common_utils';
import * as urlUtils from '~/lib/utils/url_utility';
import { toYmd } from 'ee/analytics/shared/utils';
import * as mockData from '../mock_data';
const noDataSvgPath = 'path/to/no/data';
......@@ -35,7 +38,9 @@ const defaultStubs = {
};
function createComponent({
opts = {},
opts = {
stubs: defaultStubs,
},
shallow = true,
withStageSelected = false,
scatterplotEnabled = true,
......@@ -95,6 +100,13 @@ describe('Cycle Analytics component', () => {
.findAll('.stage-nav-item')
.at(index);
const shouldSetUrlParams = result => {
return wrapper.vm.$nextTick().then(() => {
expect(urlUtils.setUrlParams).toHaveBeenCalledWith(result, window.location.href, true);
expect(commonUtils.historyPushState).toHaveBeenCalled();
});
};
const displaysProjectsDropdownFilter = flag => {
expect(wrapper.find(ProjectsDropdownFilter).exists()).toBe(flag);
};
......@@ -600,4 +612,82 @@ describe('Cycle Analytics component', () => {
});
});
});
describe('Url Sync', () => {
beforeEach(() => {
commonUtils.historyPushState = jest.fn();
urlUtils.setUrlParams = jest.fn();
mock = new MockAdapter(axios);
wrapper = createComponent({
shallow: false,
stubs: {
...defaultStubs,
},
});
wrapper.vm.$store.dispatch('initializeCycleAnalytics', {
createdAfter: mockData.startDate,
createdBefore: mockData.endDate,
});
});
afterEach(() => {
commonUtils.historyPushState = null;
urlUtils.setUrlParams = null;
wrapper.destroy();
mock.restore();
});
it('sets the created_after and created_before url parameters', () => {
shouldSetUrlParams({
created_after: toYmd(mockData.startDate),
created_before: toYmd(mockData.endDate),
group_id: null,
'project_ids[]': [],
});
});
describe('with a group selected', () => {
beforeEach(() => {
wrapper.vm.$store.dispatch('setSelectedGroup', {
...mockData.group,
});
return wrapper.vm.$nextTick();
});
it('sets the group_id url parameter', () => {
shouldSetUrlParams({
created_after: toYmd(mockData.startDate),
created_before: toYmd(mockData.endDate),
group_id: mockData.group.full_path,
'project_ids[]': [],
});
});
});
describe('with a group and selectedProjectIds set', () => {
const selectedProjectIds = mockData.selectedProjects.map(({ id }) => id);
beforeEach(() => {
wrapper.vm.$store.dispatch('setSelectedGroup', {
...mockData.group,
});
wrapper.vm.$store.dispatch('setSelectedProjects', mockData.selectedProjects);
return wrapper.vm.$nextTick();
});
it('sets the project_ids url parameter', () => {
shouldSetUrlParams({
created_after: toYmd(mockData.startDate),
created_before: toYmd(mockData.endDate),
group_id: mockData.group.full_path,
'project_ids[]': selectedProjectIds,
});
});
});
});
});
import * as commonUtils from '~/lib/utils/common_utils';
import * as urlUtils from '~/lib/utils/url_utility';
import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
import testAction from 'helpers/vuex_action_helper';
......@@ -12,7 +10,6 @@ import {
} from 'ee/analytics/cycle_analytics/constants';
import createFlash from '~/flash';
import httpStatusCodes from '~/lib/utils/http_status';
import { toYmd } from 'ee/analytics/shared/utils';
import {
group,
summaryData,
......@@ -47,9 +44,6 @@ describe('Cycle analytics actions', () => {
}
beforeEach(() => {
commonUtils.historyPushState = jest.fn();
urlUtils.setUrlParams = jest.fn();
state = {
startDate,
endDate,
......@@ -1526,8 +1520,6 @@ describe('Cycle analytics actions', () => {
};
beforeEach(() => {
commonUtils.historyPushState = jest.fn();
urlUtils.setUrlParams = jest.fn();
mockDispatch = jest.fn(() => Promise.resolve());
mockCommit = jest.fn();
store = {
......
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