diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-02 00:06:43 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-02 00:06:43 +0300 |
commit | 9c4066878fe309781bbadd20f87c223c12dc60f6 (patch) | |
tree | b5a5adefc861696c4ebb75d937fe70b9241d5bdc | |
parent | 77a73903aa803869d0ab7fe544cc2d8b1a6aa1e0 (diff) |
Add latest changes from gitlab-org/gitlab@master
-rw-r--r-- | app/assets/javascripts/create_cluster/gke_cluster_namespace/index.js (renamed from app/assets/javascripts/projects/gke_cluster_namespace/index.js) | 0 | ||||
-rw-r--r-- | app/assets/javascripts/create_cluster/init_create_cluster.js | 37 | ||||
-rw-r--r-- | app/assets/javascripts/pages/admin/clusters/index.js | 20 | ||||
-rw-r--r-- | app/assets/javascripts/pages/groups/index.js | 20 | ||||
-rw-r--r-- | app/assets/javascripts/pages/projects/clusters/new/index.js | 13 | ||||
-rw-r--r-- | app/assets/javascripts/pages/projects/clusters/show/index.js | 2 | ||||
-rw-r--r-- | app/assets/javascripts/pages/projects/index.js | 19 | ||||
-rw-r--r-- | spec/features/admin/clusters/eks_spec.rb | 29 | ||||
-rw-r--r-- | spec/features/groups/clusters/eks_spec.rb | 35 | ||||
-rw-r--r-- | spec/features/projects/clusters/eks_spec.rb | 2 | ||||
-rw-r--r-- | spec/frontend/create_cluster/gke_cluster_namespace/gke_cluster_namespace_spec.js (renamed from spec/frontend/projects/gke_cluster_namespace/gke_cluster_namespace_spec.js) | 4 | ||||
-rw-r--r-- | spec/frontend/create_cluster/init_create_cluster_spec.js | 73 |
12 files changed, 184 insertions, 70 deletions
diff --git a/app/assets/javascripts/projects/gke_cluster_namespace/index.js b/app/assets/javascripts/create_cluster/gke_cluster_namespace/index.js index 0ec4d8807b0..0ec4d8807b0 100644 --- a/app/assets/javascripts/projects/gke_cluster_namespace/index.js +++ b/app/assets/javascripts/create_cluster/gke_cluster_namespace/index.js diff --git a/app/assets/javascripts/create_cluster/init_create_cluster.js b/app/assets/javascripts/create_cluster/init_create_cluster.js new file mode 100644 index 00000000000..7c984582fd8 --- /dev/null +++ b/app/assets/javascripts/create_cluster/init_create_cluster.js @@ -0,0 +1,37 @@ +import initGkeDropdowns from './gke_cluster'; +import initGkeNamespace from './gke_cluster_namespace'; +import PersistentUserCallout from '~/persistent_user_callout'; + +const newClusterViews = [':clusters:new', ':clusters:create_gcp', ':clusters:create_user']; + +const isProjectLevelCluster = page => page.startsWith('project:clusters'); + +export default (document, gon) => { + const { page } = document.body.dataset; + const isNewClusterView = newClusterViews.some(view => page.endsWith(view)); + + if (!isNewClusterView) { + return; + } + + const callout = document.querySelector('.gcp-signup-offer'); + PersistentUserCallout.factory(callout); + + initGkeDropdowns(); + + if (gon.features.createEksClusters) { + import(/* webpackChunkName: 'eks_cluster' */ '~/create_cluster/eks_cluster') + .then(({ default: initCreateEKSCluster }) => { + const el = document.querySelector('.js-create-eks-cluster-form-container'); + + if (el) { + initCreateEKSCluster(el); + } + }) + .catch(() => {}); + } + + if (isProjectLevelCluster(page)) { + initGkeNamespace(); + } +}; diff --git a/app/assets/javascripts/pages/admin/clusters/index.js b/app/assets/javascripts/pages/admin/clusters/index.js index 43992938d07..4d04c37caa7 100644 --- a/app/assets/javascripts/pages/admin/clusters/index.js +++ b/app/assets/javascripts/pages/admin/clusters/index.js @@ -1,21 +1,5 @@ -import PersistentUserCallout from '~/persistent_user_callout'; -import initGkeDropdowns from '~/create_cluster/gke_cluster'; - -function initGcpSignupCallout() { - const callout = document.querySelector('.gcp-signup-offer'); - PersistentUserCallout.factory(callout); -} +import initCreateCluster from '~/create_cluster/init_create_cluster'; document.addEventListener('DOMContentLoaded', () => { - const { page } = document.body.dataset; - const newClusterViews = [ - 'admin:clusters:new', - 'admin:clusters:create_gcp', - 'admin:clusters:create_user', - ]; - - if (newClusterViews.indexOf(page) > -1) { - initGcpSignupCallout(); - initGkeDropdowns(); - } + initCreateCluster(document, gon); }); diff --git a/app/assets/javascripts/pages/groups/index.js b/app/assets/javascripts/pages/groups/index.js index a33d242908b..4d04c37caa7 100644 --- a/app/assets/javascripts/pages/groups/index.js +++ b/app/assets/javascripts/pages/groups/index.js @@ -1,21 +1,5 @@ -import PersistentUserCallout from '~/persistent_user_callout'; -import initGkeDropdowns from '~/create_cluster/gke_cluster'; - -function initGcpSignupCallout() { - const callout = document.querySelector('.gcp-signup-offer'); - PersistentUserCallout.factory(callout); -} +import initCreateCluster from '~/create_cluster/init_create_cluster'; document.addEventListener('DOMContentLoaded', () => { - const { page } = document.body.dataset; - const newClusterViews = [ - 'groups:clusters:new', - 'groups:clusters:create_gcp', - 'groups:clusters:create_user', - ]; - - if (newClusterViews.indexOf(page) > -1) { - initGcpSignupCallout(); - initGkeDropdowns(); - } + initCreateCluster(document, gon); }); diff --git a/app/assets/javascripts/pages/projects/clusters/new/index.js b/app/assets/javascripts/pages/projects/clusters/new/index.js deleted file mode 100644 index 14d5ab21555..00000000000 --- a/app/assets/javascripts/pages/projects/clusters/new/index.js +++ /dev/null @@ -1,13 +0,0 @@ -document.addEventListener('DOMContentLoaded', () => { - if (gon.features.createEksClusters) { - import(/* webpackChunkName: 'eks_cluster' */ '~/create_cluster/eks_cluster') - .then(({ default: initCreateEKSCluster }) => { - const el = document.querySelector('.js-create-eks-cluster-form-container'); - - if (el) { - initCreateEKSCluster(el); - } - }) - .catch(() => {}); - } -}); diff --git a/app/assets/javascripts/pages/projects/clusters/show/index.js b/app/assets/javascripts/pages/projects/clusters/show/index.js index f091c01fc98..397f9faf6fe 100644 --- a/app/assets/javascripts/pages/projects/clusters/show/index.js +++ b/app/assets/javascripts/pages/projects/clusters/show/index.js @@ -1,5 +1,5 @@ import ClustersBundle from '~/clusters/clusters_bundle'; -import initGkeNamespace from '~/projects/gke_cluster_namespace'; +import initGkeNamespace from '~/create_cluster/gke_cluster_namespace'; document.addEventListener('DOMContentLoaded', () => { new ClustersBundle(); // eslint-disable-line no-new diff --git a/app/assets/javascripts/pages/projects/index.js b/app/assets/javascripts/pages/projects/index.js index 196798a9076..190d0806c28 100644 --- a/app/assets/javascripts/pages/projects/index.js +++ b/app/assets/javascripts/pages/projects/index.js @@ -1,24 +1,9 @@ -import initGkeDropdowns from '~/create_cluster/gke_cluster'; -import initGkeNamespace from '~/projects/gke_cluster_namespace'; -import PersistentUserCallout from '../../persistent_user_callout'; import Project from './project'; import ShortcutsNavigation from '../../behaviors/shortcuts/shortcuts_navigation'; +import initCreateCluster from '~/create_cluster/init_create_cluster'; document.addEventListener('DOMContentLoaded', () => { - const { page } = document.body.dataset; - const newClusterViews = [ - 'projects:clusters:new', - 'projects:clusters:create_gcp', - 'projects:clusters:create_user', - ]; - - if (newClusterViews.indexOf(page) > -1) { - const callout = document.querySelector('.gcp-signup-offer'); - PersistentUserCallout.factory(callout); - - initGkeDropdowns(); - initGkeNamespace(); - } + initCreateCluster(document, gon); new Project(); // eslint-disable-line no-new new ShortcutsNavigation(); // eslint-disable-line no-new diff --git a/spec/features/admin/clusters/eks_spec.rb b/spec/features/admin/clusters/eks_spec.rb new file mode 100644 index 00000000000..b262db1ad7c --- /dev/null +++ b/spec/features/admin/clusters/eks_spec.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'Instance-level AWS EKS Cluster', :js do + let(:user) { create(:admin) } + + before do + sign_in(user) + end + + context 'when user does not have a cluster and visits group clusters page' do + before do + visit admin_clusters_path + + click_link 'Add Kubernetes cluster' + end + + context 'when user creates a cluster on AWS EKS' do + before do + click_link 'Amazon EKS' + end + + it 'user sees a form to create an EKS cluster' do + expect(page).to have_content('Create new Cluster on EKS') + end + end + end +end diff --git a/spec/features/groups/clusters/eks_spec.rb b/spec/features/groups/clusters/eks_spec.rb new file mode 100644 index 00000000000..b6942304c22 --- /dev/null +++ b/spec/features/groups/clusters/eks_spec.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'Group AWS EKS Cluster', :js do + let(:group) { create(:group) } + let(:user) { create(:user) } + + before do + group.add_maintainer(user) + gitlab_sign_in(user) + + allow(Groups::ClustersController).to receive(:STATUS_POLLING_INTERVAL) { 100 } + allow_any_instance_of(Clusters::Kubernetes::CreateOrUpdateNamespaceService).to receive(:execute) + allow_any_instance_of(Clusters::Cluster).to receive(:retrieve_connection_status).and_return(:connected) + end + + context 'when user does not have a cluster and visits group clusters page' do + before do + visit group_clusters_path(group) + + click_link 'Add Kubernetes cluster' + end + + context 'when user creates a cluster on AWS EKS' do + before do + click_link 'Amazon EKS' + end + + it 'user sees a form to create an EKS cluster' do + expect(page).to have_content('Create new Cluster on EKS') + end + end + end +end diff --git a/spec/features/projects/clusters/eks_spec.rb b/spec/features/projects/clusters/eks_spec.rb index 758dccd6e49..9cb989b8004 100644 --- a/spec/features/projects/clusters/eks_spec.rb +++ b/spec/features/projects/clusters/eks_spec.rb @@ -27,7 +27,7 @@ describe 'AWS EKS Cluster', :js do end it 'user sees a form to create an EKS cluster' do - expect(page).to have_selector(:css, '.js-create-eks-cluster') + expect(page).to have_content('Create new Cluster on EKS') end end end diff --git a/spec/frontend/projects/gke_cluster_namespace/gke_cluster_namespace_spec.js b/spec/frontend/create_cluster/gke_cluster_namespace/gke_cluster_namespace_spec.js index 7b8df03d3c3..b1c25d8fff7 100644 --- a/spec/frontend/projects/gke_cluster_namespace/gke_cluster_namespace_spec.js +++ b/spec/frontend/create_cluster/gke_cluster_namespace/gke_cluster_namespace_spec.js @@ -1,4 +1,4 @@ -import initGkeNamespace from '~/projects/gke_cluster_namespace'; +import initGkeNamespace from '~/create_cluster/gke_cluster_namespace'; describe('GKE cluster namespace', () => { const changeEvent = new Event('change'); @@ -14,7 +14,7 @@ describe('GKE cluster namespace', () => { <input class="js-gl-managed" type="checkbox" value="1" checked /> <div class="js-namespace"> <input type="text" /> - </div> + </div> <div class="js-namespace-prefixed"> <input type="text" /> </div> diff --git a/spec/frontend/create_cluster/init_create_cluster_spec.js b/spec/frontend/create_cluster/init_create_cluster_spec.js new file mode 100644 index 00000000000..e7b9a7adde4 --- /dev/null +++ b/spec/frontend/create_cluster/init_create_cluster_spec.js @@ -0,0 +1,73 @@ +import initCreateCluster from '~/create_cluster/init_create_cluster'; +import initGkeDropdowns from '~/create_cluster/gke_cluster'; +import initGkeNamespace from '~/create_cluster/gke_cluster_namespace'; +import PersistentUserCallout from '~/persistent_user_callout'; + +jest.mock('~/create_cluster/gke_cluster', () => jest.fn()); +jest.mock('~/create_cluster/gke_cluster_namespace', () => jest.fn()); +jest.mock('~/persistent_user_callout', () => ({ + factory: jest.fn(), +})); + +describe('initCreateCluster', () => { + let document; + let gon; + + beforeEach(() => { + document = { + body: { dataset: {} }, + querySelector: jest.fn(), + }; + gon = { features: {} }; + }); + afterEach(() => { + initGkeDropdowns.mockReset(); + initGkeNamespace.mockReset(); + PersistentUserCallout.factory.mockReset(); + }); + + describe.each` + pageSuffix | page + ${':clusters:new'} | ${'project:clusters:new'} + ${':clusters:create_gcp'} | ${'groups:clusters:create_gcp'} + ${':clusters:create_user'} | ${'admin:clusters:create_user'} + `('when cluster page ends in $pageSuffix', ({ page }) => { + beforeEach(() => { + document.body.dataset = { page }; + + initCreateCluster(document, gon); + }); + + it('initializes create GKE cluster app', () => { + expect(initGkeDropdowns).toHaveBeenCalled(); + }); + + it('initializes gcp signup offer banner', () => { + expect(PersistentUserCallout.factory).toHaveBeenCalled(); + }); + }); + + describe('when creating a project level cluster', () => { + it('initializes gke namespace app', () => { + document.body.dataset.page = 'project:clusters:new'; + + initCreateCluster(document, gon); + + expect(initGkeNamespace).toHaveBeenCalled(); + }); + }); + + describe.each` + clusterLevel | page + ${'group level'} | ${'groups:clusters:new'} + ${'instance level'} | ${'admin:clusters:create_gcp'} + `('when creating a $clusterLevel cluster', ({ page }) => { + it('does not initialize gke namespace app', () => { + document.body.dataset = { page }; + + initCreateCluster(document, gon); + + expect(initGkeNamespace).not.toHaveBeenCalled(); + }); + }); +}); |