debian-mirror-gitlab/spec/support/helpers/cycle_analytics_helpers.rb

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

239 lines
7.7 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2016-09-29 09:46:39 +05:30
module CycleAnalyticsHelpers
2021-06-08 01:23:25 +05:30
def toggle_value_stream_dropdown
page.find('[data-testid="dropdown-value-streams"]').click
end
2021-09-04 01:27:46 +05:30
def path_nav_stage_names_without_median
# Returns the path names with the median value stripped out
2022-10-11 01:57:18 +05:30
page.all('.gl-path-button').collect(&:text).map { |name_with_median| name_with_median.split("\n")[0] }
2021-09-04 01:27:46 +05:30
end
2021-09-30 23:02:18 +05:30
def fill_in_custom_stage_fields
2021-06-08 01:23:25 +05:30
index = page.all('[data-testid="value-stream-stage-fields"]').length
last_stage = page.all('[data-testid="value-stream-stage-fields"]').last
within last_stage do
find('[name*="custom-stage-name-"]').fill_in with: "Cool custom stage - name #{index}"
select_dropdown_option_by_value "custom-stage-start-event-", :merge_request_created
select_dropdown_option_by_value "custom-stage-end-event-", :merge_request_merged
end
end
2021-11-11 11:23:49 +05:30
def select_event_label(sel)
page.within(sel) do
find('.dropdown-toggle').click
page.find(".dropdown-menu").all(".dropdown-item")[1].click
end
end
def fill_in_custom_label_stage_fields
index = page.all('[data-testid="value-stream-stage-fields"]').length
last_stage = page.all('[data-testid="value-stream-stage-fields"]').last
within last_stage do
find('[name*="custom-stage-name-"]').fill_in with: "Cool custom label stage - name #{index}"
select_dropdown_option_by_value "custom-stage-start-event-", :issue_label_added
select_dropdown_option_by_value "custom-stage-end-event-", :issue_label_removed
select_event_label("[data-testid*='custom-stage-start-event-label-']")
select_event_label("[data-testid*='custom-stage-end-event-label-']")
end
end
2021-09-30 23:02:18 +05:30
def add_custom_stage_to_form
page.find_button(s_('CreateValueStreamForm|Add another stage')).click
fill_in_custom_stage_fields
end
2021-11-11 11:23:49 +05:30
def add_custom_label_stage_to_form
page.find_button(s_('CreateValueStreamForm|Add another stage')).click
fill_in_custom_label_stage_fields
end
2021-06-08 01:23:25 +05:30
def save_value_stream(custom_value_stream_name)
fill_in 'create-value-stream-name', with: custom_value_stream_name
2022-03-02 08:16:31 +05:30
page.find_button(s_('CreateValueStreamForm|Create value stream')).click
2021-06-08 01:23:25 +05:30
wait_for_requests
end
2021-12-11 22:18:48 +05:30
def click_save_value_stream_button
click_button(_('Save value stream'))
end
2021-06-08 01:23:25 +05:30
def create_custom_value_stream(custom_value_stream_name)
toggle_value_stream_dropdown
page.find_button(_('Create new Value Stream')).click
add_custom_stage_to_form
save_value_stream(custom_value_stream_name)
end
2021-11-11 11:23:49 +05:30
def wait_for_stages_to_load(selector = '[data-testid="vsa-path-navigation"]')
2021-04-29 21:17:54 +05:30
expect(page).to have_selector selector
2021-03-11 19:13:27 +05:30
wait_for_requests
end
2021-11-11 11:23:49 +05:30
def select_group(target_group, ready_selector = '[data-testid="vsa-path-navigation"]')
2021-03-11 19:13:27 +05:30
visit group_analytics_cycle_analytics_path(target_group)
2021-04-29 21:17:54 +05:30
wait_for_stages_to_load(ready_selector)
2021-03-11 19:13:27 +05:30
end
2022-06-21 17:19:12 +05:30
def select_value_stream(value_stream_name)
toggle_value_stream_dropdown
page.find('[data-testid="dropdown-value-streams"]').all('li button').find { |item| item.text == value_stream_name.to_s }.click
wait_for_requests
end
def create_value_stream_group_aggregation(group)
aggregation = Analytics::CycleAnalytics::Aggregation.safe_create_for_group(group)
Analytics::CycleAnalytics::AggregatorService.new(aggregation: aggregation).execute
end
def select_group_and_custom_value_stream(group, custom_value_stream_name)
create_value_stream_group_aggregation(group)
select_group(group)
select_value_stream(custom_value_stream_name)
end
2021-03-11 19:13:27 +05:30
def toggle_dropdown(field)
2021-04-17 20:07:23 +05:30
page.within("[data-testid*='#{field}']") do
2021-03-11 19:13:27 +05:30
find('.dropdown-toggle').click
wait_for_requests
expect(find('.dropdown-menu')).to have_selector('.dropdown-item')
end
end
def select_dropdown_option_by_value(name, value, elem = '.dropdown-item')
toggle_dropdown name
2021-04-17 20:07:23 +05:30
page.find("[data-testid*='#{name}'] .dropdown-menu").find("#{elem}[value='#{value}']").click
2021-03-11 19:13:27 +05:30
end
2017-08-17 22:00:37 +05:30
def create_commit_referencing_issue(issue, branch_name: generate(:branch))
2016-09-29 09:46:39 +05:30
project.repository.add_branch(user, branch_name, 'master')
create_commit("Commit for ##{issue.iid}", issue.project, user, branch_name)
end
2018-11-08 19:23:39 +05:30
def create_commit(message, project, user, branch_name, count: 1, commit_time: nil, skip_push_handler: false)
2018-03-17 18:26:18 +05:30
repository = project.repository
2018-11-08 19:23:39 +05:30
oldrev = repository.commit(branch_name)&.sha || Gitlab::Git::BLANK_SHA
2018-03-17 18:26:18 +05:30
2016-10-01 15:18:49 +05:30
commit_shas = Array.new(count) do |index|
2018-03-17 18:26:18 +05:30
commit_sha = repository.create_file(user, generate(:branch), "content", message: message, branch_name: branch_name)
repository.commit(commit_sha)
2016-10-01 15:18:49 +05:30
commit_sha
end
2016-09-29 09:46:39 +05:30
2018-11-08 19:23:39 +05:30
return if skip_push_handler
2019-12-21 20:55:43 +05:30
Git::BranchPushService.new(
project,
user,
change: {
oldrev: oldrev,
newrev: commit_shas.last,
ref: 'refs/heads/master'
}
).execute
2016-09-29 09:46:39 +05:30
end
2018-03-27 19:54:05 +05:30
def create_cycle(user, project, issue, mr, milestone, pipeline)
2020-10-24 23:57:45 +05:30
issue.update!(milestone: milestone)
2018-03-27 19:54:05 +05:30
pipeline.run
ci_build = create(:ci_build, pipeline: pipeline, status: :success, author: user)
merge_merge_requests_closing_issue(user, project, issue)
ProcessCommitWorker.new.perform(project.id, user.id, mr.commits.last.to_hash)
ci_build
end
def create_merge_request_closing_issue(user, project, issue, message: nil, source_branch: nil, commit_message: 'commit message')
2016-09-29 09:46:39 +05:30
if !source_branch || project.repository.commit(source_branch).blank?
2017-08-17 22:00:37 +05:30
source_branch = generate(:branch)
2016-09-29 09:46:39 +05:30
project.repository.add_branch(user, source_branch, 'master')
end
2018-11-08 19:23:39 +05:30
# Cycle analytic specs often test with frozen times, which causes metrics to be
# pinned to the current time. For example, in the plan stage, we assume that an issue
# milestone has been created before any code has been written. We add a second
# to ensure that the plan time is positive.
create_commit(commit_message, project, user, source_branch, commit_time: Time.now + 1.second, skip_push_handler: true)
2016-09-29 09:46:39 +05:30
opts = {
title: 'Awesome merge_request',
description: message || "Fixes #{issue.to_reference}",
source_branch: source_branch,
target_branch: 'master'
}
2021-06-08 01:23:25 +05:30
mr = MergeRequests::CreateService.new(project: project, current_user: user, params: opts).execute
2017-09-10 17:25:29 +05:30
NewMergeRequestWorker.new.perform(mr, user)
mr
2016-09-29 09:46:39 +05:30
end
2018-03-27 19:54:05 +05:30
def merge_merge_requests_closing_issue(user, project, issue)
2018-11-20 20:47:30 +05:30
merge_requests = Issues::ReferencedMergeRequestsService
2021-06-08 01:23:25 +05:30
.new(project: project, current_user: user)
2018-11-20 20:47:30 +05:30
.closed_by_merge_requests(issue)
2016-11-24 13:41:30 +05:30
2021-06-08 01:23:25 +05:30
merge_requests.each { |merge_request| MergeRequests::MergeService.new(project: project, current_user: user, params: { sha: merge_request.diff_head_sha }).execute(merge_request) }
2016-09-29 09:46:39 +05:30
end
2018-03-27 19:54:05 +05:30
def deploy_master(user, project, environment: 'production')
2017-09-10 17:25:29 +05:30
dummy_job =
case environment
when 'production'
2018-03-27 19:54:05 +05:30
dummy_production_job(user, project)
2017-09-10 17:25:29 +05:30
when 'staging'
2018-03-27 19:54:05 +05:30
dummy_staging_job(user, project)
2017-09-10 17:25:29 +05:30
else
raise ArgumentError
end
2018-12-13 13:39:08 +05:30
dummy_job.success! # State machine automatically update associated deployment/environment record
2017-09-10 17:25:29 +05:30
end
2018-03-27 19:54:05 +05:30
def dummy_production_job(user, project)
new_dummy_job(user, project, 'production')
2017-09-10 17:25:29 +05:30
end
2018-03-27 19:54:05 +05:30
def dummy_staging_job(user, project)
new_dummy_job(user, project, 'staging')
2017-09-10 17:25:29 +05:30
end
2018-03-27 19:54:05 +05:30
def dummy_pipeline(project)
2018-12-13 13:39:08 +05:30
create(:ci_pipeline,
2018-03-27 19:54:05 +05:30
sha: project.repository.commit('master').sha,
ref: 'master',
source: :push,
project: project,
protected: false)
2017-09-10 17:25:29 +05:30
end
2018-03-27 19:54:05 +05:30
def new_dummy_job(user, project, environment)
2018-12-13 13:39:08 +05:30
create(:ci_build,
2019-12-21 20:55:43 +05:30
:with_deployment,
2017-09-10 17:25:29 +05:30
project: project,
user: user,
environment: environment,
ref: 'master',
tag: false,
name: 'dummy',
2018-03-17 18:26:18 +05:30
stage: 'dummy',
2018-03-27 19:54:05 +05:30
pipeline: dummy_pipeline(project),
2018-03-17 18:26:18 +05:30
protected: false)
end
2016-09-29 09:46:39 +05:30
end