gitlab-org--gitlab-foss/spec/features/cycle_analytics_spec.rb

179 lines
5.6 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2016-11-24 18:00:50 -05:00
require 'spec_helper'
RSpec.describe 'Value Stream Analytics', :js do
let_it_be(:user) { create(:user) }
let_it_be(:guest) { create(:user) }
let_it_be(: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) }
let(:mr) { create_merge_request_closing_issue(user, project, issue, commit_message: "References #{issue.to_reference}") }
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
context 'as an allowed user' do
context 'when project is new' do
before(:all) do
project.add_maintainer(user)
end
2017-03-28 16:04:14 -04:00
before do
sign_in(user)
2017-03-28 16:04:14 -04:00
visit project_cycle_analytics_path(project)
wait_for_requests
2016-11-24 18:00:50 -05:00
end
it 'shows pipeline summary' do
expect(new_issues_counter).to have_content('-')
expect(commits_counter).to have_content('-')
expect(deploys_counter).to have_content('-')
expect(deployment_frequency_counter).to have_content('-')
end
2016-11-24 18:00:50 -05:00
it 'shows active stage with empty message' do
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
context "when there's value stream analytics data" do
2016-11-24 18:00:50 -05:00
before do
project.add_maintainer(user)
@build = create_cycle(user, project, issue, mr, milestone, pipeline)
deploy_master(user, project)
2016-11-24 18:00:50 -05:00
issue.metrics.update!(first_mentioned_in_commit_at: issue.metrics.first_associated_with_milestone_at + 1.day)
merge_request = issue.merge_requests_closing_issues.first.merge_request
merge_request.update!(created_at: issue.metrics.first_associated_with_milestone_at + 1.day)
merge_request.metrics.update!(
latest_build_started_at: 4.hours.ago,
latest_build_finished_at: 3.hours.ago,
merged_at: merge_request.created_at + 1.hour,
first_deployed_to_production_at: merge_request.created_at + 2.hours
)
sign_in(user)
visit project_cycle_analytics_path(project)
2016-11-24 18:00:50 -05:00
end
it 'shows pipeline summary' do
expect(new_issues_counter).to have_content('1')
expect(commits_counter).to have_content('2')
expect(deploys_counter).to have_content('1')
expect(deployment_frequency_counter).to have_content('0')
end
it 'shows data on each stage', :sidekiq_might_not_need_inline do
2016-11-24 18:00:50 -05:00
expect_issue_to_be_present
click_stage('Plan')
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')
expect_build_to_be_present
click_stage('Review')
expect_merge_request_to_be_present
click_stage('Staging')
expect_build_to_be_present
end
context "when I change the time period observed" do
before do
_two_weeks_old_issue = create(:issue, project: project, created_at: 2.weeks.ago)
click_button('Last 30 days')
click_link('Last 7 days')
wait_for_requests
end
it 'shows only relevant data' do
expect(new_issues_counter).to have_content('1')
end
end
2016-11-24 18:00:50 -05:00
end
end
context "as a guest" do
before do
project.add_developer(user)
2017-03-28 16:04:14 -04:00
project.add_guest(guest)
2016-11-24 18:00:50 -05:00
create_cycle(user, project, issue, mr, milestone, pipeline)
deploy_master(user, project)
2016-11-24 18:00:50 -05:00
sign_in(guest)
visit project_cycle_analytics_path(project)
wait_for_requests
2016-11-24 18:00:50 -05:00
end
it 'does not show the commit stats' do
expect(page).to have_no_selector(:xpath, commits_counter_selector)
end
2016-11-24 18:00:50 -05:00
it 'needs permissions to see restricted stages' do
expect(find('.stage-events')).to have_content(issue.title)
click_stage('Code')
expect(find('.stage-events')).to have_content('You need permission.')
click_stage('Review')
expect(find('.stage-events')).to have_content('You need permission.')
end
end
def new_issues_counter
find(:xpath, "//p[contains(text(),'New Issue')]/preceding-sibling::h3")
end
def commits_counter_selector
"//p[contains(text(),'Commits')]/preceding-sibling::h3"
end
def commits_counter
find(:xpath, commits_counter_selector)
end
def deploys_counter
find(:xpath, "//p[contains(text(),'Deploy')]/preceding-sibling::h3", match: :first)
end
def deployment_frequency_counter_selector
"//p[contains(text(),'Deployment Frequency')]/preceding-sibling::h3"
end
def deployment_frequency_counter
find(:xpath, deployment_frequency_counter_selector)
end
2016-11-24 18:00:50 -05:00
def expect_issue_to_be_present
expect(find('.stage-events')).to have_content(issue.title)
expect(find('.stage-events')).to have_content(issue.author.name)
expect(find('.stage-events')).to have_content("##{issue.iid}")
end
def expect_build_to_be_present
expect(find('.stage-events')).to have_content(@build.ref)
expect(find('.stage-events')).to have_content(@build.short_sha)
expect(find('.stage-events')).to have_content("##{@build.id}")
end
def expect_merge_request_to_be_present
2016-12-30 18:01:36 -05:00
expect(find('.stage-events')).to have_content(mr.title)
expect(find('.stage-events')).to have_content(mr.author.name)
expect(find('.stage-events')).to have_content("!#{mr.iid}")
2016-11-24 18:00:50 -05:00
end
def click_stage(stage_name)
find('.gl-path-nav-list-item', text: stage_name).click
wait_for_requests
2016-11-24 18:00:50 -05:00
end
end