BigW Consortium Gitlab

show.html.haml_spec.rb 7.99 KB
Newer Older
1 2
require 'spec_helper'

3
describe 'projects/builds/show', :view do
4
  let(:project) { create(:project, :repository) }
5 6
  let(:build) { create(:ci_build, pipeline: pipeline) }

7
  let(:pipeline) do
8
    create(:ci_pipeline, project: project, sha: project.commit.id)
9
  end
10 11

  before do
12
    assign(:build, build.present)
13 14 15 16 17
    assign(:project, project)

    allow(view).to receive(:can?).and_return(true)
  end

Filipa Lacerda committed
18
  describe 'job information in header' do
19 20 21 22 23 24 25 26 27 28 29 30
    let(:build) do
      create(:ci_build, :success, environment: 'staging')
    end

    before do
      render
    end

    it 'shows status name' do
      expect(rendered).to have_css('.ci-status.ci-success', text: 'passed')
    end

Filipa Lacerda committed
31
    it 'does not render a link to the job' do
Filipa Lacerda committed
32 33 34
      expect(rendered).not_to have_link('passed')
    end

Filipa Lacerda committed
35
    it 'shows job id' do
36 37 38 39 40 41 42 43 44 45 46 47
      expect(rendered).to have_css('.js-build-id', text: build.id)
    end

    it 'shows a link to the pipeline' do
      expect(rendered).to have_link(build.pipeline.id)
    end

    it 'shows a link to the commit' do
      expect(rendered).to have_link(build.pipeline.short_sha)
    end
  end

Filipa Lacerda committed
48 49
  describe 'environment info in job view' do
    context 'job with latest deployment' do
50 51 52 53 54 55 56 57
      let(:build) do
        create(:ci_build, :success, environment: 'staging')
      end

      before do
        create(:environment, name: 'staging')
        create(:deployment, deployable: build)
      end
58 59

      it 'shows deployment message' do
Filipa Lacerda committed
60
        expected_text = 'This job is the most recent deployment'
61 62 63 64
        render

        expect(rendered).to have_css(
          '.environment-information', text: expected_text)
65 66 67
      end
    end

Filipa Lacerda committed
68
    context 'job with outdated deployment' do
69 70 71
      let(:build) do
        create(:ci_build, :success, environment: 'staging', pipeline: pipeline)
      end
72

73 74 75 76
      let(:second_build) do
        create(:ci_build, :success, environment: 'staging', pipeline: pipeline)
      end

77 78 79
      let(:environment) do
        create(:environment, name: 'staging', project: project)
      end
80

81 82 83 84 85
      let!(:first_deployment) do
        create(:deployment, environment: environment, deployable: build)
      end

      let!(:second_deployment) do
86
        create(:deployment, environment: environment, deployable: second_build)
87 88 89
      end

      it 'shows deployment message' do
Filipa Lacerda committed
90
        expected_text = 'This job is an out-of-date deployment ' \
91
          "to staging.\nView the most recent deployment ##{second_deployment.iid}."
92 93 94
        render

        expect(rendered).to have_css('.environment-information', text: expected_text)
95 96 97
      end
    end

Filipa Lacerda committed
98
    context 'job failed to deploy' do
99 100 101 102 103 104 105 106 107
      let(:build) do
        create(:ci_build, :failed, environment: 'staging', pipeline: pipeline)
      end

      let!(:environment) do
        create(:environment, name: 'staging', project: project)
      end

      it 'shows deployment message' do
Filipa Lacerda committed
108
        expected_text = 'The deployment of this job to staging did not succeed.'
109 110 111 112 113
        render

        expect(rendered).to have_css(
          '.environment-information', text: expected_text)
      end
114 115
    end

Filipa Lacerda committed
116
    context 'job will deploy' do
117 118 119 120
      let(:build) do
        create(:ci_build, :running, environment: 'staging', pipeline: pipeline)
      end

121
      context 'when environment exists' do
Kamil Trzcinski committed
122 123 124 125 126
        let!(:environment) do
          create(:environment, name: 'staging', project: project)
        end

        it 'shows deployment message' do
Filipa Lacerda committed
127
          expected_text = 'This job is creating a deployment to staging'
Kamil Trzcinski committed
128 129 130 131 132 133
          render

          expect(rendered).to have_css(
            '.environment-information', text: expected_text)
        end

134
        context 'when it has deployment' do
Kamil Trzcinski committed
135 136 137 138 139
          let!(:deployment) do
            create(:deployment, environment: environment)
          end

          it 'shows that deployment will be overwritten' do
Filipa Lacerda committed
140
            expected_text = 'This job is creating a deployment to staging'
Kamil Trzcinski committed
141 142 143 144 145 146 147 148 149 150
            render

            expect(rendered).to have_css(
              '.environment-information', text: expected_text)
            expect(rendered).to have_css(
              '.environment-information', text: 'latest deployment')
          end
        end
      end

151
      context 'when environment does not exist' do
Kamil Trzcinski committed
152
        it 'shows deployment message' do
Filipa Lacerda committed
153
          expected_text = 'This job is creating a deployment to staging'
Kamil Trzcinski committed
154 155 156 157 158 159 160
          render

          expect(rendered).to have_css(
            '.environment-information', text: expected_text)
          expect(rendered).not_to have_css(
            '.environment-information', text: 'latest deployment')
        end
161
      end
162 163
    end

Filipa Lacerda committed
164
    context 'job that failed to deploy and environment has not been created' do
165 166 167 168 169 170 171 172 173
      let(:build) do
        create(:ci_build, :failed, environment: 'staging', pipeline: pipeline)
      end

      let!(:environment) do
        create(:environment, name: 'staging', project: project)
      end

      it 'shows deployment message' do
Filipa Lacerda committed
174
        expected_text = 'The deployment of this job to staging did not succeed'
175 176 177 178 179
        render

        expect(rendered).to have_css(
          '.environment-information', text: expected_text)
      end
180 181
    end

Filipa Lacerda committed
182
    context 'job that will deploy and environment has not been created' do
183 184 185 186 187 188 189 190 191
      let(:build) do
        create(:ci_build, :running, environment: 'staging', pipeline: pipeline)
      end

      let!(:environment) do
        create(:environment, name: 'staging', project: project)
      end

      it 'shows deployment message' do
Filipa Lacerda committed
192
        expected_text = 'This job is creating a deployment to staging'
193 194 195 196
        render

        expect(rendered).to have_css(
          '.environment-information', text: expected_text)
Kamil Trzcinski committed
197 198
        expect(rendered).not_to have_css(
          '.environment-information', text: 'latest deployment')
199
      end
200 201 202
    end
  end

Filipa Lacerda committed
203
  context 'when job is running' do
204 205 206 207 208 209 210 211
    before do
      build.run!
      render
    end

    it 'does not show retry button' do
      expect(rendered).not_to have_link('Retry')
    end
Alex Sanford committed
212 213 214 215

    it 'does not show New issue button' do
      expect(rendered).not_to have_link('New issue')
    end
216 217
  end

Filipa Lacerda committed
218
  context 'when job is not running' do
219 220 221 222 223 224 225 226
    before do
      build.success!
      render
    end

    it 'shows retry button' do
      expect(rendered).to have_link('Retry')
    end
Alex Sanford committed
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243

    context 'if build passed' do
      it 'does not show New issue button' do
        expect(rendered).not_to have_link('New issue')
      end
    end

    context 'if build failed' do
      before do
        build.status = 'failed'
        render
      end

      it 'shows New issue button' do
        expect(rendered).to have_link('New issue')
      end
    end
ubudzisz committed
244
  end
245

246 247 248 249 250
  describe 'commit title in sidebar' do
    let(:commit_title) { project.commit.title }

    it 'shows commit title and not show commit message' do
      render
251

252 253 254
      expect(rendered).to have_css('p.build-light-text.append-bottom-0',
        text: /\A\n#{Regexp.escape(commit_title)}\n\Z/)
    end
ubudzisz committed
255
  end
256 257

  describe 'shows trigger variables in sidebar' do
258
    let(:trigger_request) { create(:ci_trigger_request_with_variables, pipeline: pipeline) }
259 260 261

    before do
      build.trigger_request = trigger_request
262
      render
263 264 265
    end

    it 'shows trigger variables in separate lines' do
ubudzisz committed
266 267 268 269
      expect(rendered).to have_css('.js-build-variable', visible: false, text: 'TRIGGER_KEY_1')
      expect(rendered).to have_css('.js-build-variable', visible: false, text: 'TRIGGER_KEY_2')
      expect(rendered).to have_css('.js-build-value', visible: false, text: 'TRIGGER_VALUE_1')
      expect(rendered).to have_css('.js-build-value', visible: false, text: 'TRIGGER_VALUE_2')
270 271
    end
  end
Alex Sanford committed
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292

  describe 'New issue button' do
    before do
      build.status = 'failed'
      render
    end

    it 'links to issues/new with the title and description filled in' do
      title = "Build Failed ##{build.id}"
      build_url = namespace_project_build_url(project.namespace, project, build)
      href = new_namespace_project_issue_path(
        project.namespace,
        project,
        issue: {
          title: title,
          description: build_url
        }
      )
      expect(rendered).to have_link('New issue', href: href)
    end
  end
293
end