Commit 4e722a57 authored by Kushal Pandya's avatar Kushal Pandya

Fix Epic select for newly created issues in Boards

Fixes a bug where selecting Epics for newly created
Issue within Issue Board caused wrong issue ID
to be sent in request.
parent e29d68a3
......@@ -61,7 +61,10 @@ export default {
if (this.initialEpic) {
return false;
} else if (this.sidebarStore.isFetching) {
return this.sidebarStore.isFetching.epic;
// We need to cast `epic` into boolean as when
// new issue is created from board, `isFetching`
// does not contain `epic` within it.
return Boolean(this.sidebarStore.isFetching.epic);
}
return false;
},
......
......@@ -72,6 +72,22 @@ export default {
},
},
watch: {
/**
* When Issue is created from Boards
* Issue ID is updated post-render
* so we need to watch it to update in state
*/
issueId() {
this.setIssueId(this.issueId);
},
/**
* When Issues are selected within Boards
* `initialEpic` gets updated to reflect
* underlying selection.
*/
initialEpic() {
this.setSelectedEpic(this.initialEpic);
},
/**
* Initial Epic is loaded via separate Sidebar store
* So we need to watch for updates before updating local store.
......@@ -93,6 +109,7 @@ export default {
methods: {
...mapActions([
'setInitialData',
'setIssueId',
'setSearchQuery',
'setSelectedEpic',
'fetchEpics',
......
......@@ -9,6 +9,7 @@ import { noneEpic } from 'ee/vue_shared/constants';
import * as types from './mutation_types';
export const setInitialData = ({ commit }, data) => commit(types.SET_INITIAL_DATA, data);
export const setIssueId = ({ commit }, issueId) => commit(types.SET_ISSUE_ID, issueId);
export const setSearchQuery = ({ commit }, searchQuery) =>
commit(types.SET_SEARCH_QUERY, searchQuery);
......
export const SET_INITIAL_DATA = 'SET_INITIAL_DATA';
export const SET_ISSUE_ID = 'SET_ISSUE_ID';
export const SET_SEARCH_QUERY = 'SET_SEARCH_QUERY';
......
......@@ -8,6 +8,10 @@ export default {
state.selectedEpicIssueId = selectedEpicIssueId;
},
[types.SET_ISSUE_ID](state, issueId) {
state.issueId = issueId;
},
[types.SET_SEARCH_QUERY](state, searchQuery) {
state.searchQuery = searchQuery;
},
......
......@@ -49,6 +49,38 @@ describe('EpicsSelect', () => {
wrapper.destroy();
});
describe('watchers', () => {
describe('issueId', () => {
it('should update `issueId` within state when prop is updated', () => {
wrapper.setProps({
issueId: 123,
});
expect(wrapper.vm.$store.state.issueId).toBe(123);
});
});
describe('initialEpic', () => {
it('should update `selectedEpic` within state when prop is updated', () => {
wrapper.setProps({
initialEpic: mockEpic2,
});
expect(wrapper.vm.$store.state.selectedEpic).toBe(mockEpic2);
});
});
describe('initialEpicLoading', () => {
it('should update `selectedEpic` within state when prop is updated', () => {
wrapper.setProps({
initialEpic: mockEpic2,
});
expect(wrapper.vm.$store.state.selectedEpic).toBe(mockEpic2);
});
});
});
describe('methods', () => {
describe('handleDropdownShown', () => {
it('should call `fetchEpics` when `groupEpics` does not return any epics', done => {
......
......@@ -46,6 +46,21 @@ describe('EpicsSelect', () => {
});
});
describe('setIssueId', () => {
it('should set `issueId` on state', done => {
const issueId = mockIssue.id;
testAction(
actions.setIssueId,
issueId,
state,
[{ type: types.SET_ISSUE_ID, payload: issueId }],
[],
done,
);
});
});
describe('setSearchQuery', () => {
it('should set `searchQuery` param on state', done => {
const searchQuery = 'foo';
......
......@@ -32,6 +32,16 @@ describe('EpicsSelect', () => {
});
});
describe(types.SET_ISSUE_ID, () => {
it('should set provided `issueId` param to state.issueId', () => {
const issueId = mockIssue.id;
mutations[types.SET_ISSUE_ID](state, issueId);
expect(state).toHaveProperty('issueId', issueId);
});
});
describe(types.SET_SEARCH_QUERY, () => {
it('should set `searchQuery` param to state', () => {
const searchQuery = 'foo';
......
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