Commit 3aabc184 authored by Phil Hughes's avatar Phil Hughes

Merge branch '7751-add-refactored-epics-sidebar-parent-epic-support' into 'master'

[Part 5] Add support for Parent Epic in Epic sidebar

See merge request gitlab-org/gitlab-ee!9318
parents beba8dea f8dc1826
<script> <script>
import { mapState, mapGetters, mapActions } from 'vuex'; import { mapState, mapGetters, mapActions } from 'vuex';
import SidebarParentEpic from 'ee/sidebar/components/sidebar_item_epic.vue';
import epicUtils from '../utils/epic_utils'; import epicUtils from '../utils/epic_utils';
import SidebarHeader from './sidebar_items/sidebar_header.vue'; import SidebarHeader from './sidebar_items/sidebar_header.vue';
...@@ -19,6 +21,7 @@ export default { ...@@ -19,6 +21,7 @@ export default {
SidebarDatePicker, SidebarDatePicker,
SidebarDatePickerCollapsed, SidebarDatePickerCollapsed,
SidebarLabels, SidebarLabels,
SidebarParentEpic,
}, },
computed: { computed: {
...mapState([ ...mapState([
...@@ -48,6 +51,7 @@ export default { ...@@ -48,6 +51,7 @@ export default {
'dueDateTimeFromMilestones', 'dueDateTimeFromMilestones',
'dueDateTime', 'dueDateTime',
'dueDateForCollapsedSidebar', 'dueDateForCollapsedSidebar',
'parentEpic',
]), ]),
}, },
mounted() { mounted() {
...@@ -175,6 +179,9 @@ export default { ...@@ -175,6 +179,9 @@ export default {
@toggleCollapse="toggleSidebar({ sidebarCollapsed })" @toggleCollapse="toggleSidebar({ sidebarCollapsed })"
/> />
<sidebar-labels :can-update="canUpdate" :sidebar-collapsed="sidebarCollapsed" /> <sidebar-labels :can-update="canUpdate" :sidebar-collapsed="sidebarCollapsed" />
<div class="block parent-epic">
<sidebar-parent-epic :block-title="__('Parent epic')" :initial-epic="parentEpic" />
</div>
</div> </div>
</aside> </aside>
</template> </template>
...@@ -55,5 +55,7 @@ export const isDateInvalid = (state, getters) => { ...@@ -55,5 +55,7 @@ export const isDateInvalid = (state, getters) => {
); );
}; };
export const parentEpic = state => (state.parent ? state.parent : {});
// prevent babel-plugin-rewire from generating an invalid default during karma tests // prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {}; export default () => {};
...@@ -54,6 +54,7 @@ export default () => ({ ...@@ -54,6 +54,7 @@ export default () => ({
dueDateFromMilestones: '', dueDateFromMilestones: '',
dueDate: '', dueDate: '',
labels: [], labels: [],
parent: null,
participants: [], participants: [],
subscribed: false, subscribed: false,
......
...@@ -7,7 +7,7 @@ import epicUtils from 'ee/epic/utils/epic_utils'; ...@@ -7,7 +7,7 @@ import epicUtils from 'ee/epic/utils/epic_utils';
import { dateTypes } from 'ee/epic/constants'; import { dateTypes } from 'ee/epic/constants';
import { mountComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; import { mountComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
import { mockEpicMeta, mockEpicData } from '../mock_data'; import { mockEpicMeta, mockEpicData, mockParentEpic } from '../mock_data';
describe('EpicSidebarComponent', () => { describe('EpicSidebarComponent', () => {
const originalUserId = gon.current_user_id; const originalUserId = gon.current_user_id;
...@@ -19,6 +19,7 @@ describe('EpicSidebarComponent', () => { ...@@ -19,6 +19,7 @@ describe('EpicSidebarComponent', () => {
store = createStore(); store = createStore();
store.dispatch('setEpicMeta', mockEpicMeta); store.dispatch('setEpicMeta', mockEpicMeta);
store.dispatch('setEpicData', mockEpicData); store.dispatch('setEpicData', mockEpicData);
store.state.parent = mockParentEpic;
vm = mountComponentWithStore(Component, { vm = mountComponentWithStore(Component, {
store, store,
...@@ -202,5 +203,23 @@ describe('EpicSidebarComponent', () => { ...@@ -202,5 +203,23 @@ describe('EpicSidebarComponent', () => {
it('renders labels select element', () => { it('renders labels select element', () => {
expect(vm.$el.querySelector('.js-labels-block')).not.toBeNull(); expect(vm.$el.querySelector('.js-labels-block')).not.toBeNull();
}); });
it('renders parent epic link element', done => {
store.dispatch('toggleSidebarFlag', false);
vm.$nextTick()
.then(() => {
const parentEpicEl = vm.$el.querySelector('.block.parent-epic');
expect(parentEpicEl).not.toBeNull();
expect(parentEpicEl.querySelector('.title').innerText.trim()).toBe('Parent epic');
expect(parentEpicEl.querySelector('.value').innerText.trim()).toBe(mockParentEpic.title);
expect(parentEpicEl.querySelector('.value a').getAttribute('href')).toBe(
mockParentEpic.url,
);
})
.then(done)
.catch(done.fail);
});
}); });
}); });
...@@ -44,3 +44,9 @@ export const mockLabels = [ ...@@ -44,3 +44,9 @@ export const mockLabels = [
text_color: '#FFFFFF', text_color: '#FFFFFF',
}, },
]; ];
export const mockParentEpic = {
id: 1,
title: 'Sample Parent Epic',
url: '/groups/gitlab-org/-/epics/6',
};
...@@ -259,4 +259,24 @@ describe('Epic Store Getters', () => { ...@@ -259,4 +259,24 @@ describe('Epic Store Getters', () => {
).toBe(false); ).toBe(false);
}); });
}); });
describe('parentEpic', () => {
it('returns `parent` from state when parent is not null', () => {
const parent = getters.parentEpic({
parent: {
id: 1,
},
});
expect(parent.id).toBe(1);
});
it('returns empty object when `parent` within state is null', () => {
const parent = getters.parentEpic({
parent: null,
});
expect(parent).not.toBeNull();
});
});
}); });
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