debian-mirror-gitlab/spec/features/cycle_analytics_spec.rb

177 lines
6 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec.describe 'Value Stream Analytics', :js do
2020-11-24 15:15:51 +05:30
let_it_be(:user) { create(:user) }
let_it_be(:guest) { create(:user) }
2021-10-27 15:23:28 +05:30
let_it_be(:stage_table_selector) { '[data-testid="vsa-stage-table"]' }
2021-11-11 11:23:49 +05:30
let_it_be(:stage_table_event_selector) { '[data-testid="vsa-stage-event"]' }
2021-10-27 15:23:28 +05:30
let_it_be(:metrics_selector) { "[data-testid='vsa-time-metrics']" }
2021-11-11 11:23:49 +05:30
let_it_be(:metric_value_selector) { "[data-testid='displayValue']" }
2021-09-30 23:02:18 +05:30
2021-11-11 11:23:49 +05:30
let(:stage_table) { page.find(stage_table_selector) }
let(:project) { create(:project, :repository) }
2017-08-17 22:00:37 +05:30
let(:issue) { create(:issue, project: project, created_at: 2.days.ago) }
let(:milestone) { create(:milestone, project: project) }
2018-03-27 19:54:05 +05:30
let(:mr) { create_merge_request_closing_issue(user, project, issue, commit_message: "References #{issue.to_reference}") }
2017-09-10 17:25:29 +05:30
let(:pipeline) { create(:ci_empty_pipeline, status: 'created', project: project, ref: mr.source_branch, sha: mr.source_branch_sha, head_pipeline_of: mr) }
2017-08-17 22:00:37 +05:30
2021-11-11 11:23:49 +05:30
def metrics_values
page.find(metrics_selector).all(metric_value_selector).collect(&:text)
end
def set_daterange(from_date, to_date)
page.find(".js-daterange-picker-from input").set(from_date)
page.find(".js-daterange-picker-to input").set(to_date)
wait_for_all_requests
end
2017-08-17 22:00:37 +05:30
context 'as an allowed user' do
context 'when project is new' do
2020-11-24 15:15:51 +05:30
before do
2021-11-11 11:23:49 +05:30
project.add_maintainer(user)
2017-09-10 17:25:29 +05:30
sign_in(user)
visit project_cycle_analytics_path(project)
wait_for_requests
2017-08-17 22:00:37 +05:30
end
2021-11-11 11:23:49 +05:30
it 'displays metrics with relevant values' do
expect(metrics_values).to eq(['-'] * 4)
2018-03-17 18:26:18 +05:30
end
2017-08-17 22:00:37 +05:30
it 'shows active stage with empty message' do
2021-09-04 01:27:46 +05:30
expect(page).to have_selector('.gl-path-active-item-indigo', text: 'Issue')
2017-08-17 22:00:37 +05:30
expect(page).to have_content("We don't have enough data to show this stage.")
end
end
2020-03-13 15:44:24 +05:30
context "when there's value stream analytics data" do
2021-11-11 11:23:49 +05:30
# NOTE: in https://gitlab.com/gitlab-org/gitlab/-/merge_requests/68595 travel back
# 5 days in time before we create data for these specs, to mitigate some flakiness
# So setting the date range to be the last 2 days should skip past the existing data
from = 2.days.ago.strftime("%Y-%m-%d")
to = 1.day.ago.strftime("%Y-%m-%d")
around do |example|
travel_to(5.days.ago) { example.run }
end
2017-08-17 22:00:37 +05:30
before do
2018-11-18 11:00:15 +05:30
project.add_maintainer(user)
2021-11-11 11:23:49 +05:30
create_list(:issue, 2, project: project, created_at: 2.weeks.ago, milestone: milestone)
2017-09-10 17:25:29 +05:30
2021-11-11 11:23:49 +05:30
create_cycle(user, project, issue, mr, milestone, pipeline)
2018-03-27 19:54:05 +05:30
deploy_master(user, project)
2017-08-17 22:00:37 +05:30
2021-10-27 15:23:28 +05:30
issue.metrics.update!(first_mentioned_in_commit_at: issue.metrics.first_associated_with_milestone_at + 1.hour)
2021-02-22 17:27:13 +05:30
merge_request = issue.merge_requests_closing_issues.first.merge_request
2021-10-27 15:23:28 +05:30
merge_request.update!(created_at: issue.metrics.first_associated_with_milestone_at + 1.hour)
2021-02-22 17:27:13 +05:30
merge_request.metrics.update!(
2021-11-11 11:23:49 +05:30
latest_build_started_at: merge_request.created_at + 3.hours,
latest_build_finished_at: merge_request.created_at + 4.hours,
merged_at: merge_request.created_at + 4.hours,
first_deployed_to_production_at: merge_request.created_at + 5.hours
2021-02-22 17:27:13 +05:30
)
2017-09-10 17:25:29 +05:30
sign_in(user)
visit project_cycle_analytics_path(project)
2021-11-11 11:23:49 +05:30
wait_for_requests
2017-08-17 22:00:37 +05:30
end
2021-10-27 15:23:28 +05:30
it 'displays metrics' do
metrics_tiles = page.find(metrics_selector)
aggregate_failures 'with relevant values' do
expect(metrics_tiles).to have_content('Commit')
expect(metrics_tiles).to have_content('Deploy')
expect(metrics_tiles).to have_content('Deployment Frequency')
expect(metrics_tiles).to have_content('New Issue')
end
2018-03-17 18:26:18 +05:30
end
2019-12-26 22:10:19 +05:30
it 'shows data on each stage', :sidekiq_might_not_need_inline do
2017-08-17 22:00:37 +05:30
expect_issue_to_be_present
click_stage('Plan')
2019-09-04 21:01:54 +05:30
expect_issue_to_be_present
2017-08-17 22:00:37 +05:30
click_stage('Code')
expect_merge_request_to_be_present
click_stage('Test')
2021-10-27 15:23:28 +05:30
expect_merge_request_to_be_present
2017-08-17 22:00:37 +05:30
click_stage('Review')
expect_merge_request_to_be_present
click_stage('Staging')
2021-10-27 15:23:28 +05:30
expect_merge_request_to_be_present
2017-08-17 22:00:37 +05:30
end
2018-03-17 18:26:18 +05:30
2021-11-11 11:23:49 +05:30
it 'can filter the issues by date' do
expect(stage_table.all(stage_table_event_selector).length).to eq(3)
2018-03-17 18:26:18 +05:30
2021-11-11 11:23:49 +05:30
set_daterange(from, to)
2018-03-17 18:26:18 +05:30
2021-11-11 11:23:49 +05:30
expect(stage_table.all(stage_table_event_selector).length).to eq(0)
end
it 'can filter the metrics by date' do
expect(metrics_values).to eq(["3.0", "2.0", "1.0", "0.0"])
set_daterange(from, to)
expect(metrics_values).to eq(['-'] * 4)
2018-03-17 18:26:18 +05:30
end
2017-08-17 22:00:37 +05:30
end
end
context "as a guest" do
before do
2018-03-17 18:26:18 +05:30
project.add_developer(user)
2017-09-10 17:25:29 +05:30
project.add_guest(guest)
2017-08-17 22:00:37 +05:30
2018-03-27 19:54:05 +05:30
create_cycle(user, project, issue, mr, milestone, pipeline)
deploy_master(user, project)
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
sign_in(guest)
visit project_cycle_analytics_path(project)
wait_for_requests
2017-08-17 22:00:37 +05:30
end
2019-12-04 20:38:33 +05:30
it 'does not show the commit stats' do
2021-10-27 15:23:28 +05:30
expect(page.find(metrics_selector)).not_to have_selector("#commits")
2019-12-04 20:38:33 +05:30
end
2017-08-17 22:00:37 +05:30
it 'needs permissions to see restricted stages' do
2021-10-27 15:23:28 +05:30
expect(find(stage_table_selector)).to have_content(issue.title)
2017-08-17 22:00:37 +05:30
click_stage('Code')
2021-10-27 15:23:28 +05:30
expect(find(stage_table_selector)).to have_content('You need permission.')
2017-08-17 22:00:37 +05:30
click_stage('Review')
2021-10-27 15:23:28 +05:30
expect(find(stage_table_selector)).to have_content('You need permission.')
2017-08-17 22:00:37 +05:30
end
end
def expect_issue_to_be_present
2021-10-27 15:23:28 +05:30
expect(find(stage_table_selector)).to have_content(issue.title)
expect(find(stage_table_selector)).to have_content(issue.author.name)
expect(find(stage_table_selector)).to have_content("##{issue.iid}")
2017-08-17 22:00:37 +05:30
end
def expect_merge_request_to_be_present
2021-10-27 15:23:28 +05:30
expect(find(stage_table_selector)).to have_content(mr.title)
expect(find(stage_table_selector)).to have_content(mr.author.name)
expect(find(stage_table_selector)).to have_content("!#{mr.iid}")
2017-08-17 22:00:37 +05:30
end
def click_stage(stage_name)
2021-09-04 01:27:46 +05:30
find('.gl-path-nav-list-item', text: stage_name).click
2017-09-10 17:25:29 +05:30
wait_for_requests
2017-08-17 22:00:37 +05:30
end
end