debian-mirror-gitlab/spec/frontend/boards/components/board_card_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

253 lines
6.6 KiB
JavaScript
Raw Normal View History

2021-06-08 01:23:25 +05:30
import { GlLabel } from '@gitlab/ui';
2022-04-04 11:22:00 +05:30
import Vue, { nextTick } from 'vue';
2021-04-17 20:07:23 +05:30
import Vuex from 'vuex';
2023-06-20 00:43:36 +05:30
import VueApollo from 'vue-apollo';
2020-04-22 19:07:51 +05:30
2023-06-20 00:43:36 +05:30
import createMockApollo from 'helpers/mock_apollo_helper';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
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';
2022-08-13 15:12:31 +05:30
import { mockLabelList, mockIssue, DEFAULT_COLOR } 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;
2021-09-04 01:27:46 +05:30
Vue.use(Vuex);
2023-06-20 00:43:36 +05:30
Vue.use(VueApollo);
const mockSetActiveBoardItemResolver = jest.fn();
const mockApollo = createMockApollo([], {
Mutation: {
setActiveBoardItem: mockSetActiveBoardItemResolver,
},
});
2021-04-17 20:07:23 +05:30
2021-06-08 01:23:25 +05:30
const createStore = ({ initialState = {} } = {}) => {
2021-04-17 20:07:23 +05:30
mockActions = {
toggleBoardItem: jest.fn(),
toggleBoardItemMultiSelection: jest.fn(),
2021-06-08 01:23:25 +05:30
performSearch: jest.fn(),
2021-04-17 20:07:23 +05:30
};
store = new Vuex.Store({
state: {
activeId: inactiveId,
selectedBoardItems: [],
...initialState,
},
actions: mockActions,
});
};
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-06-08 01:23:25 +05:30
const mountComponent = ({
propsData = {},
provide = {},
stubs = { BoardCardInner },
2021-09-04 01:27:46 +05:30
item = mockIssue,
2021-06-08 01:23:25 +05:30
} = {}) => {
2023-06-20 00:43:36 +05:30
wrapper = shallowMountExtended(BoardCard, {
apolloProvider: mockApollo,
2022-10-11 01:57:18 +05:30
stubs: {
...stubs,
BoardCardInner,
},
2020-04-22 19:07:51 +05:30
store,
propsData: {
2021-04-17 20:07:23 +05:30
list: mockLabelList,
2021-09-04 01:27:46 +05:30
item,
2020-04-22 19:07:51 +05:30
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,
2023-06-20 00:43:36 +05:30
isIssueBoard: true,
2023-01-13 00:05:48 +05:30
isEpicBoard: false,
2023-03-17 16:20:25 +05:30
issuableType: 'issue',
isGroupBoard: true,
disabled: false,
2023-04-23 21:23:45 +05:30
isApolloBoard: 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 () => {
2021-12-11 22:18:48 +05:30
wrapper.trigger('click');
2022-04-04 11:22:00 +05:30
await nextTick();
2020-04-22 19:07:51 +05:30
};
2021-04-17 20:07:23 +05:30
const multiSelectCard = async () => {
2021-12-11 22:18:48 +05:30
wrapper.trigger('click', { ctrlKey: true });
2022-04-04 11:22:00 +05:30
await nextTick();
2021-04-17 20:07:23 +05:30
};
2020-04-22 19:07:51 +05:30
2021-09-04 01:27:46 +05:30
beforeEach(() => {
window.gon = { features: {} };
});
2020-04-22 19:07:51 +05:30
afterEach(() => {
2021-04-17 20:07:23 +05:30
store = null;
2020-04-22 19:07:51 +05:30
});
2021-06-08 01:23:25 +05:30
describe('when GlLabel is clicked in BoardCardInner', () => {
it('doesnt call toggleBoardItem', () => {
createStore({ initialState: { isShowingLabels: true } });
2022-10-11 01:57:18 +05:30
mountComponent();
2021-06-08 01:23:25 +05:30
2022-08-27 11:52:29 +05:30
wrapper.findComponent(GlLabel).trigger('mouseup');
2020-04-22 19:07:51 +05:30
2021-06-08 01:23:25 +05:30
expect(mockActions.toggleBoardItem).toHaveBeenCalledTimes(0);
2020-04-22 19:07:51 +05:30
});
2021-06-08 01:23:25 +05:30
});
2020-04-22 19:07:51 +05:30
2023-06-20 00:43:36 +05:30
it('should not highlight the card by default', () => {
2021-06-08 01:23:25 +05:30
createStore();
mountComponent();
2020-04-22 19:07:51 +05:30
2021-06-08 01:23:25 +05:30
expect(wrapper.classes()).not.toContain('is-active');
expect(wrapper.classes()).not.toContain('multi-select');
});
2023-06-20 00:43:36 +05:30
it('should highlight the card with a correct style when selected', () => {
2021-06-08 01:23:25 +05:30
createStore({
initialState: {
activeId: mockIssue.id,
},
2020-04-22 19:07:51 +05:30
});
2021-06-08 01:23:25 +05:30
mountComponent();
2020-04-22 19:07:51 +05:30
2021-06-08 01:23:25 +05:30
expect(wrapper.classes()).toContain('is-active');
expect(wrapper.classes()).not.toContain('multi-select');
});
2020-04-22 19:07:51 +05:30
2023-06-20 00:43:36 +05:30
it('should highlight the card with a correct style when multi-selected', () => {
2021-06-08 01:23:25 +05:30
createStore({
initialState: {
activeId: inactiveId,
selectedBoardItems: [mockIssue],
},
2020-04-22 19:07:51 +05:30
});
2021-06-08 01:23:25 +05:30
mountComponent();
2020-11-24 15:15:51 +05:30
2021-06-08 01:23:25 +05:30
expect(wrapper.classes()).toContain('multi-select');
expect(wrapper.classes()).not.toContain('is-active');
});
2020-04-22 19:07:51 +05:30
2021-06-08 01:23:25 +05:30
describe('when mouseup event is called on the card', () => {
beforeEach(() => {
createStore();
mountComponent();
});
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-06-08 01:23:25 +05:30
expect(mockActions.toggleBoardItem).toHaveBeenCalledTimes(1);
expect(mockActions.toggleBoardItem).toHaveBeenCalledWith(expect.any(Object), {
boardItem: mockIssue,
2021-04-17 20:07:23 +05:30
});
});
2021-06-08 01:23:25 +05:30
});
2020-04-22 19:07:51 +05:30
2021-06-08 01:23:25 +05:30
describe('when using multi-select', () => {
2021-09-04 01:27:46 +05:30
beforeEach(() => {
window.gon = { features: { boardMultiSelect: true } };
});
2021-06-08 01:23:25 +05:30
it('should call vuex action "multiSelectBoardItem" with correct parameters', async () => {
await multiSelectCard();
2020-04-22 19:07:51 +05:30
2021-06-08 01:23:25 +05:30
expect(mockActions.toggleBoardItemMultiSelection).toHaveBeenCalledTimes(1);
expect(mockActions.toggleBoardItemMultiSelection).toHaveBeenCalledWith(
expect.any(Object),
mockIssue,
);
2021-04-17 20:07:23 +05:30
});
2020-04-22 19:07:51 +05:30
});
});
2021-09-04 01:27:46 +05:30
describe('when card is loading', () => {
it('card is disabled and user cannot drag', () => {
createStore();
mountComponent({ item: { ...mockIssue, isLoading: true } });
expect(wrapper.classes()).toContain('is-disabled');
2022-03-02 08:16:31 +05:30
expect(wrapper.classes()).not.toContain('gl-cursor-grab');
2021-09-04 01:27:46 +05:30
});
});
describe('when card is not loading', () => {
it('user can drag', () => {
createStore();
mountComponent();
expect(wrapper.classes()).not.toContain('is-disabled');
2022-03-02 08:16:31 +05:30
expect(wrapper.classes()).toContain('gl-cursor-grab');
2021-09-04 01:27:46 +05:30
});
});
2022-08-13 15:12:31 +05:30
describe('when Epic colors are enabled', () => {
it('applies the correct color', () => {
window.gon.features = { epicColorHighlight: true };
createStore();
mountComponent({
item: {
...mockIssue,
color: DEFAULT_COLOR,
},
});
expect(wrapper.classes()).toEqual(
expect.arrayContaining(['gl-pl-4', 'gl-border-l-solid', 'gl-border-4']),
);
expect(wrapper.attributes('style')).toContain(`border-color: ${DEFAULT_COLOR}`);
});
});
describe('when Epic colors are not enabled', () => {
it('applies the correct color', () => {
window.gon.features = { epicColorHighlight: false };
createStore();
mountComponent({
item: {
...mockIssue,
color: DEFAULT_COLOR,
},
});
expect(wrapper.classes()).not.toEqual(
expect.arrayContaining(['gl-pl-4', 'gl-border-l-solid', 'gl-border-4']),
);
expect(wrapper.attributes('style')).toBeUndefined();
});
});
2023-06-20 00:43:36 +05:30
describe('Apollo boards', () => {
beforeEach(async () => {
createStore();
mountComponent({ provide: { isApolloBoard: true } });
await nextTick();
});
it('set active board item on client when clicking on card', async () => {
await selectCard();
expect(mockSetActiveBoardItemResolver).toHaveBeenCalledWith(
{},
{
boardItem: mockIssue,
},
expect.anything(),
expect.anything(),
);
});
});
2020-04-22 19:07:51 +05:30
});