Commit e3f23968 authored by Natalia Tepluhina's avatar Natalia Tepluhina Committed by Nicolò Maria Mezzopera

Make swimlanes choice persisting after board has been edited [RUN AS-IF-FOSS]

parent 4d647a21
......@@ -2,8 +2,9 @@
import { GlModal } from '@gitlab/ui';
import { __, s__ } from '~/locale';
import { deprecatedCreateFlash as Flash } from '~/flash';
import { visitUrl, stripFinalUrlSegment } from '~/lib/utils/url_utility';
import { getIdFromGraphQLId, convertToGraphQLId } from '~/graphql_shared/utils';
import { visitUrl } from '~/lib/utils/url_utility';
import { getParameterByName } from '~/lib/utils/common_utils';
import { convertToGraphQLId } from '~/graphql_shared/utils';
import boardsStore from '~/boards/stores/boards_store';
import { fullLabelId, fullBoardId } from '../boards_util';
......@@ -216,9 +217,15 @@ export default {
variables: { input: this.mutationVariables },
});
return this.board.id
? getIdFromGraphQLId(response.data.updateBoard.board.id)
: getIdFromGraphQLId(response.data.createBoard.board.id);
if (!this.board.id) {
return response.data.createBoard.board.webPath;
}
const path = response.data.updateBoard.board.webPath;
const param = getParameterByName('group_by')
? `?group_by=${getParameterByName('group_by')}`
: '';
return `${path}${param}`;
},
async submit() {
if (this.board.name.length === 0) return;
......@@ -239,9 +246,7 @@ export default {
}
} else {
try {
const path = await this.createOrUpdateBoard();
const strippedUrl = stripFinalUrlSegment(window.location.href);
const url = strippedUrl.includes('boards') ? `${path}` : `boards/${path}`;
const url = await this.createOrUpdateBoard();
visitUrl(url);
} catch {
Flash(this.$options.i18n.saveErrorMessage);
......
......@@ -2,6 +2,8 @@ mutation createBoard($input: CreateBoardInput!) {
createBoard(input: $input) {
board {
id
webPath
}
errors
}
}
......@@ -2,8 +2,8 @@ mutation UpdateBoard($input: UpdateBoardInput!) {
updateBoard(input: $input) {
board {
id
hideClosedList
hideBacklogList
webPath
}
errors
}
}
---
title: Resolve Grouping/swimlanes choice should persist after board has been edited
merge_request: 51317
author:
type: changed
......@@ -159,7 +159,7 @@ describe('BoardForm', () => {
beforeEach(() => {
mutate = jest.fn().mockResolvedValue({
data: {
createBoard: { board: { id: 'gid://gitlab/Board/123' } },
createBoard: { board: { id: 'gid://gitlab/Board/123', webPath: 'test-path' } },
},
});
});
......@@ -174,7 +174,6 @@ describe('BoardForm', () => {
});
it('calls a correct GraphQL mutation and redirects to correct page from existing board', async () => {
window.location = new URL('https://test/boards/1');
createComponent({ canAdminBoard: true });
fillForm();
......@@ -190,27 +189,7 @@ describe('BoardForm', () => {
});
await waitForPromises();
expect(visitUrl).toHaveBeenCalledWith('123');
});
it('calls a correct GraphQL mutation and redirects to correct page from boards list', async () => {
window.location = new URL('https://test/boards');
createComponent({ canAdminBoard: true });
fillForm();
await waitForPromises();
expect(mutate).toHaveBeenCalledWith({
mutation: createBoardMutation,
variables: {
input: expect.objectContaining({
name: 'test',
}),
},
});
await waitForPromises();
expect(visitUrl).toHaveBeenCalledWith('boards/123');
expect(visitUrl).toHaveBeenCalledWith('test-path');
});
it('shows an error flash if GraphQL mutation fails', async () => {
......@@ -261,10 +240,10 @@ describe('BoardForm', () => {
});
});
it('calls GraphQL mutation with correct parameters', async () => {
it('calls GraphQL mutation with correct parameters when issues are not grouped', async () => {
mutate = jest.fn().mockResolvedValue({
data: {
updateBoard: { board: { id: 'gid://gitlab/Board/321' } },
updateBoard: { board: { id: 'gid://gitlab/Board/321', webPath: 'test-path' } },
},
});
window.location = new URL('https://test/boards/1');
......@@ -284,7 +263,33 @@ describe('BoardForm', () => {
});
await waitForPromises();
expect(visitUrl).toHaveBeenCalledWith('321');
expect(visitUrl).toHaveBeenCalledWith('test-path');
});
it('calls GraphQL mutation with correct parameters when issues are grouped by epic', async () => {
mutate = jest.fn().mockResolvedValue({
data: {
updateBoard: { board: { id: 'gid://gitlab/Board/321', webPath: 'test-path' } },
},
});
window.location = new URL('https://test/boards/1?group_by=epic');
createComponent({ canAdminBoard: true });
findInput().trigger('keyup.enter', { metaKey: true });
await waitForPromises();
expect(mutate).toHaveBeenCalledWith({
mutation: updateBoardMutation,
variables: {
input: expect.objectContaining({
id: `gid://gitlab/Board/${currentBoard.id}`,
}),
},
});
await waitForPromises();
expect(visitUrl).toHaveBeenCalledWith('test-path?group_by=epic');
});
it('shows an error flash if GraphQL mutation fails', async () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment