diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-17 09:12:07 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-17 09:12:07 +0300 |
commit | 8624e54ae69729abf8664f1f1a57e90ee9ecab1a (patch) | |
tree | 5a582393864f83a1ae05b8c3cdcbc7e4de57f5b2 /spec | |
parent | f8edb3a740b9ba434489a50b69c2e765cecb24b0 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
5 files changed, 230 insertions, 22 deletions
diff --git a/spec/db/schema_spec.rb b/spec/db/schema_spec.rb index aebe13c39fe..521b4cd4002 100644 --- a/spec/db/schema_spec.rb +++ b/spec/db/schema_spec.rb @@ -66,7 +66,6 @@ RSpec.describe 'Database schema' do oauth_access_grants: %w[resource_owner_id application_id], oauth_access_tokens: %w[resource_owner_id application_id], oauth_applications: %w[owner_id], - open_project_tracker_data: %w[closed_status_id], packages_build_infos: %w[pipeline_id], packages_package_file_build_infos: %w[pipeline_id], product_analytics_events_experimental: %w[event_id txn_id user_id], diff --git a/spec/features/contextual_sidebar_spec.rb b/spec/features/contextual_sidebar_spec.rb index 39881a28b11..29c7e0ddd21 100644 --- a/spec/features/contextual_sidebar_spec.rb +++ b/spec/features/contextual_sidebar_spec.rb @@ -3,35 +3,110 @@ require 'spec_helper' RSpec.describe 'Contextual sidebar', :js do - let_it_be(:project) { create(:project) } + context 'when context is a project' do + let_it_be(:project) { create(:project) } - let(:user) { project.owner } + let(:user) { project.owner } - before do - sign_in(user) + before do + sign_in(user) + end - visit project_path(project) - end + context 'when analyzing the menu' do + before do + visit project_path(project) + end + + it 'shows flyout navs when collapsed or expanded apart from on the active item when expanded', :aggregate_failures do + expect(page).not_to have_selector('.js-sidebar-collapsed') + + find('.rspec-link-pipelines').hover + + expect(page).to have_selector('.is-showing-fly-out') + + find('.rspec-project-link').hover + + expect(page).not_to have_selector('.is-showing-fly-out') + + find('.rspec-toggle-sidebar').click + + find('.rspec-link-pipelines').hover + + expect(page).to have_selector('.is-showing-fly-out') - it 'shows flyout navs when collapsed or expanded apart from on the active item when expanded', :aggregate_failures do - expect(page).not_to have_selector('.js-sidebar-collapsed') + find('.rspec-project-link').hover + + expect(page).to have_selector('.is-showing-fly-out') + end + end + + context 'with invite_members_in_side_nav experiment', :experiment do + it 'allows opening of modal for the candidate experience' do + stub_experiments(invite_members_in_side_nav: :candidate) + expect(experiment(:invite_members_in_side_nav)).to track(:assignment) + .with_context(group: project.group) + .on_next_instance + + visit project_path(project) + + page.within '[data-test-id="side-nav-invite-members"' do + find('[data-test-id="invite-members-button"').click + end + + expect(page).to have_content("You're inviting members to the") + end + + it 'does not have invite members link in side nav for the control experience' do + stub_experiments(invite_members_in_side_nav: :control) + expect(experiment(:invite_members_in_side_nav)).to track(:assignment) + .with_context(group: project.group) + .on_next_instance + + visit project_path(project) + + expect(page).not_to have_css('[data-test-id="side-nav-invite-members"') + end + end + end - find('.rspec-link-pipelines').hover + context 'when context is a group' do + let_it_be(:user) { create(:user) } + let_it_be(:group) do + create(:group).tap do |g| + g.add_owner(user) + end + end - expect(page).to have_selector('.is-showing-fly-out') + before do + sign_in(user) + end - find('.rspec-project-link').hover + context 'with invite_members_in_side_nav experiment', :experiment do + it 'allows opening of modal for the candidate experience' do + stub_experiments(invite_members_in_side_nav: :candidate) + expect(experiment(:invite_members_in_side_nav)).to track(:assignment) + .with_context(group: group) + .on_next_instance - expect(page).not_to have_selector('.is-showing-fly-out') + visit group_path(group) - find('.rspec-toggle-sidebar').click + page.within '[data-test-id="side-nav-invite-members"' do + find('[data-test-id="invite-members-button"').click + end - find('.rspec-link-pipelines').hover + expect(page).to have_content("You're inviting members to the") + end - expect(page).to have_selector('.is-showing-fly-out') + it 'does not have invite members link in side nav for the control experience' do + stub_experiments(invite_members_in_side_nav: :control) + expect(experiment(:invite_members_in_side_nav)).to track(:assignment) + .with_context(group: group) + .on_next_instance - find('.rspec-project-link').hover + visit group_path(group) - expect(page).to have_selector('.is-showing-fly-out') + expect(page).not_to have_css('[data-test-id="side-nav-invite-members"') + end + end end end diff --git a/spec/frontend/invite_members/components/invite_members_trigger_spec.js b/spec/frontend/invite_members/components/invite_members_trigger_spec.js index b2ebb9e4a47..3fce23f854c 100644 --- a/spec/frontend/invite_members/components/invite_members_trigger_spec.js +++ b/spec/frontend/invite_members/components/invite_members_trigger_spec.js @@ -1,8 +1,9 @@ -import { GlButton, GlLink } from '@gitlab/ui'; +import { GlButton, GlLink, GlIcon } from '@gitlab/ui'; import { shallowMount } from '@vue/test-utils'; import ExperimentTracking from '~/experimentation/experiment_tracking'; import InviteMembersTrigger from '~/invite_members/components/invite_members_trigger.vue'; import eventHub from '~/invite_members/event_hub'; +import { TRIGGER_ELEMENT_BUTTON, TRIGGER_ELEMENT_SIDE_NAV } from '~/invite_members/constants'; jest.mock('~/experimentation/experiment_tracking'); @@ -15,6 +16,7 @@ let findButton; const triggerComponent = { button: GlButton, anchor: GlLink, + 'side-nav': GlLink, }; const createComponent = (props = {}) => { @@ -27,9 +29,23 @@ const createComponent = (props = {}) => { }); }; -describe.each(['button', 'anchor'])('with triggerElement as %s', (triggerElement) => { - triggerProps = { triggerElement, triggerSource }; - findButton = () => wrapper.findComponent(triggerComponent[triggerElement]); +const triggerItems = [ + { + triggerElement: TRIGGER_ELEMENT_BUTTON, + }, + { + triggerElement: 'anchor', + }, + { + triggerElement: TRIGGER_ELEMENT_SIDE_NAV, + icon: 'plus', + }, +]; + +describe.each(triggerItems)('with triggerElement as %s', (triggerItem) => { + triggerProps = { ...triggerItem, triggerSource }; + + findButton = () => wrapper.findComponent(triggerComponent[triggerItem.triggerElement]); afterEach(() => { wrapper.destroy(); @@ -91,3 +107,14 @@ describe.each(['button', 'anchor'])('with triggerElement as %s', (triggerElement }); }); }); + +describe('side-nav with icon', () => { + it('includes the specified icon with correct size when triggerElement is link', () => { + const findIcon = () => wrapper.findComponent(GlIcon); + + createComponent({ triggerElement: TRIGGER_ELEMENT_SIDE_NAV, icon: 'plus' }); + + expect(findIcon().exists()).toBe(true); + expect(findIcon().props('name')).toBe('plus'); + }); +}); diff --git a/spec/lib/sidebars/groups/menus/invite_team_members_menu_spec.rb b/spec/lib/sidebars/groups/menus/invite_team_members_menu_spec.rb new file mode 100644 index 00000000000..a79e5182f45 --- /dev/null +++ b/spec/lib/sidebars/groups/menus/invite_team_members_menu_spec.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Sidebars::Groups::Menus::InviteTeamMembersMenu do + let_it_be(:owner) { create(:user) } + let_it_be(:guest) { create(:user) } + let_it_be(:group) do + build(:group).tap do |g| + g.add_owner(owner) + end + end + + let(:context) { Sidebars::Groups::Context.new(current_user: owner, container: group) } + + subject(:invite_menu) { described_class.new(context) } + + context 'when the group is viewed by an owner of the group' do + describe '#render?' do + it 'renders the Invite team members link' do + expect(invite_menu.render?).to eq(true) + end + + context 'when the group already has at least 2 members' do + before do + group.add_guest(guest) + end + + it 'does not render the link' do + expect(invite_menu.render?).to eq(false) + end + end + end + + describe '#title' do + it 'displays the correct Invite team members text for the link in the side nav' do + expect(invite_menu.title).to eq('Invite members') + end + end + end + + context 'when the group is viewed by a guest user without admin permissions' do + let(:context) { Sidebars::Groups::Context.new(current_user: guest, container: group) } + + before do + group.add_guest(guest) + end + + describe '#render?' do + it 'does not render the link' do + expect(subject.render?).to eq(false) + end + end + end +end diff --git a/spec/lib/sidebars/projects/menus/invite_team_members_menu_spec.rb b/spec/lib/sidebars/projects/menus/invite_team_members_menu_spec.rb new file mode 100644 index 00000000000..df9b260d211 --- /dev/null +++ b/spec/lib/sidebars/projects/menus/invite_team_members_menu_spec.rb @@ -0,0 +1,52 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Sidebars::Projects::Menus::InviteTeamMembersMenu do + let_it_be(:project) { create(:project) } + let_it_be(:guest) { create(:user) } + + let(:context) { Sidebars::Projects::Context.new(current_user: owner, container: project) } + + subject(:invite_menu) { described_class.new(context) } + + context 'when the project is viewed by an owner of the group' do + let(:owner) { project.owner } + + describe '#render?' do + it 'renders the Invite team members link' do + expect(invite_menu.render?).to eq(true) + end + + context 'when the project already has at least 2 members' do + before do + project.add_guest(guest) + end + + it 'does not render the link' do + expect(invite_menu.render?).to eq(false) + end + end + end + + describe '#title' do + it 'displays the correct Invite team members text for the link in the side nav' do + expect(invite_menu.title).to eq('Invite members') + end + end + end + + context 'when the project is viewed by a guest user without admin permissions' do + let(:context) { Sidebars::Projects::Context.new(current_user: guest, container: project) } + + before do + project.add_guest(guest) + end + + describe '#render?' do + it 'does not render' do + expect(invite_menu.render?).to eq(false) + end + end + end +end |