BigW Consortium Gitlab

admin_builds_spec.rb 4.91 KB
Newer Older
1 2
require 'spec_helper'

3
describe 'Admin Builds' do
4
  before do
5
    login_as :admin
6 7
  end

8
  describe 'GET /admin/builds' do
9
    let(:pipeline) { create(:ci_pipeline) }
10

11 12 13
    context 'All tab' do
      context 'when have builds' do
        it 'shows all builds' do
14 15 16 17
          create(:ci_build, pipeline: pipeline, status: :pending)
          create(:ci_build, pipeline: pipeline, status: :running)
          create(:ci_build, pipeline: pipeline, status: :success)
          create(:ci_build, pipeline: pipeline, status: :failed)
18

19
          visit admin_builds_path
20

21
          expect(page).to have_selector('.nav-links li.active', text: 'All')
22
          expect(page).to have_selector('.row-content-block', text: 'All builds')
23 24 25
          expect(page.all('.build-link').size).to eq(4)
          expect(page).to have_link 'Cancel all'
        end
26
      end
27

28 29 30 31
      context 'when have no builds' do
        it 'shows a message' do
          visit admin_builds_path

32
          expect(page).to have_selector('.nav-links li.active', text: 'All')
33 34 35 36
          expect(page).to have_content 'No builds to show'
          expect(page).not_to have_link 'Cancel all'
        end
      end
37 38
    end

39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
    context 'Pending tab' do
      context 'when have pending builds' do
        it 'shows pending builds' do
          build1 = create(:ci_build, pipeline: pipeline, status: :pending)
          build2 = create(:ci_build, pipeline: pipeline, status: :running)
          build3 = create(:ci_build, pipeline: pipeline, status: :success)
          build4 = create(:ci_build, pipeline: pipeline, status: :failed)

          visit admin_builds_path(scope: :pending)

          expect(page).to have_selector('.nav-links li.active', text: 'Pending')
          expect(page.find('.build-link')).to have_content(build1.id)
          expect(page.find('.build-link')).not_to have_content(build2.id)
          expect(page.find('.build-link')).not_to have_content(build3.id)
          expect(page.find('.build-link')).not_to have_content(build4.id)
          expect(page).to have_link 'Cancel all'
        end
      end

      context 'when have no builds pending' do
        it 'shows a message' do
          create(:ci_build, pipeline: pipeline, status: :success)

          visit admin_builds_path(scope: :pending)

          expect(page).to have_selector('.nav-links li.active', text: 'Pending')
          expect(page).to have_content 'No builds to show'
          expect(page).not_to have_link 'Cancel all'
        end
      end
    end

71 72 73
    context 'Running tab' do
      context 'when have running builds' do
        it 'shows running builds' do
74
          build1 = create(:ci_build, pipeline: pipeline, status: :running)
75 76
          build2 = create(:ci_build, pipeline: pipeline, status: :success)
          build3 = create(:ci_build, pipeline: pipeline, status: :failed)
77
          build4 = create(:ci_build, pipeline: pipeline, status: :pending)
78 79 80

          visit admin_builds_path(scope: :running)

81
          expect(page).to have_selector('.nav-links li.active', text: 'Running')
82 83 84
          expect(page.find('.build-link')).to have_content(build1.id)
          expect(page.find('.build-link')).not_to have_content(build2.id)
          expect(page.find('.build-link')).not_to have_content(build3.id)
85
          expect(page.find('.build-link')).not_to have_content(build4.id)
86 87 88
          expect(page).to have_link 'Cancel all'
        end
      end
89

90 91
      context 'when have no builds running' do
        it 'shows a message' do
92
          create(:ci_build, pipeline: pipeline, status: :success)
93

94
          visit admin_builds_path(scope: :running)
95

96
          expect(page).to have_selector('.nav-links li.active', text: 'Running')
97 98 99 100
          expect(page).to have_content 'No builds to show'
          expect(page).not_to have_link 'Cancel all'
        end
      end
101 102
    end

103 104 105
    context 'Finished tab' do
      context 'when have finished builds' do
        it 'shows finished builds' do
106 107 108
          build1 = create(:ci_build, pipeline: pipeline, status: :pending)
          build2 = create(:ci_build, pipeline: pipeline, status: :running)
          build3 = create(:ci_build, pipeline: pipeline, status: :success)
109 110 111

          visit admin_builds_path(scope: :finished)

112
          expect(page).to have_selector('.nav-links li.active', text: 'Finished')
113 114 115 116 117 118
          expect(page.find('.build-link')).not_to have_content(build1.id)
          expect(page.find('.build-link')).not_to have_content(build2.id)
          expect(page.find('.build-link')).to have_content(build3.id)
          expect(page).to have_link 'Cancel all'
        end
      end
119

120 121
      context 'when have no builds finished' do
        it 'shows a message' do
122
          create(:ci_build, pipeline: pipeline, status: :running)
123

124
          visit admin_builds_path(scope: :finished)
125

126
          expect(page).to have_selector('.nav-links li.active', text: 'Finished')
127 128 129 130
          expect(page).to have_content 'No builds to show'
          expect(page).to have_link 'Cancel all'
        end
      end
131 132 133
    end
  end
end