summaryrefslogtreecommitdiff
path: root/spec/features/projects/clusters/applications_spec.rb
blob: c75259d1b0c9f999609cd520fec244c2f98a875c (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
95
96
97
98
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
require 'spec_helper'

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

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

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

  describe 'Installing applications' do
    before do
      visit project_cluster_path(project, cluster)
    end

    context 'when cluster is being created' do
      let(:cluster) { create(:cluster, :providing_by_gcp, projects: [project]) }

      it 'user is unable to install applications' do
        page.within('.js-cluster-application-row-helm') do
          expect(page).to have_css('.js-cluster-application-install-button[disabled]', exact_text: 'Install')
        end
      end
    end

    context 'when cluster is created' do
      let(:cluster) { create(:cluster, :provided_by_gcp, projects: [project]) }

      it 'user can install applications' do
        wait_for_requests

        page.within('.js-cluster-application-row-helm') do
          expect(page.find(:css, '.js-cluster-application-install-button')['disabled']).to be_nil
          expect(page).to have_css('.js-cluster-application-install-button', exact_text: 'Install')
        end
      end

      context 'when user installs Helm' do
        before do
          allow(ClusterInstallAppWorker).to receive(:perform_async)

          page.within('.js-cluster-application-row-helm') do
            page.find(:css, '.js-cluster-application-install-button').click
          end

          wait_for_requests
        end

        it 'they see status transition' do
          page.within('.js-cluster-application-row-helm') do
            # FE sends request and gets the response, then the buttons is "Installing"
            expect(page).to have_css('.js-cluster-application-install-button[disabled]', exact_text: 'Installing')

            Clusters::Cluster.last.application_helm.make_installing!

            # FE starts polling and update the buttons to "Installing"
            expect(page).to have_css('.js-cluster-application-install-button[disabled]', exact_text: 'Installing')

            Clusters::Cluster.last.application_helm.make_installed!

            expect(page).to have_css('.js-cluster-application-install-button[disabled]', exact_text: 'Installed')
          end

          expect(page).to have_content('Helm Tiller was successfully installed on your Kubernetes cluster')
        end
      end

      context 'when user installs Knative' do
        before do
          create(:clusters_applications_helm, :installed, cluster: cluster)
        end

        context 'on an abac cluster' do
          let(:cluster) { create(:cluster, :provided_by_gcp, :rbac_disabled, projects: [project]) }

          it 'shows info block and not be installable' do
            page.within('.js-cluster-application-row-knative') do
              expect(page).to have_css('.rbac-notice')
              expect(page.find(:css, '.js-cluster-application-install-button')['disabled']).to eq('true')
            end
          end
        end

        context 'on an rbac cluster' do
          let(:cluster) { create(:cluster, :provided_by_gcp, projects: [project]) }

          it 'does not show callout block and be installable' do
            page.within('.js-cluster-application-row-knative') do
              expect(page).not_to have_css('.rbac-notice')
              expect(page).to have_css('.js-cluster-application-install-button:not([disabled])')
            end
          end

          describe 'when user clicks install button' do
            def domainname_form_value
              page.find('.js-knative-domainname').value
            end

            before do
              allow(ClusterInstallAppWorker).to receive(:perform_async)
              allow(ClusterWaitForIngressIpAddressWorker).to receive(:perform_in)
              allow(ClusterWaitForIngressIpAddressWorker).to receive(:perform_async)

              page.within('.js-cluster-application-row-knative') do
                expect(page).to have_css('.js-cluster-application-install-button:not([disabled])')

                page.find('.js-knative-domainname').set("domain.example.org")

                click_button 'Install'

                wait_for_requests

                expect(page).to have_css('.js-cluster-application-install-button', exact_text: 'Installing')

                Clusters::Cluster.last.application_knative.make_installing!
                Clusters::Cluster.last.application_knative.make_installed!
                Clusters::Cluster.last.application_knative.update_attribute(:external_ip, '127.0.0.1')
              end
            end

            it 'shows status transition' do
              page.within('.js-cluster-application-row-knative') do
                expect(domainname_form_value).to eq('domain.example.org')
                expect(page).to have_css('.js-cluster-application-install-button', exact_text: 'Installed')
              end

              expect(page).to have_content('Knative was successfully installed on your Kubernetes cluster')
              expect(page).to have_css('.js-knative-save-domain-button'), exact_text: 'Save changes'
            end

            it 'can then update the domain' do
              page.within('.js-cluster-application-row-knative') do
                expect(ClusterPatchAppWorker).to receive(:perform_async)

                expect(domainname_form_value).to eq('domain.example.org')

                page.find('.js-knative-domainname').set("new.domain.example.org")

                click_button 'Save changes'

                wait_for_requests

                expect(domainname_form_value).to eq('new.domain.example.org')
              end
            end
          end
        end
      end

      context 'when user installs Cert Manager' do
        before do
          allow(ClusterInstallAppWorker).to receive(:perform_async)
          allow(ClusterWaitForIngressIpAddressWorker).to receive(:perform_in)
          allow(ClusterWaitForIngressIpAddressWorker).to receive(:perform_async)

          create(:clusters_applications_helm, :installed, cluster: cluster)

          page.within('.js-cluster-application-row-cert_manager') do
            click_button 'Install'
          end
        end

        it 'shows status transition' do
          def email_form_value
            page.find('.js-email').value
          end

          page.within('.js-cluster-application-row-cert_manager') do
            expect(email_form_value).to eq(cluster.user.email)
            expect(page).to have_css('.js-cluster-application-install-button', exact_text: 'Installing')

            page.find('.js-email').set("new_email@example.org")
            Clusters::Cluster.last.application_cert_manager.make_installing!

            expect(email_form_value).to eq('new_email@example.org')
            expect(page).to have_css('.js-cluster-application-install-button', exact_text: 'Installing')

            Clusters::Cluster.last.application_cert_manager.make_installed!

            expect(email_form_value).to eq('new_email@example.org')
            expect(page).to have_css('.js-cluster-application-install-button', exact_text: 'Installed')
          end

          expect(page).to have_content('Cert-Manager was successfully installed on your Kubernetes cluster')
        end
      end

      context 'when user installs Ingress' do
        context 'when user installs application: Ingress' do
          before do
            allow(ClusterInstallAppWorker).to receive(:perform_async)
            allow(ClusterWaitForIngressIpAddressWorker).to receive(:perform_in)
            allow(ClusterWaitForIngressIpAddressWorker).to receive(:perform_async)

            create(:clusters_applications_helm, :installed, cluster: cluster)

            page.within('.js-cluster-application-row-ingress') do
              expect(page).to have_css('.js-cluster-application-install-button:not([disabled])')
              page.find(:css, '.js-cluster-application-install-button').click

              wait_for_requests
            end
          end

          it 'they see status transition' do
            page.within('.js-cluster-application-row-ingress') do
              # FE sends request and gets the response, then the buttons is "Installing"
              expect(page).to have_css('.js-cluster-application-install-button[disabled]', exact_text: 'Installing')

              Clusters::Cluster.last.application_ingress.make_installing!

              # FE starts polling and update the buttons to "Installing"
              expect(page).to have_css('.js-cluster-application-install-button[disabled]', exact_text: 'Installing')

              # The application becomes installed but we keep waiting for external IP address
              Clusters::Cluster.last.application_ingress.make_installed!

              expect(page).to have_css('.js-cluster-application-install-button[disabled]', exact_text: 'Installed')
              expect(page).to have_selector('.js-no-endpoint-message')
              expect(page).to have_selector('.js-ingress-ip-loading-icon')

              # We receive the external IP address and display
              Clusters::Cluster.last.application_ingress.update!(external_ip: '192.168.1.100')

              expect(page).not_to have_css('.js-cluster-application-install-button')
              expect(page).to have_css('.js-cluster-application-uninstall-button:not([disabled])', exact_text: 'Uninstall')
              expect(page).not_to have_selector('.js-no-endpoint-message')
              expect(page.find('.js-endpoint').value).to eq('192.168.1.100')
            end

            expect(page).to have_content('Ingress was successfully installed on your Kubernetes cluster')
          end
        end
      end
    end
  end
end