2021-08-18 08:11:19 -04:00
|
|
|
import Draggable from 'vuedraggable';
|
2022-01-25 10:12:32 -05:00
|
|
|
import { nextTick } from 'vue';
|
2021-08-18 08:11:19 -04:00
|
|
|
import { DraggableItemTypes } from 'ee_else_ce/boards/constants';
|
2021-02-01 10:08:56 -05:00
|
|
|
import { useFakeRequestAnimationFrame } from 'helpers/fake_request_animation_frame';
|
2022-01-24 16:14:06 -05:00
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
2021-06-17 11:10:03 -04:00
|
|
|
import createComponent from 'jest/boards/board_list_helper';
|
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 eventHub from '~/boards/eventhub';
|
2021-01-18 04:11:05 -05:00
|
|
|
|
2021-06-17 11:10:03 -04:00
|
|
|
import { mockIssues } from './mock_data';
|
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-08-18 08:11:19 -04:00
|
|
|
const findDraggable = () => wrapper.findComponent(Draggable);
|
|
|
|
|
|
|
|
const startDrag = (
|
|
|
|
params = {
|
|
|
|
item: {
|
|
|
|
dataset: {
|
|
|
|
draggableItemType: DraggableItemTypes.card,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
) => {
|
|
|
|
findByTestId('tree-root-wrapper').vm.$emit('start', params);
|
|
|
|
};
|
|
|
|
|
|
|
|
const endDrag = (params) => {
|
|
|
|
findByTestId('tree-root-wrapper').vm.$emit('end', params);
|
|
|
|
};
|
2021-02-21 22:10:36 -05:00
|
|
|
|
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();
|
|
|
|
});
|
2017-03-28 05:31:16 -04:00
|
|
|
|
2021-01-18 04:11:05 -05:00
|
|
|
describe('When Expanded', () => {
|
|
|
|
beforeEach(() => {
|
2021-12-09 04:11:03 -05:00
|
|
|
wrapper = createComponent({ issuesCount: 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('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', () => {
|
2022-08-12 02:11:24 -04:00
|
|
|
expect(wrapper.findAllComponents(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
|
|
|
|
2022-01-25 10:12:32 -05:00
|
|
|
await nextTick();
|
2021-01-18 04:11:05 -05:00
|
|
|
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
|
|
|
|
2022-01-25 10:12:32 -05:00
|
|
|
await nextTick();
|
2021-01-18 04:11:05 -05:00
|
|
|
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
|
|
|
|
2022-01-25 10:12:32 -05:00
|
|
|
await nextTick();
|
2021-01-18 04:11:05 -05:00
|
|
|
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
|
|
|
|
2022-01-25 10:12:32 -05:00
|
|
|
await nextTick();
|
2021-01-18 04:11:05 -05:00
|
|
|
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
|
|
|
});
|
2017-03-28 05:31:16 -04:00
|
|
|
|
2021-01-18 04:11:05 -05:00
|
|
|
describe('load more issues', () => {
|
2021-06-17 11:10:03 -04:00
|
|
|
const actions = {
|
|
|
|
fetchItemsForList: jest.fn(),
|
|
|
|
};
|
|
|
|
|
2021-01-18 04:11:05 -05:00
|
|
|
it('does not load issues if already loading', () => {
|
|
|
|
wrapper = createComponent({
|
2021-06-17 11:10:03 -04:00
|
|
|
actions,
|
2021-01-18 04:11:05 -05:00
|
|
|
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 } } },
|
2021-12-09 04:11:03 -05:00
|
|
|
data: {
|
|
|
|
showCount: true,
|
|
|
|
},
|
2020-03-31 14:07:42 -04:00
|
|
|
});
|
2021-01-18 04:11:05 -05:00
|
|
|
|
2022-01-25 10:12:32 -05:00
|
|
|
await nextTick();
|
2021-02-21 22:10:36 -05:00
|
|
|
|
|
|
|
expect(findIssueCountLoadingIcon().exists()).toBe(true);
|
2017-03-28 05:31:16 -04:00
|
|
|
});
|
2021-12-09 04:11:03 -05:00
|
|
|
|
|
|
|
it('shows how many more issues to load', async () => {
|
|
|
|
wrapper = createComponent({
|
|
|
|
data: {
|
|
|
|
showCount: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-01-25 10:12:32 -05:00
|
|
|
await nextTick();
|
2022-01-24 16:14:06 -05:00
|
|
|
await waitForPromises();
|
2022-01-25 10:12:32 -05:00
|
|
|
await nextTick();
|
2022-02-14 07:14:02 -05:00
|
|
|
await nextTick();
|
2022-01-24 16:14:06 -05:00
|
|
|
|
2021-12-09 04:11:03 -05:00
|
|
|
expect(wrapper.find('.board-list-count').text()).toBe('Showing 1 of 20 issues');
|
|
|
|
});
|
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
|
|
|
|
2022-01-25 10:12:32 -05:00
|
|
|
await nextTick();
|
2021-01-18 04:11:05 -05:00
|
|
|
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', () => {
|
2021-08-18 08:11:19 -04:00
|
|
|
describe('when dragging is allowed', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = createComponent({
|
|
|
|
componentProps: {
|
|
|
|
disabled: false,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
2021-01-18 04:11:05 -05:00
|
|
|
|
2021-08-18 08:11:19 -04:00
|
|
|
it('Draggable is used', () => {
|
|
|
|
expect(findDraggable().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('handleDragOnStart', () => {
|
|
|
|
it('adds a class `is-dragging` to document body', () => {
|
|
|
|
expect(document.body.classList.contains('is-dragging')).toBe(false);
|
2021-01-18 04:11:05 -05:00
|
|
|
|
2021-08-18 08:11:19 -04:00
|
|
|
startDrag();
|
2021-01-18 04:11:05 -05:00
|
|
|
|
2021-08-18 08:11:19 -04:00
|
|
|
expect(document.body.classList.contains('is-dragging')).toBe(true);
|
|
|
|
});
|
2021-01-18 04:11:05 -05:00
|
|
|
});
|
|
|
|
|
2021-08-18 08:11:19 -04:00
|
|
|
describe('handleDragOnEnd', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.spyOn(wrapper.vm, 'moveItem').mockImplementation(() => {});
|
|
|
|
|
|
|
|
startDrag();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('removes class `is-dragging` from document body', () => {
|
|
|
|
document.body.classList.add('is-dragging');
|
|
|
|
|
|
|
|
endDrag({
|
|
|
|
oldIndex: 1,
|
|
|
|
newIndex: 0,
|
|
|
|
item: {
|
|
|
|
dataset: {
|
|
|
|
draggableItemType: DraggableItemTypes.card,
|
|
|
|
itemId: mockIssues[0].id,
|
|
|
|
itemIid: mockIssues[0].iid,
|
|
|
|
itemPath: mockIssues[0].referencePath,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
to: { children: [], dataset: { listId: 'gid://gitlab/List/1' } },
|
|
|
|
from: { dataset: { listId: 'gid://gitlab/List/2' } },
|
|
|
|
});
|
2021-01-18 04:11:05 -05:00
|
|
|
|
2021-08-18 08:11:19 -04:00
|
|
|
expect(document.body.classList.contains('is-dragging')).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`should not handle the event if the dragged item is not a "${DraggableItemTypes.card}"`, () => {
|
|
|
|
endDrag({
|
|
|
|
oldIndex: 1,
|
|
|
|
newIndex: 0,
|
|
|
|
item: {
|
|
|
|
dataset: {
|
|
|
|
draggableItemType: DraggableItemTypes.list,
|
|
|
|
itemId: mockIssues[0].id,
|
|
|
|
itemIid: mockIssues[0].iid,
|
|
|
|
itemPath: mockIssues[0].referencePath,
|
|
|
|
},
|
2021-01-18 04:11:05 -05:00
|
|
|
},
|
2021-08-18 08:11:19 -04:00
|
|
|
to: { children: [], dataset: { listId: 'gid://gitlab/List/1' } },
|
|
|
|
from: { dataset: { listId: 'gid://gitlab/List/2' } },
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(document.body.classList.contains('is-dragging')).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when dragging is not allowed', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = createComponent({
|
|
|
|
componentProps: {
|
|
|
|
disabled: true,
|
2021-01-18 04:11:05 -05:00
|
|
|
},
|
2019-11-21 01:06:32 -05:00
|
|
|
});
|
2021-08-18 08:11:19 -04:00
|
|
|
});
|
2021-01-18 04:11:05 -05:00
|
|
|
|
2021-08-18 08:11:19 -04:00
|
|
|
it('Draggable is not used', () => {
|
|
|
|
expect(findDraggable().exists()).toBe(false);
|
2019-11-21 01:06:32 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-03-28 05:31:16 -04:00
|
|
|
});
|