debian-mirror-gitlab/spec/frontend/boards/board_list_spec.js

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

271 lines
8.4 KiB
JavaScript
Raw Normal View History

2023-06-20 00:43:36 +05:30
import { GlIntersectionObserver } from '@gitlab/ui';
2021-10-27 15:23:28 +05:30
import Draggable from 'vuedraggable';
2022-04-04 11:22:00 +05:30
import { nextTick } from 'vue';
2023-04-23 21:23:45 +05:30
import { DraggableItemTypes, ListType } from 'ee_else_ce/boards/constants';
2021-03-08 18:12:59 +05:30
import { useFakeRequestAnimationFrame } from 'helpers/fake_request_animation_frame';
2022-04-04 11:22:00 +05:30
import waitForPromises from 'helpers/wait_for_promises';
2021-09-30 23:02:18 +05:30
import createComponent from 'jest/boards/board_list_helper';
2021-03-08 18:12:59 +05:30
import BoardCard from '~/boards/components/board_card.vue';
2021-03-11 19:13:27 +05:30
import eventHub from '~/boards/eventhub';
2023-01-13 00:05:48 +05:30
import BoardCardMoveToPosition from '~/boards/components/board_card_move_to_position.vue';
2021-03-08 18:12:59 +05:30
2023-06-20 00:43:36 +05:30
import { mockIssues, mockList, mockIssuesMore } from './mock_data';
2017-08-17 22:00:37 +05:30
describe('Board list component', () => {
2021-03-08 18:12:59 +05:30
let wrapper;
2021-04-17 20:07:23 +05:30
2021-03-08 18:12:59 +05:30
const findByTestId = (testId) => wrapper.find(`[data-testid="${testId}"]`);
2021-10-27 15:23:28 +05:30
const findDraggable = () => wrapper.findComponent(Draggable);
2023-01-13 00:05:48 +05:30
const findMoveToPositionComponent = () => wrapper.findComponent(BoardCardMoveToPosition);
2023-06-20 00:43:36 +05:30
const findIntersectionObserver = () => wrapper.findComponent(GlIntersectionObserver);
const findBoardListCount = () => wrapper.find('.board-list-count');
const triggerInfiniteScroll = () => findIntersectionObserver().vm.$emit('appear');
2021-10-27 15:23:28 +05:30
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-04-17 20:07:23 +05:30
2021-03-08 18:12:59 +05:30
useFakeRequestAnimationFrame();
2017-08-17 22:00:37 +05:30
2021-03-08 18:12:59 +05:30
describe('When Expanded', () => {
beforeEach(() => {
2022-01-26 12:08:38 +05:30
wrapper = createComponent({ issuesCount: 1 });
2019-12-26 22:10:19 +05:30
});
2017-08-17 22:00:37 +05:30
2019-12-26 22:10:19 +05:30
it('renders component', () => {
2021-03-08 18:12:59 +05:30
expect(wrapper.find('.board-list-component').exists()).toBe(true);
2019-12-26 22:10:19 +05:30
});
2020-04-22 19:07:51 +05:30
it('renders loading icon', () => {
2021-03-08 18:12:59 +05:30
wrapper = createComponent({
state: { listsFlags: { 'gid://gitlab/List/1': { isLoading: true } } },
2019-12-26 22:10:19 +05:30
});
2021-03-08 18:12:59 +05:30
expect(findByTestId('board_list_loading').exists()).toBe(true);
2017-08-17 22:00:37 +05:30
});
2019-12-26 22:10:19 +05:30
it('renders issues', () => {
2022-08-27 11:52:29 +05:30
expect(wrapper.findAllComponents(BoardCard).length).toBe(1);
2019-12-26 22:10:19 +05:30
});
2017-08-17 22:00:37 +05:30
2019-12-26 22:10:19 +05:30
it('sets data attribute with issue id', () => {
2021-04-17 20:07:23 +05:30
expect(wrapper.find('.board-card').attributes('data-item-id')).toBe('1');
2019-12-26 22:10:19 +05:30
});
2017-08-17 22:00:37 +05:30
2021-03-08 18:12:59 +05:30
it('shows new issue form after eventhub event', async () => {
2023-06-20 00:43:36 +05:30
eventHub.$emit(`toggle-issue-form-${mockList.id}`);
2017-08-17 22:00:37 +05:30
2022-04-04 11:22:00 +05:30
await nextTick();
2021-03-08 18:12:59 +05:30
expect(wrapper.find('.board-new-issue-form').exists()).toBe(true);
2017-08-17 22:00:37 +05:30
});
2023-06-20 00:43:36 +05:30
it('does not show new issue form for closed list', async () => {
wrapper = createComponent({
listProps: {
listType: ListType.closed,
},
});
await waitForPromises();
2017-08-17 22:00:37 +05:30
2023-06-20 00:43:36 +05:30
eventHub.$emit(`toggle-issue-form-${mockList.id}`);
2018-03-17 18:26:18 +05:30
2022-04-04 11:22:00 +05:30
await nextTick();
2023-06-20 00:43:36 +05:30
expect(wrapper.find('.board-new-issue-form').exists()).toBe(false);
2018-03-17 18:26:18 +05:30
});
2023-01-13 00:05:48 +05:30
it('renders the move to position icon', () => {
expect(findMoveToPositionComponent().exists()).toBe(true);
});
2021-03-08 18:12:59 +05:30
});
2017-08-17 22:00:37 +05:30
2023-04-23 21:23:45 +05:30
describe('when ListType is Closed', () => {
beforeEach(() => {
wrapper = createComponent({
listProps: {
listType: ListType.closed,
},
});
});
it('Board card move to position is not visible', () => {
expect(findMoveToPositionComponent().exists()).toBe(false);
});
});
2021-03-08 18:12:59 +05:30
describe('load more issues', () => {
2023-06-20 00:43:36 +05:30
describe('when loading is not in progress', () => {
beforeEach(() => {
wrapper = createComponent({
listProps: {
id: 'gid://gitlab/List/1',
},
componentProps: {
boardItems: mockIssuesMore,
},
actions: {
fetchItemsForList: jest.fn(),
},
state: { listsFlags: { 'gid://gitlab/List/1': { isLoadingMore: false } } },
});
2019-12-26 22:10:19 +05:30
});
2017-08-17 22:00:37 +05:30
2023-06-20 00:43:36 +05:30
it('has intersection observer when the number of board list items are more than 5', () => {
expect(findIntersectionObserver().exists()).toBe(true);
2020-04-22 19:07:51 +05:30
});
2021-03-08 18:12:59 +05:30
2023-06-20 00:43:36 +05:30
it('shows count when loaded more items and correct data attribute', async () => {
triggerInfiniteScroll();
await waitForPromises();
expect(findBoardListCount().exists()).toBe(true);
expect(findBoardListCount().attributes('data-issue-id')).toBe('-1');
2022-01-26 12:08:38 +05:30
});
});
2017-08-17 22:00:37 +05:30
});
2020-01-01 13:55:28 +05:30
describe('max issue count warning', () => {
describe('when issue count exceeds max issue count', () => {
2023-04-23 21:23:45 +05:30
it('sets background to gl-bg-red-100', async () => {
2023-06-20 00:43:36 +05:30
wrapper = createComponent({ listProps: { issuesCount: 4, maxIssueCount: 3 } });
2020-01-01 13:55:28 +05:30
2023-06-20 00:43:36 +05:30
await waitForPromises();
2023-04-23 21:23:45 +05:30
const block = wrapper.find('.gl-bg-red-100');
expect(block.exists()).toBe(true);
expect(block.attributes('class')).toContain(
'gl-rounded-bottom-left-base gl-rounded-bottom-right-base',
);
2020-01-01 13:55:28 +05:30
});
});
describe('when list issue count does NOT exceed list max issue count', () => {
2023-06-20 00:43:36 +05:30
it('does not sets background to gl-bg-red-100', async () => {
wrapper = createComponent({ list: { issuesCount: 2, maxIssueCount: 3 } });
await waitForPromises();
2020-01-01 13:55:28 +05:30
2023-04-23 21:23:45 +05:30
expect(wrapper.find('.gl-bg-red-100').exists()).toBe(false);
2020-01-01 13:55:28 +05:30
});
});
describe('when list max issue count is 0', () => {
2023-06-20 00:43:36 +05:30
it('does not sets background to gl-bg-red-100', async () => {
wrapper = createComponent({ list: { maxIssueCount: 0 } });
await waitForPromises();
2021-03-08 18:12:59 +05:30
2023-04-23 21:23:45 +05:30
expect(wrapper.find('.gl-bg-red-100').exists()).toBe(false);
2021-03-08 18:12:59 +05:30
});
});
});
2020-01-01 13:55:28 +05:30
2021-03-08 18:12:59 +05:30
describe('drag & drop issue', () => {
2021-10-27 15:23:28 +05:30
describe('when dragging is allowed', () => {
beforeEach(() => {
wrapper = createComponent({
componentProps: {
disabled: false,
},
});
});
2021-03-08 18:12:59 +05:30
2021-10-27 15:23:28 +05:30
it('Draggable is used', () => {
expect(findDraggable().exists()).toBe(true);
});
2023-03-04 22:38:38 +05:30
it('sets delay and delayOnTouchOnly attributes on board list', () => {
const listEl = wrapper.findComponent({ ref: 'list' });
expect(listEl.attributes('delay')).toBe('100');
expect(listEl.attributes('delayontouchonly')).toBe('true');
});
2021-10-27 15:23:28 +05:30
describe('handleDragOnStart', () => {
it('adds a class `is-dragging` to document body', () => {
expect(document.body.classList.contains('is-dragging')).toBe(false);
2021-03-08 18:12:59 +05:30
2021-10-27 15:23:28 +05:30
startDrag();
2021-03-08 18:12:59 +05:30
2021-10-27 15:23:28 +05:30
expect(document.body.classList.contains('is-dragging')).toBe(true);
});
2021-03-08 18:12:59 +05:30
});
2021-10-27 15:23:28 +05:30
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-03-08 18:12:59 +05:30
2021-10-27 15:23:28 +05:30
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-03-08 18:12:59 +05:30
},
2021-10-27 15:23:28 +05:30
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({
2023-03-17 16:20:25 +05:30
provide: {
2021-10-27 15:23:28 +05:30
disabled: true,
2021-03-08 18:12:59 +05:30
},
2020-01-01 13:55:28 +05:30
});
2021-10-27 15:23:28 +05:30
});
2021-03-08 18:12:59 +05:30
2021-10-27 15:23:28 +05:30
it('Draggable is not used', () => {
expect(findDraggable().exists()).toBe(false);
2020-01-01 13:55:28 +05:30
});
2023-03-04 22:38:38 +05:30
it('Board card move to position is not visible', () => {
expect(findMoveToPositionComponent().exists()).toBe(false);
});
2020-01-01 13:55:28 +05:30
});
});
2017-08-17 22:00:37 +05:30
});