clusters_spec.rb 2.27 KB
Newer Older
1 2 3
require 'spec_helper'

feature 'Clusters', :js do
Shinya Maeda's avatar
Shinya Maeda committed
4 5
  include GoogleApi::CloudPlatformHelpers

Kamil Trzcinski's avatar
Kamil Trzcinski committed
6 7
  let(:project) { create(:project) }
  let(:user) { create(:user) }
8 9 10 11 12 13

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

Kamil Trzcinski's avatar
Kamil Trzcinski committed
14
  context 'when user does not have a cluster and visits cluster index page' do
15 16 17 18
    before do
      visit project_clusters_path(project)
    end

Kamil Trzcinski's avatar
Kamil Trzcinski committed
19 20 21
    it 'sees empty state' do
      expect(page).to have_link('Add cluster')
      expect(page).to have_selector('.empty-state')
22 23
    end
  end
24

Kamil Trzcinski's avatar
Kamil Trzcinski committed
25 26 27
  context 'when user has a cluster and visits cluster index page' do
    let!(:cluster) { create(:cluster, :project, :provided_by_gcp) }
    let(:project) { cluster.project }
28

Kamil Trzcinski's avatar
Kamil Trzcinski committed
29 30 31
    before do
      visit project_clusters_path(project)
    end
32

Kamil Trzcinski's avatar
Kamil Trzcinski committed
33 34 35 36
    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
37

Kamil Trzcinski's avatar
Kamil Trzcinski committed
38 39 40 41
    context 'inline update of cluster' do
      it 'user can update cluster' do
        expect(page).to have_selector('.js-toggle-cluster-list')
      end
42

Kamil Trzcinski's avatar
Kamil Trzcinski committed
43 44 45 46 47 48
      context 'with sucessfull request' do
        it 'user sees updated cluster' do
          expect do
            page.find('.js-toggle-cluster-list').click
            wait_for_requests
          end.to change { cluster.reload.enabled }
49

Kamil Trzcinski's avatar
Kamil Trzcinski committed
50 51 52 53
          expect(page).not_to have_selector('.is-checked')
          expect(cluster.reload).not_to be_enabled
        end
      end
54

Kamil Trzcinski's avatar
Kamil Trzcinski committed
55 56 57 58 59 60 61 62 63 64 65 66 67
      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-toggle-cluster-list').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
68

Kamil Trzcinski's avatar
Kamil Trzcinski committed
69 70 71 72
    context 'when user clicks on a cluster' do
      before do
        click_link cluster.name
      end
73

Kamil Trzcinski's avatar
Kamil Trzcinski committed
74 75 76 77 78
      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
79
  end
80
end