diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-28 15:09:41 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-28 15:09:41 +0300 |
commit | 72ba138510cad0a8c4819ef0512153dd4dbced7f (patch) | |
tree | 51038f89acce6787dfaa1e04b33f25b4bbeee2a8 /spec | |
parent | 8ce5735a199949ad19db9e83544875cd81562c69 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
25 files changed, 393 insertions, 181 deletions
diff --git a/spec/controllers/projects/pipeline_schedules_controller_spec.rb b/spec/controllers/projects/pipeline_schedules_controller_spec.rb index 6d810fdcd51..486062fe52b 100644 --- a/spec/controllers/projects/pipeline_schedules_controller_spec.rb +++ b/spec/controllers/projects/pipeline_schedules_controller_spec.rb @@ -106,7 +106,8 @@ RSpec.describe Projects::PipelineSchedulesController, feature_category: :continu end end - describe 'POST #create' do + # Move this from `shared_context` to `describe` when `ci_refactoring_pipeline_schedule_create_service` is removed. + shared_context 'POST #create' do # rubocop:disable RSpec/ContextWording describe 'functionality' do before do project.add_developer(user) @@ -184,6 +185,16 @@ RSpec.describe Projects::PipelineSchedulesController, feature_category: :continu end end + it_behaves_like 'POST #create' + + context 'when the FF ci_refactoring_pipeline_schedule_create_service is disabled' do + before do + stub_feature_flags(ci_refactoring_pipeline_schedule_create_service: false) + end + + it_behaves_like 'POST #create' + end + describe 'PUT #update' do describe 'functionality' do let!(:pipeline_schedule) { create(:ci_pipeline_schedule, project: project, owner: user) } diff --git a/spec/features/merge_request/maintainer_edits_fork_spec.rb b/spec/features/merge_request/maintainer_edits_fork_spec.rb index c9aa22e396b..7603696c60c 100644 --- a/spec/features/merge_request/maintainer_edits_fork_spec.rb +++ b/spec/features/merge_request/maintainer_edits_fork_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' RSpec.describe 'a maintainer edits files on a source-branch of an MR from a fork', :js, :sidekiq_might_not_need_inline, -feature_category: :code_review_workflow do + feature_category: :code_review_workflow do include Features::SourceEditorSpecHelpers include ProjectForksHelper let(:user) { create(:user, username: 'the-maintainer') } @@ -12,13 +12,15 @@ feature_category: :code_review_workflow do let(:source_project) { fork_project(target_project, author, repository: true) } let(:merge_request) do - create(:merge_request, - source_project: source_project, - target_project: target_project, - source_branch: 'fix', - target_branch: 'master', - author: author, - allow_collaboration: true) + create( + :merge_request, + source_project: source_project, + target_project: target_project, + source_branch: 'fix', + target_branch: 'master', + author: author, + allow_collaboration: true + ) end before do diff --git a/spec/features/merge_request/user_allows_commits_from_memebers_who_can_merge_spec.rb b/spec/features/merge_request/user_allows_commits_from_memebers_who_can_merge_spec.rb index 0ff773ef02d..149b2e2bb0f 100644 --- a/spec/features/merge_request/user_allows_commits_from_memebers_who_can_merge_spec.rb +++ b/spec/features/merge_request/user_allows_commits_from_memebers_who_can_merge_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' RSpec.describe 'create a merge request, allowing commits from members who can merge to the target branch', :js, -feature_category: :code_review_workflow do + feature_category: :code_review_workflow do include ProjectForksHelper let(:user) { create(:user) } let(:target_project) { create(:project, :public, :repository) } @@ -67,10 +67,12 @@ feature_category: :code_review_workflow do context 'when a member who can merge tries to edit the option' do let(:member) { create(:user) } let(:merge_request) do - create(:merge_request, - source_project: source_project, - target_project: target_project, - source_branch: 'fixes') + create( + :merge_request, + source_project: source_project, + target_project: target_project, + source_branch: 'fixes' + ) end before do diff --git a/spec/features/merge_request/user_closes_reopens_merge_request_state_spec.rb b/spec/features/merge_request/user_closes_reopens_merge_request_state_spec.rb index 537702df12d..446f6a470de 100644 --- a/spec/features/merge_request/user_closes_reopens_merge_request_state_spec.rb +++ b/spec/features/merge_request/user_closes_reopens_merge_request_state_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' RSpec.describe 'User closes/reopens a merge request', :js, quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/297500', - feature_category: :code_review_workflow do + feature_category: :code_review_workflow do let_it_be(:project) { create(:project, :repository) } let_it_be(:user) { create(:user) } diff --git a/spec/features/merge_request/user_creates_merge_request_spec.rb b/spec/features/merge_request/user_creates_merge_request_spec.rb index 97b423f2cc2..eab5cee976e 100644 --- a/spec/features/merge_request/user_creates_merge_request_spec.rb +++ b/spec/features/merge_request/user_creates_merge_request_spec.rb @@ -110,11 +110,13 @@ RSpec.describe 'User creates a merge request', :js, feature_category: :code_revi context 'when project is public and merge requests are private' do let_it_be(:project) do - create(:project, - :public, - :repository, - group: group, - merge_requests_access_level: ProjectFeature::DISABLED) + create( + :project, + :public, + :repository, + group: group, + merge_requests_access_level: ProjectFeature::DISABLED + ) end context 'and user is a guest' do diff --git a/spec/features/merge_request/user_interacts_with_batched_mr_diffs_spec.rb b/spec/features/merge_request/user_interacts_with_batched_mr_diffs_spec.rb index a013666a496..a96ec1f68aa 100644 --- a/spec/features/merge_request/user_interacts_with_batched_mr_diffs_spec.rb +++ b/spec/features/merge_request/user_interacts_with_batched_mr_diffs_spec.rb @@ -64,7 +64,7 @@ RSpec.describe 'Batch diffs', :js, feature_category: :code_review_workflow do context 'which is in at least page 2 of the batched pages of diffs' do it 'scrolls to the correct discussion', - quarantine: { issue: 'https://gitlab.com/gitlab-org/gitlab/-/issues/293814' } do + quarantine: { issue: 'https://gitlab.com/gitlab-org/gitlab/-/issues/293814' } do page.within get_first_diff do click_link('just now') end diff --git a/spec/features/merge_request/user_merges_immediately_spec.rb b/spec/features/merge_request/user_merges_immediately_spec.rb index d47968ebc6b..71af2045bab 100644 --- a/spec/features/merge_request/user_merges_immediately_spec.rb +++ b/spec/features/merge_request/user_merges_immediately_spec.rb @@ -6,17 +6,23 @@ RSpec.describe 'Merge requests > User merges immediately', :js, feature_category let(:project) { create(:project, :public, :repository) } let(:user) { project.creator } let!(:merge_request) do - create(:merge_request_with_diffs, source_project: project, - author: user, - title: 'Bug NS-04', - head_pipeline: pipeline, - source_branch: pipeline.ref) + create( + :merge_request_with_diffs, + source_project: project, + author: user, + title: 'Bug NS-04', + head_pipeline: pipeline, + source_branch: pipeline.ref + ) end let(:pipeline) do - create(:ci_pipeline, project: project, - ref: 'master', - sha: project.repository.commit('master').id) + create( + :ci_pipeline, + project: project, + ref: 'master', + sha: project.repository.commit('master').id + ) end context 'when there is active pipeline for merge request' do diff --git a/spec/features/merge_request/user_merges_only_if_pipeline_succeeds_spec.rb b/spec/features/merge_request/user_merges_only_if_pipeline_succeeds_spec.rb index a4c03dc4e73..78814e36cfe 100644 --- a/spec/features/merge_request/user_merges_only_if_pipeline_succeeds_spec.rb +++ b/spec/features/merge_request/user_merges_only_if_pipeline_succeeds_spec.rb @@ -25,11 +25,14 @@ RSpec.describe 'Merge request > User merges only if pipeline succeeds', :js, fea context 'when project has CI enabled' do let!(:pipeline) do - create(:ci_empty_pipeline, - project: project, - sha: merge_request.diff_head_sha, - ref: merge_request.source_branch, - status: status, head_pipeline_of: merge_request) + create( + :ci_empty_pipeline, + project: project, + sha: merge_request.diff_head_sha, + ref: merge_request.source_branch, + status: status, + head_pipeline_of: merge_request + ) end context 'when merge requests can only be merged if the pipeline succeeds' do diff --git a/spec/features/merge_request/user_merges_when_pipeline_succeeds_spec.rb b/spec/features/merge_request/user_merges_when_pipeline_succeeds_spec.rb index 9a8384bfc9f..ebec8a6d2ea 100644 --- a/spec/features/merge_request/user_merges_when_pipeline_succeeds_spec.rb +++ b/spec/features/merge_request/user_merges_when_pipeline_succeeds_spec.rb @@ -6,17 +6,23 @@ RSpec.describe 'Merge request > User merges when pipeline succeeds', :js, featur let(:project) { create(:project, :public, :repository) } let(:user) { project.creator } let(:merge_request) do - create(:merge_request_with_diffs, source_project: project, - author: user, - title: 'Bug NS-04', - merge_params: { force_remove_source_branch: '1' }) + create( + :merge_request_with_diffs, + source_project: project, + author: user, + title: 'Bug NS-04', + merge_params: { force_remove_source_branch: '1' } + ) end let(:pipeline) do - create(:ci_pipeline, project: project, - sha: merge_request.diff_head_sha, - ref: merge_request.source_branch, - head_pipeline_of: merge_request) + create( + :ci_pipeline, + project: project, + sha: merge_request.diff_head_sha, + ref: merge_request.source_branch, + head_pipeline_of: merge_request + ) end before do @@ -67,12 +73,14 @@ RSpec.describe 'Merge request > User merges when pipeline succeeds', :js, featur context 'when it was enabled and then canceled' do let(:merge_request) do - create(:merge_request_with_diffs, - :merge_when_pipeline_succeeds, - source_project: project, - title: 'Bug NS-04', - author: user, - merge_user: user) + create( + :merge_request_with_diffs, + :merge_when_pipeline_succeeds, + source_project: project, + title: 'Bug NS-04', + author: user, + merge_user: user + ) end before do @@ -88,11 +96,15 @@ RSpec.describe 'Merge request > User merges when pipeline succeeds', :js, featur context 'when merge when pipeline succeeds is enabled' do let(:merge_request) do - create(:merge_request_with_diffs, :simple, :merge_when_pipeline_succeeds, - source_project: project, - author: user, - merge_user: user, - title: 'MepMep') + create( + :merge_request_with_diffs, + :simple, + :merge_when_pipeline_succeeds, + source_project: project, + author: user, + merge_user: user, + title: 'MepMep' + ) end let!(:build) do diff --git a/spec/features/merge_request/user_opens_checkout_branch_modal_spec.rb b/spec/features/merge_request/user_opens_checkout_branch_modal_spec.rb index 601310cbacf..63f03ae64e0 100644 --- a/spec/features/merge_request/user_opens_checkout_branch_modal_spec.rb +++ b/spec/features/merge_request/user_opens_checkout_branch_modal_spec.rb @@ -20,13 +20,15 @@ RSpec.describe 'Merge request > User opens checkout branch modal', :js, feature_ let(:source_project) { fork_project(project, author, repository: true) } let(:merge_request) do - create(:merge_request, - source_project: source_project, - target_project: project, - source_branch: 'fix', - target_branch: 'master', - author: author, - allow_collaboration: true) + create( + :merge_request, + source_project: source_project, + target_project: project, + source_branch: 'fix', + target_branch: 'master', + author: author, + allow_collaboration: true + ) end it 'shows instructions' do diff --git a/spec/features/merge_request/user_posts_notes_spec.rb b/spec/features/merge_request/user_posts_notes_spec.rb index d31777db42e..d1e00d730b7 100644 --- a/spec/features/merge_request/user_posts_notes_spec.rb +++ b/spec/features/merge_request/user_posts_notes_spec.rb @@ -13,8 +13,7 @@ RSpec.describe 'Merge request > User posts notes', :js, feature_category: :code_ end let!(:note) do - create(:note_on_merge_request, :with_attachment, noteable: merge_request, - project: project) + create(:note_on_merge_request, :with_attachment, noteable: merge_request, project: project) end before do diff --git a/spec/features/merge_request/user_selects_branches_for_new_mr_spec.rb b/spec/features/merge_request/user_selects_branches_for_new_mr_spec.rb index dae28cbb05c..e3be99254dc 100644 --- a/spec/features/merge_request/user_selects_branches_for_new_mr_spec.rb +++ b/spec/features/merge_request/user_selects_branches_for_new_mr_spec.rb @@ -144,9 +144,7 @@ RSpec.describe 'Merge request > User selects branches for new MR', :js, feature_ context 'when a new merge request has a pipeline' do let!(:pipeline) do - create(:ci_pipeline, sha: project.commit('fix').id, - ref: 'fix', - project: project) + create(:ci_pipeline, sha: project.commit('fix').id, ref: 'fix', project: project) end it 'shows pipelines for a new merge request' do diff --git a/spec/features/merge_request/user_squashes_merge_request_spec.rb b/spec/features/merge_request/user_squashes_merge_request_spec.rb index 63faf830f7e..5fd0f353e56 100644 --- a/spec/features/merge_request/user_squashes_merge_request_spec.rb +++ b/spec/features/merge_request/user_squashes_merge_request_spec.rb @@ -16,15 +16,19 @@ RSpec.describe 'User squashes a merge request', :js, feature_category: :code_rev latest_master_commits = project.repository.commits_between(original_head.sha, 'master').map(&:raw) - squash_commit = an_object_having_attributes(sha: a_string_matching(/\h{40}/), - message: a_string_starting_with(project.merge_requests.first.default_squash_commit_message), - author_name: user.name, - committer_name: user.name) - - merge_commit = an_object_having_attributes(sha: a_string_matching(/\h{40}/), - message: a_string_starting_with("Merge branch '#{source_branch}' into 'master'"), - author_name: user.name, - committer_name: user.name) + squash_commit = an_object_having_attributes( + sha: a_string_matching(/\h{40}/), + message: a_string_starting_with(project.merge_requests.first.default_squash_commit_message), + author_name: user.name, + committer_name: user.name + ) + + merge_commit = an_object_having_attributes( + sha: a_string_matching(/\h{40}/), + message: a_string_starting_with("Merge branch '#{source_branch}' into 'master'"), + author_name: user.name, + committer_name: user.name + ) expect(project.repository).not_to be_merged_to_root_ref(source_branch) expect(latest_master_commits).to match([squash_commit, merge_commit]) diff --git a/spec/features/merge_request/user_suggests_changes_on_diff_spec.rb b/spec/features/merge_request/user_suggests_changes_on_diff_spec.rb index efd88df0f97..6152d9f8259 100644 --- a/spec/features/merge_request/user_suggests_changes_on_diff_spec.rb +++ b/spec/features/merge_request/user_suggests_changes_on_diff_spec.rb @@ -303,13 +303,17 @@ RSpec.describe 'User comments on a diff', :js, feature_category: :code_review_wo "5 # heh" ] - expect_suggestion_has_content(suggestion_1, - suggestion_1_expected_changing_content, - suggestion_1_expected_suggested_content) - - expect_suggestion_has_content(suggestion_2, - suggestion_2_expected_changing_content, - suggestion_2_expected_suggested_content) + expect_suggestion_has_content( + suggestion_1, + suggestion_1_expected_changing_content, + suggestion_1_expected_suggested_content + ) + + expect_suggestion_has_content( + suggestion_2, + suggestion_2_expected_changing_content, + suggestion_2_expected_suggested_content + ) end end end diff --git a/spec/features/merge_request/user_tries_to_access_private_project_info_through_new_mr_spec.rb b/spec/features/merge_request/user_tries_to_access_private_project_info_through_new_mr_spec.rb index 5770f5ab94d..1232e19d22b 100644 --- a/spec/features/merge_request/user_tries_to_access_private_project_info_through_new_mr_spec.rb +++ b/spec/features/merge_request/user_tries_to_access_private_project_info_through_new_mr_spec.rb @@ -3,19 +3,27 @@ require 'spec_helper' RSpec.describe 'Merge Request > User tries to access private project information through the new mr page', -feature_category: :code_review_workflow do + feature_category: :code_review_workflow do let(:current_user) { create(:user) } let(:private_project) do - create(:project, :public, :repository, - path: 'nothing-to-see-here', - name: 'nothing to see here', - repository_access_level: ProjectFeature::PRIVATE) + create( + :project, + :public, + :repository, + path: 'nothing-to-see-here', + name: 'nothing to see here', + repository_access_level: ProjectFeature::PRIVATE + ) end let(:owned_project) do - create(:project, :public, :repository, - namespace: current_user.namespace, - creator: current_user) + create( + :project, + :public, + :repository, + namespace: current_user.namespace, + creator: current_user + ) end context 'when the user enters the querystring info for the other project' do diff --git a/spec/features/merge_request/user_uses_quick_actions_spec.rb b/spec/features/merge_request/user_uses_quick_actions_spec.rb index 1ec86948065..1c63f5b56b0 100644 --- a/spec/features/merge_request/user_uses_quick_actions_spec.rb +++ b/spec/features/merge_request/user_uses_quick_actions_spec.rb @@ -8,7 +8,7 @@ require 'spec_helper' # Because this kind of spec takes more time to run there is no need to add new ones # for each existing quick action unless they test something not tested by existing tests. RSpec.describe 'Merge request > User uses quick actions', :js, :use_clean_rails_redis_caching, -feature_category: :code_review_workflow do + feature_category: :code_review_workflow do include Features::NotesHelpers let(:project) { create(:project, :public, :repository) } diff --git a/spec/features/merge_requests/user_lists_merge_requests_spec.rb b/spec/features/merge_requests/user_lists_merge_requests_spec.rb index 371c40b40a5..f594e39b2b7 100644 --- a/spec/features/merge_requests/user_lists_merge_requests_spec.rb +++ b/spec/features/merge_requests/user_lists_merge_requests_spec.rb @@ -14,44 +14,52 @@ RSpec.describe 'Merge requests > User lists merge requests', feature_category: : let(:user5) { create(:user) } before do - @fix = create(:merge_request, - title: 'fix', - source_project: project, - source_branch: 'fix', - assignees: [user], - reviewers: [user, user2, user3, user4, user5], - milestone: create(:milestone, project: project, due_date: '2013-12-11'), - created_at: 1.minute.ago, - updated_at: 1.minute.ago) + @fix = create( + :merge_request, + title: 'fix', + source_project: project, + source_branch: 'fix', + assignees: [user], + reviewers: [user, user2, user3, user4, user5], + milestone: create(:milestone, project: project, due_date: '2013-12-11'), + created_at: 1.minute.ago, + updated_at: 1.minute.ago + ) @fix.metrics.update!(merged_at: 10.seconds.ago, latest_closed_at: 20.seconds.ago) - @markdown = create(:merge_request, - title: 'markdown', - source_project: project, - source_branch: 'markdown', - assignees: [user], - reviewers: [user, user2, user3, user4], - milestone: create(:milestone, project: project, due_date: '2013-12-12'), - created_at: 2.minutes.ago, - updated_at: 2.minutes.ago, - state: 'merged') + @markdown = create( + :merge_request, + title: 'markdown', + source_project: project, + source_branch: 'markdown', + assignees: [user], + reviewers: [user, user2, user3, user4], + milestone: create(:milestone, project: project, due_date: '2013-12-12'), + created_at: 2.minutes.ago, + updated_at: 2.minutes.ago, + state: 'merged' + ) @markdown.metrics.update!(merged_at: 10.minutes.ago, latest_closed_at: 10.seconds.ago) - @merge_test = create(:merge_request, - title: 'merge-test', - source_project: project, - source_branch: 'merge-test', - created_at: 3.minutes.ago, - updated_at: 10.seconds.ago) + @merge_test = create( + :merge_request, + title: 'merge-test', + source_project: project, + source_branch: 'merge-test', + created_at: 3.minutes.ago, + updated_at: 10.seconds.ago + ) @merge_test.metrics.update!(merged_at: 10.seconds.ago, latest_closed_at: 10.seconds.ago) - @feature = create(:merge_request, - title: 'feature', - source_project: project, - source_branch: 'feautre', - created_at: 2.minutes.ago, - updated_at: 1.minute.ago, - state: 'merged') + @feature = create( + :merge_request, + title: 'feature', + source_project: project, + source_branch: 'feautre', + created_at: 2.minutes.ago, + updated_at: 1.minute.ago, + state: 'merged' + ) @feature.metrics.update!(merged_at: 10.seconds.ago, latest_closed_at: 10.minutes.ago) end @@ -134,8 +142,7 @@ RSpec.describe 'Merge requests > User lists merge requests', feature_category: : label = create(:label, project: project) create(:label_link, label: label, target: @fix) - visit_merge_requests(project, label_name: [label.name], - sort: sort_value_milestone) + visit_merge_requests(project, label_name: [label.name], sort: sort_value_milestone) expect(first_merge_request).to include('fix') expect(count_merge_requests).to eq(1) @@ -160,8 +167,7 @@ RSpec.describe 'Merge requests > User lists merge requests', feature_category: : end it 'sorts by milestone due date' do - visit_merge_requests(project, label_name: [label.name, label2.name], - sort: sort_value_milestone) + visit_merge_requests(project, label_name: [label.name, label2.name], sort: sort_value_milestone) expect(first_merge_request).to include('fix') expect(count_merge_requests).to eq(1) @@ -169,9 +175,12 @@ RSpec.describe 'Merge requests > User lists merge requests', feature_category: : context 'filter on assignee and' do it 'sorts by milestone due date' do - visit_merge_requests(project, label_name: [label.name, label2.name], - assignee_id: user.id, - sort: sort_value_milestone) + visit_merge_requests( + project, + label_name: [label.name, label2.name], + assignee_id: user.id, + sort: sort_value_milestone + ) expect(first_merge_request).to include('fix') expect(count_merge_requests).to eq(1) diff --git a/spec/features/merge_requests/user_views_open_merge_requests_spec.rb b/spec/features/merge_requests/user_views_open_merge_requests_spec.rb index 1a2024a5511..0021f701290 100644 --- a/spec/features/merge_requests/user_views_open_merge_requests_spec.rb +++ b/spec/features/merge_requests/user_views_open_merge_requests_spec.rb @@ -57,10 +57,12 @@ RSpec.describe 'User views open merge requests', feature_category: :code_review_ let!(:build) { create :ci_build, pipeline: pipeline } let(:merge_request) do - create(:merge_request_with_diffs, - source_project: project, - target_project: project, - source_branch: 'merge-test') + create( + :merge_request_with_diffs, + source_project: project, + target_project: project, + source_branch: 'merge-test' + ) end let(:pipeline) do diff --git a/spec/features/projects/compare_spec.rb b/spec/features/projects/compare_spec.rb index beb5fa7822b..eff538513c1 100644 --- a/spec/features/projects/compare_spec.rb +++ b/spec/features/projects/compare_spec.rb @@ -24,7 +24,7 @@ RSpec.describe "Compare", :js, feature_category: :groups_and_projects do click_button 'Compare' - expect(page).to have_content 'Commits' + expect(page).to have_content 'Commits on Source' expect(page).to have_link 'Create merge request' end end @@ -53,7 +53,7 @@ RSpec.describe "Compare", :js, feature_category: :groups_and_projects do select_using_dropdown('to', RepoHelpers.sample_commit.id, commit: true) click_button 'Compare' - expect(page).to have_content 'Commits (1)' + expect(page).to have_content 'Commits on Source (1)' expect(page).to have_content "Showing 2 changed files" diff = first('.js-unfold') @@ -85,7 +85,7 @@ RSpec.describe "Compare", :js, feature_category: :groups_and_projects do click_button 'Compare' - expect(page).to have_content 'Commits (1)' + expect(page).to have_content 'Commits on Source (1)' expect(page).to have_content 'Showing 1 changed file with 5 additions and 0 deletions' expect(page).to have_link 'View open merge request', href: project_merge_request_path(project, merge_request) expect(page).not_to have_link 'Create merge request' @@ -136,14 +136,14 @@ RSpec.describe "Compare", :js, feature_category: :groups_and_projects do visit project_compare_index_path(project, from: "feature", to: "master") click_button('Compare') - expect(page).to have_content 'Commits (29)' + expect(page).to have_content 'Commits on Source (29)' # go to the second page within(".files .gl-pagination") do click_on("2") end - expect(page).not_to have_content 'Commits (29)' + expect(page).not_to have_content 'Commits on Source (29)' end end end @@ -159,7 +159,7 @@ RSpec.describe "Compare", :js, feature_category: :groups_and_projects do expect(find(".js-compare-to-dropdown .gl-dropdown-button-text")).to have_content("v1.1.0") click_button "Compare" - expect(page).to have_content "Commits" + expect(page).to have_content "Commits on Source" end end diff --git a/spec/frontend/projects/compare/components/app_spec.js b/spec/frontend/projects/compare/components/app_spec.js index f8c10311974..6cc76d4a573 100644 --- a/spec/frontend/projects/compare/components/app_spec.js +++ b/spec/frontend/projects/compare/components/app_spec.js @@ -1,24 +1,37 @@ -import { GlButton, GlCollapsibleListbox } from '@gitlab/ui'; -import { shallowMount } from '@vue/test-utils'; +import { GlIcon, GlLink, GlSprintf, GlFormGroup, GlFormRadioGroup, GlFormRadio } from '@gitlab/ui'; import { nextTick } from 'vue'; +import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; import CompareApp from '~/projects/compare/components/app.vue'; +import { + COMPARE_REVISIONS_DOCS_URL, + I18N, + COMPARE_OPTIONS, + COMPARE_OPTIONS_INPUT_NAME, +} from '~/projects/compare/constants'; import RevisionCard from '~/projects/compare/components/revision_card.vue'; +import { createMockDirective, getBinding } from 'helpers/vue_mock_directive'; import { appDefaultProps as defaultProps } from './mock_data'; jest.mock('~/lib/utils/csrf', () => ({ token: 'mock-csrf-token' })); describe('CompareApp component', () => { let wrapper; - const findSourceRevisionCard = () => wrapper.find('[data-testid="sourceRevisionCard"]'); - const findTargetRevisionCard = () => wrapper.find('[data-testid="targetRevisionCard"]'); + const findSourceRevisionCard = () => wrapper.findByTestId('sourceRevisionCard'); + const findTargetRevisionCard = () => wrapper.findByTestId('targetRevisionCard'); const createComponent = (props = {}) => { - wrapper = shallowMount(CompareApp, { + wrapper = shallowMountExtended(CompareApp, { propsData: { ...defaultProps, ...props, }, - stubs: { GlCollapsibleListbox }, + directives: { + GlTooltip: createMockDirective('gl-tooltip'), + }, + stubs: { + GlSprintf, + GlFormRadioGroup, + }, }); }; @@ -38,6 +51,21 @@ describe('CompareApp component', () => { ); }); + it('renders title', () => { + const title = wrapper.find('h1'); + expect(title.text()).toBe(I18N.title); + }); + + it('renders subtitle', () => { + const subtitle = wrapper.find('p'); + expect(subtitle.text()).toMatchInterpolatedText(I18N.subtitle); + }); + + it('renders link to docs', () => { + const docsLink = wrapper.findComponent(GlLink); + expect(docsLink.attributes('href')).toBe(COMPARE_REVISIONS_DOCS_URL); + }); + it('contains the correct form attributes', () => { expect(wrapper.attributes('action')).toBe(defaultProps.projectCompareIndexPath); expect(wrapper.attributes('method')).toBe('POST'); @@ -49,20 +77,16 @@ describe('CompareApp component', () => { ); }); - it('has ellipsis', () => { - expect(wrapper.find('[data-testid="ellipsis"]').exists()).toBe(true); - }); - it('render Source and Target BranchDropdown components', () => { const revisionCards = wrapper.findAllComponents(RevisionCard); expect(revisionCards.length).toBe(2); - expect(revisionCards.at(0).props('revisionText')).toBe('Source'); - expect(revisionCards.at(1).props('revisionText')).toBe('Target'); + expect(revisionCards.at(0).props('revisionText')).toBe(I18N.source); + expect(revisionCards.at(1).props('revisionText')).toBe(I18N.target); }); describe('compare button', () => { - const findCompareButton = () => wrapper.findComponent(GlButton); + const findCompareButton = () => wrapper.findByTestId('compare-button'); it('renders button', () => { expect(findCompareButton().exists()).toBe(true); @@ -110,14 +134,19 @@ describe('CompareApp component', () => { }); describe('swap revisions button', () => { - const findSwapRevisionsButton = () => wrapper.find('[data-testid="swapRevisionsButton"]'); + const findSwapRevisionsButton = () => wrapper.findByTestId('swapRevisionsButton'); it('renders the swap revisions button', () => { expect(findSwapRevisionsButton().exists()).toBe(true); }); - it('has the correct text', () => { - expect(findSwapRevisionsButton().text()).toBe('Swap revisions'); + it('renders icon', () => { + expect(findSwapRevisionsButton().findComponent(GlIcon).props('name')).toBe('substitute'); + }); + + it('has tooltip', () => { + const tooltip = getBinding(findSwapRevisionsButton().element, 'gl-tooltip'); + expect(tooltip.value).toBe(I18N.swapRevisions); }); it('swaps revisions when clicked', async () => { @@ -130,39 +159,43 @@ describe('CompareApp component', () => { }); }); - describe('mode dropdown', () => { - const findGlDropdown = () => wrapper.findComponent(GlCollapsibleListbox); - const findEnableStraightModeButton = () => - wrapper.findComponent('[data-testid="listbox-item-true"]'); - const findDisableStraightModeButton = () => - wrapper.findComponent('[data-testid="listbox-item-false"]'); + describe('compare options', () => { + const findGroup = () => wrapper.findComponent(GlFormGroup); + const findOptionsGroup = () => wrapper.findComponent(GlFormRadioGroup); - it('renders the mode dropdown button', () => { - expect(findGlDropdown().exists()).toBe(true); + const findOptions = () => wrapper.findAllComponents(GlFormRadio); + + it('renders label for the compare options', () => { + expect(findGroup().attributes('label')).toBe(I18N.optionsLabel); }); - it('has the correct text', () => { - expect(findEnableStraightModeButton().text()).toBe('...'); - expect(findDisableStraightModeButton().text()).toBe('..'); + it('correct input name', () => { + expect(findOptionsGroup().attributes('name')).toBe(COMPARE_OPTIONS_INPUT_NAME); + }); + + it('renders "only incoming changes" option', () => { + expect(findOptions().at(0).text()).toBe(COMPARE_OPTIONS[0].text); + }); + + it('renders "since source was created" option', () => { + expect(findOptions().at(1).text()).toBe(COMPARE_OPTIONS[1].text); }); it('straight mode button when clicked', async () => { - expect(wrapper.find('input[name="straight"]').attributes('value')).toBe('false'); + expect(wrapper.props('straight')).toBe(false); + expect(wrapper.vm.isStraight).toBe(false); - findGlDropdown().vm.$emit('select', 'true'); - await nextTick(); + findOptionsGroup().vm.$emit('input', COMPARE_OPTIONS[1].value); - expect(wrapper.find('input[name="straight"]').attributes('value')).toBe('true'); - findGlDropdown().vm.$emit('select', 'false'); await nextTick(); - expect(wrapper.find('input[name="straight"]').attributes('value')).toBe('false'); + expect(wrapper.vm.isStraight).toBe(true); }); }); describe('merge request buttons', () => { - const findProjectMrButton = () => wrapper.find('[data-testid="projectMrButton"]'); - const findCreateMrButton = () => wrapper.find('[data-testid="createMrButton"]'); + const findProjectMrButton = () => wrapper.findByTestId('projectMrButton'); + const findCreateMrButton = () => wrapper.findByTestId('createMrButton'); it('does not have merge request buttons', () => { createComponent(); diff --git a/spec/requests/api/ci/pipeline_schedules_spec.rb b/spec/requests/api/ci/pipeline_schedules_spec.rb index d760e4ddf28..d5f60e62b06 100644 --- a/spec/requests/api/ci/pipeline_schedules_spec.rb +++ b/spec/requests/api/ci/pipeline_schedules_spec.rb @@ -311,7 +311,8 @@ RSpec.describe API::Ci::PipelineSchedules, feature_category: :continuous_integra end end - describe 'POST /projects/:id/pipeline_schedules' do + # Move this from `shared_context` to `describe` when `ci_refactoring_pipeline_schedule_create_service` is removed. + shared_context 'POST /projects/:id/pipeline_schedules' do # rubocop:disable RSpec/ContextWording let(:params) { attributes_for(:ci_pipeline_schedule) } context 'authenticated user with valid permissions' do @@ -368,7 +369,8 @@ RSpec.describe API::Ci::PipelineSchedules, feature_category: :continuous_integra end end - describe 'PUT /projects/:id/pipeline_schedules/:pipeline_schedule_id' do + # Move this from `shared_context` to `describe` when `ci_refactoring_pipeline_schedule_create_service` is removed. + shared_context 'PUT /projects/:id/pipeline_schedules/:pipeline_schedule_id' do let(:pipeline_schedule) do create(:ci_pipeline_schedule, project: project, owner: developer) end @@ -437,6 +439,18 @@ RSpec.describe API::Ci::PipelineSchedules, feature_category: :continuous_integra end end + it_behaves_like 'POST /projects/:id/pipeline_schedules' + it_behaves_like 'PUT /projects/:id/pipeline_schedules/:pipeline_schedule_id' + + context 'when the FF ci_refactoring_pipeline_schedule_create_service is disabled' do + before do + stub_feature_flags(ci_refactoring_pipeline_schedule_create_service: false) + end + + it_behaves_like 'POST /projects/:id/pipeline_schedules' + it_behaves_like 'PUT /projects/:id/pipeline_schedules/:pipeline_schedule_id' + end + describe 'POST /projects/:id/pipeline_schedules/:pipeline_schedule_id/take_ownership' do let(:pipeline_schedule) do create(:ci_pipeline_schedule, project: project, owner: developer) diff --git a/spec/requests/api/graphql/mutations/ci/pipeline_schedule_create_spec.rb b/spec/requests/api/graphql/mutations/ci/pipeline_schedule_create_spec.rb index 4a45d255d99..a89fc6eb6f1 100644 --- a/spec/requests/api/graphql/mutations/ci/pipeline_schedule_create_spec.rb +++ b/spec/requests/api/graphql/mutations/ci/pipeline_schedule_create_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe 'PipelineSchedulecreate' do +RSpec.describe 'PipelineSchedulecreate', feature_category: :continuous_integration do include GraphqlHelpers let_it_be(:user) { create(:user) } @@ -68,7 +68,8 @@ RSpec.describe 'PipelineSchedulecreate' do end end - context 'when authorized' do + # Move this from `shared_context` to `context` when `ci_refactoring_pipeline_schedule_create_service` is removed. + shared_context 'when authorized' do # rubocop:disable RSpec/ContextWording before do project.add_developer(user) end @@ -148,4 +149,14 @@ RSpec.describe 'PipelineSchedulecreate' do end end end + + it_behaves_like 'when authorized' + + context 'when the FF ci_refactoring_pipeline_schedule_create_service is disabled' do + before do + stub_feature_flags(ci_refactoring_pipeline_schedule_create_service: false) + end + + it_behaves_like 'when authorized' + end end diff --git a/spec/services/ci/pipeline_schedules/create_service_spec.rb b/spec/services/ci/pipeline_schedules/create_service_spec.rb new file mode 100644 index 00000000000..a01c71432c3 --- /dev/null +++ b/spec/services/ci/pipeline_schedules/create_service_spec.rb @@ -0,0 +1,86 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Ci::PipelineSchedules::CreateService, feature_category: :continuous_integration do + let_it_be(:user) { create(:user) } + let_it_be(:reporter) { create(:user) } + let_it_be(:project) { create(:project, :public, :repository) } + + before_all do + project.add_maintainer(user) + project.add_reporter(reporter) + end + + describe "execute" do + context 'when user does not have permission' do + subject(:service) { described_class.new(project, reporter, {}) } + + it 'returns ServiceResponse.error' do + result = service.execute + + expect(result).to be_a(ServiceResponse) + expect(result.error?).to be(true) + + error_message = _('The current user is not authorized to create the pipeline schedule') + expect(result.message).to match_array([error_message]) + expect(result.payload.errors).to match_array([error_message]) + end + end + + context 'when user has permission' do + let(:params) do + { + description: 'desc', + ref: 'patch-x', + active: false, + cron: '*/1 * * * *', + cron_timezone: 'UTC' + } + end + + subject(:service) { described_class.new(project, user, params) } + + it 'saves values with passed params' do + result = service.execute + + expect(result.payload).to have_attributes( + description: 'desc', + ref: 'patch-x', + active: false, + cron: '*/1 * * * *', + cron_timezone: 'UTC' + ) + end + + it 'returns ServiceResponse.success' do + result = service.execute + + expect(result).to be_a(ServiceResponse) + expect(result.success?).to be(true) + end + + context 'when schedule save fails' do + subject(:service) { described_class.new(project, user, {}) } + + before do + errors = ActiveModel::Errors.new(project) + errors.add(:base, 'An error occurred') + + allow_next_instance_of(Ci::PipelineSchedule) do |instance| + allow(instance).to receive(:save).and_return(false) + allow(instance).to receive(:errors).and_return(errors) + end + end + + it 'returns ServiceResponse.error' do + result = service.execute + + expect(result).to be_a(ServiceResponse) + expect(result.error?).to be(true) + expect(result.message).to match_array(['An error occurred']) + end + end + end + end +end diff --git a/spec/services/ci/pipeline_schedules/update_service_spec.rb b/spec/services/ci/pipeline_schedules/update_service_spec.rb index 838f49f6dea..6899f6c7d63 100644 --- a/spec/services/ci/pipeline_schedules/update_service_spec.rb +++ b/spec/services/ci/pipeline_schedules/update_service_spec.rb @@ -22,7 +22,10 @@ RSpec.describe Ci::PipelineSchedules::UpdateService, feature_category: :continuo expect(result).to be_a(ServiceResponse) expect(result.error?).to be(true) - expect(result.message).to eq(_('The current user is not authorized to update the pipeline schedule')) + + error_message = _('The current user is not authorized to update the pipeline schedule') + expect(result.message).to match_array([error_message]) + expect(pipeline_schedule.errors).to match_array([error_message]) end end @@ -58,7 +61,7 @@ RSpec.describe Ci::PipelineSchedules::UpdateService, feature_category: :continuo subject(:service) { described_class.new(pipeline_schedule, user, {}) } before do - allow(pipeline_schedule).to receive(:update).and_return(false) + allow(pipeline_schedule).to receive(:save).and_return(false) errors = ActiveModel::Errors.new(pipeline_schedule) errors.add(:base, 'An error occurred') diff --git a/spec/support/shared_examples/features/work_items_shared_examples.rb b/spec/support/shared_examples/features/work_items_shared_examples.rb index 128bd28410c..4c15b682458 100644 --- a/spec/support/shared_examples/features/work_items_shared_examples.rb +++ b/spec/support/shared_examples/features/work_items_shared_examples.rb @@ -166,7 +166,8 @@ RSpec.shared_examples 'work items comments' do |type| end RSpec.shared_examples 'work items assignees' do - it 'successfully assigns the current user by searching' do + it 'successfully assigns the current user by searching', + quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/413074' do # The button is only when the mouse is over the input find('[data-testid="work-item-assignees-input"]').fill_in(with: user.username) wait_for_requests |