Commit b6c57eb9 authored by Samantha Ming's avatar Samantha Ming

Configure Merge Widget "Squash commits"

Issue: https://gitlab.com/gitlab-org/gitlab/-/issues/17613

Modify the Squash commits in the Merge Widget
to take in account of the Squash Options
configuration set in the Project Setting.

This is Part 2 of the FE implementation
for the Configurable defaults for "Squash commits" option feature.
parent 9937adfe
...@@ -45,7 +45,8 @@ export default { ...@@ -45,7 +45,8 @@ export default {
isMakingRequest: false, isMakingRequest: false,
isMergingImmediately: false, isMergingImmediately: false,
commitMessage: this.mr.commitMessage, commitMessage: this.mr.commitMessage,
squashBeforeMerge: this.mr.squash, squashBeforeMerge: this.mr.squashIsSelected,
isSquashReadOnly: this.mr.squashIsReadonly,
successSvg, successSvg,
warningSvg, warningSvg,
squashCommitMessage: this.mr.squashCommitMessage, squashCommitMessage: this.mr.squashCommitMessage,
...@@ -106,7 +107,12 @@ export default { ...@@ -106,7 +107,12 @@ export default {
return this.isMergeButtonDisabled; return this.isMergeButtonDisabled;
}, },
shouldShowSquashBeforeMerge() { shouldShowSquashBeforeMerge() {
const { commitsCount, enableSquashBeforeMerge } = this.mr; const { commitsCount, enableSquashBeforeMerge, squashIsReadonly, squashIsSelected } = this.mr;
if (squashIsReadonly && !squashIsSelected) {
return false;
}
return enableSquashBeforeMerge && commitsCount > 1; return enableSquashBeforeMerge && commitsCount > 1;
}, },
shouldShowMergeControls() { shouldShowMergeControls() {
...@@ -344,7 +350,7 @@ export default { ...@@ -344,7 +350,7 @@ export default {
v-if="shouldShowSquashBeforeMerge" v-if="shouldShowSquashBeforeMerge"
v-model="squashBeforeMerge" v-model="squashBeforeMerge"
:help-path="mr.squashBeforeMergeHelpPath" :help-path="mr.squashBeforeMergeHelpPath"
:is-disabled="isMergeButtonDisabled" :is-disabled="isSquashReadOnly"
/> />
</template> </template>
<template v-else> <template v-else>
......
...@@ -30,7 +30,7 @@ export default { ...@@ -30,7 +30,7 @@ export default {
<template> <template>
<div class="inline"> <div class="inline">
<label> <label :class="{ 'gl-text-gray-600': isDisabled }" data-testid="squashLabel">
<input <input
:checked="value" :checked="value"
:disabled="isDisabled" :disabled="isDisabled"
......
...@@ -22,7 +22,10 @@ export default class MergeRequestStore { ...@@ -22,7 +22,10 @@ export default class MergeRequestStore {
const pipelineStatus = data.pipeline ? data.pipeline.details.status : null; const pipelineStatus = data.pipeline ? data.pipeline.details.status : null;
this.squash = data.squash; this.squash = data.squash;
this.squashIsEnabledByDefault = data.squash_enabled_by_default;
this.squashIsReadonly = data.squash_readonly;
this.enableSquashBeforeMerge = this.enableSquashBeforeMerge || true; this.enableSquashBeforeMerge = this.enableSquashBeforeMerge || true;
this.squashIsSelected = data.squash_readonly ? data.squash_on_merge : data.squash;
this.iid = data.iid; this.iid = data.iid;
this.title = data.title; this.title = data.title;
......
...@@ -34,6 +34,9 @@ describe('ReadyToMerge', () => { ...@@ -34,6 +34,9 @@ describe('ReadyToMerge', () => {
ciStatus: null, ciStatus: null,
sha: '12345678', sha: '12345678',
squash: false, squash: false,
squashIsEnabledByDefault: false,
squashIsReadonly: false,
squashIsSelected: false,
commitMessage: 'This is the commit message', commitMessage: 'This is the commit message',
squashCommitMessage: 'This is the squash commit message', squashCommitMessage: 'This is the squash commit message',
commitMessageWithDescription: 'This is the commit message description', commitMessageWithDescription: 'This is the commit message description',
......
...@@ -34,6 +34,9 @@ const createTestMr = customConfig => { ...@@ -34,6 +34,9 @@ const createTestMr = customConfig => {
ciStatus: null, ciStatus: null,
sha: '12345678', sha: '12345678',
squash: false, squash: false,
squashIsEnabledByDefault: false,
squashIsReadonly: false,
squashIsSelected: false,
commitMessage, commitMessage,
squashCommitMessage, squashCommitMessage,
commitMessageWithDescription, commitMessageWithDescription,
...@@ -694,6 +697,37 @@ describe('ReadyToMerge', () => { ...@@ -694,6 +697,37 @@ describe('ReadyToMerge', () => {
expect(findCheckboxElement().exists()).toBeFalsy(); expect(findCheckboxElement().exists()).toBeFalsy();
}); });
describe('squash options', () => {
it.each`
squashState | state | prop | expectation
${'squashIsReadonly'} | ${'enabled'} | ${'isDisabled'} | ${false}
${'squashIsSelected'} | ${'selected'} | ${'value'} | ${false}
${'squashIsSelected'} | ${'unselected'} | ${'value'} | ${false}
`(
'is $state when squashIsReadonly returns $expectation ',
({ squashState, prop, expectation }) => {
createLocalComponent({
mr: { commitsCount: 2, enableSquashBeforeMerge: true, [squashState]: expectation },
});
expect(findCheckboxElement().props(prop)).toBe(expectation);
},
);
it('is not rendered for "Do not allow" option', () => {
createLocalComponent({
mr: {
commitsCount: 2,
enableSquashBeforeMerge: true,
squashIsReadonly: true,
squashIsSelected: false,
},
});
expect(findCheckboxElement().exists()).toBe(false);
});
});
}); });
describe('commits count collapsible header', () => { describe('commits count collapsible header', () => {
...@@ -709,7 +743,7 @@ describe('ReadyToMerge', () => { ...@@ -709,7 +743,7 @@ describe('ReadyToMerge', () => {
mr: { mr: {
ffOnlyEnabled: true, ffOnlyEnabled: true,
enableSquashBeforeMerge: true, enableSquashBeforeMerge: true,
squash: true, squashIsSelected: true,
commitsCount: 2, commitsCount: 2,
}, },
}); });
...@@ -803,7 +837,7 @@ describe('ReadyToMerge', () => { ...@@ -803,7 +837,7 @@ describe('ReadyToMerge', () => {
createLocalComponent({ createLocalComponent({
mr: { mr: {
ffOnlyEnabled: true, ffOnlyEnabled: true,
squash: true, squashIsSelected: true,
enableSquashBeforeMerge: true, enableSquashBeforeMerge: true,
commitsCount: 2, commitsCount: 2,
}, },
...@@ -824,7 +858,7 @@ describe('ReadyToMerge', () => { ...@@ -824,7 +858,7 @@ describe('ReadyToMerge', () => {
createLocalComponent({ createLocalComponent({
mr: { mr: {
commitsCount: 2, commitsCount: 2,
squash: true, squashIsSelected: true,
enableSquashBeforeMerge: true, enableSquashBeforeMerge: true,
}, },
}); });
...@@ -854,7 +888,7 @@ describe('ReadyToMerge', () => { ...@@ -854,7 +888,7 @@ describe('ReadyToMerge', () => {
createLocalComponent({ createLocalComponent({
mr: { mr: {
commitsCount: 2, commitsCount: 2,
squash: true, squashIsSelected: true,
enableSquashBeforeMerge: true, enableSquashBeforeMerge: true,
}, },
}); });
...@@ -872,7 +906,7 @@ describe('ReadyToMerge', () => { ...@@ -872,7 +906,7 @@ describe('ReadyToMerge', () => {
it('should be rendered if squash is enabled and there is more than 1 commit', () => { it('should be rendered if squash is enabled and there is more than 1 commit', () => {
createLocalComponent({ createLocalComponent({
mr: { enableSquashBeforeMerge: true, squash: true, commitsCount: 2 }, mr: { enableSquashBeforeMerge: true, squashIsSelected: true, commitsCount: 2 },
}); });
expect(findCommitDropdownElement().exists()).toBeTruthy(); expect(findCommitDropdownElement().exists()).toBeTruthy();
......
...@@ -63,6 +63,27 @@ describe('Squash before merge component', () => { ...@@ -63,6 +63,27 @@ describe('Squash before merge component', () => {
}); });
}); });
describe('label', () => {
const findLabel = () => wrapper.find('[data-testid="squashLabel"]');
describe.each`
isDisabled | expectation
${true} | ${'grays out text if it is true'}
${false} | ${'does not gray out text if it is false'}
`('isDisabled prop', ({ isDisabled, expectation }) => {
beforeEach(() => {
createComponent({
value: false,
isDisabled,
});
});
it(expectation, () => {
expect(findLabel().classes('gl-text-gray-600')).toBe(isDisabled);
});
});
});
describe('about link', () => { describe('about link', () => {
it('is not rendered if no help path is passed', () => { it('is not rendered if no help path is passed', () => {
createComponent({ createComponent({
......
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