debian-mirror-gitlab/spec/frontend/boards/stores/actions_spec.js

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

2098 lines
54 KiB
JavaScript
Raw Normal View History

2021-04-29 21:17:54 +05:30
import * as Sentry from '@sentry/browser';
2021-10-27 15:23:28 +05:30
import { cloneDeep } from 'lodash';
import Vue from 'vue';
import Vuex from 'vuex';
2023-05-27 22:25:52 +05:30
import { inactiveId, ISSUABLE, ListType, DraggableItemTypes } from 'ee_else_ce/boards/constants';
2021-04-29 21:17:54 +05:30
import issueMoveListMutation from 'ee_else_ce/boards/graphql/issue_move_list.mutation.graphql';
2020-10-24 23:57:45 +05:30
import testAction from 'helpers/vuex_action_helper';
2021-03-11 19:13:27 +05:30
import {
formatListIssues,
formatBoardLists,
formatIssueInput,
2021-04-29 21:17:54 +05:30
formatIssue,
getMoveData,
2021-09-04 01:27:46 +05:30
updateListPosition,
2022-01-26 12:08:38 +05:30
} from 'ee_else_ce/boards/boards_util';
2023-01-13 00:05:48 +05:30
import { defaultClient as gqlClient } from '~/graphql_shared/issuable_client';
2021-03-11 19:13:27 +05:30
import destroyBoardListMutation from '~/boards/graphql/board_list_destroy.mutation.graphql';
import issueCreateMutation from '~/boards/graphql/issue_create.mutation.graphql';
2021-11-18 22:05:49 +05:30
import actions from '~/boards/stores/actions';
2021-03-11 19:13:27 +05:30
import * as types from '~/boards/stores/mutation_types';
2021-10-27 15:23:28 +05:30
import mutations from '~/boards/stores/mutations';
2021-12-11 22:18:48 +05:30
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
2023-05-27 22:25:52 +05:30
import { TYPE_ISSUE, WORKSPACE_GROUP, WORKSPACE_PROJECT } from '~/issues/constants';
2021-04-29 21:17:54 +05:30
2022-03-02 08:16:31 +05:30
import projectBoardMilestones from '~/boards/graphql/project_board_milestones.query.graphql';
import groupBoardMilestones from '~/boards/graphql/group_board_milestones.query.graphql';
2020-11-24 15:15:51 +05:30
import {
2022-05-07 20:08:51 +05:30
mockBoard,
mockBoardConfig,
2020-11-24 15:15:51 +05:30
mockLists,
2021-01-29 00:20:46 +05:30
mockListsById,
2020-11-24 15:15:51 +05:30
mockIssue,
2021-02-22 17:27:13 +05:30
mockIssue2,
2020-11-24 15:15:51 +05:30
rawIssue,
2021-01-03 14:25:43 +05:30
mockIssues,
labels,
2021-01-29 00:20:46 +05:30
mockActiveIssue,
2021-03-08 18:12:59 +05:30
mockGroupProjects,
2021-04-29 21:17:54 +05:30
mockMoveIssueParams,
mockMoveState,
mockMoveData,
2021-09-04 01:27:46 +05:30
mockList,
2021-10-27 15:23:28 +05:30
mockMilestones,
2020-11-24 15:15:51 +05:30
} from '../mock_data';
2021-02-22 17:27:13 +05:30
2023-05-27 22:25:52 +05:30
jest.mock('~/alert');
2019-09-04 21:01:54 +05:30
2020-11-24 15:15:51 +05:30
// We need this helper to make sure projectPath is including
// subgroups when the movIssue action is called.
2021-03-08 18:12:59 +05:30
const getProjectPath = (path) => path.split('#')[0];
2020-11-24 15:15:51 +05:30
2021-10-27 15:23:28 +05:30
Vue.use(Vuex);
2021-02-22 17:27:13 +05:30
beforeEach(() => {
window.gon = { features: {} };
});
2022-05-07 20:08:51 +05:30
describe('fetchBoard', () => {
const payload = {
fullPath: 'gitlab-org',
fullBoardId: 'gid://gitlab/Board/1',
boardType: 'project',
};
const queryResponse = {
data: {
workspace: {
board: mockBoard,
},
},
};
2022-07-23 23:45:48 +05:30
it('should commit mutation REQUEST_CURRENT_BOARD and dispatch setBoard on success', async () => {
2022-05-07 20:08:51 +05:30
jest.spyOn(gqlClient, 'query').mockResolvedValue(queryResponse);
await testAction({
action: actions.fetchBoard,
payload,
expectedMutations: [
{
2022-07-23 23:45:48 +05:30
type: types.REQUEST_CURRENT_BOARD,
2022-05-07 20:08:51 +05:30
},
],
2022-07-23 23:45:48 +05:30
expectedActions: [{ type: 'setBoard', payload: mockBoard }],
2022-05-07 20:08:51 +05:30
});
});
it('should commit mutation RECEIVE_BOARD_FAILURE on failure', async () => {
jest.spyOn(gqlClient, 'query').mockResolvedValue(Promise.reject());
await testAction({
action: actions.fetchBoard,
payload,
expectedMutations: [
2022-07-23 23:45:48 +05:30
{
type: types.REQUEST_CURRENT_BOARD,
},
2022-05-07 20:08:51 +05:30
{
type: types.RECEIVE_BOARD_FAILURE,
},
],
});
});
});
2020-10-24 23:57:45 +05:30
describe('setInitialBoardData', () => {
it('sets data object', () => {
const mockData = {
2020-06-23 00:09:42 +05:30
foo: 'bar',
bar: 'baz',
};
2022-05-07 20:08:51 +05:30
return testAction({
action: actions.setInitialBoardData,
payload: mockData,
expectedMutations: [{ type: types.SET_INITIAL_BOARD_DATA, payload: mockData }],
});
});
});
describe('setBoardConfig', () => {
it('sets board config object from board object', () => {
return testAction({
action: actions.setBoardConfig,
payload: mockBoard,
expectedMutations: [{ type: types.SET_BOARD_CONFIG, payload: mockBoardConfig }],
});
2020-10-24 23:57:45 +05:30
});
});
2022-07-23 23:45:48 +05:30
describe('setBoard', () => {
it('dispatches setBoardConfig', () => {
return testAction({
action: actions.setBoard,
payload: mockBoard,
expectedMutations: [{ type: types.RECEIVE_BOARD_SUCCESS, payload: mockBoard }],
expectedActions: [
{ type: 'setBoardConfig', payload: mockBoard },
{ type: 'performSearch', payload: { resetLists: true } },
],
});
});
});
2020-11-24 15:15:51 +05:30
describe('setFilters', () => {
2021-06-08 01:23:25 +05:30
it.each([
[
'with correct filters as payload',
{
2021-09-04 01:27:46 +05:30
filters: { labelName: 'label', foobar: 'not-a-filter', search: 'quick brown fox' },
filterVariables: { labelName: 'label', search: 'quick brown fox', not: {} },
2021-06-08 01:23:25 +05:30
},
],
[
2022-05-07 20:08:51 +05:30
"and use 'assigneeWildcardId' as filter variable for 'assigneeId' param",
2021-06-08 01:23:25 +05:30
{
filters: { assigneeId: 'None' },
2021-09-04 01:27:46 +05:30
filterVariables: { assigneeWildcardId: 'NONE', not: {} },
2021-06-08 01:23:25 +05:30
},
],
2021-09-04 01:27:46 +05:30
])('should commit mutation SET_FILTERS %s', (_, { filters, filterVariables }) => {
2020-11-24 15:15:51 +05:30
const state = {
filters: {},
2023-04-23 21:23:45 +05:30
issuableType: TYPE_ISSUE,
2020-11-24 15:15:51 +05:30
};
testAction(
actions.setFilters,
filters,
state,
2021-09-04 01:27:46 +05:30
[{ type: types.SET_FILTERS, payload: filterVariables }],
2020-11-24 15:15:51 +05:30
[],
);
});
});
2021-02-22 17:27:13 +05:30
describe('performSearch', () => {
2022-06-21 17:19:12 +05:30
it('should dispatch setFilters, fetchLists and resetIssues action', () => {
return testAction(
2021-02-22 17:27:13 +05:30
actions.performSearch,
{},
{},
[],
2022-07-23 23:45:48 +05:30
[
{ type: 'setFilters', payload: {} },
{ type: 'fetchLists', payload: { resetLists: false } },
{ type: 'resetIssues' },
],
2021-02-22 17:27:13 +05:30
);
});
});
2020-10-24 23:57:45 +05:30
describe('setActiveId', () => {
2022-06-21 17:19:12 +05:30
it('should commit mutation SET_ACTIVE_ID', () => {
2020-10-24 23:57:45 +05:30
const state = {
activeId: inactiveId,
};
2022-06-21 17:19:12 +05:30
return testAction(
2020-10-24 23:57:45 +05:30
actions.setActiveId,
2020-11-24 15:15:51 +05:30
{ id: 1, sidebarType: 'something' },
2020-10-24 23:57:45 +05:30
state,
2020-11-24 15:15:51 +05:30
[{ type: types.SET_ACTIVE_ID, payload: { id: 1, sidebarType: 'something' } }],
2020-06-23 00:09:42 +05:30
[],
);
});
2019-09-04 21:01:54 +05:30
});
2021-01-03 14:25:43 +05:30
describe('fetchLists', () => {
2021-06-08 01:23:25 +05:30
let state = {
2021-03-08 18:12:59 +05:30
fullPath: 'gitlab-org',
2021-06-08 01:23:25 +05:30
fullBoardId: 'gid://gitlab/Board/1',
2021-01-03 14:25:43 +05:30
filterParams: {},
boardType: 'group',
2021-06-08 01:23:25 +05:30
issuableType: 'issue',
2021-01-03 14:25:43 +05:30
};
let queryResponse = {
data: {
group: {
board: {
hideBacklogList: true,
lists: {
nodes: [mockLists[1]],
},
},
},
},
};
const formattedLists = formatBoardLists(queryResponse.data.group.board.lists);
2022-06-21 17:19:12 +05:30
it('should commit mutations RECEIVE_BOARD_LISTS_SUCCESS on success', () => {
2021-01-03 14:25:43 +05:30
jest.spyOn(gqlClient, 'query').mockResolvedValue(queryResponse);
2022-06-21 17:19:12 +05:30
return testAction(
2021-06-08 01:23:25 +05:30
actions.fetchLists,
2021-01-03 14:25:43 +05:30
{},
state,
[
{
type: types.RECEIVE_BOARD_LISTS_SUCCESS,
payload: formattedLists,
},
],
2021-02-22 17:27:13 +05:30
[],
2021-01-03 14:25:43 +05:30
);
});
2022-06-21 17:19:12 +05:30
it('should commit mutations RECEIVE_BOARD_LISTS_FAILURE on failure', () => {
2021-04-17 20:07:23 +05:30
jest.spyOn(gqlClient, 'query').mockResolvedValue(Promise.reject());
2022-06-21 17:19:12 +05:30
return testAction(
2021-06-08 01:23:25 +05:30
actions.fetchLists,
2021-04-17 20:07:23 +05:30
{},
state,
[
{
type: types.RECEIVE_BOARD_LISTS_FAILURE,
},
],
[],
);
});
2022-06-21 17:19:12 +05:30
it('dispatch createList action when backlog list does not exist and is not hidden', () => {
2021-01-03 14:25:43 +05:30
queryResponse = {
data: {
group: {
board: {
hideBacklogList: false,
lists: {
nodes: [mockLists[1]],
},
},
},
},
};
jest.spyOn(gqlClient, 'query').mockResolvedValue(queryResponse);
2022-06-21 17:19:12 +05:30
return testAction(
2021-06-08 01:23:25 +05:30
actions.fetchLists,
2021-01-03 14:25:43 +05:30
{},
state,
[
{
type: types.RECEIVE_BOARD_LISTS_SUCCESS,
payload: formattedLists,
},
],
2021-02-22 17:27:13 +05:30
[{ type: 'createList', payload: { backlog: true } }],
2021-01-03 14:25:43 +05:30
);
});
2021-06-08 01:23:25 +05:30
it.each`
2023-04-23 21:23:45 +05:30
issuableType | boardType | fullBoardId | isGroup | isProject
2023-05-27 22:25:52 +05:30
${TYPE_ISSUE} | ${WORKSPACE_GROUP} | ${'gid://gitlab/Board/1'} | ${true} | ${false}
${TYPE_ISSUE} | ${WORKSPACE_PROJECT} | ${'gid://gitlab/Board/1'} | ${false} | ${true}
2021-06-08 01:23:25 +05:30
`(
'calls $issuableType query with correct variables',
async ({ issuableType, boardType, fullBoardId, isGroup, isProject }) => {
const commit = jest.fn();
const dispatch = jest.fn();
state = {
fullPath: 'gitlab-org',
fullBoardId,
filterParams: {},
boardType,
issuableType,
};
const variables = {
2023-01-13 00:05:48 +05:30
fullPath: 'gitlab-org',
boardId: fullBoardId,
filters: {},
isGroup,
isProject,
2021-06-08 01:23:25 +05:30
};
jest.spyOn(gqlClient, 'query').mockResolvedValue(queryResponse);
await actions.fetchLists({ commit, state, dispatch });
2023-01-13 00:05:48 +05:30
expect(gqlClient.query).toHaveBeenCalledWith(expect.objectContaining({ variables }));
2021-06-08 01:23:25 +05:30
},
);
2021-01-03 14:25:43 +05:30
});
2021-10-27 15:23:28 +05:30
describe('fetchMilestones', () => {
const queryResponse = {
data: {
2023-05-27 22:25:52 +05:30
workspace: {
2021-10-27 15:23:28 +05:30
milestones: {
nodes: mockMilestones,
},
},
},
};
const queryErrors = {
data: {
2023-05-27 22:25:52 +05:30
workspace: {
2021-10-27 15:23:28 +05:30
errors: ['You cannot view these milestones'],
milestones: {},
},
},
};
function createStore({
state = {
boardType: 'project',
fullPath: 'gitlab-org/gitlab',
milestones: [],
milestonesLoading: false,
},
} = {}) {
return new Vuex.Store({
state,
mutations,
});
}
it('throws error if state.boardType is not group or project', () => {
const store = createStore({
state: {
boardType: 'invalid',
},
});
expect(() => actions.fetchMilestones(store)).toThrow(new Error('Unknown board type'));
});
2022-03-02 08:16:31 +05:30
it.each([
[
'project',
{
query: projectBoardMilestones,
2022-04-04 11:22:00 +05:30
variables: { fullPath: 'gitlab-org/gitlab' },
2022-03-02 08:16:31 +05:30
},
],
[
'group',
{
query: groupBoardMilestones,
2022-04-04 11:22:00 +05:30
variables: { fullPath: 'gitlab-org/gitlab' },
2022-03-02 08:16:31 +05:30
},
],
])(
'when boardType is %s it calls fetchMilestones with the correct query and variables',
(boardType, variables) => {
jest.spyOn(gqlClient, 'query').mockResolvedValue(queryResponse);
const store = createStore();
store.state.boardType = boardType;
actions.fetchMilestones(store);
expect(gqlClient.query).toHaveBeenCalledWith(variables);
},
);
2023-06-20 00:43:36 +05:30
it('sets milestonesLoading to true', () => {
2021-10-27 15:23:28 +05:30
jest.spyOn(gqlClient, 'query').mockResolvedValue(queryResponse);
const store = createStore();
actions.fetchMilestones(store);
expect(store.state.milestonesLoading).toBe(true);
});
describe('success', () => {
it('sets state.milestones from query result', async () => {
jest.spyOn(gqlClient, 'query').mockResolvedValue(queryResponse);
const store = createStore();
await actions.fetchMilestones(store);
expect(store.state.milestonesLoading).toBe(false);
expect(store.state.milestones).toBe(mockMilestones);
});
});
describe('failure', () => {
it('sets state.milestones from query result', async () => {
jest.spyOn(gqlClient, 'query').mockResolvedValue(queryErrors);
const store = createStore();
await expect(actions.fetchMilestones(store)).rejects.toThrow();
expect(store.state.milestonesLoading).toBe(false);
expect(store.state.error).toBe('Failed to load milestones.');
});
});
});
2019-09-04 21:01:54 +05:30
describe('createList', () => {
2021-04-17 20:07:23 +05:30
it('should dispatch createIssueList action', () => {
testAction({
action: actions.createList,
payload: { backlog: true },
expectedActions: [{ type: 'createIssueList', payload: { backlog: true } }],
});
});
});
describe('createIssueList', () => {
2021-03-11 19:13:27 +05:30
let commit;
let dispatch;
let getters;
let state;
beforeEach(() => {
state = {
fullPath: 'gitlab-org',
2021-06-08 01:23:25 +05:30
fullBoardId: 'gid://gitlab/Board/1',
2021-03-11 19:13:27 +05:30
boardType: 'group',
disabled: false,
boardLists: [{ type: 'closed' }],
};
commit = jest.fn();
dispatch = jest.fn();
getters = {
getListByLabelId: jest.fn(),
};
});
it('should dispatch addList action when creating backlog list', async () => {
2020-11-24 15:15:51 +05:30
const backlogList = {
id: 'gid://gitlab/List/1',
listType: 'backlog',
title: 'Open',
position: 0,
};
jest.spyOn(gqlClient, 'mutate').mockReturnValue(
Promise.resolve({
data: {
boardListCreate: {
list: backlogList,
errors: [],
},
},
}),
);
2021-04-17 20:07:23 +05:30
await actions.createIssueList({ getters, state, commit, dispatch }, { backlog: true });
2021-03-11 19:13:27 +05:30
expect(dispatch).toHaveBeenCalledWith('addList', backlogList);
});
it('dispatches highlightList after addList has succeeded', async () => {
const list = {
id: 'gid://gitlab/List/1',
listType: 'label',
title: 'Open',
labelId: '4',
2020-11-24 15:15:51 +05:30
};
2021-03-11 19:13:27 +05:30
jest.spyOn(gqlClient, 'mutate').mockResolvedValue({
data: {
boardListCreate: {
list,
errors: [],
},
},
});
2021-04-17 20:07:23 +05:30
await actions.createIssueList({ getters, state, commit, dispatch }, { labelId: '4' });
2021-03-11 19:13:27 +05:30
expect(dispatch).toHaveBeenCalledWith('addList', list);
expect(dispatch).toHaveBeenCalledWith('highlightList', list.id);
2020-11-24 15:15:51 +05:30
});
2021-03-11 19:13:27 +05:30
it('should commit CREATE_LIST_FAILURE mutation when API returns an error', async () => {
2020-11-24 15:15:51 +05:30
jest.spyOn(gqlClient, 'mutate').mockReturnValue(
Promise.resolve({
data: {
boardListCreate: {
list: {},
2021-04-17 20:07:23 +05:30
errors: ['foo'],
2020-11-24 15:15:51 +05:30
},
},
}),
);
2021-04-17 20:07:23 +05:30
await actions.createIssueList({ getters, state, commit, dispatch }, { backlog: true });
2021-03-11 19:13:27 +05:30
2021-04-17 20:07:23 +05:30
expect(commit).toHaveBeenCalledWith(types.CREATE_LIST_FAILURE, 'foo');
2021-03-11 19:13:27 +05:30
});
it('highlights list and does not re-query if it already exists', async () => {
const existingList = {
id: 'gid://gitlab/List/1',
listType: 'label',
title: 'Some label',
position: 1,
2020-11-24 15:15:51 +05:30
};
2021-03-11 19:13:27 +05:30
getters = {
getListByLabelId: jest.fn().mockReturnValue(existingList),
};
2021-04-17 20:07:23 +05:30
await actions.createIssueList({ getters, state, commit, dispatch }, { backlog: true });
2021-03-11 19:13:27 +05:30
expect(dispatch).toHaveBeenCalledWith('highlightList', existingList.id);
expect(dispatch).toHaveBeenCalledTimes(1);
expect(commit).not.toHaveBeenCalled();
});
});
2021-09-04 01:27:46 +05:30
describe('addList', () => {
const getters = {
getListByTitle: jest.fn().mockReturnValue(mockList),
};
it('should commit RECEIVE_ADD_LIST_SUCCESS mutation and dispatch fetchItemsForList action', () => {
testAction({
action: actions.addList,
payload: mockLists[1],
state: { ...getters },
expectedMutations: [
{ type: types.RECEIVE_ADD_LIST_SUCCESS, payload: updateListPosition(mockLists[1]) },
],
expectedActions: [{ type: 'fetchItemsForList', payload: { listId: mockList.id } }],
});
});
});
2021-03-11 19:13:27 +05:30
describe('fetchLabels', () => {
it('should commit mutation RECEIVE_LABELS_SUCCESS on success', async () => {
const queryResponse = {
data: {
group: {
labels: {
nodes: labels,
},
},
},
};
jest.spyOn(gqlClient, 'query').mockResolvedValue(queryResponse);
2021-04-17 20:07:23 +05:30
const commit = jest.fn();
const state = { boardType: 'group' };
2021-11-11 11:23:49 +05:30
await actions.fetchLabels({ state, commit });
2021-04-17 20:07:23 +05:30
expect(commit).toHaveBeenCalledWith(types.RECEIVE_LABELS_SUCCESS, labels);
2020-11-24 15:15:51 +05:30
});
});
describe('moveList', () => {
2021-10-27 15:23:28 +05:30
const backlogListId = 'gid://1';
const closedListId = 'gid://5';
2021-01-03 14:25:43 +05:30
2021-10-27 15:23:28 +05:30
const boardLists1 = {
'gid://3': { listType: '', position: 0 },
'gid://4': { listType: '', position: 1 },
'gid://5': { listType: '', position: 2 },
};
2020-11-24 15:15:51 +05:30
2021-10-27 15:23:28 +05:30
const boardLists2 = {
[backlogListId]: { listType: ListType.backlog, position: -Infinity },
[closedListId]: { listType: ListType.closed, position: Infinity },
...cloneDeep(boardLists1),
};
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: [],
2020-11-24 15:15:51 +05:30
},
2021-10-27 15:23:28 +05:30
},
state: {},
expectedMutations: [],
expectedActions: [],
});
2020-11-24 15:15:51 +05:30
});
2021-02-22 17:27:13 +05:30
2021-10-27 15:23:28 +05:30
describe.each`
draggableFrom | draggableTo | boardLists | boardListsOrder | expectedMovableListsOrder
${0} | ${2} | ${boardLists1} | ${movableListsOrder} | ${['gid://4', 'gid://5', 'gid://3']}
${2} | ${0} | ${boardLists1} | ${movableListsOrder} | ${['gid://5', 'gid://3', 'gid://4']}
${0} | ${1} | ${boardLists1} | ${movableListsOrder} | ${['gid://4', 'gid://3', 'gid://5']}
${1} | ${2} | ${boardLists1} | ${movableListsOrder} | ${['gid://3', 'gid://5', 'gid://4']}
${2} | ${1} | ${boardLists1} | ${movableListsOrder} | ${['gid://3', 'gid://5', 'gid://4']}
${1} | ${3} | ${boardLists2} | ${allListsOrder} | ${['gid://4', 'gid://5', 'gid://3']}
${3} | ${1} | ${boardLists2} | ${allListsOrder} | ${['gid://5', 'gid://3', 'gid://4']}
${1} | ${2} | ${boardLists2} | ${allListsOrder} | ${['gid://4', 'gid://3', 'gid://5']}
${2} | ${3} | ${boardLists2} | ${allListsOrder} | ${['gid://3', 'gid://5', 'gid://4']}
${3} | ${2} | ${boardLists2} | ${allListsOrder} | ${['gid://3', 'gid://5', 'gid://4']}
`(
'when moving a list from position $draggableFrom to $draggableTo with lists $boardListsOrder',
({ draggableFrom, draggableTo, boardLists, boardListsOrder, expectedMovableListsOrder }) => {
const movedListId = boardListsOrder[draggableFrom];
const displacedListId = boardListsOrder[draggableTo];
const buildDraggablePayload = () => {
return {
item: {
dataset: {
listId: boardListsOrder[draggableFrom],
draggableItemType: DraggableItemTypes.list,
},
},
newIndex: draggableTo,
to: {
children: boardListsOrder.map((listId) => ({ dataset: { listId } })),
},
};
};
2021-02-22 17:27:13 +05:30
2021-10-27 15:23:28 +05:30
it('should commit MOVE_LIST mutations and dispatch updateList action with correct payloads', () => {
return testAction({
action: actions.moveList,
payload: buildDraggablePayload(),
state: { boardLists },
expectedMutations: [
{
type: types.MOVE_LISTS,
payload: expectedMovableListsOrder.map((listId, i) => ({ listId, position: i })),
},
],
expectedActions: [
{
type: 'updateList',
payload: {
listId: movedListId,
position: movableListsOrder.findIndex((i) => i === displacedListId),
},
},
],
});
});
},
);
2021-02-22 17:27:13 +05:30
2021-10-27 15:23:28 +05:30
describe('when moving from and to the same position', () => {
it('should not commit MOVE_LIST and should not dispatch updateList', () => {
const listId = 'gid://1000';
return testAction({
action: actions.moveList,
payload: {
item: { dataset: { listId, draggbaleItemType: DraggableItemTypes.list } },
newIndex: 0,
to: {
children: [{ dataset: { listId } }],
},
},
state: { boardLists: { [listId]: { position: 0 } } },
expectedMutations: [],
expectedActions: [],
});
});
2021-02-22 17:27:13 +05:30
});
2019-09-04 21:01:54 +05:30
});
describe('updateList', () => {
2021-09-30 23:02:18 +05:30
const listId = 'gid://gitlab/List/1';
const createState = (boardItemsByListId = {}) => ({
fullPath: 'gitlab-org',
fullBoardId: 'gid://gitlab/Board/1',
boardType: 'group',
disabled: false,
boardLists: [{ type: 'closed' }],
2023-04-23 21:23:45 +05:30
issuableType: TYPE_ISSUE,
2021-09-30 23:02:18 +05:30
boardItemsByListId,
});
describe('when state doesnt have list items', () => {
it('calls fetchItemsByList', async () => {
const dispatch = jest.fn();
jest.spyOn(gqlClient, 'mutate').mockResolvedValue({
data: {
updateBoardList: {
errors: [],
list: {
id: listId,
},
},
},
});
await actions.updateList({ commit: () => {}, state: createState(), dispatch }, { listId });
expect(dispatch.mock.calls).toEqual([['fetchItemsForList', { listId }]]);
});
});
describe('when state has list items', () => {
it('doesnt call fetchItemsByList', async () => {
const commit = jest.fn();
const dispatch = jest.fn();
jest.spyOn(gqlClient, 'mutate').mockResolvedValue({
data: {
updateBoardList: {
errors: [],
list: {
id: listId,
},
},
},
});
await actions.updateList(
{ commit, state: createState({ [listId]: [] }), dispatch },
{ listId },
);
expect(dispatch.mock.calls).toEqual([]);
});
});
2021-10-27 15:23:28 +05:30
it('should dispatch handleUpdateListFailure when API returns an error', () => {
2020-11-24 15:15:51 +05:30
jest.spyOn(gqlClient, 'mutate').mockResolvedValue({
data: {
updateBoardList: {
list: {},
errors: [{ foo: 'bar' }],
},
},
});
2021-10-27 15:23:28 +05:30
return testAction(
2020-11-24 15:15:51 +05:30
actions.updateList,
{ listId: 'gid://gitlab/List/1', position: 1 },
2021-09-30 23:02:18 +05:30
createState(),
2020-11-24 15:15:51 +05:30
[],
2021-10-27 15:23:28 +05:30
[{ type: 'handleUpdateListFailure' }],
2020-11-24 15:15:51 +05:30
);
});
2019-09-04 21:01:54 +05:30
});
2021-10-27 15:23:28 +05:30
describe('handleUpdateListFailure', () => {
it('should dispatch fetchLists action and commit SET_ERROR mutation', async () => {
await testAction({
action: actions.handleUpdateListFailure,
expectedMutations: [
{
type: types.SET_ERROR,
payload: 'An error occurred while updating the board list. Please try again.',
},
],
expectedActions: [{ type: 'fetchLists' }],
});
});
});
2021-04-17 20:07:23 +05:30
describe('toggleListCollapsed', () => {
it('should commit TOGGLE_LIST_COLLAPSED mutation', async () => {
const payload = { listId: 'gid://gitlab/List/1', collapsed: true };
await testAction({
action: actions.toggleListCollapsed,
payload,
expectedMutations: [
{
type: types.TOGGLE_LIST_COLLAPSED,
payload,
},
],
});
});
});
2021-01-29 00:20:46 +05:30
describe('removeList', () => {
let state;
2021-09-04 01:27:46 +05:30
let getters;
const list = mockLists[1];
2021-01-29 00:20:46 +05:30
const listId = list.id;
const mutationVariables = {
mutation: destroyBoardListMutation,
variables: {
listId,
},
};
beforeEach(() => {
state = {
boardLists: mockListsById,
2023-04-23 21:23:45 +05:30
issuableType: TYPE_ISSUE,
2021-01-29 00:20:46 +05:30
};
2021-09-04 01:27:46 +05:30
getters = {
getListByTitle: jest.fn().mockReturnValue(mockList),
};
2021-01-29 00:20:46 +05:30
});
afterEach(() => {
state = null;
});
it('optimistically deletes the list', () => {
const commit = jest.fn();
2021-09-04 01:27:46 +05:30
actions.removeList({ commit, state, getters, dispatch: () => {} }, listId);
2021-01-29 00:20:46 +05:30
expect(commit.mock.calls).toEqual([[types.REMOVE_LIST, listId]]);
});
it('keeps the updated list if remove succeeds', async () => {
const commit = jest.fn();
2021-09-04 01:27:46 +05:30
const dispatch = jest.fn();
2021-01-29 00:20:46 +05:30
jest.spyOn(gqlClient, 'mutate').mockResolvedValue({
data: {
destroyBoardList: {
errors: [],
},
},
});
2021-09-04 01:27:46 +05:30
await actions.removeList({ commit, state, getters, dispatch }, listId);
2021-01-29 00:20:46 +05:30
expect(gqlClient.mutate).toHaveBeenCalledWith(mutationVariables);
expect(commit.mock.calls).toEqual([[types.REMOVE_LIST, listId]]);
2021-09-04 01:27:46 +05:30
expect(dispatch.mock.calls).toEqual([['fetchItemsForList', { listId: mockList.id }]]);
2021-01-29 00:20:46 +05:30
});
it('restores the list if update fails', async () => {
const commit = jest.fn();
jest.spyOn(gqlClient, 'mutate').mockResolvedValue(Promise.reject());
2021-09-04 01:27:46 +05:30
await actions.removeList({ commit, state, getters, dispatch: () => {} }, listId);
2021-01-29 00:20:46 +05:30
expect(gqlClient.mutate).toHaveBeenCalledWith(mutationVariables);
expect(commit.mock.calls).toEqual([
[types.REMOVE_LIST, listId],
[types.REMOVE_LIST_FAILURE, mockListsById],
]);
});
it('restores the list if update response has errors', async () => {
const commit = jest.fn();
jest.spyOn(gqlClient, 'mutate').mockResolvedValue({
data: {
destroyBoardList: {
errors: ['update failed, ID invalid'],
},
},
});
2021-09-04 01:27:46 +05:30
await actions.removeList({ commit, state, getters, dispatch: () => {} }, listId);
2021-01-29 00:20:46 +05:30
expect(gqlClient.mutate).toHaveBeenCalledWith(mutationVariables);
expect(commit.mock.calls).toEqual([
[types.REMOVE_LIST, listId],
[types.REMOVE_LIST_FAILURE, mockListsById],
]);
});
2019-09-04 21:01:54 +05:30
});
2021-04-17 20:07:23 +05:30
describe('fetchItemsForList', () => {
2021-01-03 14:25:43 +05:30
const listId = mockLists[0].id;
const state = {
2021-03-08 18:12:59 +05:30
fullPath: 'gitlab-org',
2021-06-08 01:23:25 +05:30
fullBoardId: 'gid://gitlab/Board/1',
2021-01-03 14:25:43 +05:30
filterParams: {},
boardType: 'group',
};
2021-03-08 18:12:59 +05:30
const mockIssuesNodes = mockIssues.map((issue) => ({ node: issue }));
2021-01-03 14:25:43 +05:30
const pageInfo = {
endCursor: '',
hasNextPage: false,
};
const queryResponse = {
data: {
group: {
board: {
lists: {
nodes: [
{
id: listId,
issues: {
edges: mockIssuesNodes,
pageInfo,
},
},
],
},
},
},
},
};
const formattedIssues = formatListIssues(queryResponse.data.group.board.lists);
const listPageInfo = {
[listId]: pageInfo,
};
2021-09-30 23:02:18 +05:30
describe('when list id is undefined', () => {
it('does not call the query', async () => {
jest.spyOn(gqlClient, 'query').mockResolvedValue(queryResponse);
await actions.fetchItemsForList(
{ state, getters: () => {}, commit: () => {} },
{ listId: undefined },
);
expect(gqlClient.query).toHaveBeenCalledTimes(0);
});
});
2022-06-21 17:19:12 +05:30
it('should commit mutations REQUEST_ITEMS_FOR_LIST and RECEIVE_ITEMS_FOR_LIST_SUCCESS on success', () => {
2021-01-03 14:25:43 +05:30
jest.spyOn(gqlClient, 'query').mockResolvedValue(queryResponse);
2022-06-21 17:19:12 +05:30
return testAction(
2021-04-17 20:07:23 +05:30
actions.fetchItemsForList,
2021-01-03 14:25:43 +05:30
{ listId },
state,
[
{
2021-04-17 20:07:23 +05:30
type: types.REQUEST_ITEMS_FOR_LIST,
2021-01-03 14:25:43 +05:30
payload: { listId, fetchNext: false },
},
{
2021-04-17 20:07:23 +05:30
type: types.RECEIVE_ITEMS_FOR_LIST_SUCCESS,
payload: { listItems: formattedIssues, listPageInfo, listId },
2021-01-03 14:25:43 +05:30
},
],
[],
);
});
2022-06-21 17:19:12 +05:30
it('should commit mutations REQUEST_ITEMS_FOR_LIST and RECEIVE_ITEMS_FOR_LIST_FAILURE on failure', () => {
2021-01-03 14:25:43 +05:30
jest.spyOn(gqlClient, 'query').mockResolvedValue(Promise.reject());
2022-06-21 17:19:12 +05:30
return testAction(
2021-04-17 20:07:23 +05:30
actions.fetchItemsForList,
2021-01-03 14:25:43 +05:30
{ listId },
state,
[
{
2021-04-17 20:07:23 +05:30
type: types.REQUEST_ITEMS_FOR_LIST,
2021-01-03 14:25:43 +05:30
payload: { listId, fetchNext: false },
},
2021-04-17 20:07:23 +05:30
{ type: types.RECEIVE_ITEMS_FOR_LIST_FAILURE, payload: listId },
2021-01-03 14:25:43 +05:30
],
[],
);
});
});
describe('resetIssues', () => {
it('commits RESET_ISSUES mutation', () => {
return testAction(actions.resetIssues, {}, {}, [{ type: types.RESET_ISSUES }], []);
});
});
2021-04-17 20:07:23 +05:30
describe('moveItem', () => {
2021-04-29 21:17:54 +05:30
it('should dispatch moveIssue action with payload', () => {
const payload = { mock: 'payload' };
2021-04-17 20:07:23 +05:30
testAction({
action: actions.moveItem,
2021-04-29 21:17:54 +05:30
payload,
expectedActions: [{ type: 'moveIssue', payload }],
2021-04-17 20:07:23 +05:30
});
});
});
2019-09-04 21:01:54 +05:30
describe('moveIssue', () => {
2021-04-29 21:17:54 +05:30
it('should dispatch a correct set of actions', () => {
testAction({
action: actions.moveIssue,
payload: mockMoveIssueParams,
state: mockMoveState,
expectedActions: [
{ type: 'moveIssueCard', payload: mockMoveData },
{ type: 'updateMovedIssue', payload: mockMoveData },
{ type: 'updateIssueOrder', payload: { moveData: mockMoveData } },
],
});
});
});
2020-11-24 15:15:51 +05:30
2021-04-29 21:17:54 +05:30
describe('moveIssueCard and undoMoveIssueCard', () => {
2021-11-11 11:23:49 +05:30
describe('card should move without cloning', () => {
2021-04-29 21:17:54 +05:30
let state;
let params;
let moveMutations;
let undoMutations;
describe('when re-ordering card', () => {
2022-11-25 23:54:43 +05:30
beforeEach(() => {
const itemId = 123;
const fromListId = 'gid://gitlab/List/1';
const toListId = 'gid://gitlab/List/1';
const originalIssue = { foo: 'bar' };
const originalIndex = 0;
const moveBeforeId = undefined;
const moveAfterId = undefined;
const allItemsLoadedInList = true;
const listPosition = undefined;
state = {
boardLists: {
[toListId]: { listType: ListType.backlog },
[fromListId]: { listType: ListType.backlog },
},
boardItems: { [itemId]: originalIssue },
boardItemsByListId: { [fromListId]: [123] },
};
params = {
itemId,
fromListId,
toListId,
moveBeforeId,
moveAfterId,
listPosition,
allItemsLoadedInList,
};
moveMutations = [
{ type: types.REMOVE_BOARD_ITEM_FROM_LIST, payload: { itemId, listId: fromListId } },
{
type: types.ADD_BOARD_ITEM_TO_LIST,
payload: {
itemId,
listId: toListId,
moveBeforeId,
moveAfterId,
listPosition,
allItemsLoadedInList,
atIndex: originalIndex,
2021-04-29 21:17:54 +05:30
},
2022-11-25 23:54:43 +05:30
},
];
undoMutations = [
{ type: types.UPDATE_BOARD_ITEM, payload: originalIssue },
{ type: types.REMOVE_BOARD_ITEM_FROM_LIST, payload: { itemId, listId: fromListId } },
{
type: types.ADD_BOARD_ITEM_TO_LIST,
payload: { itemId, listId: fromListId, atIndex: originalIndex },
},
];
});
2021-04-29 21:17:54 +05:30
it('moveIssueCard commits a correct set of actions', () => {
testAction({
action: actions.moveIssueCard,
state,
payload: getMoveData(state, params),
expectedMutations: moveMutations,
});
});
it('undoMoveIssueCard commits a correct set of actions', () => {
testAction({
action: actions.undoMoveIssueCard,
state,
payload: getMoveData(state, params),
expectedMutations: undoMutations,
});
});
2020-11-24 15:15:51 +05:30
});
2021-04-29 21:17:54 +05:30
describe.each([
2020-11-24 15:15:51 +05:30
[
2021-04-29 21:17:54 +05:30
'issue moves out of backlog',
2020-11-24 15:15:51 +05:30
{
2021-04-29 21:17:54 +05:30
fromListType: ListType.backlog,
toListType: ListType.label,
2020-11-24 15:15:51 +05:30
},
2021-04-29 21:17:54 +05:30
],
[
'issue card moves to closed',
2020-11-24 15:15:51 +05:30
{
2021-04-29 21:17:54 +05:30
fromListType: ListType.label,
toListType: ListType.closed,
2020-11-24 15:15:51 +05:30
},
],
2021-04-29 21:17:54 +05:30
[
'issue card moves to non-closed, non-backlog list of the same type',
{
fromListType: ListType.label,
toListType: ListType.label,
},
],
])('when %s', (_, { toListType, fromListType }) => {
2022-11-25 23:54:43 +05:30
beforeEach(() => {
const itemId = 123;
const fromListId = 'gid://gitlab/List/1';
const toListId = 'gid://gitlab/List/2';
const originalIssue = { foo: 'bar' };
const originalIndex = 0;
const moveBeforeId = undefined;
const moveAfterId = undefined;
state = {
boardLists: {
[fromListId]: { listType: fromListType },
[toListId]: { listType: toListType },
},
boardItems: { [itemId]: originalIssue },
boardItemsByListId: { [fromListId]: [123], [toListId]: [] },
};
params = { itemId, fromListId, toListId, moveBeforeId, moveAfterId };
moveMutations = [
{ type: types.REMOVE_BOARD_ITEM_FROM_LIST, payload: { itemId, listId: fromListId } },
{
type: types.ADD_BOARD_ITEM_TO_LIST,
payload: { itemId, listId: toListId, moveBeforeId, moveAfterId },
},
];
undoMutations = [
{ type: types.UPDATE_BOARD_ITEM, payload: originalIssue },
{ type: types.REMOVE_BOARD_ITEM_FROM_LIST, payload: { itemId, listId: toListId } },
{
type: types.ADD_BOARD_ITEM_TO_LIST,
payload: { itemId, listId: fromListId, atIndex: originalIndex },
},
];
});
2021-04-29 21:17:54 +05:30
it('moveIssueCard commits a correct set of actions', () => {
testAction({
action: actions.moveIssueCard,
state,
payload: getMoveData(state, params),
expectedMutations: moveMutations,
});
});
it('undoMoveIssueCard commits a correct set of actions', () => {
testAction({
action: actions.undoMoveIssueCard,
state,
payload: getMoveData(state, params),
expectedMutations: undoMutations,
});
});
});
});
describe('card should clone on move', () => {
let state;
let params;
let moveMutations;
let undoMutations;
describe.each([
[
'issue card moves to non-closed, non-backlog list of a different type',
{
fromListType: ListType.label,
toListType: ListType.assignee,
},
],
])('when %s', (_, { toListType, fromListType }) => {
2022-11-25 23:54:43 +05:30
beforeEach(() => {
const itemId = 123;
const fromListId = 'gid://gitlab/List/1';
const toListId = 'gid://gitlab/List/2';
const originalIssue = { foo: 'bar' };
const originalIndex = 0;
const moveBeforeId = undefined;
const moveAfterId = undefined;
state = {
boardLists: {
[fromListId]: { listType: fromListType },
[toListId]: { listType: toListType },
},
boardItems: { [itemId]: originalIssue },
boardItemsByListId: { [fromListId]: [123], [toListId]: [] },
};
params = { itemId, fromListId, toListId, moveBeforeId, moveAfterId };
moveMutations = [
{ type: types.REMOVE_BOARD_ITEM_FROM_LIST, payload: { itemId, listId: fromListId } },
{
type: types.ADD_BOARD_ITEM_TO_LIST,
payload: { itemId, listId: toListId, moveBeforeId, moveAfterId },
},
{
type: types.ADD_BOARD_ITEM_TO_LIST,
payload: { itemId, listId: fromListId, atIndex: originalIndex },
},
];
undoMutations = [
{ type: types.UPDATE_BOARD_ITEM, payload: originalIssue },
{ type: types.REMOVE_BOARD_ITEM_FROM_LIST, payload: { itemId, listId: fromListId } },
{ type: types.REMOVE_BOARD_ITEM_FROM_LIST, payload: { itemId, listId: toListId } },
{
type: types.ADD_BOARD_ITEM_TO_LIST,
payload: { itemId, listId: fromListId, atIndex: originalIndex },
},
];
});
2021-04-29 21:17:54 +05:30
it('moveIssueCard commits a correct set of actions', () => {
testAction({
action: actions.moveIssueCard,
state,
payload: getMoveData(state, params),
expectedMutations: moveMutations,
});
});
it('undoMoveIssueCard commits a correct set of actions', () => {
testAction({
action: actions.undoMoveIssueCard,
state,
payload: getMoveData(state, params),
expectedMutations: undoMutations,
});
});
});
2020-11-24 15:15:51 +05:30
});
2021-04-29 21:17:54 +05:30
});
describe('updateMovedIssueCard', () => {
const label1 = {
id: 'label1',
};
it.each([
[
'issue without a label is moved to a label list',
{
state: {
boardLists: {
from: {},
to: {
listType: ListType.label,
label: label1,
},
},
boardItems: {
1: {
labels: [],
},
},
},
moveData: {
itemId: 1,
fromListId: 'from',
toListId: 'to',
},
updatedIssue: { labels: [label1] },
},
],
])(
'should commit UPDATE_BOARD_ITEM with a correctly updated issue data when %s',
(_, { state, moveData, updatedIssue }) => {
testAction({
action: actions.updateMovedIssue,
payload: moveData,
state,
expectedMutations: [{ type: types.UPDATE_BOARD_ITEM, payload: updatedIssue }],
});
},
);
});
describe('updateIssueOrder', () => {
const issues = {
2021-11-11 11:23:49 +05:30
[mockIssue.id]: mockIssue,
[mockIssue2.id]: mockIssue2,
2021-04-29 21:17:54 +05:30
};
const state = {
boardItems: issues,
2021-06-08 01:23:25 +05:30
fullBoardId: 'gid://gitlab/Board/1',
2021-04-29 21:17:54 +05:30
};
const moveData = {
2021-11-11 11:23:49 +05:30
itemId: mockIssue.id,
2021-04-29 21:17:54 +05:30
fromListId: 'gid://gitlab/List/1',
toListId: 'gid://gitlab/List/2',
};
2020-11-24 15:15:51 +05:30
it('calls mutate with the correct variables', () => {
const mutationVariables = {
mutation: issueMoveListMutation,
variables: {
projectPath: getProjectPath(mockIssue.referencePath),
2021-06-08 01:23:25 +05:30
boardId: state.fullBoardId,
2020-11-24 15:15:51 +05:30
iid: mockIssue.iid,
fromListId: 1,
toListId: 2,
moveBeforeId: undefined,
moveAfterId: undefined,
},
2022-01-26 12:08:38 +05:30
update: expect.anything(),
2020-11-24 15:15:51 +05:30
};
jest.spyOn(gqlClient, 'mutate').mockResolvedValue({
data: {
issueMoveList: {
issue: rawIssue,
errors: [],
},
},
});
2021-04-29 21:17:54 +05:30
actions.updateIssueOrder({ state, commit: () => {}, dispatch: () => {} }, { moveData });
2020-11-24 15:15:51 +05:30
expect(gqlClient.mutate).toHaveBeenCalledWith(mutationVariables);
});
2021-04-29 21:17:54 +05:30
it('should commit MUTATE_ISSUE_SUCCESS mutation when successful', () => {
2020-11-24 15:15:51 +05:30
jest.spyOn(gqlClient, 'mutate').mockResolvedValue({
data: {
issueMoveList: {
2021-04-29 21:17:54 +05:30
issue: rawIssue,
errors: [],
2020-11-24 15:15:51 +05:30
},
},
});
testAction(
2021-04-29 21:17:54 +05:30
actions.updateIssueOrder,
{ moveData },
2020-11-24 15:15:51 +05:30
state,
[
2022-10-11 01:57:18 +05:30
{
type: types.MUTATE_ISSUE_IN_PROGRESS,
payload: true,
},
2020-11-24 15:15:51 +05:30
{
2021-04-29 21:17:54 +05:30
type: types.MUTATE_ISSUE_SUCCESS,
payload: { issue: rawIssue },
2020-11-24 15:15:51 +05:30
},
2022-10-11 01:57:18 +05:30
{
type: types.MUTATE_ISSUE_IN_PROGRESS,
payload: false,
},
2021-04-29 21:17:54 +05:30
],
[],
);
});
it('should commit SET_ERROR and dispatch undoMoveIssueCard', () => {
jest.spyOn(gqlClient, 'mutate').mockResolvedValue({
data: {
issueMoveList: {
issue: {},
errors: [{ foo: 'bar' }],
},
},
});
testAction(
actions.updateIssueOrder,
{ moveData },
state,
[
2022-10-11 01:57:18 +05:30
{
type: types.MUTATE_ISSUE_IN_PROGRESS,
payload: true,
},
{
type: types.MUTATE_ISSUE_IN_PROGRESS,
payload: false,
},
2020-11-24 15:15:51 +05:30
{
2021-04-29 21:17:54 +05:30
type: types.SET_ERROR,
payload: 'An error occurred while moving the issue. Please try again.',
2020-11-24 15:15:51 +05:30
},
],
2021-04-29 21:17:54 +05:30
[{ type: 'undoMoveIssueCard', payload: moveData }],
2020-11-24 15:15:51 +05:30
);
});
2019-09-04 21:01:54 +05:30
});
2021-01-29 00:20:46 +05:30
describe('setAssignees', () => {
const node = { username: 'name' };
2021-02-22 17:27:13 +05:30
describe('when succeeds', () => {
2022-06-21 17:19:12 +05:30
it('calls the correct mutation with the correct values', () => {
return testAction(
2021-02-22 17:27:13 +05:30
actions.setAssignees,
2021-09-30 23:02:18 +05:30
{ assignees: [node], iid: '1' },
{ commit: () => {} },
2021-02-22 17:27:13 +05:30
[
{
2021-04-29 21:17:54 +05:30
type: 'UPDATE_BOARD_ITEM_BY_ID',
payload: { prop: 'assignees', itemId: undefined, value: [node] },
2021-02-22 17:27:13 +05:30
},
],
[],
);
2021-01-29 00:20:46 +05:30
});
});
2019-09-04 21:01:54 +05:30
});
2021-04-29 21:17:54 +05:30
describe('addListItem', () => {
it('should commit ADD_BOARD_ITEM_TO_LIST and UPDATE_BOARD_ITEM mutations', () => {
const payload = {
list: mockLists[0],
item: mockIssue,
position: 0,
2021-11-18 22:05:49 +05:30
inProgress: true,
2021-04-29 21:17:54 +05:30
};
2021-11-18 22:05:49 +05:30
testAction(
actions.addListItem,
payload,
{},
[
{
type: types.ADD_BOARD_ITEM_TO_LIST,
payload: {
listId: mockLists[0].id,
itemId: mockIssue.id,
atIndex: 0,
inProgress: true,
},
2021-04-29 21:17:54 +05:30
},
2021-11-18 22:05:49 +05:30
{ type: types.UPDATE_BOARD_ITEM, payload: mockIssue },
],
[],
);
});
it('should commit ADD_BOARD_ITEM_TO_LIST and UPDATE_BOARD_ITEM mutations, dispatch setActiveId action when inProgress is false', () => {
const payload = {
list: mockLists[0],
item: mockIssue,
position: 0,
};
testAction(
actions.addListItem,
payload,
{},
[
{
type: types.ADD_BOARD_ITEM_TO_LIST,
payload: {
listId: mockLists[0].id,
itemId: mockIssue.id,
atIndex: 0,
inProgress: false,
},
},
{ type: types.UPDATE_BOARD_ITEM, payload: mockIssue },
],
[{ type: 'setActiveId', payload: { id: mockIssue.id, sidebarType: ISSUABLE } }],
);
2021-04-29 21:17:54 +05:30
});
});
describe('removeListItem', () => {
it('should commit REMOVE_BOARD_ITEM_FROM_LIST and REMOVE_BOARD_ITEM mutations', () => {
const payload = {
listId: mockLists[0].id,
itemId: mockIssue.id,
};
testAction(actions.removeListItem, payload, {}, [
{ type: types.REMOVE_BOARD_ITEM_FROM_LIST, payload },
{ type: types.REMOVE_BOARD_ITEM, payload: mockIssue.id },
]);
});
});
describe('addListNewIssue', () => {
2021-01-29 00:20:46 +05:30
const state = {
boardType: 'group',
2021-03-08 18:12:59 +05:30
fullPath: 'gitlab-org/gitlab',
boardConfig: {
labelIds: [],
assigneeId: null,
milestoneId: -1,
},
};
const stateWithBoardConfig = {
boardConfig: {
labels: [
{
id: 5,
title: 'Test',
color: '#ff0000',
description: 'testing;',
textColor: 'white',
},
],
assigneeId: 2,
milestoneId: 3,
2021-01-29 00:20:46 +05:30
},
};
2021-04-29 21:17:54 +05:30
const fakeList = { id: 'gid://gitlab/List/123' };
2021-01-29 00:20:46 +05:30
2021-03-08 18:12:59 +05:30
it('should add board scope to the issue being created', async () => {
2021-01-29 00:20:46 +05:30
jest.spyOn(gqlClient, 'mutate').mockResolvedValue({
data: {
createIssue: {
2021-03-08 18:12:59 +05:30
issue: mockIssue,
errors: [],
},
},
});
2021-04-29 21:17:54 +05:30
await actions.addListNewIssue(
{ dispatch: jest.fn(), commit: jest.fn(), state: stateWithBoardConfig },
{ issueInput: mockIssue, list: fakeList },
);
2021-03-08 18:12:59 +05:30
expect(gqlClient.mutate).toHaveBeenCalledWith({
mutation: issueCreateMutation,
variables: {
input: formatIssueInput(mockIssue, stateWithBoardConfig.boardConfig),
},
2022-01-26 12:08:38 +05:30
update: expect.anything(),
2021-03-08 18:12:59 +05:30
});
});
it('should add board scope by merging attributes to the issue being created', async () => {
const issue = {
...mockIssue,
assigneeIds: ['gid://gitlab/User/1'],
labelIds: ['gid://gitlab/GroupLabel/4'],
};
jest.spyOn(gqlClient, 'mutate').mockResolvedValue({
data: {
createIssue: {
issue,
errors: [],
},
},
});
const payload = formatIssueInput(issue, stateWithBoardConfig.boardConfig);
2021-04-29 21:17:54 +05:30
await actions.addListNewIssue(
{ dispatch: jest.fn(), commit: jest.fn(), state: stateWithBoardConfig },
{ issueInput: issue, list: fakeList },
);
2021-03-08 18:12:59 +05:30
expect(gqlClient.mutate).toHaveBeenCalledWith({
mutation: issueCreateMutation,
variables: {
input: formatIssueInput(issue, stateWithBoardConfig.boardConfig),
},
2022-01-26 12:08:38 +05:30
update: expect.anything(),
2021-03-08 18:12:59 +05:30
});
expect(payload.labelIds).toEqual(['gid://gitlab/GroupLabel/4', 'gid://gitlab/GroupLabel/5']);
expect(payload.assigneeIds).toEqual(['gid://gitlab/User/1', 'gid://gitlab/User/2']);
});
2021-04-29 21:17:54 +05:30
describe('when issue creation mutation request succeeds', () => {
it('dispatches a correct set of mutations', () => {
jest.spyOn(gqlClient, 'mutate').mockResolvedValue({
data: {
createIssue: {
issue: mockIssue,
errors: [],
},
2021-01-29 00:20:46 +05:30
},
2021-04-29 21:17:54 +05:30
});
testAction({
action: actions.addListNewIssue,
payload: {
issueInput: mockIssue,
list: fakeList,
placeholderId: 'tmp',
},
state,
expectedActions: [
{
type: 'addListItem',
payload: {
list: fakeList,
2021-09-04 01:27:46 +05:30
item: formatIssue({ ...mockIssue, id: 'tmp', isLoading: true }),
2021-04-29 21:17:54 +05:30
position: 0,
2021-09-04 01:27:46 +05:30
inProgress: true,
2021-04-29 21:17:54 +05:30
},
},
{ type: 'removeListItem', payload: { listId: fakeList.id, itemId: 'tmp' } },
{
type: 'addListItem',
payload: {
list: fakeList,
2021-11-11 11:23:49 +05:30
item: formatIssue(mockIssue),
2021-04-29 21:17:54 +05:30
position: 0,
},
},
],
});
2021-01-29 00:20:46 +05:30
});
2020-11-24 15:15:51 +05:30
});
2021-04-29 21:17:54 +05:30
describe('when issue creation mutation request fails', () => {
it('dispatches a correct set of mutations', () => {
jest.spyOn(gqlClient, 'mutate').mockResolvedValue({
data: {
createIssue: {
issue: mockIssue,
errors: [{ foo: 'bar' }],
},
},
});
testAction({
action: actions.addListNewIssue,
payload: {
issueInput: mockIssue,
list: fakeList,
placeholderId: 'tmp',
},
state,
expectedActions: [
{
type: 'addListItem',
payload: {
list: fakeList,
2021-09-04 01:27:46 +05:30
item: formatIssue({ ...mockIssue, id: 'tmp', isLoading: true }),
2021-04-29 21:17:54 +05:30
position: 0,
2021-09-04 01:27:46 +05:30
inProgress: true,
2021-04-29 21:17:54 +05:30
},
},
{ type: 'removeListItem', payload: { listId: fakeList.id, itemId: 'tmp' } },
],
expectedMutations: [
{
type: types.SET_ERROR,
payload: 'An error occurred while creating the issue. Please try again.',
},
],
});
});
2020-11-24 15:15:51 +05:30
});
});
2021-01-03 14:25:43 +05:30
describe('setActiveIssueLabels', () => {
2021-04-17 20:07:23 +05:30
const state = { boardItems: { [mockIssue.id]: mockIssue } };
2022-01-26 12:08:38 +05:30
const getters = { activeBoardItem: { ...mockIssue, labels } };
2021-03-08 18:12:59 +05:30
const testLabelIds = labels.map((label) => label.id);
2021-01-03 14:25:43 +05:30
const input = {
2021-12-11 22:18:48 +05:30
labelIds: testLabelIds,
2021-01-03 14:25:43 +05:30
removeLabelIds: [],
projectPath: 'h/b',
2021-12-11 22:18:48 +05:30
labels,
2021-01-03 14:25:43 +05:30
};
2022-01-26 12:08:38 +05:30
it('should assign labels', () => {
2021-01-03 14:25:43 +05:30
const payload = {
2021-04-29 21:17:54 +05:30
itemId: getters.activeBoardItem.id,
2021-01-03 14:25:43 +05:30
prop: 'labels',
value: labels,
};
testAction(
actions.setActiveIssueLabels,
input,
{ ...state, ...getters },
[
{
2021-04-29 21:17:54 +05:30
type: types.UPDATE_BOARD_ITEM_BY_ID,
2021-01-03 14:25:43 +05:30
payload,
},
],
[],
);
});
2022-01-26 12:08:38 +05:30
it('should remove label', () => {
const payload = {
itemId: getters.activeBoardItem.id,
prop: 'labels',
value: [labels[1]],
};
2021-12-11 22:18:48 +05:30
2022-01-26 12:08:38 +05:30
testAction(
actions.setActiveIssueLabels,
{ ...input, removeLabelIds: [getIdFromGraphQLId(labels[0].id)] },
{ ...state, ...getters },
[
{
type: types.UPDATE_BOARD_ITEM_BY_ID,
payload,
},
],
[],
);
2021-12-11 22:18:48 +05:30
});
2021-01-03 14:25:43 +05:30
});
2021-04-29 21:17:54 +05:30
describe('setActiveItemSubscribed', () => {
const state = {
boardItems: {
[mockActiveIssue.id]: mockActiveIssue,
},
fullPath: 'gitlab-org',
2023-04-23 21:23:45 +05:30
issuableType: TYPE_ISSUE,
2021-04-29 21:17:54 +05:30
};
const getters = { activeBoardItem: mockActiveIssue, isEpicBoard: false };
2021-01-29 00:20:46 +05:30
const subscribedState = true;
const input = {
subscribedState,
projectPath: 'gitlab-org/gitlab-test',
};
2022-06-21 17:19:12 +05:30
it('should commit subscribed status', () => {
2021-01-29 00:20:46 +05:30
jest.spyOn(gqlClient, 'mutate').mockResolvedValue({
data: {
2021-04-29 21:17:54 +05:30
updateIssuableSubscription: {
2021-01-29 00:20:46 +05:30
issue: {
subscribed: subscribedState,
},
errors: [],
},
},
});
const payload = {
2021-04-29 21:17:54 +05:30
itemId: getters.activeBoardItem.id,
2021-01-29 00:20:46 +05:30
prop: 'subscribed',
value: subscribedState,
};
2022-06-21 17:19:12 +05:30
return testAction(
2021-04-29 21:17:54 +05:30
actions.setActiveItemSubscribed,
2021-01-29 00:20:46 +05:30
input,
{ ...state, ...getters },
[
{
2021-04-29 21:17:54 +05:30
type: types.UPDATE_BOARD_ITEM_BY_ID,
2021-01-29 00:20:46 +05:30
payload,
},
],
[],
);
});
it('throws error if fails', async () => {
jest
.spyOn(gqlClient, 'mutate')
2021-04-29 21:17:54 +05:30
.mockResolvedValue({ data: { updateIssuableSubscription: { errors: ['failed mutation'] } } });
2021-01-29 00:20:46 +05:30
2021-04-29 21:17:54 +05:30
await expect(actions.setActiveItemSubscribed({ getters }, input)).rejects.toThrow(Error);
2021-01-29 00:20:46 +05:30
});
});
2021-04-29 21:17:54 +05:30
describe('setActiveItemTitle', () => {
const state = {
boardItems: { [mockIssue.id]: mockIssue },
2023-04-23 21:23:45 +05:30
issuableType: TYPE_ISSUE,
2021-04-29 21:17:54 +05:30
fullPath: 'path/f',
};
const getters = { activeBoardItem: mockIssue, isEpicBoard: false };
2021-03-08 18:12:59 +05:30
const testTitle = 'Test Title';
const input = {
title: testTitle,
projectPath: 'h/b',
};
2022-06-21 17:19:12 +05:30
it('should commit title after setting the issue', () => {
2021-03-08 18:12:59 +05:30
jest.spyOn(gqlClient, 'mutate').mockResolvedValue({
data: {
2021-04-29 21:17:54 +05:30
updateIssuableTitle: {
2021-03-08 18:12:59 +05:30
issue: {
title: testTitle,
},
errors: [],
},
},
});
const payload = {
2021-04-29 21:17:54 +05:30
itemId: getters.activeBoardItem.id,
2021-03-08 18:12:59 +05:30
prop: 'title',
value: testTitle,
};
2022-06-21 17:19:12 +05:30
return testAction(
2021-04-29 21:17:54 +05:30
actions.setActiveItemTitle,
2021-03-08 18:12:59 +05:30
input,
{ ...state, ...getters },
[
{
2021-04-29 21:17:54 +05:30
type: types.UPDATE_BOARD_ITEM_BY_ID,
2021-03-08 18:12:59 +05:30
payload,
},
],
[],
);
});
it('throws error if fails', async () => {
jest
.spyOn(gqlClient, 'mutate')
.mockResolvedValue({ data: { updateIssue: { errors: ['failed mutation'] } } });
2021-04-29 21:17:54 +05:30
await expect(actions.setActiveItemTitle({ getters }, input)).rejects.toThrow(Error);
2021-03-08 18:12:59 +05:30
});
});
2021-06-08 01:23:25 +05:30
describe('setActiveItemConfidential', () => {
const state = { boardItems: { [mockIssue.id]: mockIssue } };
const getters = { activeBoardItem: mockIssue };
2022-06-21 17:19:12 +05:30
it('set confidential value on board item', () => {
2021-06-08 01:23:25 +05:30
const payload = {
itemId: getters.activeBoardItem.id,
prop: 'confidential',
value: true,
};
2022-06-21 17:19:12 +05:30
return testAction(
2021-06-08 01:23:25 +05:30
actions.setActiveItemConfidential,
true,
{ ...state, ...getters },
[
{
type: types.UPDATE_BOARD_ITEM_BY_ID,
payload,
},
],
[],
);
});
});
2021-03-08 18:12:59 +05:30
describe('fetchGroupProjects', () => {
const state = {
fullPath: 'gitlab-org',
};
const pageInfo = {
endCursor: '',
hasNextPage: false,
};
const queryResponse = {
data: {
group: {
projects: {
nodes: mockGroupProjects,
pageInfo: {
endCursor: '',
hasNextPage: false,
},
},
},
},
};
2022-06-21 17:19:12 +05:30
it('should commit mutations REQUEST_GROUP_PROJECTS and RECEIVE_GROUP_PROJECTS_SUCCESS on success', () => {
2021-03-08 18:12:59 +05:30
jest.spyOn(gqlClient, 'query').mockResolvedValue(queryResponse);
2022-06-21 17:19:12 +05:30
return testAction(
2021-03-08 18:12:59 +05:30
actions.fetchGroupProjects,
{},
state,
[
{
type: types.REQUEST_GROUP_PROJECTS,
payload: false,
},
{
type: types.RECEIVE_GROUP_PROJECTS_SUCCESS,
payload: { projects: mockGroupProjects, pageInfo, fetchNext: false },
},
],
[],
);
});
2022-06-21 17:19:12 +05:30
it('should commit mutations REQUEST_GROUP_PROJECTS and RECEIVE_GROUP_PROJECTS_FAILURE on failure', () => {
2021-03-08 18:12:59 +05:30
jest.spyOn(gqlClient, 'query').mockRejectedValue();
2022-06-21 17:19:12 +05:30
return testAction(
2021-03-08 18:12:59 +05:30
actions.fetchGroupProjects,
{},
state,
[
{
type: types.REQUEST_GROUP_PROJECTS,
payload: false,
},
{
type: types.RECEIVE_GROUP_PROJECTS_FAILURE,
},
],
[],
);
});
});
describe('setSelectedProject', () => {
2022-06-21 17:19:12 +05:30
it('should commit mutation SET_SELECTED_PROJECT', () => {
2021-03-08 18:12:59 +05:30
const project = mockGroupProjects[0];
2022-06-21 17:19:12 +05:30
return testAction(
2021-03-08 18:12:59 +05:30
actions.setSelectedProject,
project,
{},
[
{
type: types.SET_SELECTED_PROJECT,
payload: project,
},
],
[],
);
});
});
2021-03-11 19:13:27 +05:30
describe('toggleBoardItemMultiSelection', () => {
const boardItem = mockIssue;
2021-04-17 20:07:23 +05:30
const boardItem2 = mockIssue2;
2021-03-11 19:13:27 +05:30
it('should commit mutation ADD_BOARD_ITEM_TO_SELECTION if item is not on selection state', () => {
testAction(
actions.toggleBoardItemMultiSelection,
boardItem,
{ selectedBoardItems: [] },
[
{
type: types.ADD_BOARD_ITEM_TO_SELECTION,
payload: boardItem,
},
],
[],
);
});
it('should commit mutation REMOVE_BOARD_ITEM_FROM_SELECTION if item is on selection state', () => {
testAction(
actions.toggleBoardItemMultiSelection,
boardItem,
{ selectedBoardItems: [mockIssue] },
[
{
type: types.REMOVE_BOARD_ITEM_FROM_SELECTION,
payload: boardItem,
},
],
[],
);
});
2021-04-17 20:07:23 +05:30
it('should additionally commit mutation ADD_BOARD_ITEM_TO_SELECTION for active issue and dispatch unsetActiveId', () => {
testAction(
actions.toggleBoardItemMultiSelection,
boardItem2,
2021-04-29 21:17:54 +05:30
{ activeId: mockActiveIssue.id, activeBoardItem: mockActiveIssue, selectedBoardItems: [] },
2021-04-17 20:07:23 +05:30
[
{
type: types.ADD_BOARD_ITEM_TO_SELECTION,
payload: mockActiveIssue,
},
{
type: types.ADD_BOARD_ITEM_TO_SELECTION,
payload: boardItem2,
},
],
[{ type: 'unsetActiveId' }],
);
});
});
describe('resetBoardItemMultiSelection', () => {
it('should commit mutation RESET_BOARD_ITEM_SELECTION', () => {
testAction({
action: actions.resetBoardItemMultiSelection,
state: { selectedBoardItems: [mockIssue] },
expectedMutations: [
{
type: types.RESET_BOARD_ITEM_SELECTION,
},
],
});
});
});
describe('toggleBoardItem', () => {
it('should dispatch resetBoardItemMultiSelection and unsetActiveId when boardItem is the active item', () => {
testAction({
action: actions.toggleBoardItem,
payload: { boardItem: mockIssue },
state: {
activeId: mockIssue.id,
},
expectedActions: [{ type: 'resetBoardItemMultiSelection' }, { type: 'unsetActiveId' }],
});
});
it('should dispatch resetBoardItemMultiSelection and setActiveId when boardItem is not the active item', () => {
testAction({
action: actions.toggleBoardItem,
payload: { boardItem: mockIssue },
state: {
activeId: inactiveId,
},
expectedActions: [
{ type: 'resetBoardItemMultiSelection' },
{ type: 'setActiveId', payload: { id: mockIssue.id, sidebarType: ISSUABLE } },
],
});
});
2021-03-11 19:13:27 +05:30
});
2021-04-29 21:17:54 +05:30
describe('setError', () => {
it('should commit mutation SET_ERROR', () => {
testAction({
action: actions.setError,
payload: { message: 'mayday' },
expectedMutations: [
{
payload: 'mayday',
type: types.SET_ERROR,
},
],
});
});
it('should capture error using Sentry when captureError is true', () => {
jest.spyOn(Sentry, 'captureException');
const mockError = new Error();
actions.setError(
{ commit: () => {} },
{
message: 'mayday',
error: mockError,
captureError: true,
},
);
expect(Sentry.captureException).toHaveBeenNthCalledWith(1, mockError);
});
});
describe('unsetError', () => {
it('should commit mutation SET_ERROR with undefined as payload', () => {
testAction({
action: actions.unsetError,
expectedMutations: [
{
payload: undefined,
type: types.SET_ERROR,
},
],
});
});
});