Commit b3cdd336 authored by Shinya Maeda's avatar Shinya Maeda

Add test. Use readonly everywhere

parent 232b98b5
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
- if @project.feature_available?(:multiple_clusters) - if @project.feature_available?(:multiple_clusters)
= field.text_field :environment_scope, class: 'form-control', placeholder: s_('ClusterIntegration|Environment scope') = field.text_field :environment_scope, class: 'form-control', placeholder: s_('ClusterIntegration|Environment scope')
- else - else
= field.text_field :environment_scope, class: 'form-control', disabled: true, placeholder: s_('ClusterIntegration|Environment scope') = field.text_field :environment_scope, class: 'form-control', readonly: true, placeholder: s_('ClusterIntegration|Environment scope')
= field.fields_for :provider_gcp, @cluster.provider_gcp do |provider_gcp_field| = field.fields_for :provider_gcp, @cluster.provider_gcp do |provider_gcp_field|
.form-group .form-group
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
- if @project.feature_available?(:multiple_clusters) - if @project.feature_available?(:multiple_clusters)
= field.text_field :environment_scope, class: 'form-control js-select-on-focus', placeholder: s_('ClusterIntegration|Environment scope') = field.text_field :environment_scope, class: 'form-control js-select-on-focus', placeholder: s_('ClusterIntegration|Environment scope')
- else - else
= field.text_field :environment_scope, class: 'form-control js-select-on-focus', disabled: true, placeholder: s_('ClusterIntegration|Environment scope') = field.text_field :environment_scope, class: 'form-control js-select-on-focus', readonly: true, placeholder: s_('ClusterIntegration|Environment scope')
= field.fields_for :platform_kubernetes, @cluster.platform_kubernetes do |platform_kubernetes_field| = field.fields_for :platform_kubernetes, @cluster.platform_kubernetes do |platform_kubernetes_field|
.form-group .form-group
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
- if @project.feature_available?(:multiple_clusters) - if @project.feature_available?(:multiple_clusters)
= field.text_field :environment_scope, class: 'form-control', placeholder: s_('ClusterIntegration|Environment scope') = field.text_field :environment_scope, class: 'form-control', placeholder: s_('ClusterIntegration|Environment scope')
- else - else
= field.text_field :environment_scope, class: 'form-control', disabled: true, placeholder: s_('ClusterIntegration|Environment scope') = field.text_field :environment_scope, class: 'form-control', readonly: true, placeholder: s_('ClusterIntegration|Environment scope')
= field.fields_for :platform_kubernetes, @cluster.platform_kubernetes do |platform_kubernetes_field| = field.fields_for :platform_kubernetes, @cluster.platform_kubernetes do |platform_kubernetes_field|
.form-group .form-group
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
- if @project.feature_available?(:multiple_clusters) - if @project.feature_available?(:multiple_clusters)
= field.text_field :environment_scope, class: 'form-control js-select-on-focus', placeholder: s_('ClusterIntegration|Environment scope') = field.text_field :environment_scope, class: 'form-control js-select-on-focus', placeholder: s_('ClusterIntegration|Environment scope')
- else - else
= field.text_field :environment_scope, class: 'form-control js-select-on-focus', disabled: true, placeholder: s_('ClusterIntegration|Environment scope') = field.text_field :environment_scope, class: 'form-control js-select-on-focus', readonly: true, placeholder: s_('ClusterIntegration|Environment scope')
= field.fields_for :platform_kubernetes, @cluster.platform_kubernetes do |platform_kubernetes_field| = field.fields_for :platform_kubernetes, @cluster.platform_kubernetes do |platform_kubernetes_field|
.form-group .form-group
......
...@@ -10,49 +10,129 @@ feature 'EE Clusters' do ...@@ -10,49 +10,129 @@ feature 'EE Clusters' do
end end
context 'when user has a cluster' do context 'when user has a cluster' do
let!(:cluster) { create(:cluster, :provided_by_gcp, projects: [project]) }
context 'when license has multiple clusters feature' do context 'when license has multiple clusters feature' do
before do before do
allow(License).to receive(:feature_available?).and_call_original allow(License).to receive(:feature_available?).and_call_original
allow(License).to receive(:feature_available?).with(:multiple_clusters).and_return(true) allow(License).to receive(:feature_available?).with(:multiple_clusters).and_return(true)
end end
context 'when user visits clusters page' do context 'when user adds an existing cluster' do
before do before do
create(:cluster, :provided_by_user, name: 'default-cluster', environment_scope: '*', projects: [project])
visit project_clusters_path(project) visit project_clusters_path(project)
end end
it 'user sees a add cluster button ' do it 'user sees a add cluster button ' do
expect(page).not_to have_selector('.js-add-cluster.disabled') expect(page).not_to have_selector('.js-add-cluster.readonly')
expect(page).to have_selector('.js-add-cluster') expect(page).to have_selector('.js-add-cluster')
end end
context 'when user tries to create a cluster with a duplicate environment scope' do context 'when user filled form with environment scope' do
before do
click_link 'Add cluster'
click_link 'Add an existing cluster'
fill_in 'cluster_name', with: 'staging-cluster'
fill_in 'cluster_environment_scope', with: 'staging/*'
click_button 'Add 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 before do
allow_any_instance_of(Projects::Clusters::GcpController) click_link 'default-cluster'
.to receive(:token_in_session).and_return('token') fill_in 'cluster_environment_scope', with: 'production/*'
allow_any_instance_of(Projects::Clusters::GcpController) click_button 'Save changes'
.to receive(:expires_at_in_session).and_return(1.hour.since.to_i.to_s) end
allow_any_instance_of(GoogleApi::CloudPlatform::Client)
.to receive(:projects_zones_clusters_create) do it 'user sees a cluster details page' do
OpenStruct.new( expect(page.find_field('cluster[environment_scope]').value).to eq('production/*')
self_link: 'projects/gcp-project-12345/zones/us-central1-a/operations/ope-123', end
status: 'RUNNING' end
)
end
allow(WaitForClusterCreationWorker).to receive(:perform_in).and_return(nil)
context 'when user updates duplicated environment scope' do
before do
click_link 'Add cluster'
click_link 'Add an existing cluster'
fill_in 'cluster_name', with: 'staging-cluster'
fill_in 'cluster_environment_scope', with: '*'
click_button 'Add cluster'
end
it 'users sees an environment scope validation error' do
expect(page).to have_content('cannot add duplicated environment scope')
end
end
end
context 'when user adds an GKE cluster' do
before do
allow_any_instance_of(Projects::Clusters::GcpController)
.to receive(:token_in_session).and_return('token')
allow_any_instance_of(Projects::Clusters::GcpController)
.to receive(:expires_at_in_session).and_return(1.hour.since.to_i.to_s)
allow_any_instance_of(GoogleApi::CloudPlatform::Client)
.to receive(:projects_zones_clusters_create) do
OpenStruct.new(
self_link: 'projects/gcp-project-12345/zones/us-central1-a/operations/ope-123',
status: 'RUNNING'
)
end
allow(WaitForClusterCreationWorker).to receive(:perform_in).and_return(nil)
create(:cluster, :provided_by_gcp, name: 'default-cluster', environment_scope: '*', projects: [project])
visit project_clusters_path(project)
end
it 'user sees a add cluster button ' do
expect(page).not_to have_selector('.js-add-cluster.readonly')
expect(page).to have_selector('.js-add-cluster')
end
context 'when user filled form with environment scope' do
before do
click_link 'Add cluster' click_link 'Add cluster'
click_link 'Create on GKE' click_link 'Create on GKE'
fill_in 'cluster_provider_gcp_attributes_gcp_project_id', with: 'gcp-project-123'
fill_in 'cluster_name', with: 'staging-cluster'
fill_in 'cluster_environment_scope', with: 'staging/*'
click_button 'Create cluster'
end end
it 'users sees an error' do it 'user sees a cluster details page' do
expect(page).to have_content('Enable cluster integration')
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/*'
click_button 'Save changes'
end
it 'user sees a cluster details page' do
expect(page.find_field('cluster[environment_scope]').value).to eq('production/*')
end
end
context 'when user updates duplicated environment scope' do
before do
click_link 'Add cluster'
click_link 'Create on GKE'
fill_in 'cluster_provider_gcp_attributes_gcp_project_id', with: 'gcp-project-123' fill_in 'cluster_provider_gcp_attributes_gcp_project_id', with: 'gcp-project-123'
fill_in 'cluster_name', with: 'dev-cluster' fill_in 'cluster_name', with: 'staging-cluster'
fill_in 'cluster_environment_scope', with: cluster.environment_scope fill_in 'cluster_environment_scope', with: '*'
click_button 'Create cluster' click_button 'Create cluster'
expect(page).to have_css('#error_explanation') end
it 'users sees an environment scope validation error' do
expect(page).to have_content('cannot add duplicated environment scope')
end end
end end
end end
...@@ -62,6 +142,7 @@ feature 'EE Clusters' do ...@@ -62,6 +142,7 @@ feature 'EE Clusters' do
before do before do
allow(License).to receive(:feature_available?).and_call_original allow(License).to receive(:feature_available?).and_call_original
allow(License).to receive(:feature_available?).with(:multiple_clusters).and_return(false) allow(License).to receive(:feature_available?).with(:multiple_clusters).and_return(false)
create(:cluster, :provided_by_user, name: 'default-cluster', environment_scope: '*', projects: [project])
end end
context 'when user visits cluster index page' do context 'when user visits cluster index page' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment