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

268 lines
7.7 KiB
JavaScript
Raw Normal View History

2021-10-27 15:23:28 +05:30
import Draggable from 'vuedraggable';
import { DraggableItemTypes } from 'ee_else_ce/boards/constants';
2021-03-08 18:12:59 +05:30
import { useFakeRequestAnimationFrame } from 'helpers/fake_request_animation_frame';
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';
2021-03-08 18:12:59 +05:30
2021-09-30 23:02:18 +05:30
import { mockIssues } 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-04-17 20:07:23 +05:30
const findIssueCountLoadingIcon = () => wrapper.find('[data-testid="count-loading-icon"]');
2021-10-27 15:23:28 +05:30
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-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
afterEach(() => {
wrapper.destroy();
});
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', () => {
2021-03-08 18:12:59 +05:30
expect(wrapper.findAll(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', async () => {
wrapper.vm.toggleForm();
2017-08-17 22:00:37 +05:30
2021-03-08 18:12:59 +05:30
await wrapper.vm.$nextTick();
expect(wrapper.find('.board-new-issue-form').exists()).toBe(true);
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 () => {
eventHub.$emit(`toggle-issue-form-${wrapper.vm.list.id}`);
2017-08-17 22:00:37 +05:30
2021-03-08 18:12:59 +05:30
await wrapper.vm.$nextTick();
expect(wrapper.find('.board-new-issue-form').exists()).toBe(true);
2017-08-17 22:00:37 +05:30
});
2020-04-22 19:07:51 +05:30
it('does not show new issue form for closed list', () => {
2021-03-08 18:12:59 +05:30
wrapper.setProps({ list: { type: 'closed' } });
wrapper.vm.toggleForm();
2017-08-17 22:00:37 +05:30
2021-03-08 18:12:59 +05:30
expect(wrapper.find('.board-new-issue-form').exists()).toBe(false);
2017-08-17 22:00:37 +05:30
});
2021-03-08 18:12:59 +05:30
it('shows count list item', async () => {
wrapper.vm.showCount = true;
2017-08-17 22:00:37 +05:30
2021-03-08 18:12:59 +05:30
await wrapper.vm.$nextTick();
expect(wrapper.find('.board-list-count').exists()).toBe(true);
2017-08-17 22:00:37 +05:30
2021-03-08 18:12:59 +05:30
expect(wrapper.find('.board-list-count').text()).toBe('Showing all issues');
2017-08-17 22:00:37 +05:30
});
2021-03-08 18:12:59 +05:30
it('sets data attribute with invalid id', async () => {
wrapper.vm.showCount = true;
2018-03-17 18:26:18 +05:30
2021-03-08 18:12:59 +05:30
await wrapper.vm.$nextTick();
expect(wrapper.find('.board-list-count').attributes('data-issue-id')).toBe('-1');
2018-03-17 18:26:18 +05:30
});
2021-03-08 18:12:59 +05:30
});
2017-08-17 22:00:37 +05:30
2021-03-08 18:12:59 +05:30
describe('load more issues', () => {
2021-09-30 23:02:18 +05:30
const actions = {
fetchItemsForList: jest.fn(),
};
2021-03-08 18:12:59 +05:30
beforeEach(() => {
2022-01-26 12:08:38 +05:30
wrapper = createComponent();
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('does not load issues if already loading', () => {
wrapper = createComponent({
2021-09-30 23:02:18 +05:30
actions,
2021-03-08 18:12:59 +05:30
state: { listsFlags: { 'gid://gitlab/List/1': { isLoadingMore: true } } },
2019-12-26 22:10:19 +05:30
});
2021-03-08 18:12:59 +05:30
wrapper.vm.listRef.dispatchEvent(new Event('scroll'));
2018-11-20 20:47:30 +05:30
2021-04-17 20:07:23 +05:30
expect(actions.fetchItemsForList).not.toHaveBeenCalled();
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 loading more spinner', async () => {
wrapper = createComponent({
state: { listsFlags: { 'gid://gitlab/List/1': { isLoadingMore: true } } },
2022-01-26 12:08:38 +05:30
data: {
showCount: true,
},
2020-04-22 19:07:51 +05:30
});
2021-03-08 18:12:59 +05:30
await wrapper.vm.$nextTick();
2021-04-17 20:07:23 +05:30
expect(findIssueCountLoadingIcon().exists()).toBe(true);
2017-08-17 22:00:37 +05:30
});
2022-01-26 12:08:38 +05:30
it('shows how many more issues to load', async () => {
// wrapper.vm.showCount = true;
wrapper = createComponent({
data: {
showCount: true,
},
});
await wrapper.vm.$nextTick();
expect(wrapper.find('.board-list-count').text()).toBe('Showing 1 of 20 issues');
});
2017-08-17 22:00:37 +05:30
});
2020-01-01 13:55:28 +05:30
describe('max issue count warning', () => {
2021-03-08 18:12:59 +05:30
beforeEach(() => {
wrapper = createComponent({
listProps: { issuesCount: 50 },
});
2020-01-01 13:55:28 +05:30
});
describe('when issue count exceeds max issue count', () => {
2021-03-08 18:12:59 +05:30
it('sets background to bg-danger-100', async () => {
wrapper.setProps({ list: { issuesCount: 4, maxIssueCount: 3 } });
2020-01-01 13:55:28 +05:30
2021-03-08 18:12:59 +05:30
await wrapper.vm.$nextTick();
expect(wrapper.find('.bg-danger-100').exists()).toBe(true);
2020-01-01 13:55:28 +05:30
});
});
describe('when list issue count does NOT exceed list max issue count', () => {
2020-04-22 19:07:51 +05:30
it('does not sets background to bg-danger-100', () => {
2021-03-08 18:12:59 +05:30
wrapper.setProps({ list: { issuesCount: 2, maxIssueCount: 3 } });
2020-01-01 13:55:28 +05:30
2021-03-08 18:12:59 +05:30
expect(wrapper.find('.bg-danger-100').exists()).toBe(false);
2020-01-01 13:55:28 +05:30
});
});
describe('when list max issue count is 0', () => {
2020-04-22 19:07:51 +05:30
it('does not sets background to bg-danger-100', () => {
2021-03-08 18:12:59 +05:30
wrapper.setProps({ list: { maxIssueCount: 0 } });
expect(wrapper.find('.bg-danger-100').exists()).toBe(false);
});
});
});
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);
});
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({
componentProps: {
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
});
});
});
2017-08-17 22:00:37 +05:30
});