BigW Consortium Gitlab

cycle_analytics_spec.rb 4.35 KB
Newer Older
1 2 3 4 5
require 'spec_helper'

feature 'Cycle Analytics', feature: true, js: true do
  let(:user) { create(:user) }
  let(:guest) { create(:user) }
6
  let(:project) { create(:project, :repository) }
Alfredo Sumaran committed
7 8
  let(:issue) { create(:issue, project: project, created_at: 2.days.ago) }
  let(:milestone) { create(:milestone, project: project) }
9
  let(:mr) { create_merge_request_closing_issue(issue, commit_message: "References #{issue.to_reference}") }
10
  let(:pipeline) { create(:ci_empty_pipeline, status: 'created', project: project, ref: mr.source_branch, sha: mr.source_branch_sha, head_pipeline_of: mr) }
11 12 13 14

  context 'as an allowed user' do
    context 'when project is new' do
      before  do
Felipe Artur committed
15
        project.add_master(user)
Felipe Artur committed
16

17
        login_as(user)
Felipe Artur committed
18

19
        visit namespace_project_cycle_analytics_path(project.namespace, project)
20
        wait_for_requests
21 22 23 24 25 26 27 28 29 30 31 32 33 34
      end

      it 'shows introductory message' do
        expect(page).to have_content('Introducing Cycle Analytics')
      end

      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
35
        allow_any_instance_of(Gitlab::ReferenceExtractor).to receive(:issues).and_return([issue])
Felipe Artur committed
36
        project.add_master(user)
37

38 39 40 41 42 43 44 45 46 47 48
        create_cycle
        deploy_master

        login_as(user)
        visit namespace_project_cycle_analytics_path(project.namespace, project)
      end

      it 'shows data on each stage' do
        expect_issue_to_be_present

        click_stage('Plan')
Alfredo Sumaran committed
49
        expect(find('.stage-events')).to have_content(mr.commits.last.title)
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66

        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
    end
67 68 69 70 71 72 73 74

    context "when my preferred language is Spanish" do
      before do
        user.update_attribute(:preferred_language, 'es')

        project.team << [user, :master]
        login_as(user)
        visit namespace_project_cycle_analytics_path(project.namespace, project)
75
        wait_for_requests
76 77 78 79 80 81 82 83 84 85
      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
86 87 88 89
  end

  context "as a guest" do
    before do
Felipe Artur committed
90
      project.add_guest(guest)
91 92 93 94 95 96 97

      allow_any_instance_of(Gitlab::ReferenceExtractor).to receive(:issues).and_return([issue])
      create_cycle
      deploy_master

      login_as(guest)
      visit namespace_project_cycle_analytics_path(project.namespace, project)
98
      wait_for_requests
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
    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

  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
Alfredo Sumaran committed
125 126 127
    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}")
128 129 130 131 132 133 134 135 136
  end

  def create_cycle
    issue.update(milestone: milestone)
    pipeline.run

    @build = create(:ci_build, pipeline: pipeline, status: :success, author: user)

    merge_merge_requests_closing_issue(issue)
Alfredo Sumaran committed
137
    ProcessCommitWorker.new.perform(project.id, user.id, mr.commits.last.to_hash)
138 139 140 141
  end

  def click_stage(stage_name)
    find('.stage-nav li', text: stage_name).click
142
    wait_for_requests
143 144
  end
end