diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /spec/features/projects | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/features/projects')
42 files changed, 544 insertions, 401 deletions
diff --git a/spec/features/projects/badges/coverage_spec.rb b/spec/features/projects/badges/coverage_spec.rb index 4c144037acd..1760ec880bc 100644 --- a/spec/features/projects/badges/coverage_spec.rb +++ b/spec/features/projects/badges/coverage_spec.rb @@ -63,7 +63,7 @@ RSpec.describe 'test coverage badge' do create(:ci_pipeline, opts).tap do |pipeline| yield pipeline - pipeline.update_legacy_status + ::Ci::ProcessPipelineService.new(pipeline).execute end end diff --git a/spec/features/projects/blobs/blob_line_permalink_updater_spec.rb b/spec/features/projects/blobs/blob_line_permalink_updater_spec.rb index 6bd6634822c..a65a82fab43 100644 --- a/spec/features/projects/blobs/blob_line_permalink_updater_spec.rb +++ b/spec/features/projects/blobs/blob_line_permalink_updater_spec.rb @@ -50,7 +50,7 @@ RSpec.describe 'Blob button line permalinks (BlobLinePermalinkUpdater)', :js do visit_blob find("##{ending_fragment}").hover - find("##{ending_fragment} i").click + find("##{ending_fragment} svg").click expect(find('.js-data-file-blob-permalink-url')['href']).to eq(get_absolute_url(project_blob_path(project, tree_join(sha, path), anchor: ending_fragment))) end @@ -100,7 +100,7 @@ RSpec.describe 'Blob button line permalinks (BlobLinePermalinkUpdater)', :js do visit_blob find("##{ending_fragment}").hover - find("##{ending_fragment} i").click + find("##{ending_fragment} svg").click expect(find('.js-blob-blame-link')['href']).to eq(get_absolute_url(project_blame_path(project, tree_join('master', path), anchor: ending_fragment))) end diff --git a/spec/features/projects/ci/lint_spec.rb b/spec/features/projects/ci/lint_spec.rb index f3845bb8dec..ba063acbe70 100644 --- a/spec/features/projects/ci/lint_spec.rb +++ b/spec/features/projects/ci/lint_spec.rb @@ -21,32 +21,48 @@ RSpec.describe 'CI Lint', :js do end describe 'YAML parsing' do - before do - click_on 'Validate' - end + shared_examples 'validates the YAML' do + before do + click_on 'Validate' + end - context 'YAML is correct' do - let(:yaml_content) do - File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml')) + context 'YAML is correct' do + let(:yaml_content) do + File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml')) + end + + it 'parses Yaml and displays the jobs' do + expect(page).to have_content('Status: syntax is correct') + + within "table" do + aggregate_failures do + expect(page).to have_content('Job - rspec') + expect(page).to have_content('Job - spinach') + expect(page).to have_content('Deploy Job - staging') + expect(page).to have_content('Deploy Job - production') + end + end + end end - it 'parses Yaml' do - within "table" do - expect(page).to have_content('Job - rspec') - expect(page).to have_content('Job - spinach') - expect(page).to have_content('Deploy Job - staging') - expect(page).to have_content('Deploy Job - production') + context 'YAML is incorrect' do + let(:yaml_content) { 'value: cannot have :' } + + it 'displays information about an error' do + expect(page).to have_content('Status: syntax is incorrect') + expect(page).to have_selector('.ace_content', text: yaml_content) end end end - context 'YAML is incorrect' do - let(:yaml_content) { 'value: cannot have :' } + it_behaves_like 'validates the YAML' - it 'displays information about an error' do - expect(page).to have_content('Status: syntax is incorrect') - expect(page).to have_selector('.ace_content', text: yaml_content) + context 'when Dry Run is checked' do + before do + check 'Simulate a pipeline created for the default branch' end + + it_behaves_like 'validates the YAML' end describe 'YAML revalidate' do diff --git a/spec/features/projects/classification_label_on_project_pages_spec.rb b/spec/features/projects/classification_label_on_project_pages_spec.rb index 0f07ca7635b..9522e5ce2cf 100644 --- a/spec/features/projects/classification_label_on_project_pages_spec.rb +++ b/spec/features/projects/classification_label_on_project_pages_spec.rb @@ -6,6 +6,7 @@ RSpec.describe 'Classification label on project pages' do let(:project) do create(:project, external_authorization_classification_label: 'authorized label') end + let(:user) { create(:user) } before do diff --git a/spec/features/projects/clusters/gcp_spec.rb b/spec/features/projects/clusters/gcp_spec.rb index 2e6a366f77a..63e5546b43c 100644 --- a/spec/features/projects/clusters/gcp_spec.rb +++ b/spec/features/projects/clusters/gcp_spec.rb @@ -205,11 +205,10 @@ RSpec.describe 'Gcp Cluster', :js, :do_not_mock_admin_mode do let(:admin) { create(:admin) } before do - stub_feature_flags(instance_level_integrations: false) stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false') sign_in(admin) gitlab_enable_admin_mode_sign_in(admin) - visit integrations_admin_application_settings_path + visit general_admin_application_settings_path end it 'user does not see the offer' do diff --git a/spec/features/projects/clusters/user_spec.rb b/spec/features/projects/clusters/user_spec.rb index 15fed0c2727..450eaa7f004 100644 --- a/spec/features/projects/clusters/user_spec.rb +++ b/spec/features/projects/clusters/user_spec.rb @@ -73,6 +73,7 @@ RSpec.describe 'User Cluster', :js do end it 'user sees a cluster details page' do + expect(page).to have_content('GitLab Integration') expect(page).to have_button('Save changes') end diff --git a/spec/features/projects/commit/diff_notes_spec.rb b/spec/features/projects/commit/diff_notes_spec.rb index ff86047d812..6cebff1cc9a 100644 --- a/spec/features/projects/commit/diff_notes_spec.rb +++ b/spec/features/projects/commit/diff_notes_spec.rb @@ -8,30 +8,35 @@ RSpec.describe 'Commit diff', :js do let(:user) { create(:user) } let(:project) { create(:project, :public, :repository) } - before do - project.add_maintainer(user) - sign_in user + using RSpec::Parameterized::TableSyntax + + where(:view, :async_diff_file_loading) do + 'inline' | true + 'inline' | false + 'parallel' | true + 'parallel' | false end - %w(inline parallel).each do |view| - context "#{view} view" do - before do - visit project_commit_path(project, sample_commit.id, view: view) - end + with_them do + before do + stub_feature_flags(async_commit_diff_files: async_diff_file_loading) + project.add_maintainer(user) + sign_in user + visit project_commit_path(project, sample_commit.id, view: view) + end - it "adds comment to diff" do - diff_line_num = first('.diff-line-num.new') + it "adds comment to diff" do + diff_line_num = first('.diff-line-num.new') - diff_line_num.hover - diff_line_num.find('.js-add-diff-note-button').click + diff_line_num.hover + diff_line_num.find('.js-add-diff-note-button').click - page.within(first('.diff-viewer')) do - find('.js-note-text').set 'test comment' + page.within(first('.diff-viewer')) do + find('.js-note-text').set 'test comment' - click_button 'Comment' + click_button 'Comment' - expect(page).to have_content('test comment') - end + expect(page).to have_content('test comment') end end end diff --git a/spec/features/projects/commit/mini_pipeline_graph_spec.rb b/spec/features/projects/commit/mini_pipeline_graph_spec.rb index 9349f36282d..7bd3bce85d5 100644 --- a/spec/features/projects/commit/mini_pipeline_graph_spec.rb +++ b/spec/features/projects/commit/mini_pipeline_graph_spec.rb @@ -12,6 +12,7 @@ RSpec.describe 'Mini Pipeline Graph in Commit View', :js do ref: project.default_branch, sha: project.commit.sha) end + let(:build) { create(:ci_build, pipeline: pipeline) } it 'display icon with status' do @@ -25,6 +26,8 @@ RSpec.describe 'Mini Pipeline Graph in Commit View', :js do build.run visit project_commit_path(project, project.commit.id) + wait_for_all_requests + expect(page).to have_selector('.mr-widget-pipeline-graph') first('.mini-pipeline-graph-dropdown-toggle').click diff --git a/spec/features/projects/commit/user_views_user_status_on_commit_spec.rb b/spec/features/projects/commit/user_views_user_status_on_commit_spec.rb index 71405cf917d..89ff2f4b26d 100644 --- a/spec/features/projects/commit/user_views_user_status_on_commit_spec.rb +++ b/spec/features/projects/commit/user_views_user_status_on_commit_spec.rb @@ -30,7 +30,7 @@ RSpec.describe 'Project > Commit > View user status' do end end - describe 'status for a diff note on the commit' do + describe 'status for a diff note on the commit', :js do let(:note) { create(:diff_note_on_commit, project: project) } it_behaves_like 'showing user status' do diff --git a/spec/features/projects/commits/user_browses_commits_spec.rb b/spec/features/projects/commits/user_browses_commits_spec.rb index dee964005a4..596b4773716 100644 --- a/spec/features/projects/commits/user_browses_commits_spec.rb +++ b/spec/features/projects/commits/user_browses_commits_spec.rb @@ -41,7 +41,7 @@ RSpec.describe 'User browses commits' do .and have_selector('ul.breadcrumb a', count: 4) end - it 'renders diff links to both the previous and current image' do + it 'renders diff links to both the previous and current image', :js do visit project_commit_path(project, sample_image_commit.id) links = page.all('.file-actions a') diff --git a/spec/features/projects/environments/environment_metrics_spec.rb b/spec/features/projects/environments/environment_metrics_spec.rb index c72f88205b5..8315c821b6d 100644 --- a/spec/features/projects/environments/environment_metrics_spec.rb +++ b/spec/features/projects/environments/environment_metrics_spec.rb @@ -28,9 +28,8 @@ RSpec.describe 'Environment > Metrics' do shared_examples 'has environment selector' do it 'has a working environment selector', :js do click_link('See metrics') - # TODO: See metrics on the sidebar still points to the old metrics URL - # https://gitlab.com/gitlab-org/gitlab/-/issues/229277 - expect(page).to have_current_path(metrics_project_environment_path(project, id: environment.id)) + + expect(page).to have_current_path(project_metrics_dashboard_path(project, environment: environment.id)) expect(page).to have_css('[data-qa-selector="environments_dropdown"]') within('[data-qa-selector="environments_dropdown"]') do diff --git a/spec/features/projects/environments/environments_spec.rb b/spec/features/projects/environments/environments_spec.rb index b3f671d57a9..a05910cd892 100644 --- a/spec/features/projects/environments/environments_spec.rb +++ b/spec/features/projects/environments/environments_spec.rb @@ -37,7 +37,7 @@ RSpec.describe 'Environments page', :js do expect(page).to have_css('.environments-container') expect(page.all('.environment-name').length).to eq(1) - expect(page.all('.ic-stop').length).to eq(1) + expect(page.all('[data-testid="stop-icon"]').length).to eq(1) end end diff --git a/spec/features/projects/features_visibility_spec.rb b/spec/features/projects/features_visibility_spec.rb index d84c39de8d8..8d3ca9d9fd1 100644 --- a/spec/features/projects/features_visibility_spec.rb +++ b/spec/features/projects/features_visibility_spec.rb @@ -186,7 +186,7 @@ RSpec.describe 'Edit Project Settings' do click_button "Save changes" end - expect(find(".sharing-permissions")).to have_selector(".project-feature-toggle.is-disabled", count: 3) + expect(find(".sharing-permissions")).to have_selector(".project-feature-toggle.is-disabled", count: 4) end it "shows empty features project homepage" do diff --git a/spec/features/projects/files/user_browses_files_spec.rb b/spec/features/projects/files/user_browses_files_spec.rb index e5259bd88be..a6126fbcb33 100644 --- a/spec/features/projects/files/user_browses_files_spec.rb +++ b/spec/features/projects/files/user_browses_files_spec.rb @@ -9,6 +9,7 @@ RSpec.describe "User browses files" do "You're not allowed to make changes to this project directly. "\ "A fork of this project has been created that you can make changes in, so you can submit a merge request." end + let(:project) { create(:project, :repository, name: "Shop") } let(:project2) { create(:project, :repository, name: "Another Project", path: "another-project") } let(:tree_path_root_ref) { project_tree_path(project, project.repository.root_ref) } diff --git a/spec/features/projects/files/user_creates_directory_spec.rb b/spec/features/projects/files/user_creates_directory_spec.rb index 47c5d667f4f..f2074c78dba 100644 --- a/spec/features/projects/files/user_creates_directory_spec.rb +++ b/spec/features/projects/files/user_creates_directory_spec.rb @@ -7,6 +7,7 @@ RSpec.describe 'Projects > Files > User creates a directory', :js do "You're not allowed to make changes to this project directly. "\ "A fork of this project has been created that you can make changes in, so you can submit a merge request." end + let(:project) { create(:project, :repository) } let(:project2) { create(:project, :repository, name: 'Another Project', path: 'another-project') } let(:project2_tree_path_root_ref) { project_tree_path(project2, project2.repository.root_ref) } diff --git a/spec/features/projects/files/user_creates_files_spec.rb b/spec/features/projects/files/user_creates_files_spec.rb index 5abc048c135..39bc139656b 100644 --- a/spec/features/projects/files/user_creates_files_spec.rb +++ b/spec/features/projects/files/user_creates_files_spec.rb @@ -7,6 +7,7 @@ RSpec.describe 'Projects > Files > User creates files', :js do "You're not allowed to make changes to this project directly. "\ "A fork of this project has been created that you can make changes in, so you can submit a merge request." end + let(:project) { create(:project, :repository, name: 'Shop') } let(:project2) { create(:project, :repository, name: 'Another Project', path: 'another-project') } let(:project_tree_path_root_ref) { project_tree_path(project, project.repository.root_ref) } diff --git a/spec/features/projects/files/user_deletes_files_spec.rb b/spec/features/projects/files/user_deletes_files_spec.rb index 4df23b852ff..b6e300e9e59 100644 --- a/spec/features/projects/files/user_deletes_files_spec.rb +++ b/spec/features/projects/files/user_deletes_files_spec.rb @@ -7,6 +7,7 @@ RSpec.describe 'Projects > Files > User deletes files', :js do "You're not allowed to make changes to this project directly. "\ "A fork of this project has been created that you can make changes in, so you can submit a merge request." end + let(:project) { create(:project, :repository, name: 'Shop') } let(:project2) { create(:project, :repository, name: 'Another Project', path: 'another-project') } let(:project_tree_path_root_ref) { project_tree_path(project, project.repository.root_ref) } diff --git a/spec/features/projects/files/user_replaces_files_spec.rb b/spec/features/projects/files/user_replaces_files_spec.rb index b11cf732c95..c9b472260bd 100644 --- a/spec/features/projects/files/user_replaces_files_spec.rb +++ b/spec/features/projects/files/user_replaces_files_spec.rb @@ -9,6 +9,7 @@ RSpec.describe 'Projects > Files > User replaces files', :js do "You're not allowed to make changes to this project directly. "\ "A fork of this project has been created that you can make changes in, so you can submit a merge request." end + let(:project) { create(:project, :repository, name: 'Shop') } let(:project2) { create(:project, :repository, name: 'Another Project', path: 'another-project') } let(:project_tree_path_root_ref) { project_tree_path(project, project.repository.root_ref) } diff --git a/spec/features/projects/fork_spec.rb b/spec/features/projects/fork_spec.rb index f0ed4013230..1e84d1552a1 100644 --- a/spec/features/projects/fork_spec.rb +++ b/spec/features/projects/fork_spec.rb @@ -15,7 +15,7 @@ RSpec.describe 'Project fork' do it 'allows user to fork project' do visit project_path(project) - expect(page).not_to have_css('a.disabled', text: 'Fork') + expect(page).not_to have_css('a.disabled', text: 'Select') end it 'disables fork button when user has exceeded project limit' do @@ -40,7 +40,7 @@ RSpec.describe 'Project fork' do visit project_path(project) expect(page).to have_css('a', text: 'Fork') - expect(page).not_to have_css('a.disabled', text: 'Fork') + expect(page).not_to have_css('a.disabled', text: 'Select') end it 'renders new project fork page' do @@ -116,7 +116,7 @@ RSpec.describe 'Project fork' do click_link 'Fork' page.within '.fork-thumbnail-container' do - click_link user.name + click_link 'Select' end expect(page).to have_content 'Forked from' @@ -156,7 +156,7 @@ RSpec.describe 'Project fork' do click_link 'Fork' page.within '.fork-thumbnail-container' do - click_link user.name + click_link 'Select' end visit project_forks_path(project) @@ -193,7 +193,7 @@ RSpec.describe 'Project fork' do click_link 'Fork' page.within '.fork-thumbnail-container' do - click_link user.name + click_link 'Select' end visit project_forks_path(project) @@ -218,7 +218,7 @@ RSpec.describe 'Project fork' do click_link 'Fork' page.within '.fork-thumbnail-container' do - click_link user.name + click_link 'Select' end expect(page).to have_content "Name has already been taken" @@ -232,39 +232,43 @@ RSpec.describe 'Project fork' do group.add_maintainer(user) end - it 'allows user to fork project to group or to user namespace' do + it 'allows user to fork project to group or to user namespace', :js do visit project_path(project) + wait_for_requests expect(page).not_to have_css('a.disabled', text: 'Fork') click_link 'Fork' - expect(page).to have_css('.fork-thumbnail', count: 2) + expect(page).to have_css('.fork-thumbnail') + expect(page).to have_css('.group-row') expect(page).not_to have_css('.fork-thumbnail.disabled') end - it 'allows user to fork project to group and not user when exceeded project limit' do + it 'allows user to fork project to group and not user when exceeded project limit', :js do user.projects_limit = 0 user.save! visit project_path(project) + wait_for_requests expect(page).not_to have_css('a.disabled', text: 'Fork') click_link 'Fork' - expect(page).to have_css('.fork-thumbnail', count: 2) expect(page).to have_css('.fork-thumbnail.disabled') + expect(page).to have_css('.group-row') end - it 'links to the fork if the project was already forked within that namespace', :sidekiq_might_not_need_inline do + it 'links to the fork if the project was already forked within that namespace', :sidekiq_might_not_need_inline, :js do forked_project = fork_project(project, user, namespace: group, repository: true) visit new_project_fork_path(project) + wait_for_requests - expect(page).to have_css('div.forked', text: group.full_name) + expect(page).to have_css('.group-row a.btn', text: 'Go to fork') - click_link group.full_name + click_link 'Go to fork' expect(current_path).to eq(project_path(forked_project)) end diff --git a/spec/features/projects/import_export/export_file_spec.rb b/spec/features/projects/import_export/export_file_spec.rb index 86aeb2bc80c..7f8ded4fa43 100644 --- a/spec/features/projects/import_export/export_file_spec.rb +++ b/spec/features/projects/import_export/export_file_spec.rb @@ -19,6 +19,7 @@ RSpec.describe 'Import/Export - project export integration test', :js do key: [Project, Ci::Variable, :yaml_variables] } end + let(:safe_hashes) { { yaml_variables: %w[key value public] } } let(:project) { setup_project } diff --git a/spec/features/projects/issues/design_management/user_uploads_designs_spec.rb b/spec/features/projects/issues/design_management/user_uploads_designs_spec.rb index 8070fee5804..29a27992a0d 100644 --- a/spec/features/projects/issues/design_management/user_uploads_designs_spec.rb +++ b/spec/features/projects/issues/design_management/user_uploads_designs_spec.rb @@ -5,9 +5,9 @@ require 'spec_helper' RSpec.describe 'User uploads new design', :js do include DesignManagementTestHelpers - let_it_be(:project) { create(:project_empty_repo, :public) } - let_it_be(:user) { project.owner } - let_it_be(:issue) { create(:issue, project: project) } + let(:project) { create(:project_empty_repo, :public) } + let(:user) { project.owner } + let(:issue) { create(:issue, project: project) } before do sign_in(user) @@ -28,7 +28,7 @@ RSpec.describe 'User uploads new design', :js do let(:feature_enabled) { true } it 'uploads designs' do - attach_file(:design_file, logo_fixture, make_visible: true) + upload_design(logo_fixture, count: 1) expect(page).to have_selector('.js-design-list-item', count: 1) @@ -36,9 +36,12 @@ RSpec.describe 'User uploads new design', :js do expect(page).to have_content('dk.png') end - attach_file(:design_file, gif_fixture, make_visible: true) + upload_design(gif_fixture, count: 2) + # Known bug in the legacy implementation: new designs are inserted + # in the beginning on the frontend. expect(page).to have_selector('.js-design-list-item', count: 2) + expect(page.all('.js-design-list-item').map(&:text)).to eq(['banana_sample.gif', 'dk.png']) end end @@ -61,8 +64,8 @@ RSpec.describe 'User uploads new design', :js do context "when the feature is available" do let(:feature_enabled) { true } - it 'uploads designs', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/225616' do - attach_file(:design_file, logo_fixture, make_visible: true) + it 'uploads designs' do + upload_design(logo_fixture, count: 1) expect(page).to have_selector('.js-design-list-item', count: 1) @@ -70,9 +73,10 @@ RSpec.describe 'User uploads new design', :js do expect(page).to have_content('dk.png') end - attach_file(:design_file, gif_fixture, make_visible: true) + upload_design(gif_fixture, count: 2) expect(page).to have_selector('.js-design-list-item', count: 2) + expect(page.all('.js-design-list-item').map(&:text)).to eq(['dk.png', 'banana_sample.gif']) end end @@ -92,4 +96,12 @@ RSpec.describe 'User uploads new design', :js do def gif_fixture Rails.root.join('spec', 'fixtures', 'banana_sample.gif') end + + def upload_design(fixture, count:) + attach_file(:design_file, fixture, match: :first, make_visible: true) + + wait_for('designs uploaded') do + issue.reload.designs.count == count + end + end end 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 6feefff9207..b423543dc33 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 @@ -11,33 +11,39 @@ RSpec.describe 'viewing an issue with cross project references' do create(:project, :public, external_authorization_classification_label: 'other_label') end + let(:other_issue) do create(:issue, :closed, title: 'I am in another project', project: other_project) end + let(:other_confidential_issue) do create(:issue, :confidential, :closed, title: 'I am in another project and confidential', project: other_project) end + let(:other_merge_request) do create(:merge_request, :closed, title: 'I am a merge request in another project', source_project: other_project) end + let(:description_referencing_other_issue) do "Referencing: #{other_issue.to_reference(project)}, "\ "a confidential issue #{confidential_issue.to_reference}, "\ "a cross project confidential issue #{other_confidential_issue.to_reference(project)}, and "\ "a cross project merge request #{other_merge_request.to_reference(project)}" end + let(:project) { create(:project) } let(:issue) do create(:issue, project: project, description: description_referencing_other_issue ) end + let(:confidential_issue) do create(:issue, :confidential, :closed, title: "I am in the same project and confidential", diff --git a/spec/features/projects/jobs/user_browses_job_spec.rb b/spec/features/projects/jobs/user_browses_job_spec.rb index 67299e852b3..b935b99642b 100644 --- a/spec/features/projects/jobs/user_browses_job_spec.rb +++ b/spec/features/projects/jobs/user_browses_job_spec.rb @@ -26,7 +26,7 @@ RSpec.describe 'User browses a job', :js do # scroll to the top of the page first execute_script "window.scrollTo(0,0)" - accept_confirm { find('.js-erase-link').click } + accept_confirm { find('[data-testid="job-log-erase-link"]').click } expect(page).to have_no_css('.artifacts') expect(build).not_to have_trace diff --git a/spec/features/projects/jobs_spec.rb b/spec/features/projects/jobs_spec.rb index fc005dd4718..0a6f204454e 100644 --- a/spec/features/projects/jobs_spec.rb +++ b/spec/features/projects/jobs_spec.rb @@ -282,7 +282,7 @@ RSpec.describe 'Jobs', :clean_gitlab_redis_shared_state do href = new_project_issue_path(project, options) page.within('.build-sidebar') do - expect(find('.js-new-issue')['href']).to include(href) + expect(find('[data-testid="job-new-issue"]')['href']).to include(href) end end end @@ -425,7 +425,7 @@ RSpec.describe 'Jobs', :clean_gitlab_redis_shared_state do it do wait_for_all_requests - expect(page).to have_css('.js-raw-link-controller') + expect(page).to have_css('[data-testid="job-raw-link-controller"]') end end @@ -875,7 +875,7 @@ RSpec.describe 'Jobs', :clean_gitlab_redis_shared_state do visit project_job_path(project, job) wait_for_requests - page.within('.js-job-erased-block') do + page.within('[data-testid="job-erased-block"]') do expect(page).to have_content('Job has been erased') end end @@ -888,7 +888,7 @@ RSpec.describe 'Jobs', :clean_gitlab_redis_shared_state do visit project_job_path(project, job) wait_for_requests - expect(page).not_to have_css('.js-job-erased-block') + expect(page).not_to have_css('[data-testid="job-erased-block"]') end end @@ -901,8 +901,8 @@ RSpec.describe 'Jobs', :clean_gitlab_redis_shared_state do visit project_job_path(project, job) wait_for_requests - expect(page).to have_css('.js-job-sidebar.right-sidebar-collapsed', visible: false) - expect(page).not_to have_css('.js-job-sidebar.right-sidebar-expanded', visible: false) + expect(page).to have_css('[data-testid="job-sidebar"].right-sidebar-collapsed', visible: false) + expect(page).not_to have_css('[data-testid="job-sidebar"].right-sidebar-expanded', visible: false) end end @@ -913,8 +913,8 @@ RSpec.describe 'Jobs', :clean_gitlab_redis_shared_state do visit project_job_path(project, job) wait_for_requests - expect(page).to have_css('.js-job-sidebar.right-sidebar-expanded') - expect(page).not_to have_css('.js-job-sidebar.right-sidebar-collapsed') + expect(page).to have_css('[data-testid="job-sidebar"].right-sidebar-expanded') + expect(page).not_to have_css('[data-testid="job-sidebar"].right-sidebar-collapsed') end end @@ -929,7 +929,7 @@ RSpec.describe 'Jobs', :clean_gitlab_redis_shared_state do let(:job) { create(:ci_build, :pending, pipeline: pipeline, runner: runner) } it 'renders message about job being stuck because no runners are active' do - expect(page).to have_css('.js-stuck-no-active-runner') + expect(page).to have_selector('[data-testid="job-stuck-no-active-runners"]') expect(page).to have_content("This job is stuck because you don't have any active runners that can run this job.") end end @@ -939,7 +939,7 @@ RSpec.describe 'Jobs', :clean_gitlab_redis_shared_state do let(:job) { create(:ci_build, :pending, pipeline: pipeline, runner: runner, tag_list: %w(docker linux)) } it 'renders message about job being stuck because of no runners with the specified tags' do - expect(page).to have_css('.js-stuck-with-tags') + expect(page).to have_selector('[data-testid="job-stuck-with-tags"') expect(page).to have_content("This job is stuck because you don't have any active runners online or available with any of these tags assigned to them:") end end @@ -949,7 +949,7 @@ RSpec.describe 'Jobs', :clean_gitlab_redis_shared_state do let(:job) { create(:ci_build, :pending, pipeline: pipeline, runner: runner, tag_list: %w(docker linux)) } it 'renders message about job being stuck because of no runners with the specified tags' do - expect(page).to have_css('.js-stuck-with-tags') + expect(page).to have_selector('[data-testid="job-stuck-with-tags"') expect(page).to have_content("This job is stuck because you don't have any active runners online or available with any of these tags assigned to them:") end end @@ -957,8 +957,8 @@ RSpec.describe 'Jobs', :clean_gitlab_redis_shared_state do context 'without any runners available' do let(:job) { create(:ci_build, :pending, pipeline: pipeline) } - it 'renders message about job being stuck because not runners are available' do - expect(page).to have_css('.js-stuck-no-active-runner') + it 'renders message about job being stuck because no runners are available' do + expect(page).to have_selector('[data-testid="job-stuck-no-active-runners"]') expect(page).to have_content("This job is stuck because you don't have any active runners that can run this job.") end end @@ -968,7 +968,7 @@ RSpec.describe 'Jobs', :clean_gitlab_redis_shared_state do let(:job) { create(:ci_build, :pending, pipeline: pipeline, runner: runner) } it 'renders message about job being stuck because runners are offline' do - expect(page).to have_css('.js-stuck-no-runners') + expect(page).to have_selector('[data-testid="job-stuck-no-runners"') expect(page).to have_content("This job is stuck because the project doesn't have any runners online assigned to it.") end end diff --git a/spec/features/projects/members/list_spec.rb b/spec/features/projects/members/list_spec.rb index 56b807e08d7..b32ccb0ccef 100644 --- a/spec/features/projects/members/list_spec.rb +++ b/spec/features/projects/members/list_spec.rb @@ -65,7 +65,7 @@ RSpec.describe 'Project members list' do visit_members_page # Open modal - find(:css, 'li.project_member', text: other_user.name).find(:css, 'button.btn-remove').click + find(:css, 'li.project_member', text: other_user.name).find(:css, 'button.btn-danger').click expect(page).to have_unchecked_field 'Also unassign this user from related issues and merge requests' diff --git a/spec/features/projects/members/master_manages_access_requests_spec.rb b/spec/features/projects/members/master_manages_access_requests_spec.rb index 4c3eaa93352..2fdc75dca91 100644 --- a/spec/features/projects/members/master_manages_access_requests_spec.rb +++ b/spec/features/projects/members/master_manages_access_requests_spec.rb @@ -4,6 +4,7 @@ require 'spec_helper' RSpec.describe 'Projects > Members > Maintainer manages access requests' do it_behaves_like 'Maintainer manages access requests' do + let(:has_tabs) { false } let(:entity) { create(:project, :public) } let(:members_page_path) { project_project_members_path(entity) } end diff --git a/spec/features/projects/navbar_spec.rb b/spec/features/projects/navbar_spec.rb index 22cd832ff06..dcb901bcf11 100644 --- a/spec/features/projects/navbar_spec.rb +++ b/spec/features/projects/navbar_spec.rb @@ -12,6 +12,10 @@ RSpec.describe 'Project navbar' do let_it_be(:project) { create(:project, :repository) } before do + stub_feature_flags(project_iterations: false) + + insert_package_nav(_('Operations')) + project.add_maintainer(user) sign_in(user) end @@ -58,13 +62,8 @@ RSpec.describe 'Project navbar' do before do stub_config(registry: { enabled: true }) - insert_after_nav_item( - _('Operations'), - new_nav_item: { - nav_item: _('Packages & Registries'), - nav_sub_items: [_('Container Registry')] - } - ) + insert_container_nav(_('Operations')) + visit project_path(project) end diff --git a/spec/features/projects/package_files_spec.rb b/spec/features/projects/package_files_spec.rb new file mode 100644 index 00000000000..bea9a9929b9 --- /dev/null +++ b/spec/features/projects/package_files_spec.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'PackageFiles' do + let(:user) { create(:user) } + let(:project) { create(:project) } + let!(:package) { create(:maven_package, project: project) } + let!(:package_file) { package.package_files.first } + + before do + sign_in(user) + end + + context 'user with master role' do + before do + project.add_maintainer(user) + end + + it 'allows direct download by url' do + visit download_project_package_file_path(project, package_file) + + expect(status_code).to eq(200) + end + + it 'renders the download link with the correct url', :js do + visit project_package_path(project, package) + + download_url = download_project_package_file_path(project, package_file) + + expect(page).to have_link(package_file.file_name, href: download_url) + end + + it 'does not allow download of package belonging to different project' do + another_package = create(:maven_package) + another_file = another_package.package_files.first + + visit download_project_package_file_path(project, another_file) + + expect(status_code).to eq(404) + end + end + + it 'does not allow direct download when no access to the project' do + visit download_project_package_file_path(project, package_file) + + expect(status_code).to eq(404) + end + + it 'gives 404 when no package file exist' do + visit download_project_package_file_path(project, non_existing_record_id) + + expect(status_code).to eq(404) + end +end diff --git a/spec/features/projects/packages_spec.rb b/spec/features/projects/packages_spec.rb new file mode 100644 index 00000000000..e5c684bdff5 --- /dev/null +++ b/spec/features/projects/packages_spec.rb @@ -0,0 +1,67 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Packages' do + let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project) } + + before do + sign_in(user) + project.add_maintainer(user) + end + + context 'when feature is not available' do + context 'packages feature is disabled by config' do + before do + allow(Gitlab.config.packages).to receive(:enabled).and_return(false) + end + + it 'gives 404' do + visit_project_packages + + expect(status_code).to eq(404) + end + end + end + + context 'when feature is available', :js do + before do + visit_project_packages + end + + context 'when there are packages' do + let_it_be(:conan_package) { create(:conan_package, project: project, name: 'zzz', created_at: 1.day.ago, version: '1.0.0') } + let_it_be(:maven_package) { create(:maven_package, project: project, name: 'aaa', created_at: 2.days.ago, version: '2.0.0') } + let_it_be(:packages) { [conan_package, maven_package] } + + it_behaves_like 'packages list' + + it_behaves_like 'package details link' + + context 'deleting a package' do + let_it_be(:project) { create(:project) } + let_it_be(:package) { create(:package, project: project) } + + it 'allows you to delete a package' do + first('[title="Remove package"]').click + click_button('Delete package') + + expect(page).to have_content 'Package deleted successfully' + expect(page).not_to have_content(package.name) + end + end + + it_behaves_like 'shared package sorting' do + let_it_be(:package_one) { maven_package } + let_it_be(:package_two) { conan_package } + end + end + + it_behaves_like 'when there are no packages' + end + + def visit_project_packages + visit project_packages_path(project) + end +end diff --git a/spec/features/projects/pipelines/pipeline_spec.rb b/spec/features/projects/pipelines/pipeline_spec.rb index 2ca584ab8f6..26c46190e7d 100644 --- a/spec/features/projects/pipelines/pipeline_spec.rb +++ b/spec/features/projects/pipelines/pipeline_spec.rb @@ -137,6 +137,7 @@ RSpec.describe 'Pipeline', :js do source_project: project, source_branch: pipeline.ref) end + let!(:merge_request2) do create(:merge_request, source_project: project, @@ -363,66 +364,29 @@ RSpec.describe 'Pipeline', :js do describe 'test tabs' do let(:pipeline) { create(:ci_pipeline, :with_test_reports, :with_report_results, project: project) } - context 'with build_report_summary feature flag disabled' do - before do - stub_feature_flags(build_report_summary: false) - visit_pipeline - wait_for_requests - end - - context 'with test reports' do - it 'shows badge counter in Tests tab' do - expect(pipeline.test_reports.total_count).to eq(4) - expect(page.find('.js-test-report-badge-counter').text).to eq(pipeline.test_reports.total_count.to_s) - end - - it 'does not call test_report.json endpoint by default', :js do - expect(page).to have_selector('.js-no-tests-to-show', visible: :all) - end - - it 'does call test_report.json endpoint when tab is selected', :js do - find('.js-tests-tab-link').click - wait_for_requests - - expect(page).to have_content('Jobs') - expect(page).to have_selector('.js-tests-detail', visible: :all) - end - end - - context 'without test reports' do - let(:pipeline) { create(:ci_pipeline, project: project) } - - it 'shows zero' do - expect(page.find('.js-test-report-badge-counter', visible: :all).text).to eq("0") - end - end + before do + visit_pipeline + wait_for_requests end - context 'with build_report_summary feature flag enabled' do - before do - visit_pipeline - wait_for_requests + context 'with test reports' do + it 'shows badge counter in Tests tab' do + expect(page.find('.js-test-report-badge-counter').text).to eq(pipeline.test_report_summary.total[:count].to_s) end - context 'with test reports' do - it 'shows badge counter in Tests tab' do - expect(page.find('.js-test-report-badge-counter').text).to eq(pipeline.test_report_summary.total_count.to_s) - end - - it 'calls summary.json endpoint', :js do - find('.js-tests-tab-link').click + it 'calls summary.json endpoint', :js do + find('.js-tests-tab-link').click - expect(page).to have_content('Jobs') - expect(page).to have_selector('.js-tests-detail', visible: :all) - end + expect(page).to have_content('Jobs') + expect(page).to have_selector('.js-tests-detail', visible: :all) end + end - context 'without test reports' do - let(:pipeline) { create(:ci_pipeline, project: project) } + context 'without test reports' do + let(:pipeline) { create(:ci_pipeline, project: project) } - it 'shows zero' do - expect(page.find('.js-test-report-badge-counter', visible: :all).text).to eq("0") - end + it 'shows zero' do + expect(page.find('.js-test-report-badge-counter', visible: :all).text).to eq("0") end end end @@ -436,7 +400,7 @@ RSpec.describe 'Pipeline', :js do context 'when retrying' do before do - find('.js-retry-button').click + find('[data-testid="retryButton"]').click end it 'does not show a "Retry" button', :sidekiq_might_not_need_inline do @@ -938,7 +902,7 @@ RSpec.describe 'Pipeline', :js do context 'when retrying' do before do - find('.js-retry-button').click + find('[data-testid="retryButton"]').click end it 'does not show a "Retry" button', :sidekiq_might_not_need_inline do diff --git a/spec/features/projects/pipelines/pipelines_spec.rb b/spec/features/projects/pipelines/pipelines_spec.rb index 0eb92f3e679..8747b3ab54c 100644 --- a/spec/features/projects/pipelines/pipelines_spec.rb +++ b/spec/features/projects/pipelines/pipelines_spec.rb @@ -652,6 +652,7 @@ RSpec.describe 'Pipelines', :js do let(:project) { create(:project, :repository) } before do + stub_feature_flags(new_pipeline_form: false) visit new_project_pipeline_path(project) end @@ -718,6 +719,7 @@ RSpec.describe 'Pipelines', :js do let(:project) { create(:project, :repository) } before do + stub_feature_flags(new_pipeline_form: false) visit new_project_pipeline_path(project) end diff --git a/spec/features/projects/product_analytics/events_spec.rb b/spec/features/projects/product_analytics/events_spec.rb new file mode 100644 index 00000000000..12f1c4d291a --- /dev/null +++ b/spec/features/projects/product_analytics/events_spec.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Product Analytics > Events' do + let_it_be(:project) { create(:project_empty_repo) } + let_it_be(:user) { create(:user) } + let(:event) { create(:product_analytics_event, project: project) } + + before do + project.add_maintainer(user) + sign_in(user) + end + + it 'shows no events message' do + visit(project_product_analytics_path(project)) + + expect(page).to have_content('There are currently no events') + end + + it 'shows events' do + event + + visit(project_product_analytics_path(project)) + + expect(page).to have_content('dvce_created_tstamp') + expect(page).to have_content(event.event_id) + end +end diff --git a/spec/features/projects/product_analytics/graphs_spec.rb b/spec/features/projects/product_analytics/graphs_spec.rb new file mode 100644 index 00000000000..e2293893589 --- /dev/null +++ b/spec/features/projects/product_analytics/graphs_spec.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Product Analytics > Graphs' do + let_it_be(:project) { create(:project) } + let_it_be(:user) { create(:user) } + + before do + project.add_maintainer(user) + sign_in(user) + end + + it 'shows graphs', :js do + create(:product_analytics_event, project: project) + + visit(graphs_project_product_analytics_path(project)) + + expect(page).to have_content('Showing graphs based on events') + expect(page).to have_content('platform') + expect(page).to have_content('os_timezone') + expect(page).to have_content('br_lang') + expect(page).to have_content('doc_charset') + end +end diff --git a/spec/features/projects/product_analytics/setup_spec.rb b/spec/features/projects/product_analytics/setup_spec.rb new file mode 100644 index 00000000000..45c2b67502c --- /dev/null +++ b/spec/features/projects/product_analytics/setup_spec.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Product Analytics > Setup' do + let_it_be(:project) { create(:project_empty_repo) } + let_it_be(:user) { create(:user) } + + before do + project.add_maintainer(user) + sign_in(user) + end + + it 'shows the setup instructions' do + visit(setup_project_product_analytics_path(project)) + + expect(page).to have_content('Copy the code below to implement tracking in your application') + end +end diff --git a/spec/features/projects/product_analytics/test_spec.rb b/spec/features/projects/product_analytics/test_spec.rb new file mode 100644 index 00000000000..8984fb409d1 --- /dev/null +++ b/spec/features/projects/product_analytics/test_spec.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Product Analytics > Test' do + let_it_be(:project) { create(:project_empty_repo) } + let_it_be(:user) { create(:user) } + + before do + project.add_maintainer(user) + sign_in(user) + end + + it 'says it sends a payload' do + visit(test_project_product_analytics_path(project)) + + expect(page).to have_content('This page sends a payload.') + end + + it 'shows the last event if there is one' do + event = create(:product_analytics_event, project: project) + + visit(test_project_product_analytics_path(project)) + + expect(page).to have_content(event.event_id) + end +end diff --git a/spec/features/projects/settings/operations_settings_spec.rb b/spec/features/projects/settings/operations_settings_spec.rb index 878794bd897..de7251db5c9 100644 --- a/spec/features/projects/settings/operations_settings_spec.rb +++ b/spec/features/projects/settings/operations_settings_spec.rb @@ -35,7 +35,7 @@ RSpec.describe 'Projects > Settings > For a forked project', :js do end it 'renders form for incident management' do - expect(page).to have_selector('h3', text: 'Incidents') + expect(page).to have_selector('h4', text: 'Incidents') end it 'sets correct default values' do @@ -46,11 +46,14 @@ RSpec.describe 'Projects > Settings > For a forked project', :js do it 'updates form values' do check(create_issue) uncheck(send_email) + click_on('No template selected') + click_on('bug') save_form click_expand_incident_management_button expect(find_field(create_issue)).to be_checked + expect(page).to have_selector(:id, 'alert-integration-settings-issue-template', text: 'bug') expect(find_field(send_email)).not_to be_checked end diff --git a/spec/features/projects/settings/packages_settings_spec.rb b/spec/features/projects/settings/packages_settings_spec.rb new file mode 100644 index 00000000000..0b40cbee582 --- /dev/null +++ b/spec/features/projects/settings/packages_settings_spec.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Projects > Settings > Packages', :js do + let(:project) { create(:project) } + let(:user) { create(:user) } + + before do + sign_in(user) + project.add_maintainer(user) + end + + context 'Packages enabled in config' do + before do + allow(Gitlab.config.packages).to receive(:enabled).and_return(true) + end + + it 'displays the packages toggle button' do + visit edit_project_path(project) + + expect(page).to have_content('Packages') + expect(page).to have_selector('input[name="project[packages_enabled]"] + button', visible: true) + end + end + + context 'Packages disabled in config' do + before do + allow(Gitlab.config.packages).to receive(:enabled).and_return(false) + end + + it 'does not show up in UI' do + visit edit_project_path(project) + + expect(page).not_to have_content('Packages') + end + end +end diff --git a/spec/features/projects/show/user_manages_notifications_spec.rb b/spec/features/projects/show/user_manages_notifications_spec.rb index 58a2c793b7b..9d9a75c22be 100644 --- a/spec/features/projects/show/user_manages_notifications_spec.rb +++ b/spec/features/projects/show/user_manages_notifications_spec.rb @@ -22,7 +22,7 @@ RSpec.describe 'Projects > Show > User manages notifications', :js do click_notifications_button expect(find('.update-notification.is-active')).to have_content('On mention') - expect(find('.notifications-icon use')[:'xlink:href']).to end_with('#notifications') + expect(page).to have_css('.notifications-icon[data-testid="notifications-icon"]') end it 'changes the notification setting to disabled' do @@ -32,7 +32,7 @@ RSpec.describe 'Projects > Show > User manages notifications', :js do wait_for_requests - expect(find('.notifications-icon use')[:'xlink:href']).to end_with('#notifications-off') + expect(page).to have_css('.notifications-icon[data-testid="notifications-off-icon"]') end context 'custom notification settings' do @@ -52,7 +52,8 @@ RSpec.describe 'Projects > Show > User manages notifications', :js do :merge_merge_request, :failed_pipeline, :fixed_pipeline, - :success_pipeline + :success_pipeline, + :moved_project ] end @@ -67,20 +68,6 @@ RSpec.describe 'Projects > Show > User manages notifications', :js do end end end - - context 'when ci_pipeline_fixed_notifications is disabled' do - before do - stub_feature_flags(ci_pipeline_fixed_notifications: false) - end - - it 'hides fixed_pipeline checkbox' do - visit project_path(project) - click_notifications_button - page.find('a[data-notification-level="custom"]').click - - expect(page).not_to have_selector("input[name='notification_setting[fixed_pipeline]']") - end - end end context 'when project emails are disabled' do diff --git a/spec/features/projects/snippets/create_snippet_spec.rb b/spec/features/projects/snippets/create_snippet_spec.rb index 73d033cbdb8..3db870f229a 100644 --- a/spec/features/projects/snippets/create_snippet_spec.rb +++ b/spec/features/projects/snippets/create_snippet_spec.rb @@ -2,9 +2,28 @@ require 'spec_helper' -RSpec.shared_examples_for 'snippet editor' do +RSpec.describe 'Projects > Snippets > Create Snippet', :js do + include DropzoneHelper + + let_it_be(:user) { create(:user) } + let_it_be(:project) do + create(:project, :public, creator: user).tap do |p| + p.add_maintainer(user) + end + end + + let(:title) { 'My Snippet Title' } + let(:file_content) { 'Hello World!' } + let(:md_description) { 'My Snippet **Description**' } + let(:description) { 'My Snippet Description' } + before do + stub_feature_flags(snippets_vue: false) stub_feature_flags(snippets_edit_vue: false) + + sign_in(user) + + visit new_project_snippet_path(project) end def description_field @@ -12,137 +31,81 @@ RSpec.shared_examples_for 'snippet editor' do end def fill_form - fill_in 'project_snippet_title', with: 'My Snippet Title' + fill_in 'project_snippet_title', with: title # Click placeholder first to expand full description field description_field.click - fill_in 'project_snippet_description', with: 'My Snippet **Description**' + fill_in 'project_snippet_description', with: md_description page.within('.file-editor') do el = find('.inputarea') - el.send_keys 'Hello World!' + el.send_keys file_content end end - context 'when a user is authenticated' do - before do - stub_feature_flags(snippets_vue: false) - project.add_maintainer(user) - sign_in(user) + it 'shows collapsible description input' do + collapsed = description_field - visit project_snippets_path(project) - - # Wait for the SVG to ensure the button location doesn't shift - within('.empty-state') { find('img.js-lazy-loaded') } - click_on('New snippet') - wait_for_requests - end + expect(page).not_to have_field('project_snippet_description') + expect(collapsed).to be_visible - it 'shows collapsible description input' do - collapsed = description_field + collapsed.click - expect(page).not_to have_field('project_snippet_description') - expect(collapsed).to be_visible + expect(page).to have_field('project_snippet_description') + expect(collapsed).not_to be_visible + end - collapsed.click + it 'creates a new snippet' do + fill_form + click_button('Create snippet') + wait_for_requests - expect(page).to have_field('project_snippet_description') - expect(collapsed).not_to be_visible + expect(page).to have_content(title) + expect(page).to have_content(file_content) + page.within('.snippet-header .description') do + expect(page).to have_content(description) + expect(page).to have_selector('strong') end + end - it 'creates a new snippet' do - fill_form - click_button('Create snippet') - wait_for_requests + it 'uploads a file when dragging into textarea' do + fill_form + dropzone_file Rails.root.join('spec', 'fixtures', 'banana_sample.gif') - expect(page).to have_content('My Snippet Title') - expect(page).to have_content('Hello World!') - page.within('.snippet-header .description') do - expect(page).to have_content('My Snippet Description') - expect(page).to have_selector('strong') - end - end + expect(page.find_field('project_snippet_description').value).to have_content('banana_sample') - it 'uploads a file when dragging into textarea' do - fill_form - dropzone_file Rails.root.join('spec', 'fixtures', 'banana_sample.gif') + click_button('Create snippet') + wait_for_requests - expect(page.find_field("project_snippet_description").value).to have_content('banana_sample') + link = find('a.no-attachment-icon img[alt="banana_sample"]')['src'] + expect(link).to match(%r{/#{Regexp.escape(project.full_path)}/uploads/\h{32}/banana_sample\.gif\z}) + end - click_button('Create snippet') - wait_for_requests + it 'displays validation errors' do + fill_in 'project_snippet_title', with: title + click_button('Create snippet') + wait_for_requests - link = find('a.no-attachment-icon img[alt="banana_sample"]')['src'] - expect(link).to match(%r{/#{Regexp.escape(project.full_path)}/uploads/\h{32}/banana_sample\.gif\z}) - end + expect(page).to have_selector('#error_explanation') + end - it 'creates a snippet when all required fields are filled in after validation failing' do - fill_in 'project_snippet_title', with: 'My Snippet Title' - click_button('Create snippet') + context 'when the git operation fails' do + let(:error) { 'Error creating the snippet' } - expect(page).to have_selector('#error_explanation') + before do + allow_next_instance_of(Snippets::CreateService) do |instance| + allow(instance).to receive(:create_commit).and_raise(StandardError, error) + end fill_form - dropzone_file Rails.root.join('spec', 'fixtures', 'banana_sample.gif') - find("input[value='Create snippet']").send_keys(:return) + click_button('Create snippet') wait_for_requests - - expect(page).to have_content('My Snippet Title') - expect(page).to have_content('Hello World!') - page.within('.snippet-header .description') do - expect(page).to have_content('My Snippet Description') - expect(page).to have_selector('strong') - end - link = find('a.no-attachment-icon img[alt="banana_sample"]')['src'] - expect(link).to match(%r{/#{Regexp.escape(project.full_path)}/uploads/\h{32}/banana_sample\.gif\z}) - end - - context 'when the git operation fails' do - let(:error) { 'Error creating the snippet' } - - before do - allow_next_instance_of(Snippets::CreateService) do |instance| - allow(instance).to receive(:create_commit).and_raise(StandardError, error) - end - - fill_form - - click_button('Create snippet') - wait_for_requests - end - - it 'displays the error' do - expect(page).to have_content(error) - end - - it 'renders new page' do - expect(page).to have_content('New Snippet') - end end - end - - context 'when a user is not authenticated' do - before do - stub_feature_flags(snippets_vue: false) - end - - it 'shows a public snippet on the index page but not the New snippet button' do - snippet = create(:project_snippet, :public, :repository, project: project) - - visit project_snippets_path(project) - expect(page).to have_content(snippet.title) - expect(page).not_to have_content('New snippet') + it 'renders the new page and displays the error' do + expect(page).to have_content(error) + expect(page).to have_content('New Snippet') end end end - -RSpec.describe 'Projects > Snippets > Create Snippet', :js do - include DropzoneHelper - - let_it_be(:user) { create(:user) } - let_it_be(:project) { create(:project, :public) } - - it_behaves_like "snippet editor" -end diff --git a/spec/features/projects/snippets/show_spec.rb b/spec/features/projects/snippets/show_spec.rb index 0f6429d49f6..8fded3cde80 100644 --- a/spec/features/projects/snippets/show_spec.rb +++ b/spec/features/projects/snippets/show_spec.rb @@ -3,157 +3,41 @@ require 'spec_helper' RSpec.describe 'Projects > Snippets > Project snippet', :js do - let(:user) { create(:user) } - let(:project) { create(:project, :repository) } - let(:snippet) { create(:project_snippet, project: project, file_name: file_name, content: content) } + let_it_be(:user) { create(:user) } + let_it_be(:project) do + create(:project, creator: user).tap do |p| + p.add_maintainer(user) + end + end + + let_it_be(:snippet) { create(:project_snippet, :repository, project: project, author: user) } before do stub_feature_flags(snippets_vue: false) - project.add_maintainer(user) + sign_in(user) end - context 'Ruby file' do - let(:file_name) { 'popen.rb' } - let(:content) { project.repository.blob_at('master', 'files/ruby/popen.rb').data } + it_behaves_like 'show and render proper snippet blob' do + let(:anchor) { nil } - before do - visit project_snippet_path(project, snippet) + subject do + visit project_snippet_path(project, snippet, anchor: anchor) wait_for_requests end - - it 'displays the blob' do - aggregate_failures do - # shows highlighted Ruby code - expect(page).to have_content("require 'fileutils'") - - # does not show a viewer switcher - expect(page).not_to have_selector('.js-blob-viewer-switcher') - - # shows an enabled copy button - expect(page).to have_selector('.js-copy-blob-source-btn:not(.disabled)') - - # shows a raw button - expect(page).to have_link('Open raw') - - # shows a download button - expect(page).to have_link('Download') - end - end end - context 'Markdown file' do - let(:file_name) { 'ruby-style-guide.md' } - let(:content) { project.repository.blob_at('master', 'files/markdown/ruby-style-guide.md').data } - - context 'visiting directly' do - before do - visit project_snippet_path(project, snippet) - - wait_for_requests - end - - it 'displays the blob using the rich viewer' do - aggregate_failures do - # hides the simple viewer - expect(page).to have_selector('.blob-viewer[data-type="simple"]', visible: false) - expect(page).to have_selector('.blob-viewer[data-type="rich"]') - - # shows rendered Markdown - expect(page).to have_link("PEP-8") - - # shows a viewer switcher - expect(page).to have_selector('.js-blob-viewer-switcher') - - # shows a disabled copy button - expect(page).to have_selector('.js-copy-blob-source-btn.disabled') - - # shows a raw button - expect(page).to have_link('Open raw') - - # shows a download button - expect(page).to have_link('Download') - end - end - - context 'switching to the simple viewer' do - before do - find('.js-blob-viewer-switch-btn[data-viewer=simple]').click - - wait_for_requests - end - - it 'displays the blob using the simple viewer' do - aggregate_failures do - # hides the rich viewer - expect(page).to have_selector('.blob-viewer[data-type="simple"]') - expect(page).to have_selector('.blob-viewer[data-type="rich"]', visible: false) - - # shows highlighted Markdown code - expect(page).to have_content("[PEP-8](http://www.python.org/dev/peps/pep-0008/)") - - # shows an enabled copy button - expect(page).to have_selector('.js-copy-blob-source-btn:not(.disabled)') - end - end - - context 'switching to the rich viewer again' do - before do - find('.js-blob-viewer-switch-btn[data-viewer=rich]').click - - wait_for_requests - end - - it 'displays the blob using the rich viewer' do - aggregate_failures do - # hides the simple viewer - expect(page).to have_selector('.blob-viewer[data-type="simple"]', visible: false) - expect(page).to have_selector('.blob-viewer[data-type="rich"]') - - # shows an enabled copy button - expect(page).to have_selector('.js-copy-blob-source-btn:not(.disabled)') - end - end - end - end - end - - context 'visiting with a line number anchor' do - before do - visit project_snippet_path(project, snippet, anchor: 'L1') - - wait_for_requests - end - - it 'displays the blob using the simple viewer' do - aggregate_failures do - # hides the rich viewer - expect(page).to have_selector('.blob-viewer[data-type="simple"]') - expect(page).to have_selector('.blob-viewer[data-type="rich"]', visible: false) - - # highlights the line in question - expect(page).to have_selector('#LC1.hll') - - # shows highlighted Markdown code - expect(page).to have_content("[PEP-8](http://www.python.org/dev/peps/pep-0008/)") + it_behaves_like 'showing user status' do + let(:file_path) { 'files/ruby/popen.rb' } + let(:user_with_status) { snippet.author } - # shows an enabled copy button - expect(page).to have_selector('.js-copy-blob-source-btn:not(.disabled)') - end - end - end + subject { visit project_snippet_path(project, snippet) } end - it_behaves_like 'showing user status' do - let(:file_name) { 'ruby-style-guide.md' } - let(:content) { project.repository.blob_at('master', 'files/markdown/ruby-style-guide.md').data } - - let(:user_with_status) { snippet.author } + it_behaves_like 'does not show New Snippet button' do + let(:file_path) { 'files/ruby/popen.rb' } - subject do - visit project_snippet_path(project, snippet) - wait_for_requests - end + subject { visit project_snippet_path(project, snippet) } end end diff --git a/spec/features/projects/wiki/user_updates_wiki_page_spec.rb b/spec/features/projects/wiki/user_updates_wiki_page_spec.rb index 05d8989d88a..fdab63a56b8 100644 --- a/spec/features/projects/wiki/user_updates_wiki_page_spec.rb +++ b/spec/features/projects/wiki/user_updates_wiki_page_spec.rb @@ -234,4 +234,30 @@ RSpec.describe 'User updates wiki page' do it_behaves_like 'wiki file attachments' end + + context 'when an existing page exceeds the content size limit' do + let_it_be(:project) { create(:project, :wiki_repo) } + let!(:wiki_page) { create(:wiki_page, wiki: project.wiki, content: "one\ntwo\nthree") } + + before do + stub_application_setting(wiki_page_max_content_bytes: 10) + + visit wiki_page_path(wiki_page.wiki, wiki_page, action: :edit) + end + + it 'allows changing the title if the content does not change' do + fill_in 'Title', with: 'new title' + click_on 'Save changes' + + expect(page).to have_content('Wiki was successfully updated.') + end + + it 'shows a validation error when trying to change the content' do + fill_in 'Content', with: 'new content' + click_on 'Save changes' + + expect(page).to have_content('The form contains the following error:') + expect(page).to have_content('Content is too long (11 Bytes). The maximum size is 10 Bytes.') + end + end end diff --git a/spec/features/projects/wiki/user_views_wiki_pages_spec.rb b/spec/features/projects/wiki/user_views_wiki_pages_spec.rb index fea913b8212..4f29ae0cc8a 100644 --- a/spec/features/projects/wiki/user_views_wiki_pages_spec.rb +++ b/spec/features/projects/wiki/user_views_wiki_pages_spec.rb @@ -11,9 +11,11 @@ RSpec.describe 'User views wiki pages' do let!(:wiki_page1) do create(:wiki_page, wiki: project.wiki, title: '3 home', content: '3') end + let!(:wiki_page2) do create(:wiki_page, wiki: project.wiki, title: '1 home', content: '1') end + let!(:wiki_page3) do create(:wiki_page, wiki: project.wiki, title: '2 home', content: '2') end |