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

220 lines
6.2 KiB
JavaScript
Raw Normal View History

2020-04-22 19:07:51 +05:30
/* global List */
/* global ListAssignee */
/* global ListLabel */
2020-11-24 15:15:51 +05:30
import { mount } from '@vue/test-utils';
2020-04-22 19:07:51 +05:30
import MockAdapter from 'axios-mock-adapter';
import waitForPromises from 'helpers/wait_for_promises';
2021-03-11 19:13:27 +05:30
import BoardCard from '~/boards/components/board_card.vue';
import issueCardInner from '~/boards/components/issue_card_inner.vue';
import eventHub from '~/boards/eventhub';
import store from '~/boards/stores';
import boardsStore from '~/boards/stores/boards_store';
2020-10-24 23:57:45 +05:30
import axios from '~/lib/utils/axios_utils';
2020-04-22 19:07:51 +05:30
import sidebarEventHub from '~/sidebar/event_hub';
import '~/boards/models/label';
import '~/boards/models/assignee';
import '~/boards/models/list';
import userAvatarLink from '~/vue_shared/components/user_avatar/user_avatar_link.vue';
2020-11-24 15:15:51 +05:30
import { listObj, boardsMockInterceptor, setMockEndpoints } from '../mock_data';
2020-04-22 19:07:51 +05:30
2020-11-24 15:15:51 +05:30
describe('BoardCard', () => {
2020-04-22 19:07:51 +05:30
let wrapper;
let mock;
let list;
const findIssueCardInner = () => wrapper.find(issueCardInner);
const findUserAvatarLink = () => wrapper.find(userAvatarLink);
// this particular mount component needs to be used after the root beforeEach because it depends on list being initialized
2021-03-08 18:12:59 +05:30
const mountComponent = (propsData) => {
2020-11-24 15:15:51 +05:30
wrapper = mount(BoardCard, {
2020-04-22 19:07:51 +05:30
stubs: {
issueCardInner,
},
store,
propsData: {
list,
issue: list.issues[0],
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,
2020-11-24 15:15:51 +05:30
},
2020-04-22 19:07:51 +05:30
});
};
2020-11-24 15:15:51 +05:30
const setupData = async () => {
2020-04-22 19:07:51 +05:30
list = new List(listObj);
boardsStore.create();
boardsStore.detail.issue = {};
const label1 = new ListLabel({
id: 3,
title: 'testing 123',
color: '#000cff',
text_color: 'white',
description: 'test',
});
2020-11-24 15:15:51 +05:30
await waitForPromises();
list.issues[0].labels.push(label1);
2020-04-22 19:07:51 +05:30
};
beforeEach(() => {
mock = new MockAdapter(axios);
mock.onAny().reply(boardsMockInterceptor);
setMockEndpoints();
return setupData();
});
afterEach(() => {
wrapper.destroy();
wrapper = null;
list = null;
mock.restore();
});
it('when details issue is empty does not show the element', () => {
mountComponent();
2020-11-24 15:15:51 +05:30
expect(wrapper.find('[data-testid="board_card"').classes()).not.toContain('is-active');
2020-04-22 19:07:51 +05:30
});
it('when detailIssue is equal to card issue shows the element', () => {
[boardsStore.detail.issue] = list.issues;
mountComponent();
expect(wrapper.classes()).toContain('is-active');
});
it('when multiSelect does not contain issue removes multi select class', () => {
mountComponent();
expect(wrapper.classes()).not.toContain('multi-select');
});
it('when multiSelect contain issue add multi select class', () => {
boardsStore.multiSelect.list = [list.issues[0]];
mountComponent();
expect(wrapper.classes()).toContain('multi-select');
});
it('adds user-can-drag class if not disabled', () => {
mountComponent();
expect(wrapper.classes()).toContain('user-can-drag');
});
it('does not add user-can-drag class disabled', () => {
mountComponent({ disabled: true });
expect(wrapper.classes()).not.toContain('user-can-drag');
});
it('does not add disabled class', () => {
mountComponent();
expect(wrapper.classes()).not.toContain('is-disabled');
});
it('adds disabled class is disabled is true', () => {
mountComponent({ disabled: true });
expect(wrapper.classes()).toContain('is-disabled');
});
describe('mouse events', () => {
it('does not set detail issue if showDetail is false', () => {
mountComponent();
expect(boardsStore.detail.issue).toEqual({});
});
it('does not set detail issue if link is clicked', () => {
mountComponent();
2021-03-08 18:12:59 +05:30
findIssueCardInner().find('a').trigger('mouseup');
2020-04-22 19:07:51 +05:30
expect(boardsStore.detail.issue).toEqual({});
});
it('does not set detail issue if img is clicked', () => {
mountComponent({
issue: {
...list.issues[0],
assignees: [
new ListAssignee({
id: 1,
name: 'testing 123',
username: 'test',
avatar: 'test_image',
}),
],
},
});
findUserAvatarLink().trigger('mouseup');
expect(boardsStore.detail.issue).toEqual({});
});
it('does not set detail issue if showDetail is false after mouseup', () => {
mountComponent();
wrapper.trigger('mouseup');
expect(boardsStore.detail.issue).toEqual({});
});
it('sets detail issue to card issue on mouse up', () => {
jest.spyOn(eventHub, '$emit').mockImplementation(() => {});
mountComponent();
wrapper.trigger('mousedown');
wrapper.trigger('mouseup');
2021-01-29 00:20:46 +05:30
expect(eventHub.$emit).toHaveBeenCalledWith('newDetailIssue', wrapper.vm.issue, false);
2020-04-22 19:07:51 +05:30
expect(boardsStore.detail.list).toEqual(wrapper.vm.list);
});
it('resets detail issue to empty if already set', () => {
jest.spyOn(eventHub, '$emit').mockImplementation(() => {});
const [issue] = list.issues;
boardsStore.detail.issue = issue;
mountComponent();
wrapper.trigger('mousedown');
wrapper.trigger('mouseup');
2021-01-29 00:20:46 +05:30
expect(eventHub.$emit).toHaveBeenCalledWith('clearDetailIssue', false);
2020-04-22 19:07:51 +05:30
});
});
describe('sidebarHub events', () => {
it('closes all sidebars before showing an issue if no issues are opened', () => {
jest.spyOn(sidebarEventHub, '$emit').mockImplementation(() => {});
boardsStore.detail.issue = {};
mountComponent();
2020-11-24 15:15:51 +05:30
// sets conditional so that event is emitted.
wrapper.trigger('mousedown');
2020-04-22 19:07:51 +05:30
wrapper.trigger('mouseup');
expect(sidebarEventHub.$emit).toHaveBeenCalledWith('sidebar.closeAll');
});
it('it does not closes all sidebars before showing an issue if an issue is opened', () => {
jest.spyOn(sidebarEventHub, '$emit').mockImplementation(() => {});
const [issue] = list.issues;
boardsStore.detail.issue = issue;
mountComponent();
wrapper.trigger('mousedown');
expect(sidebarEventHub.$emit).not.toHaveBeenCalledWith('sidebar.closeAll');
});
});
});