2021-02-21 22:10:36 -05:00
|
|
|
import { createLocalVue, shallowMount } from '@vue/test-utils';
|
2021-02-14 13:09:20 -05:00
|
|
|
import Vuex from 'vuex';
|
2021-02-01 10:08:56 -05:00
|
|
|
import { useFakeRequestAnimationFrame } from 'helpers/fake_request_animation_frame';
|
2021-01-18 04:11:05 -05:00
|
|
|
import BoardCard from '~/boards/components/board_card.vue';
|
2021-02-14 13:09:20 -05:00
|
|
|
import BoardList from '~/boards/components/board_list.vue';
|
2021-02-21 22:10:36 -05:00
|
|
|
import BoardNewIssue from '~/boards/components/board_new_issue.vue';
|
2021-02-14 13:09:20 -05:00
|
|
|
import eventHub from '~/boards/eventhub';
|
2021-01-18 04:11:05 -05:00
|
|
|
import defaultState from '~/boards/stores/state';
|
2021-02-01 10:08:56 -05:00
|
|
|
import { mockList, mockIssuesByListId, issues, mockIssues } from './mock_data';
|
2021-01-18 04:11:05 -05:00
|
|
|
|
|
|
|
const localVue = createLocalVue();
|
|
|
|
localVue.use(Vuex);
|
|
|
|
|
|
|
|
const actions = {
|
2021-02-17 22:09:22 -05:00
|
|
|
fetchItemsForList: jest.fn(),
|
2021-01-18 04:11:05 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
const createStore = (state = defaultState) => {
|
|
|
|
return new Vuex.Store({
|
|
|
|
state,
|
|
|
|
actions,
|
2021-03-10 04:09:29 -05:00
|
|
|
getters: {
|
|
|
|
isGroupBoard: () => false,
|
|
|
|
isProjectBoard: () => true,
|
|
|
|
isEpicBoard: () => false,
|
|
|
|
},
|
2021-01-18 04:11:05 -05:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const createComponent = ({
|
|
|
|
listIssueProps = {},
|
|
|
|
componentProps = {},
|
|
|
|
listProps = {},
|
|
|
|
state = {},
|
|
|
|
} = {}) => {
|
|
|
|
const store = createStore({
|
2021-02-22 04:10:46 -05:00
|
|
|
boardItemsByListId: mockIssuesByListId,
|
|
|
|
boardItems: issues,
|
2021-01-18 04:11:05 -05:00
|
|
|
pageInfoByListId: {
|
|
|
|
'gid://gitlab/List/1': { hasNextPage: true },
|
|
|
|
'gid://gitlab/List/2': {},
|
|
|
|
},
|
|
|
|
listsFlags: {
|
|
|
|
'gid://gitlab/List/1': {},
|
|
|
|
'gid://gitlab/List/2': {},
|
|
|
|
},
|
2021-02-21 22:10:36 -05:00
|
|
|
selectedBoardItems: [],
|
2021-01-18 04:11:05 -05:00
|
|
|
...state,
|
|
|
|
});
|
|
|
|
|
|
|
|
const list = {
|
|
|
|
...mockList,
|
|
|
|
...listProps,
|
|
|
|
};
|
|
|
|
const issue = {
|
2020-03-31 14:07:42 -04:00
|
|
|
title: 'Testing',
|
|
|
|
id: 1,
|
|
|
|
iid: 1,
|
|
|
|
confidential: false,
|
|
|
|
labels: [],
|
|
|
|
assignees: [],
|
|
|
|
...listIssueProps,
|
2021-01-18 04:11:05 -05:00
|
|
|
};
|
|
|
|
if (!Object.prototype.hasOwnProperty.call(listProps, 'issuesCount')) {
|
|
|
|
list.issuesCount = 1;
|
2020-03-31 14:07:42 -04:00
|
|
|
}
|
|
|
|
|
2021-02-21 22:10:36 -05:00
|
|
|
const component = shallowMount(BoardList, {
|
2021-01-18 04:11:05 -05:00
|
|
|
localVue,
|
2020-03-31 14:07:42 -04:00
|
|
|
propsData: {
|
|
|
|
disabled: false,
|
|
|
|
list,
|
2021-02-22 04:10:46 -05:00
|
|
|
boardItems: [issue],
|
2021-01-18 04:11:05 -05:00
|
|
|
canAdminList: true,
|
2020-03-31 14:07:42 -04:00
|
|
|
...componentProps,
|
|
|
|
},
|
2021-01-18 04:11:05 -05:00
|
|
|
store,
|
2020-09-17 05:09:32 -04:00
|
|
|
provide: {
|
|
|
|
groupId: null,
|
|
|
|
rootPath: '/',
|
2021-01-18 04:11:05 -05:00
|
|
|
weightFeatureAvailable: false,
|
|
|
|
boardWeight: null,
|
2020-09-17 05:09:32 -04:00
|
|
|
},
|
2021-02-21 22:10:36 -05:00
|
|
|
stubs: {
|
|
|
|
BoardCard,
|
|
|
|
BoardNewIssue,
|
|
|
|
},
|
2020-03-31 14:07:42 -04:00
|
|
|
});
|
|
|
|
|
2021-01-18 04:11:05 -05:00
|
|
|
return component;
|
2020-03-31 14:07:42 -04:00
|
|
|
};
|
2017-03-28 05:31:16 -04:00
|
|
|
|
|
|
|
describe('Board list component', () => {
|
2021-01-18 04:11:05 -05:00
|
|
|
let wrapper;
|
2021-02-21 22:10:36 -05:00
|
|
|
|
2021-01-18 04:11:05 -05:00
|
|
|
const findByTestId = (testId) => wrapper.find(`[data-testid="${testId}"]`);
|
2021-02-21 22:10:36 -05:00
|
|
|
const findIssueCountLoadingIcon = () => wrapper.find('[data-testid="count-loading-icon"]');
|
|
|
|
|
2021-01-18 04:11:05 -05:00
|
|
|
useFakeRequestAnimationFrame();
|
2017-03-28 05:31:16 -04:00
|
|
|
|
2021-01-18 04:11:05 -05:00
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
});
|
2017-03-28 05:31:16 -04:00
|
|
|
|
2021-01-18 04:11:05 -05:00
|
|
|
describe('When Expanded', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = createComponent();
|
2019-11-12 10:06:26 -05:00
|
|
|
});
|
2017-03-28 05:31:16 -04:00
|
|
|
|
2019-11-12 10:06:26 -05:00
|
|
|
it('renders component', () => {
|
2021-01-18 04:11:05 -05:00
|
|
|
expect(wrapper.find('.board-list-component').exists()).toBe(true);
|
2019-11-12 10:06:26 -05:00
|
|
|
});
|
|
|
|
|
2020-03-31 14:07:42 -04:00
|
|
|
it('renders loading icon', () => {
|
2021-01-18 04:11:05 -05:00
|
|
|
wrapper = createComponent({
|
|
|
|
state: { listsFlags: { 'gid://gitlab/List/1': { isLoading: true } } },
|
2019-11-12 10:06:26 -05:00
|
|
|
});
|
2021-01-18 04:11:05 -05:00
|
|
|
|
|
|
|
expect(findByTestId('board_list_loading').exists()).toBe(true);
|
2017-03-28 05:31:16 -04:00
|
|
|
});
|
|
|
|
|
2019-11-12 10:06:26 -05:00
|
|
|
it('renders issues', () => {
|
2021-01-18 04:11:05 -05:00
|
|
|
expect(wrapper.findAll(BoardCard).length).toBe(1);
|
2019-11-12 10:06:26 -05:00
|
|
|
});
|
2017-03-28 05:31:16 -04:00
|
|
|
|
2019-11-12 10:06:26 -05:00
|
|
|
it('sets data attribute with issue id', () => {
|
2021-03-11 04:09:36 -05:00
|
|
|
expect(wrapper.find('.board-card').attributes('data-item-id')).toBe('1');
|
2019-11-12 10:06:26 -05:00
|
|
|
});
|
2017-03-28 05:31:16 -04:00
|
|
|
|
2021-01-18 04:11:05 -05:00
|
|
|
it('shows new issue form', async () => {
|
|
|
|
wrapper.vm.toggleForm();
|
2017-03-28 05:31:16 -04:00
|
|
|
|
2021-01-18 04:11:05 -05:00
|
|
|
await wrapper.vm.$nextTick();
|
|
|
|
expect(wrapper.find('.board-new-issue-form').exists()).toBe(true);
|
2017-03-28 05:31:16 -04:00
|
|
|
});
|
|
|
|
|
2021-01-18 04:11:05 -05:00
|
|
|
it('shows new issue form after eventhub event', async () => {
|
|
|
|
eventHub.$emit(`toggle-issue-form-${wrapper.vm.list.id}`);
|
2017-03-28 05:31:16 -04:00
|
|
|
|
2021-01-18 04:11:05 -05:00
|
|
|
await wrapper.vm.$nextTick();
|
|
|
|
expect(wrapper.find('.board-new-issue-form').exists()).toBe(true);
|
2017-03-28 05:31:16 -04:00
|
|
|
});
|
|
|
|
|
2020-03-31 14:07:42 -04:00
|
|
|
it('does not show new issue form for closed list', () => {
|
2021-01-18 04:11:05 -05:00
|
|
|
wrapper.setProps({ list: { type: 'closed' } });
|
|
|
|
wrapper.vm.toggleForm();
|
2017-03-28 05:31:16 -04:00
|
|
|
|
2021-01-18 04:11:05 -05:00
|
|
|
expect(wrapper.find('.board-new-issue-form').exists()).toBe(false);
|
2017-03-28 05:31:16 -04:00
|
|
|
});
|
|
|
|
|
2021-01-18 04:11:05 -05:00
|
|
|
it('shows count list item', async () => {
|
|
|
|
wrapper.vm.showCount = true;
|
2017-03-28 05:31:16 -04:00
|
|
|
|
2021-01-18 04:11:05 -05:00
|
|
|
await wrapper.vm.$nextTick();
|
|
|
|
expect(wrapper.find('.board-list-count').exists()).toBe(true);
|
2017-03-28 05:31:16 -04:00
|
|
|
|
2021-01-18 04:11:05 -05:00
|
|
|
expect(wrapper.find('.board-list-count').text()).toBe('Showing all issues');
|
2017-03-28 05:31:16 -04:00
|
|
|
});
|
|
|
|
|
2021-01-18 04:11:05 -05:00
|
|
|
it('sets data attribute with invalid id', async () => {
|
|
|
|
wrapper.vm.showCount = true;
|
2018-01-09 04:24:08 -05:00
|
|
|
|
2021-01-18 04:11:05 -05:00
|
|
|
await wrapper.vm.$nextTick();
|
|
|
|
expect(wrapper.find('.board-list-count').attributes('data-issue-id')).toBe('-1');
|
2018-01-09 04:24:08 -05:00
|
|
|
});
|
|
|
|
|
2021-01-18 04:11:05 -05:00
|
|
|
it('shows how many more issues to load', async () => {
|
|
|
|
wrapper.vm.showCount = true;
|
|
|
|
wrapper.setProps({ list: { issuesCount: 20 } });
|
2017-03-28 05:31:16 -04:00
|
|
|
|
2021-01-18 04:11:05 -05:00
|
|
|
await wrapper.vm.$nextTick();
|
|
|
|
expect(wrapper.find('.board-list-count').text()).toBe('Showing 1 of 20 issues');
|
2017-03-28 05:31:16 -04:00
|
|
|
});
|
2021-01-18 04:11:05 -05:00
|
|
|
});
|
2017-03-28 05:31:16 -04:00
|
|
|
|
2021-01-18 04:11:05 -05:00
|
|
|
describe('load more issues', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = createComponent({
|
|
|
|
listProps: { issuesCount: 25 },
|
2019-11-12 10:06:26 -05:00
|
|
|
});
|
|
|
|
});
|
2017-03-28 05:31:16 -04:00
|
|
|
|
2021-01-18 04:11:05 -05:00
|
|
|
it('does not load issues if already loading', () => {
|
|
|
|
wrapper = createComponent({
|
|
|
|
state: { listsFlags: { 'gid://gitlab/List/1': { isLoadingMore: true } } },
|
2019-11-12 10:06:26 -05:00
|
|
|
});
|
2021-01-18 04:11:05 -05:00
|
|
|
wrapper.vm.listRef.dispatchEvent(new Event('scroll'));
|
2018-08-16 11:27:56 -04:00
|
|
|
|
2021-02-17 22:09:22 -05:00
|
|
|
expect(actions.fetchItemsForList).not.toHaveBeenCalled();
|
2019-11-12 10:06:26 -05:00
|
|
|
});
|
2017-03-28 05:31:16 -04:00
|
|
|
|
2021-01-18 04:11:05 -05:00
|
|
|
it('shows loading more spinner', async () => {
|
|
|
|
wrapper = createComponent({
|
|
|
|
state: { listsFlags: { 'gid://gitlab/List/1': { isLoadingMore: true } } },
|
2020-03-31 14:07:42 -04:00
|
|
|
});
|
2021-01-18 04:11:05 -05:00
|
|
|
wrapper.vm.showCount = true;
|
|
|
|
|
|
|
|
await wrapper.vm.$nextTick();
|
2021-02-21 22:10:36 -05:00
|
|
|
|
|
|
|
expect(findIssueCountLoadingIcon().exists()).toBe(true);
|
2017-03-28 05:31:16 -04:00
|
|
|
});
|
|
|
|
});
|
2019-11-21 01:06:32 -05:00
|
|
|
|
|
|
|
describe('max issue count warning', () => {
|
2021-01-18 04:11:05 -05:00
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = createComponent({
|
|
|
|
listProps: { issuesCount: 50 },
|
|
|
|
});
|
2019-11-21 01:06:32 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('when issue count exceeds max issue count', () => {
|
2021-01-18 04:11:05 -05:00
|
|
|
it('sets background to bg-danger-100', async () => {
|
|
|
|
wrapper.setProps({ list: { issuesCount: 4, maxIssueCount: 3 } });
|
2019-11-21 01:06:32 -05:00
|
|
|
|
2021-01-18 04:11:05 -05:00
|
|
|
await wrapper.vm.$nextTick();
|
|
|
|
expect(wrapper.find('.bg-danger-100').exists()).toBe(true);
|
2019-11-21 01:06:32 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when list issue count does NOT exceed list max issue count', () => {
|
2020-03-31 14:07:42 -04:00
|
|
|
it('does not sets background to bg-danger-100', () => {
|
2021-01-18 04:11:05 -05:00
|
|
|
wrapper.setProps({ list: { issuesCount: 2, maxIssueCount: 3 } });
|
2019-11-21 01:06:32 -05:00
|
|
|
|
2021-01-18 04:11:05 -05:00
|
|
|
expect(wrapper.find('.bg-danger-100').exists()).toBe(false);
|
2019-11-21 01:06:32 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when list max issue count is 0', () => {
|
2020-03-31 14:07:42 -04:00
|
|
|
it('does not sets background to bg-danger-100', () => {
|
2021-01-18 04:11:05 -05:00
|
|
|
wrapper.setProps({ list: { maxIssueCount: 0 } });
|
|
|
|
|
|
|
|
expect(wrapper.find('.bg-danger-100').exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2019-11-21 01:06:32 -05:00
|
|
|
|
2021-01-18 04:11:05 -05:00
|
|
|
describe('drag & drop issue', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = createComponent();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('handleDragOnStart', () => {
|
|
|
|
it('adds a class `is-dragging` to document body', () => {
|
|
|
|
expect(document.body.classList.contains('is-dragging')).toBe(false);
|
|
|
|
|
|
|
|
findByTestId('tree-root-wrapper').vm.$emit('start');
|
|
|
|
|
|
|
|
expect(document.body.classList.contains('is-dragging')).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('handleDragOnEnd', () => {
|
|
|
|
it('removes class `is-dragging` from document body', () => {
|
2021-03-11 04:09:36 -05:00
|
|
|
jest.spyOn(wrapper.vm, 'moveItem').mockImplementation(() => {});
|
2021-01-18 04:11:05 -05:00
|
|
|
document.body.classList.add('is-dragging');
|
|
|
|
|
|
|
|
findByTestId('tree-root-wrapper').vm.$emit('end', {
|
|
|
|
oldIndex: 1,
|
|
|
|
newIndex: 0,
|
|
|
|
item: {
|
|
|
|
dataset: {
|
2021-03-11 04:09:36 -05:00
|
|
|
itemId: mockIssues[0].id,
|
|
|
|
itemIid: mockIssues[0].iid,
|
|
|
|
itemPath: mockIssues[0].referencePath,
|
2021-01-18 04:11:05 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
to: { children: [], dataset: { listId: 'gid://gitlab/List/1' } },
|
|
|
|
from: { dataset: { listId: 'gid://gitlab/List/2' } },
|
2019-11-21 01:06:32 -05:00
|
|
|
});
|
2021-01-18 04:11:05 -05:00
|
|
|
|
|
|
|
expect(document.body.classList.contains('is-dragging')).toBe(false);
|
2019-11-21 01:06:32 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-03-28 05:31:16 -04:00
|
|
|
});
|