debian-mirror-gitlab/spec/features/projects/jobs/user_browses_jobs_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

251 lines
6.4 KiB
Ruby
Raw Permalink Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
require 'spec_helper'
2021-11-18 22:05:49 +05:30
def visit_jobs_page
visit(project_jobs_path(project))
wait_for_requests
end
2023-03-04 22:38:38 +05:30
RSpec.describe 'User browses jobs', feature_category: :projects do
2022-08-13 15:12:31 +05:30
describe 'Jobs', :js do
2021-11-18 22:05:49 +05:30
let(:project) { create(:project, :repository) }
let(:user) { create(:user) }
before do
project.add_maintainer(user)
project.enable_ci
sign_in(user)
end
describe 'header tabs' do
before do
visit_jobs_page
end
it 'shows a tab for All jobs and count' do
expect(page.find('[data-testid="jobs-all-tab"]').text).to include('All')
expect(page.find('[data-testid="jobs-all-tab"] .badge').text).to include('0')
end
it 'shows a tab for Finished jobs and count' do
expect(page.find('[data-testid="jobs-finished-tab"]').text).to include('Finished')
end
it 'updates the content when tab is clicked' do
page.find('[data-testid="jobs-finished-tab"]').click
wait_for_requests
expect(page).to have_content('No jobs to show')
end
end
describe 'Empty state' do
before do
visit_jobs_page
end
it 'renders an empty state' do
expect(page).to have_content 'Use jobs to automate your tasks'
expect(page).to have_content 'Create CI/CD configuration file'
end
end
describe 'Job actions' do
let!(:pipeline) { create(:ci_empty_pipeline, project: project, sha: project.commit.id, ref: 'master') }
context 'when a job can be canceled' do
let!(:job) do
2022-10-11 01:57:18 +05:30
create(:ci_build, pipeline: pipeline, stage: 'test')
2021-11-18 22:05:49 +05:30
end
before do
job.run
visit_jobs_page
end
it 'cancels a job successfully' do
page.find('[data-testid="cancel-button"]').click
wait_for_requests
expect(page).to have_selector('.ci-canceled')
2022-08-27 11:52:29 +05:30
expect(page).not_to have_selector('[data-testid="jobs-table-error-alert"]')
2021-11-18 22:05:49 +05:30
end
end
context 'when a job can be retried' do
let!(:job) do
create(:ci_build, pipeline: pipeline,
2022-10-11 01:57:18 +05:30
stage: 'test')
2021-11-18 22:05:49 +05:30
end
before do
job.drop
visit_jobs_page
end
it 'retries a job successfully' do
page.find('[data-testid="retry"]').click
wait_for_requests
expect(page).to have_selector('.ci-pending')
end
end
2022-08-13 15:12:31 +05:30
context 'with a coverage job' do
let!(:job) do
create(:ci_build, :coverage, pipeline: pipeline)
end
before do
job.update!(coverage_regex: '/Coverage (\d+)%/')
visit_jobs_page
wait_for_requests
end
it 'shows the coverage' do
page.within('[data-testid="job-coverage"]') do
expect(page).to have_content('99.9%')
end
end
end
2021-11-18 22:05:49 +05:30
context 'with a scheduled job' do
let!(:scheduled_job) { create(:ci_build, :scheduled, pipeline: pipeline, name: 'build') }
before do
visit_jobs_page
end
it 'plays a job successfully' do
page.find('[data-testid="play-scheduled"]').click
page.within '#play-job-modal' do
page.find_button('OK').click
end
wait_for_requests
expect(page).to have_selector('.ci-pending')
end
it 'unschedules a job successfully' do
page.find('[data-testid="unschedule"]').click
wait_for_requests
expect(page).to have_selector('.ci-manual')
end
end
context 'with downloadable artifacts' do
let!(:with_artifacts) do
build = create(:ci_build, :success,
pipeline: pipeline,
name: 'rspec tests',
stage: 'test')
2022-01-26 12:08:38 +05:30
create(:ci_job_artifact, :archive, job: build)
2021-11-18 22:05:49 +05:30
end
before do
visit_jobs_page
end
it 'shows the download artifacts button' do
expect(page).to have_selector('[data-testid="download-artifacts"]')
end
end
context 'with artifacts expired' do
let!(:with_artifacts_expired) do
create(:ci_build, :expired, :success,
pipeline: pipeline,
name: 'rspec',
stage: 'test')
end
before do
visit_jobs_page
end
it 'does not show the download artifacts button' do
expect(page).not_to have_selector('[data-testid="download-artifacts"]')
end
end
end
describe 'Jobs table' do
let!(:pipeline) { create(:ci_empty_pipeline, project: project, sha: project.commit.id, ref: 'master') }
context 'column links' do
let!(:job) do
create(:ci_build, pipeline: pipeline,
2022-10-11 01:57:18 +05:30
stage: 'test')
2021-11-18 22:05:49 +05:30
end
before do
job.run
visit_jobs_page
end
it 'contains a link to the pipeline' do
expect(page.find('[data-testid="pipeline-id"]')).to have_content "##{pipeline.id}"
end
it 'contains a link to the job sha' do
2023-01-13 00:05:48 +05:30
expect(page.find('[data-testid="job-sha"]')).to have_content job.sha[0..7].to_s
2021-11-18 22:05:49 +05:30
end
it 'contains a link to the job id' do
2023-01-13 00:05:48 +05:30
expect(page.find('[data-testid="job-id-link"]')).to have_content job.id.to_s
2021-11-18 22:05:49 +05:30
end
it 'contains a link to the job ref' do
2023-01-13 00:05:48 +05:30
expect(page.find('[data-testid="job-ref"]')).to have_content job.ref.to_s
2021-11-18 22:05:49 +05:30
end
end
end
describe 'when user is not logged in' do
before do
sign_out(user)
end
context 'when project is public' do
let(:public_project) { create(:project, :public, :repository) }
context 'without jobs' do
it 'shows an empty state' do
visit project_jobs_path(public_project)
wait_for_requests
expect(page).to have_content 'Use jobs to automate your tasks'
end
end
end
context 'when project is private' do
let(:private_project) { create(:project, :private, :repository) }
it 'redirects the user to sign_in and displays the flash alert' do
visit project_jobs_path(private_project)
wait_for_requests
2018-05-09 12:01:36 +05:30
2021-11-18 22:05:49 +05:30
expect(page).to have_content 'You need to sign in'
2022-05-07 20:08:51 +05:30
expect(page).to have_current_path("/users/sign_in")
2021-11-18 22:05:49 +05:30
end
2018-05-09 12:01:36 +05:30
end
end
end
2018-03-17 18:26:18 +05:30
end