Commit ec9a5dc8 authored by Mireya Andres's avatar Mireya Andres Committed by Fabio Pitino

Enable Merge Train checkbox based on Merge Pipelines checkbox

The Merge Train checkbox is enabled only when the Merge Pipelines
checkbox is enabled and checked. The initial state is set by querying
`ciCdSettings` via GraphQL.
parent 141b45f3
- form = local_assigns.fetch(:form)
.form-group
.form-group#project-merge-options{ data: { project_full_path: @project.full_path } }
%b= s_('ProjectSettings|Merge options')
%p.text-secondary= s_('ProjectSettings|Additional merge request capabilities that influence how and when merges will be performed')
= render_if_exists 'projects/merge_pipelines_settings', form: form
......
......@@ -3,6 +3,7 @@
import '~/pages/projects/edit';
import mountApprovals from 'ee/approvals/mount_project_settings';
import initProjectAdjournedDeleteButton from 'ee/projects/project_adjourned_delete_button';
import initMergeOptionSettings from 'ee/pages/projects/edit/merge_options';
import UsersSelect from '~/users_select';
import UserCallout from '~/user_callout';
import groupsSelect from '~/groups_select';
......@@ -15,3 +16,4 @@ new UserCallout({ className: 'js-mr-approval-callout' });
mountApprovals(document.getElementById('js-mr-approvals-settings'));
initProjectAdjournedDeleteButton();
initMergeOptionSettings();
import gql from 'graphql-tag';
import createDefaultClient from '~/lib/graphql';
const containerEl = document.querySelector('#project-merge-options');
const mergePipelinesCheckbox = document.querySelector('.js-merge-options-merge-pipelines');
const mergeTrainsCheckbox = document.querySelector('.js-merge-options-merge-trains');
const getCiCdSettingsQuery = (projectFullPath) =>
gql`
query {
project(fullPath:"${projectFullPath}") {
id,
ciCdSettings {
mergePipelinesEnabled,
mergeTrainsEnabled,
}
}
}
`;
const disableMergeTrains = () => {
mergeTrainsCheckbox.disabled = true;
mergeTrainsCheckbox.checked = false;
};
export default function () {
const { projectFullPath } = containerEl.dataset;
const defaultClient = createDefaultClient();
defaultClient
.query({
query: getCiCdSettingsQuery(projectFullPath),
})
.then((result) => {
const { mergePipelinesEnabled, mergeTrainsEnabled } = result?.data?.project?.ciCdSettings;
mergePipelinesCheckbox.checked = mergePipelinesEnabled;
mergeTrainsCheckbox.checked = mergeTrainsEnabled;
if (!mergePipelinesEnabled) {
disableMergeTrains();
}
})
.catch(() => {
if (!mergePipelinesCheckbox.checked) {
disableMergeTrains();
}
});
mergePipelinesCheckbox.addEventListener('change', () => {
mergeTrainsCheckbox.disabled = !mergePipelinesCheckbox.checked;
if (!mergePipelinesCheckbox.checked) {
mergeTrainsCheckbox.checked = false;
}
});
}
- return unless merge_trains_available?
.form-check
= form.check_box :merge_trains_enabled, class: 'form-check-input', data: { qa_selector: 'merge_trains_checkbox' }
= form.label :merge_trains_enabled, class: 'form-check-label' do
= s_('ProjectSettings|Enable merge trains.')
.text-secondary.mb-2
= s_('ProjectSettings|When approved for merge, merge requests are queued and pipelines validate the combined results of the source and target branches before merge.')
= link_to sprite_icon('question-o'),
help_page_path('ci/merge_request_pipelines/pipelines_for_merged_results/merge_trains/index.md',
anchor: 'merge-trains'),
target: '_blank',
rel: 'noopener noreferer'
.gl-pl-6
= form.check_box :merge_trains_enabled, class: 'form-check-input js-merge-options-merge-trains gl-pl-6', data: { qa_selector: 'merge_trains_checkbox' }
= form.label :merge_trains_enabled, class: 'form-check-label' do
= s_('ProjectSettings|Enable merge trains.')
.text-secondary.mb-2
= s_('ProjectSettings|When approved for merge, merge requests are queued and pipelines validate the combined results of the source and target branches before merge.')
= link_to sprite_icon('question-o'),
help_page_path('ci/merge_request_pipelines/pipelines_for_merged_results/merge_trains/index.md',
anchor: 'merge-trains'),
target: '_blank',
rel: 'noopener noreferer'
---
title: Enable Merge Train checkbox based on Merge Pipelines checkbox
merge_request: 51233
author:
type: changed
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Disable Merge Trains Setting', :js do
let_it_be_with_reload(:project) { create(:project) }
let_it_be(:user) { create(:user) }
before do
stub_licensed_features(merge_pipelines: true, merge_trains: true)
project.add_maintainer(user)
sign_in(user)
end
shared_examples 'loads correct checkbox state' do
it 'merge pipelines checkbox is always enabled' do
expect(find('#project_merge_pipelines_enabled')).not_to be_disabled
end
it 'merge trains checkbox is enabled only when merge_pipelines_enabled is true' do
expect(find('#project_merge_trains_enabled').disabled?).not_to eq(project.merge_pipelines_enabled)
end
end
context 'when visiting the project settings page' do
using RSpec::Parameterized::TableSyntax
where(:merge_pipelines_setting, :merge_trains_setting) do
true | true
true | false
false | true
false | false
end
with_them do
before do
project.update!(merge_pipelines_enabled: merge_pipelines_setting, merge_trains_enabled: merge_trains_setting)
visit edit_project_path(project)
wait_for_requests
end
include_examples 'loads correct checkbox state'
end
end
context 'when merge pipelines is enabled' do
before do
project.update!(merge_pipelines_enabled: true)
visit edit_project_path(project)
wait_for_requests
end
include_examples 'loads correct checkbox state'
it "checking merge trains checkbox doesn't affect merge pipelines checkbox" do
check('Enable merge trains.')
expect(find('#project_merge_trains_enabled')).to be_checked
expect(find('#project_merge_pipelines_enabled')).not_to be_disabled
expect(find('#project_merge_pipelines_enabled')).to be_checked
end
it 'unchecking merge pipelines checkbox disables merge trains checkbox' do
uncheck('Enable merged results pipelines.')
expect(find('#project_merge_pipelines_enabled')).not_to be_checked
expect(find('#project_merge_trains_enabled')).to be_disabled
end
it 'unchecking merge pipelines checkbox unchecks merge trains checkbox if it was previously checked' do
check('Enable merge trains.')
uncheck('Enable merged results pipelines.')
expect(find('#project_merge_pipelines_enabled')).not_to be_checked
expect(find('#project_merge_trains_enabled')).to be_disabled
expect(find('#project_merge_trains_enabled')).not_to be_checked
end
end
context 'when merge pipelines is disabled' do
before do
project.update!(merge_pipelines_enabled: false)
visit edit_project_path(project)
wait_for_requests
end
include_examples 'loads correct checkbox state'
it 'checking merge pipelines checkbox enables merge trains checkbox' do
check('Enable merged results pipelines.')
expect(find('#project_merge_pipelines_enabled')).to be_checked
expect(find('#project_merge_trains_enabled')).not_to be_disabled
end
it 'checking merge pipelines checkbox should leave merge trains checkbox unchecked' do
check('Enable merged results pipelines.')
expect(find('#project_merge_pipelines_enabled')).to be_checked
expect(find('#project_merge_trains_enabled')).not_to be_checked
end
end
context 'when both merge pipelines and merge trains are enabled' do
before do
project.update!(merge_pipelines_enabled: true, merge_trains_enabled: true)
visit edit_project_path(project)
wait_for_requests
end
include_examples 'loads correct checkbox state'
it 'unchecking merge pipelines checkbox disables and unchecks merge trains checkbox' do
uncheck('Enable merged results pipelines.')
expect(find('#project_merge_pipelines_enabled')).not_to be_checked
expect(find('#project_merge_trains_enabled')).to be_disabled
expect(find('#project_merge_trains_enabled')).not_to be_checked
end
it "unchecking merge trains checkbox doesn't affect merge pipelines checkbox" do
uncheck('Enable merge trains.')
expect(find('#project_merge_trains_enabled')).not_to be_checked
expect(find('#project_merge_pipelines_enabled')).not_to be_disabled
expect(find('#project_merge_pipelines_enabled')).to be_checked
end
end
end
......@@ -9,12 +9,14 @@ RSpec.describe 'User manages merge trains option', :js do
before do
stub_licensed_features(merge_pipelines: true, merge_trains: true)
project.update!(merge_pipelines_enabled: true)
project.add_maintainer(user)
sign_in(user)
end
it 'sees unchecked merge trains checkbox' do
visit edit_project_path(project)
wait_for_requests
expect(page.find('#project_merge_trains_enabled')).not_to be_checked
end
......@@ -22,6 +24,7 @@ RSpec.describe 'User manages merge trains option', :js do
context 'when user enabled the checkbox' do
before do
visit edit_project_path(project)
wait_for_requests
check('Enable merge trains.')
end
......
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