2016-11-24 18:00:50 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
describe 'Cycle Analytics', :js do
|
2016-11-24 18:00:50 -05:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:guest) { create(:user) }
|
2017-03-28 17:13:16 -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
|
|
|
|
|
|
|
context 'as an allowed user' do
|
|
|
|
context 'when project is new' do
|
|
|
|
before do
|
2017-03-22 15:36:14 -04:00
|
|
|
project.add_master(user)
|
2017-03-28 16:04:14 -04:00
|
|
|
|
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
|
|
|
|
|
|
|
|
it 'shows introductory message' do
|
|
|
|
expect(page).to have_content('Introducing Cycle Analytics')
|
|
|
|
end
|
|
|
|
|
2017-08-10 02:41:41 -04:00
|
|
|
it 'shows pipeline summary' do
|
|
|
|
expect(new_issues_counter).to have_content('-')
|
|
|
|
expect(commits_counter).to have_content('-')
|
|
|
|
expect(deploys_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('.stage-nav-item.active', text: 'Issue')
|
|
|
|
expect(page).to have_content("We don't have enough data to show this stage.")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when there's cycle analytics data" do
|
|
|
|
before do
|
2017-05-05 15:00:18 -04:00
|
|
|
allow_any_instance_of(Gitlab::ReferenceExtractor).to receive(:issues).and_return([issue])
|
2017-03-28 16:04:14 -04:00
|
|
|
project.add_master(user)
|
2017-05-05 15:00:18 -04:00
|
|
|
|
2018-02-15 08:23:39 -05:00
|
|
|
@build = 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(user)
|
2017-07-06 12:20:50 -04:00
|
|
|
visit project_cycle_analytics_path(project)
|
2016-11-24 18:00:50 -05:00
|
|
|
end
|
|
|
|
|
2017-08-10 02:41:41 -04:00
|
|
|
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')
|
|
|
|
end
|
|
|
|
|
2016-11-24 18:00:50 -05:00
|
|
|
it 'shows data on each stage' do
|
|
|
|
expect_issue_to_be_present
|
|
|
|
|
|
|
|
click_stage('Plan')
|
2016-12-30 18:01:36 -05:00
|
|
|
expect(find('.stage-events')).to have_content(mr.commits.last.title)
|
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
|
|
|
|
|
|
|
|
click_stage('Production')
|
|
|
|
expect_issue_to_be_present
|
|
|
|
end
|
2017-08-10 02:42:28 -04:00
|
|
|
|
|
|
|
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
|
2017-05-04 19:44:19 -04:00
|
|
|
|
|
|
|
context "when my preferred language is Spanish" do
|
|
|
|
before do
|
|
|
|
user.update_attribute(:preferred_language, 'es')
|
|
|
|
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_master(user)
|
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)
|
2017-05-17 14:25:13 -04:00
|
|
|
wait_for_requests
|
2017-05-04 19:44:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows the content in Spanish' do
|
|
|
|
expect(page).to have_content('Estado del Pipeline')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'resets the language to English' do
|
|
|
|
expect(I18n.locale).to eq(:en)
|
|
|
|
end
|
|
|
|
end
|
2016-11-24 18:00:50 -05:00
|
|
|
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
|
|
|
|
|
|
|
allow_any_instance_of(Gitlab::ReferenceExtractor).to receive(:issues).and_return([issue])
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2017-08-10 02:41:41 -04:00
|
|
|
def new_issues_counter
|
|
|
|
find(:xpath, "//p[contains(text(),'New Issue')]/preceding-sibling::h3")
|
|
|
|
end
|
|
|
|
|
|
|
|
def commits_counter
|
|
|
|
find(:xpath, "//p[contains(text(),'Commits')]/preceding-sibling::h3")
|
|
|
|
end
|
|
|
|
|
|
|
|
def deploys_counter
|
|
|
|
find(:xpath, "//p[contains(text(),'Deploy')]/preceding-sibling::h3")
|
|
|
|
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('.stage-nav li', 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
|