2021-04-17 20:07:23 +05:30
|
|
|
import { createLocalVue, shallowMount } from '@vue/test-utils';
|
|
|
|
import Vuex from 'vuex';
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
import BoardCard from '~/boards/components/board_card.vue';
|
2021-04-17 20:07:23 +05:30
|
|
|
import BoardCardInner from '~/boards/components/board_card_inner.vue';
|
|
|
|
import { inactiveId } from '~/boards/constants';
|
|
|
|
import { mockLabelList, mockIssue } from '../mock_data';
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
describe('Board card', () => {
|
|
|
|
let wrapper;
|
|
|
|
let store;
|
|
|
|
let mockActions;
|
|
|
|
|
|
|
|
const localVue = createLocalVue();
|
|
|
|
localVue.use(Vuex);
|
|
|
|
|
|
|
|
const createStore = ({ initialState = {}, isSwimlanesOn = false } = {}) => {
|
|
|
|
mockActions = {
|
|
|
|
toggleBoardItem: jest.fn(),
|
|
|
|
toggleBoardItemMultiSelection: jest.fn(),
|
|
|
|
};
|
|
|
|
|
|
|
|
store = new Vuex.Store({
|
|
|
|
state: {
|
|
|
|
activeId: inactiveId,
|
|
|
|
selectedBoardItems: [],
|
|
|
|
...initialState,
|
|
|
|
},
|
|
|
|
actions: mockActions,
|
|
|
|
getters: {
|
|
|
|
isSwimlanesOn: () => isSwimlanesOn,
|
|
|
|
isEpicBoard: () => false,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
// this particular mount component needs to be used after the root beforeEach because it depends on list being initialized
|
2021-04-17 20:07:23 +05:30
|
|
|
const mountComponent = ({ propsData = {}, provide = {} } = {}) => {
|
|
|
|
wrapper = shallowMount(BoardCard, {
|
|
|
|
localVue,
|
2020-04-22 19:07:51 +05:30
|
|
|
stubs: {
|
2021-04-17 20:07:23 +05:30
|
|
|
BoardCardInner,
|
2020-04-22 19:07:51 +05:30
|
|
|
},
|
|
|
|
store,
|
|
|
|
propsData: {
|
2021-04-17 20:07:23 +05:30
|
|
|
list: mockLabelList,
|
|
|
|
item: mockIssue,
|
2020-04-22 19:07:51 +05:30
|
|
|
disabled: false,
|
|
|
|
index: 0,
|
|
|
|
...propsData,
|
|
|
|
},
|
2020-11-24 15:15:51 +05:30
|
|
|
provide: {
|
|
|
|
groupId: null,
|
|
|
|
rootPath: '/',
|
2021-03-08 18:12:59 +05:30
|
|
|
scopedLabelsAvailable: false,
|
2021-04-17 20:07:23 +05:30
|
|
|
...provide,
|
2020-11-24 15:15:51 +05:30
|
|
|
},
|
2020-04-22 19:07:51 +05:30
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
const selectCard = async () => {
|
|
|
|
wrapper.trigger('mouseup');
|
|
|
|
await wrapper.vm.$nextTick();
|
2020-04-22 19:07:51 +05:30
|
|
|
};
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
const multiSelectCard = async () => {
|
|
|
|
wrapper.trigger('mouseup', { ctrlKey: true });
|
|
|
|
await wrapper.vm.$nextTick();
|
|
|
|
};
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
2021-04-17 20:07:23 +05:30
|
|
|
store = null;
|
2020-04-22 19:07:51 +05:30
|
|
|
});
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
describe.each`
|
|
|
|
isSwimlanesOn
|
|
|
|
${true} | ${false}
|
|
|
|
`('when isSwimlanesOn is $isSwimlanesOn', ({ isSwimlanesOn }) => {
|
|
|
|
it('should not highlight the card by default', async () => {
|
|
|
|
createStore({ isSwimlanesOn });
|
2020-04-22 19:07:51 +05:30
|
|
|
mountComponent();
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
expect(wrapper.classes()).not.toContain('is-active');
|
|
|
|
expect(wrapper.classes()).not.toContain('multi-select');
|
2020-04-22 19:07:51 +05:30
|
|
|
});
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
it('should highlight the card with a correct style when selected', async () => {
|
|
|
|
createStore({
|
|
|
|
initialState: {
|
|
|
|
activeId: mockIssue.id,
|
2020-04-22 19:07:51 +05:30
|
|
|
},
|
2021-04-17 20:07:23 +05:30
|
|
|
isSwimlanesOn,
|
2020-04-22 19:07:51 +05:30
|
|
|
});
|
|
|
|
mountComponent();
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
expect(wrapper.classes()).toContain('is-active');
|
|
|
|
expect(wrapper.classes()).not.toContain('multi-select');
|
2020-04-22 19:07:51 +05:30
|
|
|
});
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
it('should highlight the card with a correct style when multi-selected', async () => {
|
|
|
|
createStore({
|
|
|
|
initialState: {
|
|
|
|
activeId: inactiveId,
|
|
|
|
selectedBoardItems: [mockIssue],
|
|
|
|
},
|
|
|
|
isSwimlanesOn,
|
|
|
|
});
|
2020-04-22 19:07:51 +05:30
|
|
|
mountComponent();
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
expect(wrapper.classes()).toContain('multi-select');
|
|
|
|
expect(wrapper.classes()).not.toContain('is-active');
|
2020-04-22 19:07:51 +05:30
|
|
|
});
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
describe('when mouseup event is called on the card', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createStore({ isSwimlanesOn });
|
|
|
|
mountComponent();
|
|
|
|
});
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
describe('when not using multi-select', () => {
|
|
|
|
it('should call vuex action "toggleBoardItem" with correct parameters', async () => {
|
|
|
|
await selectCard();
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
expect(mockActions.toggleBoardItem).toHaveBeenCalledTimes(1);
|
|
|
|
expect(mockActions.toggleBoardItem).toHaveBeenCalledWith(expect.any(Object), {
|
|
|
|
boardItem: mockIssue,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
describe('when using multi-select', () => {
|
|
|
|
it('should call vuex action "multiSelectBoardItem" with correct parameters', async () => {
|
|
|
|
await multiSelectCard();
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
expect(mockActions.toggleBoardItemMultiSelection).toHaveBeenCalledTimes(1);
|
|
|
|
expect(mockActions.toggleBoardItemMultiSelection).toHaveBeenCalledWith(
|
|
|
|
expect.any(Object),
|
|
|
|
mockIssue,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2020-04-22 19:07:51 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|