diff options
Diffstat (limited to 'spec/helpers/invite_members_helper_spec.rb')
-rw-r--r-- | spec/helpers/invite_members_helper_spec.rb | 174 |
1 files changed, 74 insertions, 100 deletions
diff --git a/spec/helpers/invite_members_helper_spec.rb b/spec/helpers/invite_members_helper_spec.rb index 02f0416a17a..d8a97b93bc9 100644 --- a/spec/helpers/invite_members_helper_spec.rb +++ b/spec/helpers/invite_members_helper_spec.rb @@ -6,6 +6,7 @@ RSpec.describe InviteMembersHelper do include Devise::Test::ControllerHelpers let_it_be(:project) { create(:project) } + let_it_be(:group) { create(:group, projects: [project]) } let_it_be(:developer) { create(:user, developer_projects: [project]) } let(:owner) { project.owner } @@ -15,97 +16,24 @@ RSpec.describe InviteMembersHelper do end describe '#common_invite_modal_dataset' do - context 'when member_areas_of_focus is enabled', :experiment do - context 'with control experience' do - before do - stub_experiments(member_areas_of_focus: :control) - end - - it 'has expected attributes' do - attributes = { - areas_of_focus_options: [], - no_selection_areas_of_focus: [] - } - - expect(helper.common_invite_modal_dataset(project)).to include(attributes) - end - end - - context 'with candidate experience' do - before do - stub_experiments(member_areas_of_focus: :candidate) - end - - it 'has expected attributes', :aggregate_failures do - output = helper.common_invite_modal_dataset(project) - - expect(output[:no_selection_areas_of_focus]).to eq ['no_selection'] - expect(Gitlab::Json.parse(output[:areas_of_focus_options]).first['value']).to eq 'Contribute to the codebase' - end - end - end - - context 'when member_areas_of_focus is disabled' do - before do - stub_feature_flags(member_areas_of_focus: false) - end - - it 'has expected attributes' do - attributes = { - id: project.id, - name: project.name, - default_access_level: Gitlab::Access::GUEST, - areas_of_focus_options: [], - no_selection_areas_of_focus: [] - } - - expect(helper.common_invite_modal_dataset(project)).to include(attributes) - end + it 'has expected common attributes' do + attributes = { + id: project.id, + name: project.name, + default_access_level: Gitlab::Access::GUEST + } + + expect(helper.common_invite_modal_dataset(project)).to include(attributes) end context 'tasks_to_be_done' do - subject(:output) { helper.common_invite_modal_dataset(source) } - - let_it_be(:source) { project } - - before do - stub_experiments(invite_members_for_task: true) - end - - context 'when not logged in' do - before do - allow(helper).to receive(:params).and_return({ open_modal: 'invite_members_for_task' }) - end - - it "doesn't have the tasks to be done attributes" do - expect(output[:tasks_to_be_done_options]).to be_nil - expect(output[:projects]).to be_nil - expect(output[:new_project_path]).to be_nil - end - end + using RSpec::Parameterized::TableSyntax - context 'when logged in but the open_modal param is not present' do - before do - allow(helper).to receive(:current_user).and_return(developer) - end - - it "doesn't have the tasks to be done attributes" do - expect(output[:tasks_to_be_done_options]).to be_nil - expect(output[:projects]).to be_nil - expect(output[:new_project_path]).to be_nil - end - end - - context 'when logged in and the open_modal param is present' do - before do - allow(helper).to receive(:current_user).and_return(developer) - allow(helper).to receive(:params).and_return({ open_modal: 'invite_members_for_task' }) - end - - context 'for a group' do - let_it_be(:source) { create(:group, projects: [project]) } + subject(:output) { helper.common_invite_modal_dataset(source) } - it 'has the expected attributes', :aggregate_failures do + shared_examples_for 'including the tasks to be done attributes' do + it 'includes the tasks to be done attributes when expected' do + if expected? expect(output[:tasks_to_be_done_options]).to eq( [ { value: :code, text: 'Create/import code into a project (repository)' }, @@ -117,24 +45,70 @@ RSpec.describe InviteMembersHelper do [{ id: project.id, title: project.title }].to_json ) expect(output[:new_project_path]).to eq( - new_project_path(namespace_id: source.id) + source.is_a?(Project) ? '' : new_project_path(namespace_id: group.id) ) + else + expect(output[:tasks_to_be_done_options]).to be_nil + expect(output[:projects]).to be_nil + expect(output[:new_project_path]).to be_nil end end + end - context 'for a project' do - it 'has the expected attributes', :aggregate_failures do - expect(output[:tasks_to_be_done_options]).to eq( - [ - { value: :code, text: 'Create/import code into a project (repository)' }, - { value: :ci, text: 'Set up CI/CD pipelines to build, test, deploy, and monitor code' }, - { value: :issues, text: 'Create/import issues (tickets) to collaborate on ideas and plan work' } - ].to_json - ) - expect(output[:projects]).to eq( - [{ id: project.id, title: project.title }].to_json - ) - expect(output[:new_project_path]).to eq('') + context 'inviting members for tasks' do + where(:open_modal_param_present?, :logged_in?, :expected?) do + true | true | true + true | false | false + false | true | false + false | false | false + end + + with_them do + before do + allow(helper).to receive(:current_user).and_return(developer) if logged_in? + allow(helper).to receive(:params).and_return({ open_modal: 'invite_members_for_task' }) if open_modal_param_present? + end + + context 'when the source is a project' do + let_it_be(:source) { project } + + it_behaves_like 'including the tasks to be done attributes' + end + + context 'when the source is a group' do + let_it_be(:source) { group } + + it_behaves_like 'including the tasks to be done attributes' + end + end + end + + context 'the invite_for_help_continuous_onboarding experiment' do + where(:invite_for_help_continuous_onboarding?, :logged_in?, :expected?) do + true | true | true + true | false | false + false | true | false + false | false | false + end + + with_them do + before do + allow(helper).to receive(:current_user).and_return(developer) if logged_in? + stub_experiments(invite_for_help_continuous_onboarding: :candidate) if invite_for_help_continuous_onboarding? + end + + context 'when the source is a project' do + let_it_be(:source) { project } + + it_behaves_like 'including the tasks to be done attributes' + end + + context 'when the source is a group' do + let_it_be(:source) { group } + + let(:expected?) { false } + + it_behaves_like 'including the tasks to be done attributes' end end end |