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:
Diffstat (limited to 'spec/frontend/boards')
-rw-r--r--spec/frontend/boards/components/board_column_spec.js5
-rw-r--r--spec/frontend/boards/components/board_form_spec.js38
-rw-r--r--spec/frontend/boards/components/boards_selector_spec.js36
-rw-r--r--spec/frontend/boards/mock_data.js36
-rw-r--r--spec/frontend/boards/stores/actions_spec.js38
-rw-r--r--spec/frontend/boards/stores/mutations_spec.js26
6 files changed, 75 insertions, 104 deletions
diff --git a/spec/frontend/boards/components/board_column_spec.js b/spec/frontend/boards/components/board_column_spec.js
index f1964daa8b2..c13f7caba76 100644
--- a/spec/frontend/boards/components/board_column_spec.js
+++ b/spec/frontend/boards/components/board_column_spec.js
@@ -20,8 +20,6 @@ describe('Board Column Component', () => {
};
const createComponent = ({ listType = ListType.backlog, collapsed = false } = {}) => {
- const boardId = '1';
-
const listMock = {
...listObj,
listType,
@@ -39,9 +37,6 @@ describe('Board Column Component', () => {
disabled: false,
list: listMock,
},
- provide: {
- boardId,
- },
});
};
diff --git a/spec/frontend/boards/components/board_form_spec.js b/spec/frontend/boards/components/board_form_spec.js
index 6a659623b53..fdc16b46167 100644
--- a/spec/frontend/boards/components/board_form_spec.js
+++ b/spec/frontend/boards/components/board_form_spec.js
@@ -1,4 +1,6 @@
import { GlModal } from '@gitlab/ui';
+import Vue from 'vue';
+import Vuex from 'vuex';
import setWindowLocation from 'helpers/set_window_location_helper';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import waitForPromises from 'helpers/wait_for_promises';
@@ -8,7 +10,6 @@ import { formType } from '~/boards/constants';
import createBoardMutation from '~/boards/graphql/board_create.mutation.graphql';
import destroyBoardMutation from '~/boards/graphql/board_destroy.mutation.graphql';
import updateBoardMutation from '~/boards/graphql/board_update.mutation.graphql';
-import { createStore } from '~/boards/stores';
import { visitUrl } from '~/lib/utils/url_utility';
jest.mock('~/lib/utils/url_utility', () => ({
@@ -16,6 +17,8 @@ jest.mock('~/lib/utils/url_utility', () => ({
visitUrl: jest.fn().mockName('visitUrlMock'),
}));
+Vue.use(Vuex);
+
const currentBoard = {
id: 'gid://gitlab/Board/1',
name: 'test',
@@ -46,11 +49,18 @@ describe('BoardForm', () => {
const findDeleteConfirmation = () => wrapper.findByTestId('delete-confirmation-message');
const findInput = () => wrapper.find('#board-new-name');
- const store = createStore({
+ const setBoardMock = jest.fn();
+ const setErrorMock = jest.fn();
+
+ const store = new Vuex.Store({
getters: {
isGroupBoard: () => true,
isProjectBoard: () => false,
},
+ actions: {
+ setBoard: setBoardMock,
+ setError: setErrorMock,
+ },
});
const createComponent = (props, data) => {
@@ -168,7 +178,7 @@ describe('BoardForm', () => {
expect(mutate).not.toHaveBeenCalled();
});
- it('calls a correct GraphQL mutation and redirects to correct page from existing board', async () => {
+ it('calls a correct GraphQL mutation and sets board in state', async () => {
createComponent({ canAdminBoard: true, currentPage: formType.new });
fillForm();
@@ -184,13 +194,12 @@ describe('BoardForm', () => {
});
await waitForPromises();
- expect(visitUrl).toHaveBeenCalledWith('test-path');
+ expect(setBoardMock).toHaveBeenCalledTimes(1);
});
- it('shows a GlAlert if GraphQL mutation fails', async () => {
+ it('sets error in state if GraphQL mutation fails', async () => {
mutate = jest.fn().mockRejectedValue('Houston, we have a problem');
createComponent({ canAdminBoard: true, currentPage: formType.new });
- jest.spyOn(wrapper.vm, 'setError').mockImplementation(() => {});
fillForm();
@@ -199,8 +208,8 @@ describe('BoardForm', () => {
expect(mutate).toHaveBeenCalled();
await waitForPromises();
- expect(visitUrl).not.toHaveBeenCalled();
- expect(wrapper.vm.setError).toHaveBeenCalled();
+ expect(setBoardMock).not.toHaveBeenCalled();
+ expect(setErrorMock).toHaveBeenCalled();
});
});
});
@@ -256,7 +265,8 @@ describe('BoardForm', () => {
});
await waitForPromises();
- expect(visitUrl).toHaveBeenCalledWith('test-path');
+ expect(setBoardMock).toHaveBeenCalledTimes(1);
+ expect(global.window.location.href).not.toContain('?group_by=epic');
});
it('calls GraphQL mutation with correct parameters when issues are grouped by epic', async () => {
@@ -282,13 +292,13 @@ describe('BoardForm', () => {
});
await waitForPromises();
- expect(visitUrl).toHaveBeenCalledWith('test-path?group_by=epic');
+ expect(setBoardMock).toHaveBeenCalledTimes(1);
+ expect(global.window.location.href).toContain('?group_by=epic');
});
- it('shows a GlAlert if GraphQL mutation fails', async () => {
+ it('sets error in state if GraphQL mutation fails', async () => {
mutate = jest.fn().mockRejectedValue('Houston, we have a problem');
createComponent({ canAdminBoard: true, currentPage: formType.edit });
- jest.spyOn(wrapper.vm, 'setError').mockImplementation(() => {});
findInput().trigger('keyup.enter', { metaKey: true });
@@ -297,8 +307,8 @@ describe('BoardForm', () => {
expect(mutate).toHaveBeenCalled();
await waitForPromises();
- expect(visitUrl).not.toHaveBeenCalled();
- expect(wrapper.vm.setError).toHaveBeenCalled();
+ expect(setBoardMock).not.toHaveBeenCalled();
+ expect(setErrorMock).toHaveBeenCalled();
});
});
diff --git a/spec/frontend/boards/components/boards_selector_spec.js b/spec/frontend/boards/components/boards_selector_spec.js
index f60d04af4fc..d91e81fe4d0 100644
--- a/spec/frontend/boards/components/boards_selector_spec.js
+++ b/spec/frontend/boards/components/boards_selector_spec.js
@@ -2,11 +2,10 @@ import { GlDropdown, GlLoadingIcon, GlDropdownSectionHeader } from '@gitlab/ui';
import Vue, { nextTick } from 'vue';
import VueApollo from 'vue-apollo';
import Vuex from 'vuex';
+import waitForPromises from 'helpers/wait_for_promises';
import { TEST_HOST } from 'spec/test_constants';
import BoardsSelector from '~/boards/components/boards_selector.vue';
import { BoardType } from '~/boards/constants';
-import groupBoardQuery from '~/boards/graphql/group_board.query.graphql';
-import projectBoardQuery from '~/boards/graphql/project_board.query.graphql';
import groupBoardsQuery from '~/boards/graphql/group_boards.query.graphql';
import projectBoardsQuery from '~/boards/graphql/project_boards.query.graphql';
import groupRecentBoardsQuery from '~/boards/graphql/group_recent_boards.query.graphql';
@@ -15,8 +14,7 @@ import defaultStore from '~/boards/stores';
import createMockApollo from 'helpers/mock_apollo_helper';
import { mountExtended } from 'helpers/vue_test_utils_helper';
import {
- mockGroupBoardResponse,
- mockProjectBoardResponse,
+ mockBoard,
mockGroupAllBoardsResponse,
mockProjectAllBoardsResponse,
mockGroupRecentBoardsResponse,
@@ -49,6 +47,7 @@ describe('BoardsSelector', () => {
},
state: {
boardType: isGroupBoard ? 'group' : 'project',
+ board: mockBoard,
},
});
};
@@ -65,9 +64,6 @@ describe('BoardsSelector', () => {
const getLoadingIcon = () => wrapper.findComponent(GlLoadingIcon);
const findDropdown = () => wrapper.findComponent(GlDropdown);
- const projectBoardQueryHandlerSuccess = jest.fn().mockResolvedValue(mockProjectBoardResponse);
- const groupBoardQueryHandlerSuccess = jest.fn().mockResolvedValue(mockGroupBoardResponse);
-
const projectBoardsQueryHandlerSuccess = jest
.fn()
.mockResolvedValue(mockProjectAllBoardsResponse);
@@ -92,8 +88,6 @@ describe('BoardsSelector', () => {
projectRecentBoardsQueryHandler = projectRecentBoardsQueryHandlerSuccess,
} = {}) => {
fakeApollo = createMockApollo([
- [projectBoardQuery, projectBoardQueryHandlerSuccess],
- [groupBoardQuery, groupBoardQueryHandlerSuccess],
[projectBoardsQuery, projectBoardsQueryHandler],
[groupBoardsQuery, groupBoardsQueryHandlerSuccess],
[projectRecentBoardsQuery, projectRecentBoardsQueryHandler],
@@ -133,12 +127,13 @@ describe('BoardsSelector', () => {
describe('loading', () => {
// we are testing loading state, so don't resolve responses until after the tests
afterEach(async () => {
- await nextTick();
+ await waitForPromises();
});
- it('shows loading spinner', () => {
+ it('shows loading spinner', async () => {
// Emits gl-dropdown show event to simulate the dropdown is opened at initialization time
findDropdown().vm.$emit('show');
+ await nextTick();
expect(getLoadingIcon().exists()).toBe(true);
expect(getDropdownHeaders()).toHaveLength(0);
@@ -251,23 +246,4 @@ describe('BoardsSelector', () => {
expect(notCalledHandler).not.toHaveBeenCalled();
});
});
-
- describe('fetching current board', () => {
- it.each`
- boardType | queryHandler | notCalledHandler
- ${BoardType.group} | ${groupBoardQueryHandlerSuccess} | ${projectBoardQueryHandlerSuccess}
- ${BoardType.project} | ${projectBoardQueryHandlerSuccess} | ${groupBoardQueryHandlerSuccess}
- `('fetches $boardType board', async ({ boardType, queryHandler, notCalledHandler }) => {
- createStore({
- isProjectBoard: boardType === BoardType.project,
- isGroupBoard: boardType === BoardType.group,
- });
- createComponent();
-
- await nextTick();
-
- expect(queryHandler).toHaveBeenCalled();
- expect(notCalledHandler).not.toHaveBeenCalled();
- });
- });
});
diff --git a/spec/frontend/boards/mock_data.js b/spec/frontend/boards/mock_data.js
index 26ad9790840..6ec39be5d29 100644
--- a/spec/frontend/boards/mock_data.js
+++ b/spec/frontend/boards/mock_data.js
@@ -144,30 +144,6 @@ export const mockProjectRecentBoardsResponse = {
},
};
-export const mockGroupBoardResponse = {
- data: {
- workspace: {
- board: {
- id: 'gid://gitlab/Board/1',
- name: 'Development',
- },
- __typename: 'Group',
- },
- },
-};
-
-export const mockProjectBoardResponse = {
- data: {
- workspace: {
- board: {
- id: 'gid://gitlab/Board/2',
- name: 'Development',
- },
- __typename: 'Project',
- },
- },
-};
-
export const mockAssigneesList = [
{
id: 2,
@@ -802,3 +778,15 @@ export const boardListQueryResponse = (issuesCount = 20) => ({
},
},
});
+
+export const epicBoardListQueryResponse = (totalWeight = 5) => ({
+ data: {
+ epicBoardList: {
+ __typename: 'EpicList',
+ id: 'gid://gitlab/Boards::EpicList/3',
+ metadata: {
+ totalWeight,
+ },
+ },
+ },
+});
diff --git a/spec/frontend/boards/stores/actions_spec.js b/spec/frontend/boards/stores/actions_spec.js
index eacf9db191e..e48b946ff1b 100644
--- a/spec/frontend/boards/stores/actions_spec.js
+++ b/spec/frontend/boards/stores/actions_spec.js
@@ -77,7 +77,7 @@ describe('fetchBoard', () => {
},
};
- it('should commit mutation RECEIVE_BOARD_SUCCESS and dispatch setBoardConfig on success', async () => {
+ it('should commit mutation REQUEST_CURRENT_BOARD and dispatch setBoard on success', async () => {
jest.spyOn(gqlClient, 'query').mockResolvedValue(queryResponse);
await testAction({
@@ -85,11 +85,10 @@ describe('fetchBoard', () => {
payload,
expectedMutations: [
{
- type: types.RECEIVE_BOARD_SUCCESS,
- payload: mockBoard,
+ type: types.REQUEST_CURRENT_BOARD,
},
],
- expectedActions: [{ type: 'setBoardConfig', payload: mockBoard }],
+ expectedActions: [{ type: 'setBoard', payload: mockBoard }],
});
});
@@ -101,6 +100,9 @@ describe('fetchBoard', () => {
payload,
expectedMutations: [
{
+ type: types.REQUEST_CURRENT_BOARD,
+ },
+ {
type: types.RECEIVE_BOARD_FAILURE,
},
],
@@ -133,6 +135,20 @@ describe('setBoardConfig', () => {
});
});
+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 } },
+ ],
+ });
+ });
+});
+
describe('setFilters', () => {
it.each([
[
@@ -172,7 +188,11 @@ describe('performSearch', () => {
{},
{},
[],
- [{ type: 'setFilters', payload: {} }, { type: 'fetchLists' }, { type: 'resetIssues' }],
+ [
+ { type: 'setFilters', payload: {} },
+ { type: 'fetchLists', payload: { resetLists: false } },
+ { type: 'resetIssues' },
+ ],
);
});
});
@@ -955,10 +975,6 @@ describe('fetchItemsForList', () => {
state,
[
{
- type: types.RESET_ITEMS_FOR_LIST,
- payload: listId,
- },
- {
type: types.REQUEST_ITEMS_FOR_LIST,
payload: { listId, fetchNext: false },
},
@@ -980,10 +996,6 @@ describe('fetchItemsForList', () => {
state,
[
{
- type: types.RESET_ITEMS_FOR_LIST,
- payload: listId,
- },
- {
type: types.REQUEST_ITEMS_FOR_LIST,
payload: { listId, fetchNext: false },
},
diff --git a/spec/frontend/boards/stores/mutations_spec.js b/spec/frontend/boards/stores/mutations_spec.js
index 738737bf4b6..7d79993a0ee 100644
--- a/spec/frontend/boards/stores/mutations_spec.js
+++ b/spec/frontend/boards/stores/mutations_spec.js
@@ -34,6 +34,14 @@ describe('Board Store Mutations', () => {
state = defaultState();
});
+ describe('REQUEST_CURRENT_BOARD', () => {
+ it('Should set isBoardLoading state to true', () => {
+ mutations[types.REQUEST_CURRENT_BOARD](state);
+
+ expect(state.isBoardLoading).toBe(true);
+ });
+ });
+
describe('RECEIVE_BOARD_SUCCESS', () => {
it('Should set board to state', () => {
mutations[types.RECEIVE_BOARD_SUCCESS](state, mockBoard);
@@ -292,24 +300,6 @@ describe('Board Store Mutations', () => {
});
});
- describe('RESET_ITEMS_FOR_LIST', () => {
- it('should remove issues from boardItemsByListId state', () => {
- const listId = 'gid://gitlab/List/1';
- const boardItemsByListId = {
- [listId]: [mockIssue.id],
- };
-
- state = {
- ...state,
- boardItemsByListId,
- };
-
- mutations[types.RESET_ITEMS_FOR_LIST](state, listId);
-
- expect(state.boardItemsByListId[listId]).toEqual([]);
- });
- });
-
describe('REQUEST_ITEMS_FOR_LIST', () => {
const listId = 'gid://gitlab/List/1';
const boardItemsByListId = {