2019-05-23 18:07:59 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-10-05 14:58:05 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-16 18:09:01 +00:00
|
|
|
RSpec.describe 'Clusters', :js do
|
2017-10-31 18:59:40 +00:00
|
|
|
include GoogleApi::CloudPlatformHelpers
|
|
|
|
|
2017-12-03 20:34:00 +00:00
|
|
|
let(:project) { create(:project) }
|
|
|
|
let(:user) { create(:user) }
|
2017-10-05 14:58:05 +00:00
|
|
|
|
|
|
|
before do
|
2018-07-11 14:36:08 +00:00
|
|
|
project.add_maintainer(user)
|
2021-12-02 21:10:16 +00:00
|
|
|
sign_in(user)
|
2020-09-23 15:10:14 +00:00
|
|
|
end
|
|
|
|
|
2017-12-03 20:34:00 +00:00
|
|
|
context 'when user does not have a cluster and visits cluster index page' do
|
2017-10-05 14:58:05 +00:00
|
|
|
before do
|
|
|
|
visit project_clusters_path(project)
|
2021-12-02 21:10:16 +00:00
|
|
|
click_link 'Certificate'
|
2017-10-05 14:58:05 +00:00
|
|
|
end
|
|
|
|
|
2017-12-03 21:55:32 +00:00
|
|
|
it 'sees empty state' do
|
|
|
|
expect(page).to have_selector('.empty-state')
|
2017-10-05 14:58:05 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-08 12:09:33 +00:00
|
|
|
context 'when user has a cluster' do
|
|
|
|
before do
|
|
|
|
allow_any_instance_of(Clusters::Cluster).to receive(:retrieve_connection_status).and_return(:connected)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user adds an existing cluster' do
|
|
|
|
before do
|
|
|
|
create(:cluster, :provided_by_user, name: 'default-cluster', environment_scope: '*', projects: [project])
|
|
|
|
visit project_clusters_path(project)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user filled form with environment scope' do
|
|
|
|
before do
|
2022-03-16 18:08:16 +00:00
|
|
|
visit_connect_cluster_page
|
|
|
|
|
2020-07-08 12:09:33 +00:00
|
|
|
fill_in 'cluster_name', with: 'staging-cluster'
|
|
|
|
fill_in 'cluster_environment_scope', with: 'staging/*'
|
|
|
|
click_button 'Add Kubernetes cluster'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'user sees a cluster details page' do
|
|
|
|
expect(page.find_field('cluster[name]').value).to eq('staging-cluster')
|
|
|
|
expect(page.find_field('cluster[environment_scope]').value).to eq('staging/*')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user updates environment scope' do
|
|
|
|
before do
|
|
|
|
click_link 'default-cluster'
|
|
|
|
fill_in 'cluster_environment_scope', with: 'production/*'
|
2021-03-31 12:08:55 +00:00
|
|
|
within '.js-cluster-details-form' do
|
2020-07-08 12:09:33 +00:00
|
|
|
click_button 'Save changes'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates the environment scope' do
|
|
|
|
expect(page.find_field('cluster[environment_scope]').value).to eq('production/*')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user updates duplicated environment scope' do
|
|
|
|
before do
|
2022-03-16 18:08:16 +00:00
|
|
|
visit_connect_cluster_page
|
|
|
|
|
2020-07-08 12:09:33 +00:00
|
|
|
fill_in 'cluster_name', with: 'staging-cluster'
|
|
|
|
fill_in 'cluster_environment_scope', with: '*'
|
|
|
|
fill_in 'cluster_platform_kubernetes_attributes_api_url', with: 'https://0.0.0.0'
|
|
|
|
fill_in 'cluster_platform_kubernetes_attributes_token', with: 'token'
|
|
|
|
|
|
|
|
click_button 'Add Kubernetes cluster'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'users sees an environment scope validation error' do
|
|
|
|
expect(page).to have_content('cannot add duplicated environment scope')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-12-03 21:55:32 +00:00
|
|
|
context 'when user has a cluster and visits cluster index page' do
|
|
|
|
let!(:cluster) { create(:cluster, :project, :provided_by_gcp) }
|
|
|
|
let(:project) { cluster.project }
|
2017-11-07 16:22:28 +00:00
|
|
|
|
2017-12-03 21:55:32 +00:00
|
|
|
before do
|
|
|
|
visit project_clusters_path(project)
|
2021-12-02 21:10:16 +00:00
|
|
|
click_link 'Certificate'
|
2017-12-03 21:55:32 +00:00
|
|
|
end
|
2017-10-05 14:58:05 +00:00
|
|
|
|
2017-12-03 21:55:32 +00:00
|
|
|
it 'user sees a table with one cluster' do
|
2020-09-23 15:10:14 +00:00
|
|
|
expect(page).to have_selector('[data-testid="cluster_list_table"] tbody tr', count: 1)
|
2017-12-03 21:55:32 +00:00
|
|
|
end
|
2017-11-07 16:22:28 +00:00
|
|
|
|
2017-12-03 21:55:32 +00:00
|
|
|
context 'when user clicks on a cluster' do
|
2017-10-05 14:58:05 +00:00
|
|
|
before do
|
2017-12-03 21:55:32 +00:00
|
|
|
click_link cluster.name
|
2017-10-05 14:58:05 +00:00
|
|
|
end
|
|
|
|
|
2017-12-03 21:55:32 +00:00
|
|
|
it 'user sees a cluster details page' do
|
2017-10-06 14:14:14 +00:00
|
|
|
expect(page).to have_button('Save')
|
2017-10-31 18:59:40 +00:00
|
|
|
expect(page.find(:css, '.cluster-name').value).to eq(cluster.name)
|
2017-10-05 14:58:05 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-11-27 00:06:23 +00:00
|
|
|
context 'user visits create cluster page' do
|
2017-10-05 14:58:05 +00:00
|
|
|
before do
|
2022-03-16 18:08:16 +00:00
|
|
|
visit_create_cluster_page
|
2017-10-05 14:58:05 +00:00
|
|
|
end
|
|
|
|
|
2019-11-27 00:06:23 +00:00
|
|
|
it 'user sees a link to create a GKE cluster' do
|
|
|
|
expect(page).to have_link('Google GKE')
|
2017-10-05 14:58:05 +00:00
|
|
|
end
|
2019-09-09 20:27:51 +00:00
|
|
|
|
2019-11-27 00:06:23 +00:00
|
|
|
it 'user sees a link to create an EKS cluster' do
|
|
|
|
expect(page).to have_link('Amazon EKS')
|
2019-09-09 20:27:51 +00:00
|
|
|
end
|
|
|
|
end
|
2022-03-16 18:08:16 +00:00
|
|
|
|
|
|
|
def visit_create_cluster_page
|
|
|
|
visit project_clusters_path(project)
|
|
|
|
|
|
|
|
click_button(class: 'dropdown-toggle-split')
|
2022-05-05 12:08:03 +00:00
|
|
|
click_link 'Create a cluster'
|
2022-03-16 18:08:16 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def visit_connect_cluster_page
|
|
|
|
click_button(class: 'dropdown-toggle-split')
|
2022-03-28 09:07:06 +00:00
|
|
|
click_link 'Connect a cluster (certificate - deprecated)'
|
2022-03-16 18:08:16 +00:00
|
|
|
end
|
2017-10-05 14:58:05 +00:00
|
|
|
end
|