Commit 5d12b2d9 authored by Axel García's avatar Axel García Committed by Paul Slaughter

Use sidebar.closeAll event on board_column lists

parent 9c871324
...@@ -8,6 +8,8 @@ export const ListType = { ...@@ -8,6 +8,8 @@ export const ListType = {
blank: 'blank', blank: 'blank',
}; };
export const inactiveListId = 0;
export default { export default {
ListType, ListType,
}; };
<script> <script>
import { mapActions } from 'vuex'; import { mapState, mapActions } from 'vuex';
import BoardColumnFoss from '~/boards/components/board_column.vue'; import BoardColumnFoss from '~/boards/components/board_column.vue';
import { __, sprintf, s__ } from '~/locale'; import { __, sprintf, s__ } from '~/locale';
import boardsStore from '~/boards/stores/boards_store'; import boardsStore from '~/boards/stores/boards_store';
import { inactiveListId } from '~/boards/constants';
import BoardPromotionState from 'ee/boards/components/board_promotion_state'; import BoardPromotionState from 'ee/boards/components/board_promotion_state';
import eventHub from '~/sidebar/event_hub';
export default { export default {
components: { components: {
...@@ -16,6 +18,7 @@ export default { ...@@ -16,6 +18,7 @@ export default {
}; };
}, },
computed: { computed: {
...mapState(['activeListId']),
issuesTooltip() { issuesTooltip() {
const { issuesSize, maxIssueCount } = this.list; const { issuesSize, maxIssueCount } = this.list;
...@@ -42,6 +45,10 @@ export default { ...@@ -42,6 +45,10 @@ export default {
methods: { methods: {
...mapActions(['setActiveListId']), ...mapActions(['setActiveListId']),
openSidebarSettings() { openSidebarSettings() {
if (this.activeListId === inactiveListId) {
eventHub.$emit('sidebar.closeAll');
}
this.setActiveListId(this.list.id); this.setActiveListId(this.list.id);
}, },
}, },
......
import Vue from 'vue'; import Vue from 'vue';
import { shallowMount } from '@vue/test-utils'; import Vuex from 'vuex';
import { shallowMount, createLocalVue } from '@vue/test-utils';
import AxiosMockAdapter from 'axios-mock-adapter'; import AxiosMockAdapter from 'axios-mock-adapter';
import Board from 'ee/boards/components/board_column.vue'; import Board from 'ee/boards/components/board_column.vue';
import List from '~/boards/models/list'; import List from '~/boards/models/list';
import { ListType } from '~/boards/constants'; import { ListType, inactiveListId } from '~/boards/constants';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import sidebarEventHub from '~/sidebar/event_hub';
import { TEST_HOST } from 'helpers/test_constants'; import { TEST_HOST } from 'helpers/test_constants';
import { listObj } from 'jest/boards/mock_data'; import { listObj } from 'jest/boards/mock_data';
...@@ -14,7 +16,12 @@ import { listObj } from 'jest/boards/mock_data'; ...@@ -14,7 +16,12 @@ import { listObj } from 'jest/boards/mock_data';
// so we are mocking it in this test // so we are mocking it in this test
jest.mock('ee/boards/components/board_promotion_state', () => ({})); jest.mock('ee/boards/components/board_promotion_state', () => ({}));
const localVue = createLocalVue();
localVue.use(Vuex);
describe('Board Column Component', () => { describe('Board Column Component', () => {
let store;
let wrapper; let wrapper;
let axiosMock; let axiosMock;
...@@ -22,6 +29,8 @@ describe('Board Column Component', () => { ...@@ -22,6 +29,8 @@ describe('Board Column Component', () => {
window.gon = {}; window.gon = {};
axiosMock = new AxiosMockAdapter(axios); axiosMock = new AxiosMockAdapter(axios);
axiosMock.onGet(`${TEST_HOST}/lists/1/issues`).reply(200, { issues: [] }); axiosMock.onGet(`${TEST_HOST}/lists/1/issues`).reply(200, { issues: [] });
store = new Vuex.Store({ state: { activeListId: inactiveListId } });
jest.spyOn(store, 'dispatch').mockImplementation();
}); });
afterEach(() => { afterEach(() => {
...@@ -61,6 +70,8 @@ describe('Board Column Component', () => { ...@@ -61,6 +70,8 @@ describe('Board Column Component', () => {
} }
wrapper = shallowMount(Board, { wrapper = shallowMount(Board, {
store,
localVue,
propsData: { propsData: {
boardId, boardId,
disabled: false, disabled: false,
...@@ -117,6 +128,28 @@ describe('Board Column Component', () => { ...@@ -117,6 +128,28 @@ describe('Board Column Component', () => {
expect([...hasSettings, ...hasNoSettings]).toContain(value); expect([...hasSettings, ...hasNoSettings]).toContain(value);
}); });
}); });
describe('emits sidebar.closeAll event on openSidebarSettings', () => {
beforeEach(() => {
jest.spyOn(sidebarEventHub, '$emit');
});
it('emits event if no active List', () => {
// Shares the same behavior for any settings-enabled List type
createComponent({ listType: hasSettings[0] });
wrapper.vm.openSidebarSettings();
expect(sidebarEventHub.$emit).toHaveBeenCalledWith('sidebar.closeAll');
});
it('does not emits event when there is an active List', () => {
store.state.activeListId = listObj.id;
createComponent({ listType: hasSettings[0] });
wrapper.vm.openSidebarSettings();
expect(sidebarEventHub.$emit).not.toHaveBeenCalled();
});
});
}); });
}); });
}); });
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