Skip to content
代码片段 群组 项目
提交 c41e5ef9 编辑于 作者: Miguel Rincon's avatar Miguel Rincon
浏览文件

Merge branch '391081-roadmap-filters-spec' into 'master'

No related branches found
No related tags found
无相关合并请求
...@@ -37,43 +37,45 @@ jest.mock('~/lib/utils/url_utility', () => ({ ...@@ -37,43 +37,45 @@ jest.mock('~/lib/utils/url_utility', () => ({
Vue.use(Vuex); Vue.use(Vuex);
const createComponent = ({
presetType = PRESET_TYPES.MONTHS,
epicsState = STATUS_ALL,
sortedBy = mockSortedBy,
groupFullPath = 'gitlab-org',
groupMilestonesPath = '/groups/gitlab-org/-/milestones.json',
timeframe = getTimeframeForRangeType({
timeframeRangeType: DATE_RANGES.THREE_YEARS,
presetType: PRESET_TYPES.MONTHS,
initialDate: mockTimeframeInitialDate,
}),
filterParams = {},
} = {}) => {
const store = createStore();
store.dispatch('setInitialData', {
presetType,
epicsState,
sortedBy,
filterParams,
timeframe,
isProgressTrackingActive: true,
progressTracking: PROGRESS_WEIGHT,
milestonesType: MILESTONES_ALL,
});
return shallowMountExtended(RoadmapFilters, {
store,
provide: {
groupFullPath,
groupMilestonesPath,
},
});
};
describe('RoadmapFilters', () => { describe('RoadmapFilters', () => {
let wrapper; let wrapper;
let store;
const createComponent = ({
presetType = PRESET_TYPES.MONTHS,
epicsState = STATUS_ALL,
sortedBy = mockSortedBy,
groupFullPath = 'gitlab-org',
groupMilestonesPath = '/groups/gitlab-org/-/milestones.json',
timeframe = getTimeframeForRangeType({
timeframeRangeType: DATE_RANGES.THREE_YEARS,
presetType: PRESET_TYPES.MONTHS,
initialDate: mockTimeframeInitialDate,
}),
filterParams = {},
} = {}) => {
store = createStore();
store.dispatch('setInitialData', {
presetType,
epicsState,
sortedBy,
filterParams,
timeframe,
isProgressTrackingActive: true,
progressTracking: PROGRESS_WEIGHT,
milestonesType: MILESTONES_ALL,
});
return shallowMountExtended(RoadmapFilters, {
store,
provide: {
groupFullPath,
groupMilestonesPath,
},
});
};
const findSettingsButton = () => wrapper.findByTestId('settings-button'); const findSettingsButton = () => wrapper.findByTestId('settings-button');
beforeEach(() => { beforeEach(() => {
...@@ -83,15 +85,15 @@ describe('RoadmapFilters', () => { ...@@ -83,15 +85,15 @@ describe('RoadmapFilters', () => {
describe('watch', () => { describe('watch', () => {
describe('urlParams', () => { describe('urlParams', () => {
it('updates window URL based on presence of props for state, filtered search and sort criteria', async () => { it('updates window URL based on presence of props for state, filtered search and sort criteria', async () => {
wrapper.vm.$store.dispatch('setEpicsState', STATUS_CLOSED); store.dispatch('setEpicsState', STATUS_CLOSED);
wrapper.vm.$store.dispatch('setFilterParams', { store.dispatch('setFilterParams', {
authorUsername: 'root', authorUsername: 'root',
labelName: ['Bug'], labelName: ['Bug'],
milestoneTitle: '4.0', milestoneTitle: '4.0',
confidential: true, confidential: true,
}); });
wrapper.vm.$store.dispatch('setSortedBy', 'end_date_asc'); store.dispatch('setSortedBy', 'end_date_asc');
wrapper.vm.$store.dispatch('setDaterange', { store.dispatch('setDaterange', {
timeframeRangeType: DATE_RANGES.CURRENT_YEAR, timeframeRangeType: DATE_RANGES.CURRENT_YEAR,
presetType: PRESET_TYPES.MONTHS, presetType: PRESET_TYPES.MONTHS,
}); });
...@@ -196,7 +198,7 @@ describe('RoadmapFilters', () => { ...@@ -196,7 +198,7 @@ describe('RoadmapFilters', () => {
}); });
it('has initialFilterValue prop set to array of formatted values based on `filterParams`', async () => { it('has initialFilterValue prop set to array of formatted values based on `filterParams`', async () => {
wrapper.vm.$store.dispatch('setFilterParams', { store.dispatch('setFilterParams', {
authorUsername: 'root', authorUsername: 'root',
labelName: ['Bug'], labelName: ['Bug'],
milestoneTitle: '4.0', milestoneTitle: '4.0',
...@@ -212,8 +214,7 @@ describe('RoadmapFilters', () => { ...@@ -212,8 +214,7 @@ describe('RoadmapFilters', () => {
}); });
it('fetches filtered epics when `onFilter` event is emitted', async () => { it('fetches filtered epics when `onFilter` event is emitted', async () => {
jest.spyOn(wrapper.vm, 'setFilterParams'); jest.spyOn(store, 'dispatch');
jest.spyOn(wrapper.vm, 'fetchEpics');
await nextTick(); await nextTick();
...@@ -221,7 +222,7 @@ describe('RoadmapFilters', () => { ...@@ -221,7 +222,7 @@ describe('RoadmapFilters', () => {
await nextTick(); await nextTick();
expect(wrapper.vm.setFilterParams).toHaveBeenCalledWith({ expect(store.dispatch).toHaveBeenCalledWith('setFilterParams', {
authorUsername: 'root', authorUsername: 'root',
labelName: ['Bug'], labelName: ['Bug'],
milestoneTitle: '4.0', milestoneTitle: '4.0',
...@@ -230,12 +231,11 @@ describe('RoadmapFilters', () => { ...@@ -230,12 +231,11 @@ describe('RoadmapFilters', () => {
'not[labelName]': ['Feature'], 'not[labelName]': ['Feature'],
'not[myReactionEmoji]': 'thumbs_up', 'not[myReactionEmoji]': 'thumbs_up',
}); });
expect(wrapper.vm.fetchEpics).toHaveBeenCalled(); expect(store.dispatch).toHaveBeenCalledWith('fetchEpics');
}); });
it('fetches epics with updated sort order when `onSort` event is emitted', async () => { it('fetches epics with updated sort order when `onSort` event is emitted', async () => {
jest.spyOn(wrapper.vm, 'setSortedBy'); jest.spyOn(store, 'dispatch');
jest.spyOn(wrapper.vm, 'fetchEpics');
await nextTick(); await nextTick();
...@@ -243,20 +243,19 @@ describe('RoadmapFilters', () => { ...@@ -243,20 +243,19 @@ describe('RoadmapFilters', () => {
await nextTick(); await nextTick();
expect(wrapper.vm.setSortedBy).toHaveBeenCalledWith('end_date_asc'); expect(store.dispatch).toHaveBeenCalledWith('setSortedBy', 'end_date_asc');
expect(wrapper.vm.fetchEpics).toHaveBeenCalled(); expect(store.dispatch).toHaveBeenCalledWith('fetchEpics');
}); });
it('does not set filters params or fetch epics when onFilter event is triggered with empty filters array and cleared param set to false', async () => { it('does not set filters params or fetch epics when onFilter event is triggered with empty filters array and cleared param set to false', async () => {
jest.spyOn(wrapper.vm, 'setFilterParams'); jest.spyOn(store, 'dispatch');
jest.spyOn(wrapper.vm, 'fetchEpics');
filteredSearchBar.vm.$emit('onFilter', [], false); filteredSearchBar.vm.$emit('onFilter', [], false);
await nextTick(); await nextTick();
expect(wrapper.vm.setFilterParams).not.toHaveBeenCalled(); expect(store.dispatch).not.toHaveBeenCalledWith('setFilterParams');
expect(wrapper.vm.fetchEpics).not.toHaveBeenCalled(); expect(store.dispatch).not.toHaveBeenCalledWith('fetchEpics');
}); });
describe('when user is logged in', () => { describe('when user is logged in', () => {
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册