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 { ...@@ -170,6 +170,11 @@ export default {
type: String, type: String,
required: true, required: true,
}, },
showVisibilityConfirmModal: {
type: Boolean,
required: true,
default: false,
},
}, },
data() { data() {
const defaults = { const defaults = {
...@@ -282,7 +287,10 @@ export default { ...@@ -282,7 +287,10 @@ export default {
return this.visibilityLevel !== visibilityOptions.PUBLIC; return this.visibilityLevel !== visibilityOptions.PUBLIC;
}, },
isVisibilityReduced() { isVisibilityReduced() {
return this.visibilityLevel < this.currentSettings.visibilityLevel; return (
this.showVisibilityConfirmModal &&
this.visibilityLevel < this.currentSettings.visibilityLevel
);
}, },
}, },
......
import Vue from 'vue'; import Vue from 'vue';
import { parseBoolean } from '~/lib/utils/common_utils';
import settingsPanel from './components/settings_panel.vue'; import settingsPanel from './components/settings_panel.vue';
export default function initProjectPermissionsSettings() { export default function initProjectPermissionsSettings() {
...@@ -11,22 +12,25 @@ export default function initProjectPermissionsSettings() { ...@@ -11,22 +12,25 @@ export default function initProjectPermissionsSettings() {
additionalInformation, additionalInformation,
confirmDangerMessage, confirmDangerMessage,
confirmButtonText, confirmButtonText,
showVisibilityConfirmModal,
htmlConfirmationMessage,
phrase: confirmationPhrase, phrase: confirmationPhrase,
} = mountPoint.dataset; } = mountPoint.dataset;
return new Vue({ return new Vue({
el: mountPoint, el: mountPoint,
provide: { provide: {
htmlConfirmationMessage: true,
additionalInformation, additionalInformation,
confirmDangerMessage, confirmDangerMessage,
confirmButtonText, confirmButtonText,
htmlConfirmationMessage: parseBoolean(htmlConfirmationMessage),
}, },
render: (createElement) => render: (createElement) =>
createElement(settingsPanel, { createElement(settingsPanel, {
props: { props: {
...componentProps, ...componentProps,
confirmationPhrase, confirmationPhrase,
showVisibilityConfirmModal: parseBoolean(showVisibilityConfirmModal),
}, },
on: { on: {
confirm: () => { confirm: () => {
......
...@@ -680,7 +680,8 @@ module ProjectsHelper ...@@ -680,7 +680,8 @@ module ProjectsHelper
confirm_danger_message: confirm_reduce_visibility_message(project), confirm_danger_message: confirm_reduce_visibility_message(project),
phrase: project.full_path, phrase: project.full_path,
additional_information: _('Note: current forks will keep their visibility level.'), 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 end
......
- strong_start = "<strong>".html_safe - strong_start = "<strong>".html_safe
- strong_end = "</strong>".html_safe - strong_end = "</strong>".html_safe
-# TODO: we should remove this
.modal.js-confirm-project-visiblity{ tabindex: -1 } .modal.js-confirm-project-visiblity{ tabindex: -1 }
.modal-dialog .modal-dialog
.modal-content .modal-content
......
...@@ -5,14 +5,6 @@ require 'spec_helper' ...@@ -5,14 +5,6 @@ require 'spec_helper'
RSpec.describe 'User changes public project visibility', :js do RSpec.describe 'User changes public project visibility', :js do
include ProjectForksHelper 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 shared_examples 'changing visibility to private' do
it 'requires confirmation' do it 'requires confirmation' do
visibility_select = first('.project-feature-controls .select-control') visibility_select = first('.project-feature-controls .select-control')
...@@ -34,15 +26,85 @@ RSpec.describe 'User changes public project visibility', :js do ...@@ -34,15 +26,85 @@ RSpec.describe 'User changes public project visibility', :js do
end end
end end
context 'when a project is public' do 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) }
it_behaves_like 'changing visibility to private'
end
context 'when the project is internal' do
let(:project) { create(:project, :empty_repo, :internal) }
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) } let(:project) { create(:project, :empty_repo, :public) }
it_behaves_like 'changing visibility to private' before do
sign_in(project.owner)
visit edit_project_path(project)
end
it_behaves_like 'does not require confirmation'
end end
context 'when the project is internal' do context 'with unlink_fork_network_upon_visibility_decrease = false' do
let(:project) { create(:project, :empty_repo, :internal) } 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 'changing visibility to private' it_behaves_like 'does not require confirmation'
end end
end end
...@@ -49,6 +49,7 @@ const defaultProps = { ...@@ -49,6 +49,7 @@ const defaultProps = {
packagesHelpPath: '/help/user/packages/index', packagesHelpPath: '/help/user/packages/index',
requestCveAvailable: true, requestCveAvailable: true,
confirmationPhrase: 'my-fake-project', confirmationPhrase: 'my-fake-project',
showVisibilityConfirmModal: false,
}; };
describe('Settings Panel', () => { describe('Settings Panel', () => {
...@@ -181,7 +182,7 @@ describe('Settings Panel', () => { ...@@ -181,7 +182,7 @@ describe('Settings Panel', () => {
expect(findRequestAccessEnabledInput().exists()).toBe(false); 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({ wrapper = mountComponent({
currentSettings: { visibilityLevel: visibilityOptions.INTERNAL }, currentSettings: { visibilityLevel: visibilityOptions.INTERNAL },
}); });
...@@ -190,7 +191,33 @@ describe('Settings Panel', () => { ...@@ -190,7 +191,33 @@ describe('Settings Panel', () => {
await findProjectVisibilityLevelInput().setValue(visibilityOptions.PRIVATE); await findProjectVisibilityLevelInput().setValue(visibilityOptions.PRIVATE);
expect(findConfirmDangerButton().exists()).toBe(true); 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);
});
}); });
}); });
......
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