Commit 0daa0e44 authored by Simon Knox's avatar Simon Knox

Merge branch 'psi-rollover' into 'master'

Fix cadence roll over issues checkbox

See merge request gitlab-org/gitlab!74753
parents 8ed0987b 147ca147
...@@ -145,6 +145,7 @@ export default { ...@@ -145,6 +145,7 @@ export default {
id, id,
title: this.title, title: this.title,
automatic: this.automatic, automatic: this.automatic,
rollOver: this.rollOver,
startDate: this.startDate, startDate: this.startDate,
durationInWeeks: this.durationInWeeks, durationInWeeks: this.durationInWeeks,
active: true, active: true,
......
...@@ -4,6 +4,7 @@ import Vue, { nextTick } from 'vue'; ...@@ -4,6 +4,7 @@ import Vue, { nextTick } from 'vue';
import VueApollo from 'vue-apollo'; import VueApollo from 'vue-apollo';
import IterationCadenceForm from 'ee/iterations/components/iteration_cadence_form.vue'; import IterationCadenceForm from 'ee/iterations/components/iteration_cadence_form.vue';
import createCadence from 'ee/iterations/queries/cadence_create.mutation.graphql'; import createCadence from 'ee/iterations/queries/cadence_create.mutation.graphql';
import updateCadence from 'ee/iterations/queries/cadence_update.mutation.graphql';
import getCadence from 'ee/iterations/queries/iteration_cadence.query.graphql'; import getCadence from 'ee/iterations/queries/iteration_cadence.query.graphql';
import createMockApollo from 'helpers/mock_apollo_helper'; import createMockApollo from 'helpers/mock_apollo_helper';
import { TEST_HOST } from 'helpers/test_constants'; import { TEST_HOST } from 'helpers/test_constants';
...@@ -50,8 +51,16 @@ describe('Iteration cadence form', () => { ...@@ -50,8 +51,16 @@ describe('Iteration cadence form', () => {
}, },
}; };
function createComponent({ query = createCadence, resolverMock } = {}) { function createComponent({
const apolloProvider = createMockApolloProvider([[query, resolverMock]]); query = getCadence,
resolverMock,
mutation = createCadence,
mutationMock,
} = {}) {
const apolloProvider = createMockApolloProvider([
[query, resolverMock],
[mutation, mutationMock],
]);
wrapper = extendedWrapper( wrapper = extendedWrapper(
mount(IterationCadenceForm, { mount(IterationCadenceForm, {
apolloProvider, apolloProvider,
...@@ -74,6 +83,7 @@ describe('Iteration cadence form', () => { ...@@ -74,6 +83,7 @@ describe('Iteration cadence form', () => {
const findAutomatedSchedulingGroup = () => wrapper.findAllComponents(GlFormGroup).at(1); const findAutomatedSchedulingGroup = () => wrapper.findAllComponents(GlFormGroup).at(1);
const findStartDateGroup = () => wrapper.findAllComponents(GlFormGroup).at(2); const findStartDateGroup = () => wrapper.findAllComponents(GlFormGroup).at(2);
const findDurationGroup = () => wrapper.findAllComponents(GlFormGroup).at(3); const findDurationGroup = () => wrapper.findAllComponents(GlFormGroup).at(3);
const findRollOverGroup = () => wrapper.findAllComponents(GlFormGroup).at(4);
const findFutureIterationsGroup = () => wrapper.findAllComponents(GlFormGroup).at(5); const findFutureIterationsGroup = () => wrapper.findAllComponents(GlFormGroup).at(5);
const findError = () => wrapper.findComponent(GlAlert); const findError = () => wrapper.findComponent(GlAlert);
...@@ -82,6 +92,7 @@ describe('Iteration cadence form', () => { ...@@ -82,6 +92,7 @@ describe('Iteration cadence form', () => {
const findStartDate = () => wrapper.find('#cadence-start-date'); const findStartDate = () => wrapper.find('#cadence-start-date');
const findFutureIterations = () => wrapper.find('#cadence-schedule-future-iterations'); const findFutureIterations = () => wrapper.find('#cadence-schedule-future-iterations');
const findDuration = () => wrapper.find('#cadence-duration'); const findDuration = () => wrapper.find('#cadence-duration');
const findRollOver = () => wrapper.find('#cadence-rollover-issues');
const findDescription = () => wrapper.find('#cadence-description'); const findDescription = () => wrapper.find('#cadence-description');
const setTitle = (value) => findTitle().vm.$emit('input', value); const setTitle = (value) => findTitle().vm.$emit('input', value);
...@@ -89,7 +100,13 @@ describe('Iteration cadence form', () => { ...@@ -89,7 +100,13 @@ describe('Iteration cadence form', () => {
const setFutureIterations = (value) => findFutureIterations().vm.$emit('input', value); const setFutureIterations = (value) => findFutureIterations().vm.$emit('input', value);
const setDuration = (value) => findDuration().vm.$emit('input', value); const setDuration = (value) => findDuration().vm.$emit('input', value);
const setAutomaticValue = (value) => { const setAutomaticValue = (value) => {
const checkbox = findAutomatedSchedulingGroup().find(GlFormCheckbox).vm; const checkbox = findAutomatedSchedulingGroup().findComponent(GlFormCheckbox).vm;
checkbox.$emit('input', value);
checkbox.$emit('change', value);
};
const setRollOver = (value) => {
const checkbox = findRollOverGroup().findComponent(GlFormCheckbox).vm;
checkbox.$emit('input', value); checkbox.$emit('input', value);
checkbox.$emit('change', value); checkbox.$emit('change', value);
}; };
...@@ -108,11 +125,11 @@ describe('Iteration cadence form', () => { ...@@ -108,11 +125,11 @@ describe('Iteration cadence form', () => {
const clickCancel = () => findCancelButton().vm.$emit('click'); const clickCancel = () => findCancelButton().vm.$emit('click');
describe('Create cadence', () => { describe('Create cadence', () => {
let resolverMock; let mutationMock;
beforeEach(() => { beforeEach(() => {
resolverMock = jest.fn().mockResolvedValue(createMutationSuccess); mutationMock = jest.fn().mockResolvedValue(createMutationSuccess);
createComponent({ resolverMock }); createComponent({ mutationMock });
}); });
it('cancel button links to list page', () => { it('cancel button links to list page', () => {
...@@ -125,12 +142,14 @@ describe('Iteration cadence form', () => { ...@@ -125,12 +142,14 @@ describe('Iteration cadence form', () => {
const title = 'Iteration 5'; const title = 'Iteration 5';
const startDate = '2020-05-05'; const startDate = '2020-05-05';
const durationInWeeks = 2; const durationInWeeks = 2;
const rollOver = true;
const iterationsInAdvance = 6; const iterationsInAdvance = 6;
it('triggers mutation with form data', async () => { it('triggers mutation with form data', async () => {
setTitle(title); setTitle(title);
setStartDate(startDate); setStartDate(startDate);
setDuration(durationInWeeks); setDuration(durationInWeeks);
setRollOver(rollOver);
setFutureIterations(iterationsInAdvance); setFutureIterations(iterationsInAdvance);
clickSave(); clickSave();
...@@ -138,13 +157,14 @@ describe('Iteration cadence form', () => { ...@@ -138,13 +157,14 @@ describe('Iteration cadence form', () => {
await nextTick(); await nextTick();
expect(findError().exists()).toBe(false); expect(findError().exists()).toBe(false);
expect(resolverMock).toHaveBeenCalledWith({ expect(mutationMock).toHaveBeenCalledWith({
input: { input: {
groupPath, groupPath,
title, title,
automatic: true, automatic: true,
startDate, startDate,
durationInWeeks, durationInWeeks,
rollOver,
iterationsInAdvance, iterationsInAdvance,
active: true, active: true,
description: '', description: '',
...@@ -173,7 +193,7 @@ describe('Iteration cadence form', () => { ...@@ -173,7 +193,7 @@ describe('Iteration cadence form', () => {
it('does not submit if required fields missing', () => { it('does not submit if required fields missing', () => {
clickSave(); clickSave();
expect(resolverMock).not.toHaveBeenCalled(); expect(mutationMock).not.toHaveBeenCalled();
expect(findTitleGroup().text()).toContain('This field is required'); expect(findTitleGroup().text()).toContain('This field is required');
expect(findStartDateGroup().text()).toContain('This field is required'); expect(findStartDateGroup().text()).toContain('This field is required');
expect(findDurationGroup().text()).toContain('This field is required'); expect(findDurationGroup().text()).toContain('This field is required');
...@@ -181,8 +201,8 @@ describe('Iteration cadence form', () => { ...@@ -181,8 +201,8 @@ describe('Iteration cadence form', () => {
}); });
it('loading=false on error', async () => { it('loading=false on error', async () => {
resolverMock = jest.fn().mockResolvedValue(createMutationFailure); mutationMock = jest.fn().mockResolvedValue(createMutationFailure);
createComponent({ resolverMock }); createComponent({ mutationMock });
clickSave(); clickSave();
...@@ -226,12 +246,13 @@ describe('Iteration cadence form', () => { ...@@ -226,12 +246,13 @@ describe('Iteration cadence form', () => {
await nextTick(); await nextTick();
expect(resolverMock).toHaveBeenCalledWith({ expect(mutationMock).toHaveBeenCalledWith({
input: { input: {
groupPath, groupPath,
title, title,
automatic: false, automatic: false,
startDate, startDate,
rollOver: false,
durationInWeeks: 0, durationInWeeks: 0,
iterationsInAdvance: 0, iterationsInAdvance: 0,
description: '', description: '',
...@@ -249,11 +270,12 @@ describe('Iteration cadence form', () => { ...@@ -249,11 +270,12 @@ describe('Iteration cadence form', () => {
describe('Edit cadence', () => { describe('Edit cadence', () => {
const query = getCadence; const query = getCadence;
const resolverMock = jest.fn().mockResolvedValue(getCadenceSuccess); const resolverMock = jest.fn().mockResolvedValue(getCadenceSuccess);
const mutationMock = jest.fn().mockResolvedValue(createMutationSuccess);
beforeEach(() => { beforeEach(() => {
$router.currentRoute.params.cadenceId = id; $router.currentRoute.params.cadenceId = id;
createComponent({ query, resolverMock }); createComponent({ query, resolverMock, mutation: updateCadence, mutationMock });
}); });
afterEach(() => { afterEach(() => {
...@@ -280,7 +302,7 @@ describe('Iteration cadence form', () => { ...@@ -280,7 +302,7 @@ describe('Iteration cadence form', () => {
}); });
it('fills fields with existing cadence info after loading', async () => { it('fills fields with existing cadence info after loading', async () => {
createComponent({ query, resolverMock }); createComponent({ query, resolverMock, mutation: updateCadence });
await waitForPromises(); await waitForPromises();
...@@ -288,8 +310,9 @@ describe('Iteration cadence form', () => { ...@@ -288,8 +310,9 @@ describe('Iteration cadence form', () => {
expect(findTitle().element.value).toBe(iterationCadence.title); expect(findTitle().element.value).toBe(iterationCadence.title);
expect(findStartDate().element.value).toBe(iterationCadence.startDate); expect(findStartDate().element.value).toBe(iterationCadence.startDate);
expect(findFutureIterations().element.value).toBe(iterationCadence.iterationsInAdvance); expect(findFutureIterations().element.value).toBe(`${iterationCadence.iterationsInAdvance}`);
expect(findDuration().element.value).toBe(iterationCadence.durationInWeeks); expect(findDuration().element.value).toBe(`${iterationCadence.durationInWeeks}`);
expect(findRollOver().element.checked).toBe(iterationCadence.rollOver);
expect(findDescription().element.value).toBe(iterationCadence.description); expect(findDescription().element.value).toBe(iterationCadence.description);
}); });
...@@ -300,5 +323,22 @@ describe('Iteration cadence form', () => { ...@@ -300,5 +323,22 @@ describe('Iteration cadence form', () => {
expect(findSaveAndStartButton().exists()).toBe(false); expect(findSaveAndStartButton().exists()).toBe(false);
}); });
it('updates roll over issues checkbox', async () => {
const rollOver = true;
setRollOver(rollOver);
clickSave();
await nextTick();
expect(findError().exists()).toBe(false);
expect(mutationMock).toHaveBeenCalledWith({
input: {
...iterationCadence,
rollOver,
},
});
});
}); });
}); });
...@@ -38,15 +38,15 @@ export const mockProjectIterations = { ...@@ -38,15 +38,15 @@ export const mockProjectIterations = {
}; };
export const manualIterationCadence = { export const manualIterationCadence = {
active: true,
id: `gid://gitlab/Iterations::Cadence/72`, id: `gid://gitlab/Iterations::Cadence/72`,
title: 'A manual iteration cadence', title: 'A manual iteration cadence',
automatic: true, automatic: true,
rollOver: false, rollOver: false,
durationInWeeks: '3', durationInWeeks: 3,
description: 'The words', description: 'The words',
duration: '3',
startDate: '2020-06-28', startDate: '2020-06-28',
iterationsInAdvance: '2', iterationsInAdvance: 2,
}; };
export const createMutationSuccess = { export const createMutationSuccess = {
......
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