summaryrefslogtreecommitdiff
path: root/spec/features/projects/clusters_spec.rb
blob: f13c35c00d3e8e4d5f06f52b0847a5ecc9973faf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
require 'spec_helper'

describe 'Clusters', :js do
  include GoogleApi::CloudPlatformHelpers

  let(:project) { create(:project) }
  let(:user) { create(:user) }

  before do
    project.add_maintainer(user)
    gitlab_sign_in(user)
  end

  context 'when user does not have a cluster and visits cluster index page' do
    before do
      visit project_clusters_path(project)
    end

    it 'sees empty state' do
      expect(page).to have_link('Add Kubernetes cluster')
      expect(page).to have_selector('.empty-state')
    end
  end

  context 'when user has a cluster and visits cluster index page' do
    let!(:cluster) { create(:cluster, :project, :provided_by_gcp) }
    let(:project) { cluster.project }

    before do
      visit project_clusters_path(project)
    end

    it 'user sees a table with one cluster' do
      # One is the header row, the other the cluster row
      expect(page).to have_selector('.gl-responsive-table-row', count: 2)
    end

    context 'inline update of cluster' do
      it 'user can update cluster' do
        expect(page).to have_selector('.js-project-feature-toggle')
      end

      context 'with successful request' do
        it 'user sees updated cluster' do
          expect do
            page.find('.js-project-feature-toggle').click
            wait_for_requests
          end.to change { cluster.reload.enabled }

          expect(page).not_to have_selector('.is-checked')
          expect(cluster.reload).not_to be_enabled
        end
      end

      context 'with failed request' do
        it 'user sees not update cluster and error message' do
          expect_any_instance_of(Clusters::UpdateService).to receive(:execute).and_call_original
          allow_any_instance_of(Clusters::Cluster).to receive(:valid?) { false }

          page.find('.js-project-feature-toggle').click

          expect(page).to have_content('Something went wrong on our end.')
          expect(page).to have_selector('.is-checked')
          expect(cluster.reload).to be_enabled
        end
      end
    end

    context 'when user clicks on a cluster' do
      before do
        click_link cluster.name
      end

      it 'user sees a cluster details page' do
        expect(page).to have_button('Save')
        expect(page.find(:css, '.cluster-name').value).to eq(cluster.name)
      end
    end
  end

  context 'when user has not signed in Google' do
    before do
      visit project_clusters_path(project)

      click_link 'Add Kubernetes cluster'
      click_link 'Create new Cluster on GKE'
    end

    it 'user sees a login page' do
      expect(page).to have_css('.signin-with-google')
      expect(page).to have_link('Google account')
    end
  end
end