Fix specs for forms

This commit is contained in:
Kamil Trzcinski 2017-12-03 22:55:32 +01:00
parent 4709e1dc01
commit b1994c366f
4 changed files with 117 additions and 42 deletions

View File

@ -242,7 +242,8 @@ describe Projects::ClustersController do
end end
context 'when format is json' do context 'when format is json' do
context 'when update enabled' do context 'when changing parameters' do
context 'when valid parameters are used' do
let(:params) do let(:params) do
{ {
cluster: { cluster: {
@ -264,9 +265,19 @@ describe Projects::ClustersController do
expect(cluster.name).to eq('my-new-cluster-name') expect(cluster.name).to eq('my-new-cluster-name')
expect(cluster.platform_kubernetes.namespace).to eq('my-namespace') expect(cluster.platform_kubernetes.namespace).to eq('my-namespace')
end end
end
context 'when cluster is being created' do context 'when invalid parameters are used' do
let(:cluster) { create(:cluster, :project, :providing_by_gcp) } let(:params) do
{
cluster: {
enabled: false,
platform_kubernetes_attributes: {
namespace: 'my invalid namespace #@'
}
}
}
end
it "rejects changes" do it "rejects changes" do
go_json go_json
@ -281,7 +292,13 @@ describe Projects::ClustersController do
context 'when update enabled' do context 'when update enabled' do
let(:params) do let(:params) do
{ {
cluster: { enabled: false } cluster: {
enabled: false,
name: 'my-new-cluster-name',
platform_kubernetes_attributes: {
namespace: 'my-namespace'
}
}
} }
end end
@ -295,18 +312,6 @@ describe Projects::ClustersController do
expect(cluster.name).to eq('my-new-cluster-name') expect(cluster.name).to eq('my-new-cluster-name')
expect(cluster.platform_kubernetes.namespace).to eq('my-namespace') expect(cluster.platform_kubernetes.namespace).to eq('my-namespace')
end end
context 'when cluster is being created' do
let(:cluster) { create(:cluster, :project, :providing_by_gcp) }
it "rejects changes" do
go
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template(:show)
expect(cluster.enabled).to be_truthy
end
end
end end
end end
end end

View File

@ -24,6 +24,7 @@ feature 'Gcp Cluster', :js do
before do before do
visit project_clusters_path(project) visit project_clusters_path(project)
click_link 'Add cluster'
click_link 'Create on GKE' click_link 'Create on GKE'
end end
@ -116,7 +117,7 @@ feature 'Gcp Cluster', :js do
it 'user sees creation form with the successful message' do it 'user sees creation form with the successful message' do
expect(page).to have_content('Cluster integration was successfully removed.') expect(page).to have_content('Cluster integration was successfully removed.')
expect(page).to have_link('Create on GKE') expect(page).to have_link('Add cluster')
end end
end end
end end
@ -126,6 +127,7 @@ feature 'Gcp Cluster', :js do
before do before do
visit project_clusters_path(project) visit project_clusters_path(project)
click_link 'Add cluster'
click_link 'Create on GKE' click_link 'Create on GKE'
end end

View File

@ -16,6 +16,7 @@ feature 'User Cluster', :js do
before do before do
visit project_clusters_path(project) visit project_clusters_path(project)
click_link 'Add cluster'
click_link 'Add an existing cluster' click_link 'Add an existing cluster'
end end
@ -89,7 +90,7 @@ feature 'User Cluster', :js do
it 'user sees creation form with the successful message' do it 'user sees creation form with the successful message' do
expect(page).to have_content('Cluster integration was successfully removed.') expect(page).to have_content('Cluster integration was successfully removed.')
expect(page).to have_link('Add an existing cluster') expect(page).to have_link('Add cluster')
end end
end end
end end

View File

@ -14,15 +14,82 @@ feature 'Clusters', :js do
context 'when user does not have a cluster and visits cluster index page' do context 'when user does not have a cluster and visits cluster index page' do
before do before do
visit project_clusters_path(project) visit project_clusters_path(project)
click_link 'Add cluster'
click_link 'Create on GKE'
end end
it 'user sees a new page' do it 'sees empty state' do
expect(page).to have_button('Create cluster') expect(page).to have_link('Add cluster')
expect(page).to have_selector('.empty-state')
end end
end end
context 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
it 'user sees a disabled add cluster button ' do
expect(page).to have_selector('.js-add-cluster.disabled')
end
it 'user sees navigation tabs' do
expect(page.find('.js-active-tab').text).to include('Active')
expect(page.find('.js-active-tab .badge').text).to include('1')
expect(page.find('.js-inactive-tab').text).to include('Inactive')
expect(page.find('.js-inactive-tab .badge').text).to include('0')
expect(page.find('.js-all-tab').text).to include('All')
expect(page.find('.js-all-tab .badge').text).to include('1')
end
context 'inline update of cluster' do
it 'user can update cluster' do
expect(page).to have_selector('.js-toggle-cluster-list')
end
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 }
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-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
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
end end