Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-08-18 15:11:19 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-08-18 15:11:19 +0300
commitfba018726310be5fdf4014f18debbbabde19a8cd (patch)
treeb335c53c751983139d07f0e7b1fa757a19e1c5db /spec/frontend
parent3b4c0d27d5ad32fecdcc95e86bf919fc13830c5b (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend')
-rw-r--r--spec/frontend/boards/board_list_spec.js116
-rw-r--r--spec/frontend/boards/stores/actions_spec.js25
2 files changed, 115 insertions, 26 deletions
diff --git a/spec/frontend/boards/board_list_spec.js b/spec/frontend/boards/board_list_spec.js
index a3b1810ab80..6f623eab1af 100644
--- a/spec/frontend/boards/board_list_spec.js
+++ b/spec/frontend/boards/board_list_spec.js
@@ -1,3 +1,5 @@
+import Draggable from 'vuedraggable';
+import { DraggableItemTypes } from 'ee_else_ce/boards/constants';
import { useFakeRequestAnimationFrame } from 'helpers/fake_request_animation_frame';
import createComponent from 'jest/boards/board_list_helper';
import BoardCard from '~/boards/components/board_card.vue';
@@ -10,6 +12,23 @@ describe('Board list component', () => {
const findByTestId = (testId) => wrapper.find(`[data-testid="${testId}"]`);
const findIssueCountLoadingIcon = () => wrapper.find('[data-testid="count-loading-icon"]');
+ 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);
+ };
useFakeRequestAnimationFrame();
@@ -155,40 +174,89 @@ describe('Board list component', () => {
});
describe('drag & drop issue', () => {
- beforeEach(() => {
- wrapper = createComponent();
- });
+ describe('when dragging is allowed', () => {
+ beforeEach(() => {
+ wrapper = createComponent({
+ componentProps: {
+ disabled: false,
+ },
+ });
+ });
- describe('handleDragOnStart', () => {
- it('adds a class `is-dragging` to document body', () => {
- expect(document.body.classList.contains('is-dragging')).toBe(false);
+ 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);
- findByTestId('tree-root-wrapper').vm.$emit('start');
+ startDrag();
- expect(document.body.classList.contains('is-dragging')).toBe(true);
+ expect(document.body.classList.contains('is-dragging')).toBe(true);
+ });
});
- });
- describe('handleDragOnEnd', () => {
- it('removes class `is-dragging` from document body', () => {
- jest.spyOn(wrapper.vm, 'moveItem').mockImplementation(() => {});
- document.body.classList.add('is-dragging');
+ 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' } },
+ });
- findByTestId('tree-root-wrapper').vm.$emit('end', {
- oldIndex: 1,
- newIndex: 0,
- item: {
- dataset: {
- itemId: mockIssues[0].id,
- itemIid: mockIssues[0].iid,
- itemPath: mockIssues[0].referencePath,
+ 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,
+ },
},
+ 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,
},
- to: { children: [], dataset: { listId: 'gid://gitlab/List/1' } },
- from: { dataset: { listId: 'gid://gitlab/List/2' } },
});
+ });
- expect(document.body.classList.contains('is-dragging')).toBe(false);
+ it('Draggable is not used', () => {
+ expect(findDraggable().exists()).toBe(false);
});
});
});
diff --git a/spec/frontend/boards/stores/actions_spec.js b/spec/frontend/boards/stores/actions_spec.js
index 9d3ba5b105e..1272a573d2f 100644
--- a/spec/frontend/boards/stores/actions_spec.js
+++ b/spec/frontend/boards/stores/actions_spec.js
@@ -9,6 +9,7 @@ import {
issuableTypes,
BoardType,
listsQuery,
+ DraggableItemTypes,
} from 'ee_else_ce/boards/constants';
import issueMoveListMutation from 'ee_else_ce/boards/graphql/issue_move_list.mutation.graphql';
import testAction from 'helpers/vuex_action_helper';
@@ -525,6 +526,21 @@ describe('moveList', () => {
const movableListsOrder = ['gid://3', 'gid://4', 'gid://5'];
const allListsOrder = [backlogListId, ...movableListsOrder, closedListId];
+ it(`should not handle the event if the dragged item is not a "${DraggableItemTypes.list}"`, () => {
+ return testAction({
+ action: actions.moveList,
+ payload: {
+ item: { dataset: { listId: '', draggableItemType: DraggableItemTypes.card } },
+ to: {
+ children: [],
+ },
+ },
+ state: {},
+ expectedMutations: [],
+ expectedActions: [],
+ });
+ });
+
describe.each`
draggableFrom | draggableTo | boardLists | boardListsOrder | expectedMovableListsOrder
${0} | ${2} | ${boardLists1} | ${movableListsOrder} | ${['gid://4', 'gid://5', 'gid://3']}
@@ -544,7 +560,12 @@ describe('moveList', () => {
const displacedListId = boardListsOrder[draggableTo];
const buildDraggablePayload = () => {
return {
- item: { dataset: { listId: boardListsOrder[draggableFrom] } },
+ item: {
+ dataset: {
+ listId: boardListsOrder[draggableFrom],
+ draggableItemType: DraggableItemTypes.list,
+ },
+ },
newIndex: draggableTo,
to: {
children: boardListsOrder.map((listId) => ({ dataset: { listId } })),
@@ -584,7 +605,7 @@ describe('moveList', () => {
return testAction({
action: actions.moveList,
payload: {
- item: { dataset: { listId } },
+ item: { dataset: { listId, draggbaleItemType: DraggableItemTypes.list } },
newIndex: 0,
to: {
children: [{ dataset: { listId } }],