Commit 6e5717fb authored by Ezekiel Kigbo's avatar Ezekiel Kigbo

Update feature specs

Ensure we dont display the confirmation modal
if the feature flag is off or there are no forks
available.
parent eb120c22
......@@ -170,6 +170,11 @@ export default {
type: String,
required: true,
},
showVisibilityConfirmModal: {
type: Boolean,
required: true,
default: false,
},
},
data() {
const defaults = {
......@@ -282,7 +287,10 @@ export default {
return this.visibilityLevel !== visibilityOptions.PUBLIC;
},
isVisibilityReduced() {
return this.visibilityLevel < this.currentSettings.visibilityLevel;
return (
this.showVisibilityConfirmModal &&
this.visibilityLevel < this.currentSettings.visibilityLevel
);
},
},
......
import Vue from 'vue';
import { parseBoolean } from '~/lib/utils/common_utils';
import settingsPanel from './components/settings_panel.vue';
export default function initProjectPermissionsSettings() {
......@@ -11,22 +12,25 @@ export default function initProjectPermissionsSettings() {
additionalInformation,
confirmDangerMessage,
confirmButtonText,
showVisibilityConfirmModal,
htmlConfirmationMessage,
phrase: confirmationPhrase,
} = mountPoint.dataset;
return new Vue({
el: mountPoint,
provide: {
htmlConfirmationMessage: true,
additionalInformation,
confirmDangerMessage,
confirmButtonText,
htmlConfirmationMessage: parseBoolean(htmlConfirmationMessage),
},
render: (createElement) =>
createElement(settingsPanel, {
props: {
...componentProps,
confirmationPhrase,
showVisibilityConfirmModal: parseBoolean(showVisibilityConfirmModal),
},
on: {
confirm: () => {
......
......@@ -680,7 +680,8 @@ module ProjectsHelper
confirm_danger_message: confirm_reduce_visibility_message(project),
phrase: project.full_path,
additional_information: _('Note: current forks will keep their visibility level.'),
html_confirmation_message: true
html_confirmation_message: true.to_s,
show_visibility_confirm_modal: show_visibility_confirm_modal?(project).to_s
}
end
......
- strong_start = "<strong>".html_safe
- strong_end = "</strong>".html_safe
-# TODO: we should remove this
.modal.js-confirm-project-visiblity{ tabindex: -1 }
.modal-dialog
.modal-content
......
......@@ -5,14 +5,6 @@ require 'spec_helper'
RSpec.describe 'User changes public project visibility', :js do
include ProjectForksHelper
before do
fork_project(project, project.owner)
sign_in(project.owner)
visit edit_project_path(project)
end
shared_examples 'changing visibility to private' do
it 'requires confirmation' do
visibility_select = first('.project-feature-controls .select-control')
......@@ -34,6 +26,30 @@ RSpec.describe 'User changes public project visibility', :js do
end
end
shared_examples 'does not require confirmation' do
it 'saves without confirmation' do
visibility_select = first('.project-feature-controls .select-control')
visibility_select.select('Private')
page.within('#js-shared-permissions') do
click_button 'Save changes'
end
wait_for_requests
expect(project.reload).to be_private
end
end
context 'when the project has forks' do
before do
fork_project(project, project.owner)
sign_in(project.owner)
visit edit_project_path(project)
end
context 'when a project is public' do
let(:project) { create(:project, :empty_repo, :public) }
......@@ -45,4 +61,50 @@ RSpec.describe 'User changes public project visibility', :js do
it_behaves_like 'changing visibility to private'
end
context 'when the visibility level is untouched' do
let(:project) { create(:project, :empty_repo, :public) }
it 'saves without confirmation' do
expect(page).to have_selector('.js-emails-disabled', visible: true)
find('.js-emails-disabled input[type="checkbox"]').click
page.within('#js-shared-permissions') do
click_button 'Save changes'
end
wait_for_requests
expect(project.reload).to be_public
end
end
end
context 'when the project is not forked' do
let(:project) { create(:project, :empty_repo, :public) }
before do
sign_in(project.owner)
visit edit_project_path(project)
end
it_behaves_like 'does not require confirmation'
end
context 'with unlink_fork_network_upon_visibility_decrease = false' do
let(:project) { create(:project, :empty_repo, :public) }
before do
stub_feature_flags(unlink_fork_network_upon_visibility_decrease: false)
fork_project(project, project.owner)
sign_in(project.owner)
visit edit_project_path(project)
end
it_behaves_like 'does not require confirmation'
end
end
......@@ -49,6 +49,7 @@ const defaultProps = {
packagesHelpPath: '/help/user/packages/index',
requestCveAvailable: true,
confirmationPhrase: 'my-fake-project',
showVisibilityConfirmModal: false,
};
describe('Settings Panel', () => {
......@@ -181,7 +182,7 @@ describe('Settings Panel', () => {
expect(findRequestAccessEnabledInput().exists()).toBe(false);
});
it('should render the confirmation dialog if the visibility is reduced', async () => {
it('does not require confirmation if the visibility is reduced', async () => {
wrapper = mountComponent({
currentSettings: { visibilityLevel: visibilityOptions.INTERNAL },
});
......@@ -190,8 +191,34 @@ describe('Settings Panel', () => {
await findProjectVisibilityLevelInput().setValue(visibilityOptions.PRIVATE);
expect(findConfirmDangerButton().exists()).toBe(false);
});
describe('showVisibilityConfirmModal=true', () => {
beforeEach(() => {
wrapper = mountComponent({
currentSettings: { visibilityLevel: visibilityOptions.INTERNAL },
showVisibilityConfirmModal: true,
});
});
it('will render the confirmation dialog if the visibility is reduced', async () => {
expect(findConfirmDangerButton().exists()).toBe(false);
await findProjectVisibilityLevelInput().setValue(visibilityOptions.PRIVATE);
expect(findConfirmDangerButton().exists()).toBe(true);
});
it('emits the `confirm` event when the reduce visibility warning is confirmed', async () => {
expect(wrapper.emitted('confirm')).toBeUndefined();
await findProjectVisibilityLevelInput().setValue(visibilityOptions.PRIVATE);
await findConfirmDangerButton().vm.$emit('confirm');
expect(wrapper.emitted('confirm').length).toBe(1);
});
});
});
describe('Issues settings', () => {
......
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