diff options
Diffstat (limited to 'spec/javascripts/clusters')
-rw-r--r-- | spec/javascripts/clusters/clusters_bundle_spec.js | 191 | ||||
-rw-r--r-- | spec/javascripts/clusters/components/application_row_spec.js | 41 | ||||
-rw-r--r-- | spec/javascripts/clusters/services/mock_data.js | 117 | ||||
-rw-r--r-- | spec/javascripts/clusters/stores/clusters_store_spec.js | 12 |
4 files changed, 184 insertions, 177 deletions
diff --git a/spec/javascripts/clusters/clusters_bundle_spec.js b/spec/javascripts/clusters/clusters_bundle_spec.js index 337afc08a21..880b469284b 100644 --- a/spec/javascripts/clusters/clusters_bundle_spec.js +++ b/spec/javascripts/clusters/clusters_bundle_spec.js @@ -21,21 +21,21 @@ describe('Clusters', () => { }); describe('toggle', () => { - it('should update the button and the input field on click', (done) => { - const toggleButton = document.querySelector('.js-cluster-enable-toggle-area .js-project-feature-toggle'); - const toggleInput = document.querySelector('.js-cluster-enable-toggle-area .js-project-feature-toggle-input'); + it('should update the button and the input field on click', done => { + const toggleButton = document.querySelector( + '.js-cluster-enable-toggle-area .js-project-feature-toggle', + ); + const toggleInput = document.querySelector( + '.js-cluster-enable-toggle-area .js-project-feature-toggle-input', + ); toggleButton.click(); getSetTimeoutPromise() .then(() => { - expect( - toggleButton.classList, - ).not.toContain('is-checked'); + expect(toggleButton.classList).not.toContain('is-checked'); - expect( - toggleInput.getAttribute('value'), - ).toEqual('false'); + expect(toggleInput.getAttribute('value')).toEqual('false'); }) .then(done) .catch(done.fail); @@ -46,29 +46,21 @@ describe('Clusters', () => { it('should update token field type', () => { cluster.showTokenButton.click(); - expect( - cluster.tokenField.getAttribute('type'), - ).toEqual('text'); + expect(cluster.tokenField.getAttribute('type')).toEqual('text'); cluster.showTokenButton.click(); - expect( - cluster.tokenField.getAttribute('type'), - ).toEqual('password'); + expect(cluster.tokenField.getAttribute('type')).toEqual('password'); }); it('should update show token button text', () => { cluster.showTokenButton.click(); - expect( - cluster.showTokenButton.textContent, - ).toEqual('Hide'); + expect(cluster.showTokenButton.textContent).toEqual('Hide'); cluster.showTokenButton.click(); - expect( - cluster.showTokenButton.textContent, - ).toEqual('Show'); + expect(cluster.showTokenButton.textContent).toEqual('Show'); }); }); @@ -91,35 +83,45 @@ describe('Clusters', () => { }); it('shows an alert when something gets newly installed', () => { - cluster.checkForNewInstalls({ - ...INITIAL_APP_MAP, - helm: { status: APPLICATION_STATUS.INSTALLING, title: 'Helm Tiller' }, - }, { - ...INITIAL_APP_MAP, - helm: { status: APPLICATION_STATUS.INSTALLED, title: 'Helm Tiller' }, - }); + cluster.checkForNewInstalls( + { + ...INITIAL_APP_MAP, + helm: { status: APPLICATION_STATUS.INSTALLING, title: 'Helm Tiller' }, + }, + { + ...INITIAL_APP_MAP, + helm: { status: APPLICATION_STATUS.INSTALLED, title: 'Helm Tiller' }, + }, + ); const flashMessage = document.querySelector('.js-cluster-application-notice .flash-text'); expect(flashMessage).not.toBeNull(); - expect(flashMessage.textContent.trim()).toEqual('Helm Tiller was successfully installed on your Kubernetes cluster'); + expect(flashMessage.textContent.trim()).toEqual( + 'Helm Tiller was successfully installed on your Kubernetes cluster', + ); }); it('shows an alert when multiple things gets newly installed', () => { - cluster.checkForNewInstalls({ - ...INITIAL_APP_MAP, - helm: { status: APPLICATION_STATUS.INSTALLING, title: 'Helm Tiller' }, - ingress: { status: APPLICATION_STATUS.INSTALLABLE, title: 'Ingress' }, - }, { - ...INITIAL_APP_MAP, - helm: { status: APPLICATION_STATUS.INSTALLED, title: 'Helm Tiller' }, - ingress: { status: APPLICATION_STATUS.INSTALLED, title: 'Ingress' }, - }); + cluster.checkForNewInstalls( + { + ...INITIAL_APP_MAP, + helm: { status: APPLICATION_STATUS.INSTALLING, title: 'Helm Tiller' }, + ingress: { status: APPLICATION_STATUS.INSTALLABLE, title: 'Ingress' }, + }, + { + ...INITIAL_APP_MAP, + helm: { status: APPLICATION_STATUS.INSTALLED, title: 'Helm Tiller' }, + ingress: { status: APPLICATION_STATUS.INSTALLED, title: 'Ingress' }, + }, + ); const flashMessage = document.querySelector('.js-cluster-application-notice .flash-text'); expect(flashMessage).not.toBeNull(); - expect(flashMessage.textContent.trim()).toEqual('Helm Tiller, Ingress was successfully installed on your Kubernetes cluster'); + expect(flashMessage.textContent.trim()).toEqual( + 'Helm Tiller, Ingress was successfully installed on your Kubernetes cluster', + ); }); }); @@ -128,33 +130,21 @@ describe('Clusters', () => { it('should show the creating container', () => { cluster.updateContainer(null, 'creating'); - expect( - cluster.creatingContainer.classList.contains('hidden'), - ).toBeFalsy(); + expect(cluster.creatingContainer.classList.contains('hidden')).toBeFalsy(); - expect( - cluster.successContainer.classList.contains('hidden'), - ).toBeTruthy(); + expect(cluster.successContainer.classList.contains('hidden')).toBeTruthy(); - expect( - cluster.errorContainer.classList.contains('hidden'), - ).toBeTruthy(); + expect(cluster.errorContainer.classList.contains('hidden')).toBeTruthy(); }); it('should continue to show `creating` banner with subsequent updates of the same status', () => { cluster.updateContainer('creating', 'creating'); - expect( - cluster.creatingContainer.classList.contains('hidden'), - ).toBeFalsy(); + expect(cluster.creatingContainer.classList.contains('hidden')).toBeFalsy(); - expect( - cluster.successContainer.classList.contains('hidden'), - ).toBeTruthy(); + expect(cluster.successContainer.classList.contains('hidden')).toBeTruthy(); - expect( - cluster.errorContainer.classList.contains('hidden'), - ).toBeTruthy(); + expect(cluster.errorContainer.classList.contains('hidden')).toBeTruthy(); }); }); @@ -162,33 +152,21 @@ describe('Clusters', () => { it('should show the success container and fresh the page', () => { cluster.updateContainer(null, 'created'); - expect( - cluster.creatingContainer.classList.contains('hidden'), - ).toBeTruthy(); + expect(cluster.creatingContainer.classList.contains('hidden')).toBeTruthy(); - expect( - cluster.successContainer.classList.contains('hidden'), - ).toBeFalsy(); + expect(cluster.successContainer.classList.contains('hidden')).toBeFalsy(); - expect( - cluster.errorContainer.classList.contains('hidden'), - ).toBeTruthy(); + expect(cluster.errorContainer.classList.contains('hidden')).toBeTruthy(); }); it('should not show a banner when status is already `created`', () => { cluster.updateContainer('created', 'created'); - expect( - cluster.creatingContainer.classList.contains('hidden'), - ).toBeTruthy(); + expect(cluster.creatingContainer.classList.contains('hidden')).toBeTruthy(); - expect( - cluster.successContainer.classList.contains('hidden'), - ).toBeTruthy(); + expect(cluster.successContainer.classList.contains('hidden')).toBeTruthy(); - expect( - cluster.errorContainer.classList.contains('hidden'), - ).toBeTruthy(); + expect(cluster.errorContainer.classList.contains('hidden')).toBeTruthy(); }); }); @@ -196,43 +174,29 @@ describe('Clusters', () => { it('should show the error container', () => { cluster.updateContainer(null, 'errored', 'this is an error'); - expect( - cluster.creatingContainer.classList.contains('hidden'), - ).toBeTruthy(); + expect(cluster.creatingContainer.classList.contains('hidden')).toBeTruthy(); - expect( - cluster.successContainer.classList.contains('hidden'), - ).toBeTruthy(); + expect(cluster.successContainer.classList.contains('hidden')).toBeTruthy(); - expect( - cluster.errorContainer.classList.contains('hidden'), - ).toBeFalsy(); + expect(cluster.errorContainer.classList.contains('hidden')).toBeFalsy(); - expect( - cluster.errorReasonContainer.textContent, - ).toContain('this is an error'); + expect(cluster.errorReasonContainer.textContent).toContain('this is an error'); }); it('should show `error` banner when previously `creating`', () => { cluster.updateContainer('creating', 'errored'); - expect( - cluster.creatingContainer.classList.contains('hidden'), - ).toBeTruthy(); + expect(cluster.creatingContainer.classList.contains('hidden')).toBeTruthy(); - expect( - cluster.successContainer.classList.contains('hidden'), - ).toBeTruthy(); + expect(cluster.successContainer.classList.contains('hidden')).toBeTruthy(); - expect( - cluster.errorContainer.classList.contains('hidden'), - ).toBeFalsy(); + expect(cluster.errorContainer.classList.contains('hidden')).toBeFalsy(); }); }); }); describe('installApplication', () => { - it('tries to install helm', (done) => { + it('tries to install helm', done => { spyOn(cluster.service, 'installApplication').and.returnValue(Promise.resolve()); expect(cluster.store.state.applications.helm.requestStatus).toEqual(null); @@ -252,7 +216,7 @@ describe('Clusters', () => { .catch(done.fail); }); - it('tries to install ingress', (done) => { + it('tries to install ingress', done => { spyOn(cluster.service, 'installApplication').and.returnValue(Promise.resolve()); expect(cluster.store.state.applications.ingress.requestStatus).toEqual(null); @@ -272,7 +236,7 @@ describe('Clusters', () => { .catch(done.fail); }); - it('tries to install runner', (done) => { + it('tries to install runner', done => { spyOn(cluster.service, 'installApplication').and.returnValue(Promise.resolve()); expect(cluster.store.state.applications.runner.requestStatus).toEqual(null); @@ -292,27 +256,34 @@ describe('Clusters', () => { .catch(done.fail); }); - it('tries to install jupyter', (done) => { + it('tries to install jupyter', done => { spyOn(cluster.service, 'installApplication').and.returnValue(Promise.resolve()); expect(cluster.store.state.applications.jupyter.requestStatus).toEqual(null); - cluster.installApplication({ id: 'jupyter', params: { hostname: cluster.store.state.applications.jupyter.hostname } }); + cluster.installApplication({ + id: 'jupyter', + params: { hostname: cluster.store.state.applications.jupyter.hostname }, + }); expect(cluster.store.state.applications.jupyter.requestStatus).toEqual(REQUEST_LOADING); expect(cluster.store.state.applications.jupyter.requestReason).toEqual(null); - expect(cluster.service.installApplication).toHaveBeenCalledWith('jupyter', { hostname: cluster.store.state.applications.jupyter.hostname }); + expect(cluster.service.installApplication).toHaveBeenCalledWith('jupyter', { + hostname: cluster.store.state.applications.jupyter.hostname, + }); getSetTimeoutPromise() - .then(() => { - expect(cluster.store.state.applications.jupyter.requestStatus).toEqual(REQUEST_SUCCESS); - expect(cluster.store.state.applications.jupyter.requestReason).toEqual(null); - }) - .then(done) - .catch(done.fail); + .then(() => { + expect(cluster.store.state.applications.jupyter.requestStatus).toEqual(REQUEST_SUCCESS); + expect(cluster.store.state.applications.jupyter.requestReason).toEqual(null); + }) + .then(done) + .catch(done.fail); }); - it('sets error request status when the request fails', (done) => { - spyOn(cluster.service, 'installApplication').and.returnValue(Promise.reject(new Error('STUBBED ERROR'))); + it('sets error request status when the request fails', done => { + spyOn(cluster.service, 'installApplication').and.returnValue( + Promise.reject(new Error('STUBBED ERROR')), + ); expect(cluster.store.state.applications.helm.requestStatus).toEqual(null); diff --git a/spec/javascripts/clusters/components/application_row_spec.js b/spec/javascripts/clusters/components/application_row_spec.js index 9da5c248371..45d56514930 100644 --- a/spec/javascripts/clusters/components/application_row_spec.js +++ b/spec/javascripts/clusters/components/application_row_spec.js @@ -112,6 +112,17 @@ describe('Application Row', () => { expect(vm.installButtonDisabled).toEqual(true); }); + it('has disabled "Installed" when APPLICATION_STATUS.UPDATING', () => { + vm = mountComponent(ApplicationRow, { + ...DEFAULT_APPLICATION_STATE, + status: APPLICATION_STATUS.UPDATING, + }); + + expect(vm.installButtonLabel).toEqual('Installed'); + expect(vm.installButtonLoading).toEqual(false); + expect(vm.installButtonDisabled).toEqual(true); + }); + it('has enabled "Install" when APPLICATION_STATUS.ERROR', () => { vm = mountComponent(ApplicationRow, { ...DEFAULT_APPLICATION_STATE, @@ -215,7 +226,9 @@ describe('Application Row', () => { status: null, requestStatus: null, }); - const generalErrorMessage = vm.$el.querySelector('.js-cluster-application-general-error-message'); + const generalErrorMessage = vm.$el.querySelector( + '.js-cluster-application-general-error-message', + ); expect(generalErrorMessage).toBeNull(); }); @@ -227,10 +240,17 @@ describe('Application Row', () => { status: APPLICATION_STATUS.ERROR, statusReason, }); - const generalErrorMessage = vm.$el.querySelector('.js-cluster-application-general-error-message'); - const statusErrorMessage = vm.$el.querySelector('.js-cluster-application-status-error-message'); + const generalErrorMessage = vm.$el.querySelector( + '.js-cluster-application-general-error-message', + ); + const statusErrorMessage = vm.$el.querySelector( + '.js-cluster-application-status-error-message', + ); + + expect(generalErrorMessage.textContent.trim()).toEqual( + `Something went wrong while installing ${DEFAULT_APPLICATION_STATE.title}`, + ); - expect(generalErrorMessage.textContent.trim()).toEqual(`Something went wrong while installing ${DEFAULT_APPLICATION_STATE.title}`); expect(statusErrorMessage.textContent.trim()).toEqual(statusReason); }); @@ -242,10 +262,17 @@ describe('Application Row', () => { requestStatus: REQUEST_FAILURE, requestReason, }); - const generalErrorMessage = vm.$el.querySelector('.js-cluster-application-general-error-message'); - const requestErrorMessage = vm.$el.querySelector('.js-cluster-application-request-error-message'); + const generalErrorMessage = vm.$el.querySelector( + '.js-cluster-application-general-error-message', + ); + const requestErrorMessage = vm.$el.querySelector( + '.js-cluster-application-request-error-message', + ); + + expect(generalErrorMessage.textContent.trim()).toEqual( + `Something went wrong while installing ${DEFAULT_APPLICATION_STATE.title}`, + ); - expect(generalErrorMessage.textContent.trim()).toEqual(`Something went wrong while installing ${DEFAULT_APPLICATION_STATE.title}`); expect(requestErrorMessage.textContent.trim()).toEqual(requestReason); }); }); diff --git a/spec/javascripts/clusters/services/mock_data.js b/spec/javascripts/clusters/services/mock_data.js index c7c1412e1c6..4e6ad11cd92 100644 --- a/spec/javascripts/clusters/services/mock_data.js +++ b/spec/javascripts/clusters/services/mock_data.js @@ -6,67 +6,77 @@ const CLUSTERS_MOCK_DATA = { data: { status: 'errored', status_reason: 'Failed to request to CloudPlatform.', - applications: [{ - name: 'helm', - status: APPLICATION_STATUS.INSTALLABLE, - status_reason: null, - }, { - name: 'ingress', - status: APPLICATION_STATUS.ERROR, - status_reason: 'Cannot connect', - external_ip: null, - }, { - name: 'runner', - status: APPLICATION_STATUS.INSTALLING, - status_reason: null, - }, - { - name: 'prometheus', - status: APPLICATION_STATUS.ERROR, - status_reason: 'Cannot connect', - }, { - name: 'jupyter', - status: APPLICATION_STATUS.INSTALLING, - status_reason: 'Cannot connect', - }], + applications: [ + { + name: 'helm', + status: APPLICATION_STATUS.INSTALLABLE, + status_reason: null, + }, + { + name: 'ingress', + status: APPLICATION_STATUS.ERROR, + status_reason: 'Cannot connect', + external_ip: null, + }, + { + name: 'runner', + status: APPLICATION_STATUS.INSTALLING, + status_reason: null, + }, + { + name: 'prometheus', + status: APPLICATION_STATUS.ERROR, + status_reason: 'Cannot connect', + }, + { + name: 'jupyter', + status: APPLICATION_STATUS.INSTALLING, + status_reason: 'Cannot connect', + }, + ], }, }, '/gitlab-org/gitlab-shell/clusters/2/status.json': { data: { status: 'errored', status_reason: 'Failed to request to CloudPlatform.', - applications: [{ - name: 'helm', - status: APPLICATION_STATUS.INSTALLED, - status_reason: null, - }, { - name: 'ingress', - status: APPLICATION_STATUS.INSTALLED, - status_reason: 'Cannot connect', - external_ip: '1.1.1.1', - }, { - name: 'runner', - status: APPLICATION_STATUS.INSTALLING, - status_reason: null, - }, - { - name: 'prometheus', - status: APPLICATION_STATUS.ERROR, - status_reason: 'Cannot connect', - }, { - name: 'jupyter', - status: APPLICATION_STATUS.INSTALLABLE, - status_reason: 'Cannot connect', - }], + applications: [ + { + name: 'helm', + status: APPLICATION_STATUS.INSTALLED, + status_reason: null, + }, + { + name: 'ingress', + status: APPLICATION_STATUS.INSTALLED, + status_reason: 'Cannot connect', + external_ip: '1.1.1.1', + }, + { + name: 'runner', + status: APPLICATION_STATUS.INSTALLING, + status_reason: null, + }, + { + name: 'prometheus', + status: APPLICATION_STATUS.ERROR, + status_reason: 'Cannot connect', + }, + { + name: 'jupyter', + status: APPLICATION_STATUS.INSTALLABLE, + status_reason: 'Cannot connect', + }, + ], }, }, }, POST: { - '/gitlab-org/gitlab-shell/clusters/1/applications/helm': { }, - '/gitlab-org/gitlab-shell/clusters/1/applications/ingress': { }, - '/gitlab-org/gitlab-shell/clusters/1/applications/runner': { }, - '/gitlab-org/gitlab-shell/clusters/1/applications/prometheus': { }, - '/gitlab-org/gitlab-shell/clusters/1/applications/jupyter': { }, + '/gitlab-org/gitlab-shell/clusters/1/applications/helm': {}, + '/gitlab-org/gitlab-shell/clusters/1/applications/ingress': {}, + '/gitlab-org/gitlab-shell/clusters/1/applications/runner': {}, + '/gitlab-org/gitlab-shell/clusters/1/applications/prometheus': {}, + '/gitlab-org/gitlab-shell/clusters/1/applications/jupyter': {}, }, }; @@ -81,7 +91,4 @@ const DEFAULT_APPLICATION_STATE = { requestReason: null, }; -export { - CLUSTERS_MOCK_DATA, - DEFAULT_APPLICATION_STATE, -}; +export { CLUSTERS_MOCK_DATA, DEFAULT_APPLICATION_STATE }; diff --git a/spec/javascripts/clusters/stores/clusters_store_spec.js b/spec/javascripts/clusters/stores/clusters_store_spec.js index 104a064bdd3..e0f55a12fca 100644 --- a/spec/javascripts/clusters/stores/clusters_store_spec.js +++ b/spec/javascripts/clusters/stores/clusters_store_spec.js @@ -53,7 +53,8 @@ describe('Clusters Store', () => { describe('updateStateFromServer', () => { it('should store new polling data from server', () => { - const mockResponseData = CLUSTERS_MOCK_DATA.GET['/gitlab-org/gitlab-shell/clusters/1/status.json'].data; + const mockResponseData = + CLUSTERS_MOCK_DATA.GET['/gitlab-org/gitlab-shell/clusters/1/status.json'].data; store.updateStateFromServer(mockResponseData); expect(store.state).toEqual({ @@ -104,13 +105,14 @@ describe('Clusters Store', () => { }); it('sets default hostname for jupyter when ingress has a ip address', () => { - const mockResponseData = CLUSTERS_MOCK_DATA.GET['/gitlab-org/gitlab-shell/clusters/2/status.json'].data; + const mockResponseData = + CLUSTERS_MOCK_DATA.GET['/gitlab-org/gitlab-shell/clusters/2/status.json'].data; store.updateStateFromServer(mockResponseData); - expect( - store.state.applications.jupyter.hostname, - ).toEqual(`jupyter.${store.state.applications.ingress.externalIp}.nip.io`); + expect(store.state.applications.jupyter.hostname).toEqual( + `jupyter.${store.state.applications.ingress.externalIp}.nip.io`, + ); }); }); }); |