diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-25 03:09:22 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-25 03:09:22 +0300 |
commit | 7162e84914ae8bbfaa3da643f17cd66dde321217 (patch) | |
tree | 3c0dd5131f7a4d73b8d50b15c47f04830b26a518 /spec | |
parent | 76bbc06371e3ea6cffa4fda45e7773006ec76dd7 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
27 files changed, 222 insertions, 177 deletions
diff --git a/spec/controllers/registrations_controller_spec.rb b/spec/controllers/registrations_controller_spec.rb index 637c774c38b..782350edfdb 100644 --- a/spec/controllers/registrations_controller_spec.rb +++ b/spec/controllers/registrations_controller_spec.rb @@ -4,6 +4,7 @@ require 'spec_helper' RSpec.describe RegistrationsController do include TermsHelper + include FullNameHelper before do stub_application_setting(require_admin_approval_after_user_signup: false) @@ -463,7 +464,7 @@ RSpec.describe RegistrationsController do expect(User.last.first_name).to eq(base_user_params[:first_name]) expect(User.last.last_name).to eq(base_user_params[:last_name]) - expect(User.last.name).to eq("#{base_user_params[:first_name]} #{base_user_params[:last_name]}") + expect(User.last.name).to eq full_name(base_user_params[:first_name], base_user_params[:last_name]) end it 'sets the caller_id in the context' do diff --git a/spec/features/boards/board_filters_spec.rb b/spec/features/boards/board_filters_spec.rb index 2e4dc4a29fc..1184aea1114 100644 --- a/spec/features/boards/board_filters_spec.rb +++ b/spec/features/boards/board_filters_spec.rb @@ -7,8 +7,8 @@ RSpec.describe 'Issue board filters', :js do let_it_be(:user) { create(:user) } let_it_be(:board) { create(:board, project: project) } let_it_be(:project_label) { create(:label, project: project, title: 'Label') } - let_it_be(:milestone_1) { create(:milestone, project: project, due_date: 3.days.from_now ) } - let_it_be(:milestone_2) { create(:milestone, project: project, due_date: Date.tomorrow ) } + let_it_be(:milestone_1) { create(:milestone, project: project, due_date: 3.days.from_now) } + let_it_be(:milestone_2) { create(:milestone, project: project, due_date: Date.tomorrow) } let_it_be(:release) { create(:release, tag: 'v1.0', project: project, milestones: [milestone_1]) } let_it_be(:release_2) { create(:release, tag: 'v2.0', project: project, milestones: [milestone_2]) } let_it_be(:issue_1) { create(:issue, project: project, milestone: milestone_1, author: user) } diff --git a/spec/features/boards/user_visits_board_spec.rb b/spec/features/boards/user_visits_board_spec.rb index 7fe32557d6a..5587d9560a2 100644 --- a/spec/features/boards/user_visits_board_spec.rb +++ b/spec/features/boards/user_visits_board_spec.rb @@ -21,7 +21,7 @@ RSpec.describe 'User visits issue boards', :js do let_it_be(:label1) { create(:group_label, group: group, name: label_name1) } let_it_be(:label2) { create(:group_label, group: group, name: label_name2) } - let_it_be(:assignee) { create_default(:group_member, :maintainer, user: create(:user, username: assignee_username), group: group ).user } + let_it_be(:assignee) { create_default(:group_member, :maintainer, user: create(:user, username: assignee_username), group: group).user } let_it_be(:milestone) { create_default(:milestone, project: project, start_date: Date.today - 1, due_date: 7.days.from_now) } before_all do diff --git a/spec/features/dashboard/datetime_on_tooltips_spec.rb b/spec/features/dashboard/datetime_on_tooltips_spec.rb index 875ae41c55d..de8858fa8fa 100644 --- a/spec/features/dashboard/datetime_on_tooltips_spec.rb +++ b/spec/features/dashboard/datetime_on_tooltips_spec.rb @@ -14,8 +14,8 @@ RSpec.describe 'Tooltips on .timeago dates', :js do context 'on the activity tab' do before do - Event.create!( project: project, author_id: user.id, action: :joined, - updated_at: created_date, created_at: created_date) + Event.create!(project: project, author_id: user.id, action: :joined, + updated_at: created_date, created_at: created_date) sign_in user visit user_activity_path(user) diff --git a/spec/features/graphql_known_operations_spec.rb b/spec/features/graphql_known_operations_spec.rb index ef406f12902..80214307be3 100644 --- a/spec/features/graphql_known_operations_spec.rb +++ b/spec/features/graphql_known_operations_spec.rb @@ -24,6 +24,6 @@ RSpec.describe 'Graphql known operations', :js do expect(known_operations).to include("searchProjects") expect(known_operations.length).to be > 20 - expect(known_operations).to all( match(%r{^[a-z]+}i) ) + expect(known_operations).to all(match(%r{^[a-z]+}i)) end end diff --git a/spec/features/groups/activity_spec.rb b/spec/features/groups/activity_spec.rb index 6ca69e76d33..5bac80959b1 100644 --- a/spec/features/groups/activity_spec.rb +++ b/spec/features/groups/activity_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' RSpec.describe 'Group activity page' do - let(:user) { create(:group_member, :developer, user: create(:user), group: group ).user } + let(:user) { create(:group_member, :developer, user: create(:user), group: group).user } let(:group) { create(:group) } let(:path) { activity_group_path(group) } diff --git a/spec/features/groups/board_sidebar_spec.rb b/spec/features/groups/board_sidebar_spec.rb index 69a6788e438..aa42b29b3ac 100644 --- a/spec/features/groups/board_sidebar_spec.rb +++ b/spec/features/groups/board_sidebar_spec.rb @@ -6,7 +6,7 @@ RSpec.describe 'Group Issue Boards', :js do include BoardHelpers let(:group) { create(:group) } - let(:user) { create(:group_member, user: create(:user), group: group ).user } + let(:user) { create(:group_member, user: create(:user), group: group).user } let!(:project_1) { create(:project, :public, group: group) } let!(:project_2) { create(:project, :public, group: group) } let!(:project_1_label) { create(:label, project: project_1, name: 'Development 1') } diff --git a/spec/features/groups/empty_states_spec.rb b/spec/features/groups/empty_states_spec.rb index 84882fc674e..f1a8f97461a 100644 --- a/spec/features/groups/empty_states_spec.rb +++ b/spec/features/groups/empty_states_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' RSpec.describe 'Group empty states' do let(:group) { create(:group) } - let(:user) { create(:group_member, :developer, user: create(:user), group: group ).user } + let(:user) { create(:group_member, :developer, user: create(:user), group: group).user } before do sign_in(user) diff --git a/spec/features/groups/issues_spec.rb b/spec/features/groups/issues_spec.rb index a3fc6a620e7..d4e88505118 100644 --- a/spec/features/groups/issues_spec.rb +++ b/spec/features/groups/issues_spec.rb @@ -69,7 +69,7 @@ RSpec.describe 'Group issues page' do context 'issues list', :js do let(:subgroup) { create(:group, parent: group) } let(:subgroup_project) { create(:project, :public, group: subgroup) } - let(:user_in_group) { create(:group_member, :maintainer, user: create(:user), group: group ).user } + let(:user_in_group) { create(:group_member, :maintainer, user: create(:user), group: group).user } let!(:issue) { create(:issue, project: project, title: 'root group issue') } let!(:subgroup_issue) { create(:issue, project: subgroup_project, title: 'subgroup issue') } @@ -111,7 +111,7 @@ RSpec.describe 'Group issues page' do context 'projects with issues disabled' do describe 'issue dropdown' do - let(:user_in_group) { create(:group_member, :maintainer, user: create(:user), group: group ).user } + let(:user_in_group) { create(:group_member, :maintainer, user: create(:user), group: group).user } before do [project, project_with_issues_disabled].each { |project| project.add_maintainer(user_in_group) } @@ -129,7 +129,7 @@ RSpec.describe 'Group issues page' do end context 'manual ordering', :js do - let(:user_in_group) { create(:group_member, :maintainer, user: create(:user), group: group ).user } + let(:user_in_group) { create(:group_member, :maintainer, user: create(:user), group: group).user } let!(:issue1) { create(:issue, project: project, title: 'Issue #1', relative_position: 1) } let!(:issue2) { create(:issue, project: project, title: 'Issue #2', relative_position: 2) } @@ -199,7 +199,7 @@ RSpec.describe 'Group issues page' do end context 'issues pagination', :js do - let(:user_in_group) { create(:group_member, :maintainer, user: create(:user), group: group ).user } + let(:user_in_group) { create(:group_member, :maintainer, user: create(:user), group: group).user } let!(:issues) do (1..25).to_a.map { |index| create(:issue, project: project, title: "Issue #{index}") } diff --git a/spec/features/groups/milestone_spec.rb b/spec/features/groups/milestone_spec.rb index 42eaa8358a1..92a40459737 100644 --- a/spec/features/groups/milestone_spec.rb +++ b/spec/features/groups/milestone_spec.rb @@ -5,7 +5,7 @@ require 'spec_helper' RSpec.describe 'Group milestones' do let_it_be(:group) { create(:group) } let_it_be(:project) { create(:project_empty_repo, group: group) } - let_it_be(:user) { create(:group_member, :maintainer, user: create(:user), group: group ).user } + let_it_be(:user) { create(:group_member, :maintainer, user: create(:user), group: group).user } around do |example| freeze_time { example.run } diff --git a/spec/features/groups/milestones_sorting_spec.rb b/spec/features/groups/milestones_sorting_spec.rb index 125bf9ce3a7..6f3fc72775f 100644 --- a/spec/features/groups/milestones_sorting_spec.rb +++ b/spec/features/groups/milestones_sorting_spec.rb @@ -11,7 +11,7 @@ RSpec.describe 'Milestones sorting', :js do let!(:project_milestone2) { create(:milestone, project: project, title: 'v2.0', due_date: 5.days.from_now) } let!(:other_project_milestone2) { create(:milestone, project: other_project, title: 'v2.0', due_date: 5.days.from_now) } let!(:group_milestone) { create(:milestone, group: group, title: 'v3.0', due_date: 7.days.from_now) } - let(:user) { create(:group_member, :maintainer, user: create(:user), group: group ).user } + let(:user) { create(:group_member, :maintainer, user: create(:user), group: group).user } before do sign_in(user) diff --git a/spec/features/merge_request/user_edits_assignees_sidebar_spec.rb b/spec/features/merge_request/user_edits_assignees_sidebar_spec.rb index 0dd87ac3e24..59b5923b2a1 100644 --- a/spec/features/merge_request/user_edits_assignees_sidebar_spec.rb +++ b/spec/features/merge_request/user_edits_assignees_sidebar_spec.rb @@ -88,7 +88,7 @@ RSpec.describe 'Merge request > User edits assignees sidebar', :js do end context 'when GraphQL assignees widget feature flag is enabled' do - let(:sidebar_assignee_dropdown_item) { sidebar_assignee_block.find(".dropdown-item", text: assignee.username ) } + let(:sidebar_assignee_dropdown_item) { sidebar_assignee_block.find(".dropdown-item", text: assignee.username) } let(:sidebar_assignee_dropdown_tooltip) { sidebar_assignee_dropdown_item['title'] } context 'when user is an owner' do diff --git a/spec/features/profiles/two_factor_auths_spec.rb b/spec/features/profiles/two_factor_auths_spec.rb index b4355f2d669..decc2904b6e 100644 --- a/spec/features/profiles/two_factor_auths_spec.rb +++ b/spec/features/profiles/two_factor_auths_spec.rb @@ -13,7 +13,7 @@ RSpec.describe 'Two factor auths' do end context 'when user has two-factor authentication disabled' do - let_it_be(:user) { create(:user ) } + let_it_be(:user) { create(:user) } it 'requires the current password to set up two factor authentication', :js do visit profile_two_factor_auth_path diff --git a/spec/features/projects/branches/user_views_branches_spec.rb b/spec/features/projects/branches/user_views_branches_spec.rb index b6b6dcb5cf1..3f0614532f1 100644 --- a/spec/features/projects/branches/user_views_branches_spec.rb +++ b/spec/features/projects/branches/user_views_branches_spec.rb @@ -21,7 +21,7 @@ RSpec.describe "User views branches", :js do it "shows branches" do expect(page).to have_content("Branches").and have_content("master") - expect(page.all(".graph-side")).to all( have_content(/\d+/) ) + expect(page.all(".graph-side")).to all(have_content(/\d+/)) end it "displays a disabled button with a tooltip for the default branch that cannot be deleted", :js do diff --git a/spec/features/projects/fork_spec.rb b/spec/features/projects/fork_spec.rb index 24943e7dd0f..9ceadb63178 100644 --- a/spec/features/projects/fork_spec.rb +++ b/spec/features/projects/fork_spec.rb @@ -134,7 +134,7 @@ RSpec.describe 'Project fork' do context 'fork form', :js do let(:group) { create(:group) } let(:group2) { create(:group) } - let(:user) { create(:group_member, :maintainer, user: create(:user), group: group ).user } + let(:user) { create(:group_member, :maintainer, user: create(:user), group: group).user } def submit_form(group_obj = group) find('[data-testid="select_namespace_dropdown"]').click @@ -180,7 +180,7 @@ RSpec.describe 'Project fork' do context 'with cache_home_panel feature flag' do before do - create(:group_member, :maintainer, user: user, group: group2 ) + create(:group_member, :maintainer, user: user, group: group2) end context 'when caching is enabled' do diff --git a/spec/features/projects/issues/viewing_issues_with_external_authorization_enabled_spec.rb b/spec/features/projects/issues/viewing_issues_with_external_authorization_enabled_spec.rb index b423543dc33..4415f1f009f 100644 --- a/spec/features/projects/issues/viewing_issues_with_external_authorization_enabled_spec.rb +++ b/spec/features/projects/issues/viewing_issues_with_external_authorization_enabled_spec.rb @@ -41,7 +41,7 @@ RSpec.describe 'viewing an issue with cross project references' do let(:issue) do create(:issue, project: project, - description: description_referencing_other_issue ) + description: description_referencing_other_issue) end let(:confidential_issue) do diff --git a/spec/features/projects/jobs_spec.rb b/spec/features/projects/jobs_spec.rb index 84c75752bc1..96a8168e708 100644 --- a/spec/features/projects/jobs_spec.rb +++ b/spec/features/projects/jobs_spec.rb @@ -463,7 +463,7 @@ RSpec.describe 'Jobs', :clean_gitlab_redis_shared_state do context 'when variables are stored in trigger_request' do before do - trigger_request.update_attribute(:variables, { 'TRIGGER_KEY_1' => 'TRIGGER_VALUE_1' } ) + trigger_request.update_attribute(:variables, { 'TRIGGER_KEY_1' => 'TRIGGER_VALUE_1' }) visit project_job_path(project, job) end @@ -508,7 +508,7 @@ RSpec.describe 'Jobs', :clean_gitlab_redis_shared_state do context 'when variables are stored in trigger_request' do before do - trigger_request.update_attribute(:variables, { 'TRIGGER_KEY_1' => 'TRIGGER_VALUE_1' } ) + trigger_request.update_attribute(:variables, { 'TRIGGER_KEY_1' => 'TRIGGER_VALUE_1' }) visit project_job_path(project, job) end diff --git a/spec/features/projects/pipeline_schedules_spec.rb b/spec/features/projects/pipeline_schedules_spec.rb index 4ed0a11da38..3252b5eaa95 100644 --- a/spec/features/projects/pipeline_schedules_spec.rb +++ b/spec/features/projects/pipeline_schedules_spec.rb @@ -6,7 +6,7 @@ RSpec.describe 'Pipeline Schedules', :js do include Spec::Support::Helpers::ModalHelpers let!(:project) { create(:project, :repository) } - let!(:pipeline_schedule) { create(:ci_pipeline_schedule, :nightly, project: project ) } + let!(:pipeline_schedule) { create(:ci_pipeline_schedule, :nightly, project: project) } let!(:pipeline) { create(:ci_pipeline, pipeline_schedule: pipeline_schedule) } let(:scope) { nil } let!(:user) { create(:user) } diff --git a/spec/features/projects/pipelines/pipeline_spec.rb b/spec/features/projects/pipelines/pipeline_spec.rb index 0b43e13996f..9a99f16b669 100644 --- a/spec/features/projects/pipelines/pipeline_spec.rb +++ b/spec/features/projects/pipelines/pipeline_spec.rb @@ -363,7 +363,7 @@ RSpec.describe 'Pipeline', :js do project: downstream_project, ref: 'master', sha: downstream_project.commit.id, - child_of: pipeline ) + child_of: pipeline) end let!(:build) { create(:ci_build, status, pipeline: downstream_pipeline, user: user) } diff --git a/spec/features/projects/releases/user_views_edit_release_spec.rb b/spec/features/projects/releases/user_views_edit_release_spec.rb index 6551b254643..78b9798941a 100644 --- a/spec/features/projects/releases/user_views_edit_release_spec.rb +++ b/spec/features/projects/releases/user_views_edit_release_spec.rb @@ -6,7 +6,7 @@ RSpec.describe 'User edits Release', :js do let_it_be(:project) { create(:project, :repository) } let_it_be(:user) { create(:user) } - let(:release) { create(:release, :with_milestones, milestones_count: 1, project: project, name: 'The first release', tag: "v1.1.0" ) } + let(:release) { create(:release, :with_milestones, milestones_count: 1, project: project, name: 'The first release', tag: "v1.1.0") } let(:release_link) { create(:release_link, release: release) } before do diff --git a/spec/features/projects/releases/user_views_releases_spec.rb b/spec/features/projects/releases/user_views_releases_spec.rb index a7348b62fc0..10418e8072d 100644 --- a/spec/features/projects/releases/user_views_releases_spec.rb +++ b/spec/features/projects/releases/user_views_releases_spec.rb @@ -15,7 +15,7 @@ RSpec.describe 'User views releases', :js do let_it_be(:guest) { create(:user) } let_it_be(:internal_link) { create(:release_link, release: release_v1, name: 'An internal link', url: "#{project.web_url}/-/jobs/1/artifacts/download", filepath: nil) } - let_it_be(:internal_link_with_redirect) { create(:release_link, release: release_v1, name: 'An internal link with a redirect', url: "#{project.web_url}/-/jobs/2/artifacts/download", filepath: '/binaries/linux-amd64' ) } + let_it_be(:internal_link_with_redirect) { create(:release_link, release: release_v1, name: 'An internal link with a redirect', url: "#{project.web_url}/-/jobs/2/artifacts/download", filepath: '/binaries/linux-amd64') } let_it_be(:external_link) { create(:release_link, release: release_v1, name: 'An external link', url: "https://example.com/an/external/link", filepath: nil) } before do diff --git a/spec/frontend/packages_and_registries/infrastructure_registry/components/list/components/packages_list_spec.js b/spec/frontend/packages_and_registries/infrastructure_registry/components/list/components/packages_list_spec.js index fb5ee4e6884..0164d92ce34 100644 --- a/spec/frontend/packages_and_registries/infrastructure_registry/components/list/components/packages_list_spec.js +++ b/spec/frontend/packages_and_registries/infrastructure_registry/components/list/components/packages_list_spec.js @@ -1,12 +1,13 @@ -import { GlTable, GlPagination, GlModal } from '@gitlab/ui'; +import { GlTable, GlPagination } from '@gitlab/ui'; import { mount } from '@vue/test-utils'; -import Vue, { nextTick } from 'vue'; +import Vue from 'vue'; import { last } from 'lodash'; import Vuex from 'vuex'; import stubChildren from 'helpers/stub_children'; import PackagesList from '~/packages_and_registries/infrastructure_registry/list/components/packages_list.vue'; import PackagesListRow from '~/packages_and_registries/infrastructure_registry/shared/package_list_row.vue'; import PackagesListLoader from '~/packages_and_registries/shared/components/packages_list_loader.vue'; +import DeletePackageModal from '~/packages_and_registries/shared/components/delete_package_modal.vue'; import { TRACKING_ACTIONS } from '~/packages_and_registries/shared/constants'; import { TRACK_CATEGORY } from '~/packages_and_registries/infrastructure_registry/shared/constants'; import Tracking from '~/tracking'; @@ -22,7 +23,7 @@ describe('packages_list', () => { const findPackagesListLoader = () => wrapper.findComponent(PackagesListLoader); const findPackageListPagination = () => wrapper.findComponent(GlPagination); - const findPackageListDeleteModal = () => wrapper.findComponent(GlModal); + const findPackageListDeleteModal = () => wrapper.findComponent(DeletePackageModal); const findEmptySlot = () => wrapper.findComponent(EmptySlotStub); const findPackagesListRow = () => wrapper.findComponent(PackagesListRow); @@ -65,7 +66,7 @@ describe('packages_list', () => { stubs: { ...stubChildren(PackagesList), GlTable, - GlModal, + DeletePackageModal, }, ...options, }); @@ -109,52 +110,38 @@ describe('packages_list', () => { expect(sorting.exists()).toBe(true); }); - it('contains a modal component', () => { - const sorting = findPackageListDeleteModal(); - expect(sorting.exists()).toBe(true); + it("doesn't contain a modal component", () => { + expect(findPackageListDeleteModal().props('itemToBeDeleted')).toBeNull(); }); }); describe('when the user can destroy the package', () => { - beforeEach(() => { + let itemToBeDeleted; + + beforeEach(async () => { mountComponent(); + itemToBeDeleted = last(packageList); + await findPackagesListRow().vm.$emit('packageToDelete', itemToBeDeleted); }); - it('setItemToBeDeleted sets itemToBeDeleted and open the modal', async () => { - const mockModalShow = jest.spyOn(wrapper.vm.$refs.packageListDeleteModal, 'show'); - const item = last(wrapper.vm.list); - - findPackagesListRow().vm.$emit('packageToDelete', item); - - await nextTick(); - expect(wrapper.vm.itemToBeDeleted).toEqual(item); - expect(mockModalShow).toHaveBeenCalled(); + afterEach(() => { + itemToBeDeleted = null; }); - it('deleteItemConfirmation resets itemToBeDeleted', () => { - // setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details - // eslint-disable-next-line no-restricted-syntax - wrapper.setData({ itemToBeDeleted: 1 }); - wrapper.vm.deleteItemConfirmation(); - expect(wrapper.vm.itemToBeDeleted).toEqual(null); + it('passes itemToBeDeleted to the modal', () => { + expect(findPackageListDeleteModal().props('itemToBeDeleted')).toStrictEqual(itemToBeDeleted); }); it('deleteItemConfirmation emit package:delete', async () => { - const itemToBeDeleted = { id: 2 }; - // setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details - // eslint-disable-next-line no-restricted-syntax - wrapper.setData({ itemToBeDeleted }); - wrapper.vm.deleteItemConfirmation(); - await nextTick(); + await findPackageListDeleteModal().vm.$emit('ok'); + expect(wrapper.emitted('package:delete')[0]).toEqual([itemToBeDeleted]); }); - it('deleteItemCanceled resets itemToBeDeleted', () => { - // setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details - // eslint-disable-next-line no-restricted-syntax - wrapper.setData({ itemToBeDeleted: 1 }); - wrapper.vm.deleteItemCanceled(); - expect(wrapper.vm.itemToBeDeleted).toEqual(null); + it.each(['ok', 'cancel'])('resets itemToBeDeleted when modal emits %s', async (event) => { + await findPackageListDeleteModal().vm.$emit(event); + + expect(findPackageListDeleteModal().props('itemToBeDeleted')).toBeNull(); }); }); diff --git a/spec/frontend/packages_and_registries/package_registry/components/list/packages_list_spec.js b/spec/frontend/packages_and_registries/package_registry/components/list/packages_list_spec.js index 3e3607a361c..e086ee84073 100644 --- a/spec/frontend/packages_and_registries/package_registry/components/list/packages_list_spec.js +++ b/spec/frontend/packages_and_registries/package_registry/components/list/packages_list_spec.js @@ -1,8 +1,9 @@ -import { GlAlert, GlKeysetPagination, GlModal, GlSprintf } from '@gitlab/ui'; +import { GlAlert, GlKeysetPagination, GlSprintf } from '@gitlab/ui'; import { nextTick } from 'vue'; import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; import PackagesListRow from '~/packages_and_registries/package_registry/components/list/package_list_row.vue'; import PackagesListLoader from '~/packages_and_registries/shared/components/packages_list_loader.vue'; +import DeletePackageModal from '~/packages_and_registries/shared/components/delete_package_modal.vue'; import { DELETE_PACKAGE_TRACKING_ACTION, REQUEST_DELETE_PACKAGE_TRACKING_ACTION, @@ -35,15 +36,10 @@ describe('packages_list', () => { }; const EmptySlotStub = { name: 'empty-slot-stub', template: '<div>bar</div>' }; - const GlModalStub = { - name: GlModal.name, - template: '<div><slot></slot></div>', - methods: { show: jest.fn() }, - }; const findPackagesListLoader = () => wrapper.findComponent(PackagesListLoader); const findPackageListPagination = () => wrapper.findComponent(GlKeysetPagination); - const findPackageListDeleteModal = () => wrapper.findComponent(GlModalStub); + const findPackageListDeleteModal = () => wrapper.findComponent(DeletePackageModal); const findEmptySlot = () => wrapper.findComponent(EmptySlotStub); const findPackagesListRow = () => wrapper.findComponent(PackagesListRow); const findErrorPackageAlert = () => wrapper.findComponent(GlAlert); @@ -55,7 +51,7 @@ describe('packages_list', () => { ...props, }, stubs: { - GlModal: GlModalStub, + DeletePackageModal, GlSprintf, }, slots: { @@ -64,10 +60,6 @@ describe('packages_list', () => { }); }; - beforeEach(() => { - GlModalStub.methods.show.mockReset(); - }); - afterEach(() => { wrapper.destroy(); }); @@ -111,10 +103,10 @@ describe('packages_list', () => { expect(findPackageListPagination().exists()).toBe(true); }); - it('contains a modal component', () => { + it("doesn't contain a visible modal component", () => { mountComponent(); - expect(findPackageListDeleteModal().exists()).toBe(true); + expect(findPackageListDeleteModal().props('itemToBeDeleted')).toBeNull(); }); it('does not have an error alert displayed', () => { @@ -125,31 +117,25 @@ describe('packages_list', () => { }); describe('when the user can destroy the package', () => { - beforeEach(() => { + beforeEach(async () => { mountComponent(); - findPackagesListRow().vm.$emit('packageToDelete', firstPackage); - return nextTick(); + await findPackagesListRow().vm.$emit('packageToDelete', firstPackage); }); - it('deleting a package opens the modal', () => { - expect(findPackageListDeleteModal().text()).toContain(firstPackage.name); + it('passes itemToBeDeleted to the modla', () => { + expect(findPackageListDeleteModal().props('itemToBeDeleted')).toStrictEqual(firstPackage); }); - it('confirming on the modal emits package:delete', async () => { - findPackageListDeleteModal().vm.$emit('ok'); - - await nextTick(); + it('emits package:delete when modal confirms', async () => { + await findPackageListDeleteModal().vm.$emit('ok'); expect(wrapper.emitted('package:delete')[0]).toEqual([firstPackage]); }); - it('closing the modal resets itemToBeDeleted', async () => { - // triggering the v-model - findPackageListDeleteModal().vm.$emit('input', false); - - await nextTick(); + it.each(['ok', 'cancel'])('resets itemToBeDeleted when modal emits %s', async (event) => { + await findPackageListDeleteModal().vm.$emit(event); - expect(findPackageListDeleteModal().text()).not.toContain(firstPackage.name); + expect(findPackageListDeleteModal().props('itemToBeDeleted')).toBeNull(); }); }); diff --git a/spec/frontend/packages_and_registries/shared/components/delete_package_modal_spec.js b/spec/frontend/packages_and_registries/shared/components/delete_package_modal_spec.js new file mode 100644 index 00000000000..357dab593e8 --- /dev/null +++ b/spec/frontend/packages_and_registries/shared/components/delete_package_modal_spec.js @@ -0,0 +1,82 @@ +import { GlSprintf, GlModal } from '@gitlab/ui'; +import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; +import DeletePackageModal from '~/packages_and_registries/shared/components/delete_package_modal.vue'; + +describe('DeletePackageModal', () => { + let wrapper; + + const defaultItemToBeDeleted = { + name: 'package 01', + }; + + const findModal = () => wrapper.findComponent(GlModal); + + const mountComponent = ({ itemToBeDeleted = defaultItemToBeDeleted } = {}) => { + wrapper = shallowMountExtended(DeletePackageModal, { + propsData: { + itemToBeDeleted, + }, + }); + }; + + afterEach(() => { + wrapper.destroy(); + wrapper = null; + }); + + describe('when itemToBeDeleted prop is defined', () => { + beforeEach(() => { + mountComponent(); + }); + + it('displays modal', () => { + expect(findModal().props('visible')).toBe(true); + }); + + it('passes title prop', () => { + expect(findModal().props('title')).toBe(wrapper.vm.$options.i18n.modalTitle); + }); + + it('passes actionPrimary prop', () => { + expect(findModal().props('actionPrimary')).toStrictEqual({ + text: wrapper.vm.$options.i18n.modalAction, + attributes: { + variant: 'danger', + }, + }); + }); + + it('displays description', () => { + const descriptionEl = findModal().findComponent(GlSprintf); + + expect(descriptionEl.exists()).toBe(true); + expect(descriptionEl.attributes('message')).toBe(wrapper.vm.$options.i18n.modalDescription); + }); + + it('emits ok when modal is validate', () => { + expect(wrapper.emitted().ok).toBeUndefined(); + + findModal().vm.$emit('ok'); + + expect(wrapper.emitted().ok).toHaveLength(1); + }); + + it('emits cancel when modal close', () => { + expect(wrapper.emitted().cancel).toBeUndefined(); + + findModal().vm.$emit('change', false); + + expect(wrapper.emitted().cancel).toHaveLength(1); + }); + }); + + describe('when itemToBeDeleted prop is null', () => { + beforeEach(() => { + mountComponent({ itemToBeDeleted: null }); + }); + + it("doesn't display modal", () => { + expect(findModal().props('visible')).toBe(false); + }); + }); +}); diff --git a/spec/helpers/search_helper_spec.rb b/spec/helpers/search_helper_spec.rb index 20718ad2f48..8770640e769 100644 --- a/spec/helpers/search_helper_spec.rb +++ b/spec/helpers/search_helper_spec.rb @@ -705,112 +705,94 @@ RSpec.describe SearchHelper do let(:user) { create(:user) } let(:can_download) { false } - let(:for_group) { false } - let(:group) { nil } - let(:group_metadata) { nil } - - let(:for_project) { false } - let(:project) { nil } - let(:project_metadata) { nil } + let_it_be(:group) { nil } + let_it_be(:project) { nil } let(:scope) { nil } - let(:code_search) { false } + let(:ref) { nil } - let(:for_snippets) { false } - - let(:search_context) do - instance_double(Gitlab::SearchContext, - group: group, - group_metadata: group_metadata, - project: project, - project_metadata: project_metadata, - scope: scope, - ref: ref) - end + let(:snippet) { nil } before do - allow(self).to receive(:search_context).and_return(search_context) + @project = project + @group = group + @ref = ref + @snippet = snippet + allow(self).to receive(:current_user).and_return(user) + allow(self).to receive(:search_scope).and_return(scope) allow(self).to receive(:can?).and_return(can_download) + end - allow(search_context).to receive(:for_group?).and_return(for_group) - allow(search_context).to receive(:for_project?).and_return(for_project) + context 'no group or project data' do + it 'does not add :group, :group_metadata, or :scope to hash' do + expect(header_search_context[:group]).to eq(nil) + expect(header_search_context[:group_metadata]).to eq(nil) + expect(header_search_context[:scope]).to eq(nil) + end - allow(search_context).to receive(:code_search?).and_return(code_search) - allow(search_context).to receive(:for_snippets?).and_return(for_snippets) + it 'does not add :project, :project_metadata, :code_search, or :ref' do + expect(header_search_context[:project]).to eq(nil) + expect(header_search_context[:project_metadata]).to eq(nil) + expect(header_search_context[:code_search]).to eq(nil) + expect(header_search_context[:ref]).to eq(nil) + end end context 'group data' do - let(:group) { create(:group) } - let(:group_metadata) { { group_path: group.path, issues_path: "/issues" } } + let_it_be(:group) { create(:group) } + let(:group_metadata) { { issues_path: issues_group_path(group), mr_path: merge_requests_group_path(group) } } let(:scope) { 'issues' } - let(:code_search) { true } - context 'when for_group? is true' do - let(:for_group) { true } - - it 'adds the :group and :group_metadata correctly to hash' do - expect(header_search_context[:group]).to eq({ id: group.id, name: group.name, full_name: group.full_name }) - expect(header_search_context[:group_metadata]).to eq(group_metadata) - end - - it 'adds scope and code_search? correctly to hash' do - expect(header_search_context[:scope]).to eq(scope) - expect(header_search_context[:code_search]).to eq(code_search) - end + it 'adds the :group, :group_metadata, and :scope correctly to hash' do + expect(header_search_context[:group]).to eq({ id: group.id, name: group.name, full_name: group.full_name }) + expect(header_search_context[:group_metadata]).to eq(group_metadata) + expect(header_search_context[:scope]).to eq(scope) end - context 'when for_group? is false' do - let(:for_group) { false } - - it 'does not add the :group and :group_metadata to hash' do - expect(header_search_context[:group]).to eq(nil) - expect(header_search_context[:group_metadata]).to eq(nil) - end - - it 'does not add scope and code_search? to hash' do - expect(header_search_context[:scope]).to eq(nil) - expect(header_search_context[:code_search]).to eq(nil) - end + it 'does not add :project, :project_metadata, :code_search, or :ref' do + expect(header_search_context[:project]).to eq(nil) + expect(header_search_context[:project_metadata]).to eq(nil) + expect(header_search_context[:code_search]).to eq(nil) + expect(header_search_context[:ref]).to eq(nil) end end context 'project data' do - let_it_be(:project) { create(:project) } - let(:project_metadata) { { project_path: project.path, issues_path: "/issues" } } - let(:scope) { 'issues' } - let(:code_search) { true } - - context 'when for_project? is true' do - let(:for_project) { true } + let_it_be(:project_group) { create(:group) } + let_it_be(:project) { create(:project, group: project_group) } + let(:project_metadata) { { issues_path: project_issues_path(project), mr_path: project_merge_requests_path(project) } } + let(:group_metadata) { { issues_path: issues_group_path(project_group), mr_path: merge_requests_group_path(project_group) } } - it 'adds the :project and :project_metadata correctly to hash' do - expect(header_search_context[:project]).to eq({ id: project.id, name: project.name }) - expect(header_search_context[:project_metadata]).to eq(project_metadata) - end + it 'adds the :group and :group-metadata from the project correctly to hash' do + expect(header_search_context[:group]).to eq({ id: project_group.id, name: project_group.name, full_name: project_group.full_name }) + expect(header_search_context[:group_metadata]).to eq(group_metadata) + end - it 'adds scope and code_search? correctly to hash' do - expect(header_search_context[:scope]).to eq(scope) - expect(header_search_context[:code_search]).to eq(code_search) - end + it 'adds the :project and :project-metadata correctly to hash' do + expect(header_search_context[:project]).to eq({ id: project.id, name: project.name }) + expect(header_search_context[:project_metadata]).to eq(project_metadata) end - context 'when for_project? is false' do - let(:for_project) { false } + context 'with scope' do + let(:scope) { 'issues' } - it 'does not add the :project and :project_metadata to hash' do - expect(header_search_context[:project]).to eq(nil) - expect(header_search_context[:project_metadata]).to eq(nil) + it 'adds :scope and false :code_search to hash' do + expect(header_search_context[:scope]).to eq(scope) + expect(header_search_context[:code_search]).to eq(false) end + end - it 'does not add scope and code_search? to hash' do + context 'without scope' do + it 'adds code_search true to hash and not :scope' do expect(header_search_context[:scope]).to eq(nil) - expect(header_search_context[:code_search]).to eq(nil) + expect(header_search_context[:code_search]).to eq(true) end end end context 'ref data' do + let_it_be(:project) { create(:project) } let(:ref) { 'test-branch' } context 'when user can? download project data' do @@ -830,20 +812,18 @@ RSpec.describe SearchHelper do end end - context 'snippets' do - context 'when for_snippets? is true' do - let(:for_snippets) { true } + context 'snippet' do + context 'when searching from snippets' do + let(:snippet) { create(:snippet) } - it 'adds :for_snippets correctly to hash' do - expect(header_search_context[:for_snippets]).to eq(for_snippets) + it 'adds :for_snippets true correctly to hash' do + expect(header_search_context[:for_snippets]).to eq(true) end end - context 'when for_snippets? is false' do - let(:for_snippets) { false } - - it 'adds :for_snippets correctly to hash' do - expect(header_search_context[:for_snippets]).to eq(for_snippets) + context 'when not searching from snippets' do + it 'adds :for_snippets nil correctly to hash' do + expect(header_search_context[:for_snippets]).to eq(nil) end end end diff --git a/spec/support/helpers/full_name_helper.rb b/spec/support/helpers/full_name_helper.rb new file mode 100644 index 00000000000..a41c0da74d4 --- /dev/null +++ b/spec/support/helpers/full_name_helper.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +module FullNameHelper + def full_name(first_name, last_name) + "#{first_name} #{last_name}" + end +end + +FullNameHelper.prepend_mod diff --git a/spec/tooling/lib/tooling/find_codeowners_spec.rb b/spec/tooling/lib/tooling/find_codeowners_spec.rb index 5f6f83ab2c7..e75793b69c6 100644 --- a/spec/tooling/lib/tooling/find_codeowners_spec.rb +++ b/spec/tooling/lib/tooling/find_codeowners_spec.rb @@ -63,7 +63,7 @@ RSpec.describe Tooling::FindCodeowners do } }, '[Compliance]': { - '@gitlab-org/manage/compliance': { + '@gitlab-org/govern/compliance': { entries: %w[ /ee/app/services/audit_events/build_service.rb ], @@ -115,7 +115,7 @@ RSpec.describe Tooling::FindCodeowners do it 'retains the array and expands the patterns for the compliance group' do compliance = subject.load_definitions.dig( :'[Compliance]', - :'@gitlab-org/manage/compliance') + :'@gitlab-org/govern/compliance') expect(compliance).to eq( entries: %w[ |