2019-07-25 01:24:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-24 18:00:50 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-16 14:09:01 -04:00
|
|
|
RSpec.describe 'Value Stream Analytics', :js do
|
2022-08-02 17:09:18 -04:00
|
|
|
include CycleAnalyticsHelpers
|
|
|
|
|
2020-08-25 05:10:42 -04:00
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:guest) { create(:user) }
|
2021-07-20 05:08:43 -04:00
|
|
|
let_it_be(:stage_table_selector) { '[data-testid="vsa-stage-table"]' }
|
2021-11-12 22:09:49 -05:00
|
|
|
let_it_be(:stage_filter_bar) { '[data-testid="vsa-filter-bar"]' }
|
2021-09-07 11:11:06 -04:00
|
|
|
let_it_be(:stage_table_event_selector) { '[data-testid="vsa-stage-event"]' }
|
2021-10-12 11:12:08 -04:00
|
|
|
let_it_be(:stage_table_event_title_selector) { '[data-testid="vsa-stage-event-title"]' }
|
|
|
|
let_it_be(:stage_table_pagination_selector) { '[data-testid="vsa-stage-pagination"]' }
|
|
|
|
let_it_be(:stage_table_duration_column_header_selector) { '[data-testid="vsa-stage-header-duration"]' }
|
2022-01-26 10:12:36 -05:00
|
|
|
let_it_be(:metrics_selector) { "[data-testid='vsa-metrics']" }
|
2021-09-07 11:11:06 -04:00
|
|
|
let_it_be(:metric_value_selector) { "[data-testid='displayValue']" }
|
2021-06-28 23:07:32 -04:00
|
|
|
|
2021-10-12 11:12:08 -04:00
|
|
|
let(:stage_table) { find(stage_table_selector) }
|
2021-09-07 11:11:06 -04:00
|
|
|
let(:project) { create(:project, :repository) }
|
2016-12-30 18:01:36 -05:00
|
|
|
let(:issue) { create(:issue, project: project, created_at: 2.days.ago) }
|
|
|
|
let(:milestone) { create(:milestone, project: project) }
|
2018-02-21 07:13:56 -05:00
|
|
|
let(:mr) { create_merge_request_closing_issue(user, project, issue, commit_message: "References #{issue.to_reference}") }
|
2017-05-19 16:51:07 -04:00
|
|
|
let(:pipeline) { create(:ci_empty_pipeline, status: 'created', project: project, ref: mr.source_branch, sha: mr.source_branch_sha, head_pipeline_of: mr) }
|
2016-11-24 18:00:50 -05:00
|
|
|
|
2021-09-07 11:11:06 -04:00
|
|
|
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)
|
2021-11-12 22:09:49 -05:00
|
|
|
|
|
|
|
# simulate a blur event
|
|
|
|
page.find(".js-daterange-picker-to input").send_keys(:tab)
|
2021-09-07 11:11:06 -04:00
|
|
|
wait_for_all_requests
|
|
|
|
end
|
|
|
|
|
2016-11-24 18:00:50 -05:00
|
|
|
context 'as an allowed user' do
|
|
|
|
context 'when project is new' do
|
2020-08-25 05:10:42 -04:00
|
|
|
before do
|
2021-09-07 11:11:06 -04:00
|
|
|
project.add_maintainer(user)
|
2017-06-21 19:44:10 -04:00
|
|
|
sign_in(user)
|
2017-03-28 16:04:14 -04:00
|
|
|
|
2017-07-06 12:20:50 -04:00
|
|
|
visit project_cycle_analytics_path(project)
|
2017-05-17 14:25:13 -04:00
|
|
|
wait_for_requests
|
2016-11-24 18:00:50 -05:00
|
|
|
end
|
|
|
|
|
2021-09-07 11:11:06 -04:00
|
|
|
it 'displays metrics with relevant values' do
|
|
|
|
expect(metrics_values).to eq(['-'] * 4)
|
2017-08-10 02:41:41 -04:00
|
|
|
end
|
|
|
|
|
2016-11-24 18:00:50 -05:00
|
|
|
it 'shows active stage with empty message' do
|
2021-06-02 05:09:46 -04:00
|
|
|
expect(page).to have_selector('.gl-path-active-item-indigo', text: 'Issue')
|
2016-11-24 18:00:50 -05:00
|
|
|
expect(page).to have_content("We don't have enough data to show this stage.")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-10-20 02:09:59 -04:00
|
|
|
context "when there's value stream analytics data", :sidekiq_inline do
|
2021-09-07 11:11:06 -04:00
|
|
|
# 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")
|
2021-10-12 11:12:08 -04:00
|
|
|
max_items_per_page = 20
|
2021-09-07 11:11:06 -04:00
|
|
|
|
2021-08-20 02:11:03 -04:00
|
|
|
around do |example|
|
|
|
|
travel_to(5.days.ago) { example.run }
|
|
|
|
end
|
|
|
|
|
2016-11-24 18:00:50 -05:00
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2021-09-07 11:11:06 -04:00
|
|
|
create_cycle(user, project, issue, mr, milestone, pipeline)
|
2021-10-12 11:12:08 -04:00
|
|
|
create_list(:issue, max_items_per_page, project: project, created_at: 2.weeks.ago, milestone: milestone)
|
2018-02-21 07:13:56 -05:00
|
|
|
deploy_master(user, project)
|
2016-11-24 18:00:50 -05:00
|
|
|
|
2021-08-04 14:09:57 -04:00
|
|
|
issue.metrics.update!(first_mentioned_in_commit_at: issue.metrics.first_associated_with_milestone_at + 1.hour)
|
2020-12-11 07:09:43 -05:00
|
|
|
merge_request = issue.merge_requests_closing_issues.first.merge_request
|
2021-08-04 14:09:57 -04:00
|
|
|
merge_request.update!(created_at: issue.metrics.first_associated_with_milestone_at + 1.hour)
|
2020-12-11 07:09:43 -05:00
|
|
|
merge_request.metrics.update!(
|
2021-08-20 02:11:03 -04:00
|
|
|
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
|
2020-12-11 07:09:43 -05:00
|
|
|
)
|
|
|
|
|
2017-06-21 19:44:10 -04:00
|
|
|
sign_in(user)
|
2017-07-06 12:20:50 -04:00
|
|
|
visit project_cycle_analytics_path(project)
|
2021-09-07 11:11:06 -04:00
|
|
|
|
|
|
|
wait_for_requests
|
2016-11-24 18:00:50 -05:00
|
|
|
end
|
|
|
|
|
2021-10-12 11:12:08 -04:00
|
|
|
let(:stage_table_events) { stage_table.all(stage_table_event_selector) }
|
|
|
|
|
2021-08-16 08:09:17 -04:00
|
|
|
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
|
2017-08-10 02:41:41 -04:00
|
|
|
end
|
|
|
|
|
2022-10-20 02:09:59 -04:00
|
|
|
it 'shows data on each stage', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/338332' do
|
2016-11-24 18:00:50 -05:00
|
|
|
expect_issue_to_be_present
|
|
|
|
|
|
|
|
click_stage('Plan')
|
2019-06-17 09:17:18 -04:00
|
|
|
expect_issue_to_be_present
|
2016-11-24 18:00:50 -05:00
|
|
|
|
|
|
|
click_stage('Code')
|
|
|
|
expect_merge_request_to_be_present
|
|
|
|
|
|
|
|
click_stage('Test')
|
2021-08-18 02:11:01 -04:00
|
|
|
expect_merge_request_to_be_present
|
2016-11-24 18:00:50 -05:00
|
|
|
|
|
|
|
click_stage('Review')
|
|
|
|
expect_merge_request_to_be_present
|
|
|
|
|
|
|
|
click_stage('Staging')
|
2021-08-18 02:11:01 -04:00
|
|
|
expect_merge_request_to_be_present
|
2016-11-24 18:00:50 -05:00
|
|
|
end
|
2017-08-10 02:42:28 -04:00
|
|
|
|
2021-09-07 11:11:06 -04:00
|
|
|
it 'can filter the issues by date' do
|
2021-10-12 11:12:08 -04:00
|
|
|
expect(page).to have_selector(stage_table_event_selector)
|
2017-08-10 02:42:28 -04:00
|
|
|
|
2021-09-07 11:11:06 -04:00
|
|
|
set_daterange(from, to)
|
2017-08-10 02:42:28 -04:00
|
|
|
|
2021-10-12 11:12:08 -04:00
|
|
|
expect(page).not_to have_selector(stage_table_event_selector)
|
|
|
|
expect(page).not_to have_selector(stage_table_pagination_selector)
|
2021-09-07 11:11:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'can filter the metrics by date' do
|
2022-01-21 13:12:45 -05:00
|
|
|
expect(metrics_values).to match_array(%w[21 2 1 0])
|
2021-09-07 11:11:06 -04:00
|
|
|
|
|
|
|
set_daterange(from, to)
|
|
|
|
|
|
|
|
expect(metrics_values).to eq(['-'] * 4)
|
2017-08-10 02:42:28 -04:00
|
|
|
end
|
2021-10-12 11:12:08 -04:00
|
|
|
|
2021-10-21 23:11:57 -04:00
|
|
|
it 'can sort records', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/338332' do
|
2021-10-12 11:12:08 -04:00
|
|
|
# NOTE: checking that the string changes should suffice
|
|
|
|
# depending on the order the tests are run we might run into problems with hard coded strings
|
|
|
|
original_first_title = first_stage_title
|
|
|
|
stage_time_column.click
|
|
|
|
|
|
|
|
expect_to_be_sorted "descending"
|
|
|
|
expect(first_stage_title).not_to have_text(original_first_title, exact: true)
|
|
|
|
|
|
|
|
stage_time_column.click
|
|
|
|
|
|
|
|
expect_to_be_sorted "ascending"
|
|
|
|
expect(first_stage_title).to have_text(original_first_title, exact: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'paginates the results' do
|
|
|
|
original_first_title = first_stage_title
|
|
|
|
|
|
|
|
expect(page).to have_selector(stage_table_pagination_selector)
|
|
|
|
|
|
|
|
go_to_next_page
|
|
|
|
|
|
|
|
expect(page).not_to have_text(original_first_title, exact: true)
|
|
|
|
end
|
|
|
|
|
2021-11-12 22:09:49 -05:00
|
|
|
it 'can navigate directly to a value stream stream stage with filters applied' do
|
|
|
|
visit project_cycle_analytics_path(project, created_before: '2019-12-31', created_after: '2019-11-01', stage_id: 'code', milestone_title: milestone.title)
|
|
|
|
wait_for_requests
|
|
|
|
|
|
|
|
expect(page).to have_selector('.gl-path-active-item-indigo', text: 'Code')
|
|
|
|
expect(page.find(".js-daterange-picker-from input").value).to eq("2019-11-01")
|
|
|
|
expect(page.find(".js-daterange-picker-to input").value).to eq("2019-12-31")
|
|
|
|
|
|
|
|
filter_bar = page.find(stage_filter_bar)
|
|
|
|
expect(filter_bar.find(".gl-filtered-search-token-data-content").text).to eq("%#{milestone.title}")
|
|
|
|
end
|
|
|
|
|
2021-10-12 11:12:08 -04:00
|
|
|
def stage_time_column
|
|
|
|
stage_table.find(stage_table_duration_column_header_selector).ancestor("th")
|
|
|
|
end
|
|
|
|
|
|
|
|
def first_stage_title
|
|
|
|
stage_table.all(stage_table_event_title_selector).first.text
|
|
|
|
end
|
|
|
|
|
|
|
|
def expect_to_be_sorted(direction)
|
|
|
|
expect(stage_time_column['aria-sort']).to eq(direction)
|
|
|
|
end
|
|
|
|
|
|
|
|
def go_to_next_page
|
|
|
|
page.find(stage_table_pagination_selector).find_link("Next").click
|
|
|
|
end
|
2016-11-24 18:00:50 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "as a guest" do
|
|
|
|
before do
|
2018-01-05 12:55:37 -05:00
|
|
|
project.add_developer(user)
|
2017-03-28 16:04:14 -04:00
|
|
|
project.add_guest(guest)
|
2016-11-24 18:00:50 -05:00
|
|
|
|
2018-02-15 08:23:39 -05:00
|
|
|
create_cycle(user, project, issue, mr, milestone, pipeline)
|
2018-02-21 07:13:56 -05:00
|
|
|
deploy_master(user, project)
|
2016-11-24 18:00:50 -05:00
|
|
|
|
2017-06-21 19:44:10 -04:00
|
|
|
sign_in(guest)
|
2017-07-06 12:20:50 -04:00
|
|
|
visit project_cycle_analytics_path(project)
|
2017-05-17 14:25:13 -04:00
|
|
|
wait_for_requests
|
2016-11-24 18:00:50 -05:00
|
|
|
end
|
|
|
|
|
2022-10-20 02:09:59 -04:00
|
|
|
it 'does not show the commit stats', :sidekiq_inline do
|
2021-08-16 08:09:17 -04:00
|
|
|
expect(page.find(metrics_selector)).not_to have_selector("#commits")
|
2019-11-06 11:07:11 -05:00
|
|
|
end
|
|
|
|
|
2022-10-20 02:09:59 -04:00
|
|
|
it 'does not show restricted stages', :aggregate_failures, :sidekiq_inline do
|
2021-07-20 05:08:43 -04:00
|
|
|
expect(find(stage_table_selector)).to have_content(issue.title)
|
2016-11-24 18:00:50 -05:00
|
|
|
|
2022-07-22 02:10:47 -04:00
|
|
|
expect(page).to have_selector('.gl-path-nav-list-item', text: 'Issue')
|
2016-11-24 18:00:50 -05:00
|
|
|
|
2022-07-22 02:10:47 -04:00
|
|
|
expect(page).to have_selector('.gl-path-nav-list-item', text: 'Plan')
|
|
|
|
|
|
|
|
expect(page).to have_selector('.gl-path-nav-list-item', text: 'Test')
|
|
|
|
|
|
|
|
expect(page).to have_selector('.gl-path-nav-list-item', text: 'Staging')
|
|
|
|
|
|
|
|
expect(page).not_to have_selector('.gl-path-nav-list-item', text: 'Code')
|
|
|
|
|
|
|
|
expect(page).not_to have_selector('.gl-path-nav-list-item', text: 'Review')
|
2016-11-24 18:00:50 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def expect_issue_to_be_present
|
2021-07-20 05:08:43 -04:00
|
|
|
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}")
|
2016-11-24 18:00:50 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def expect_merge_request_to_be_present
|
2021-07-20 05:08:43 -04:00
|
|
|
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}")
|
2016-11-24 18:00:50 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def click_stage(stage_name)
|
2021-06-02 05:09:46 -04:00
|
|
|
find('.gl-path-nav-list-item', text: stage_name).click
|
2017-05-17 14:25:13 -04:00
|
|
|
wait_for_requests
|
2016-11-24 18:00:50 -05:00
|
|
|
end
|
|
|
|
end
|