gitlab-org--gitlab-foss/spec/javascripts/clusters/clusters_bundle_spec.js

269 lines
9.6 KiB
JavaScript
Raw Normal View History

import Clusters from '~/clusters/clusters_bundle';
import { REQUEST_SUBMITTED, REQUEST_FAILURE, APPLICATION_STATUS } from '~/clusters/constants';
import getSetTimeoutPromise from 'spec/helpers/set_timeout_promise_helper';
describe('Clusters', () => {
let cluster;
preloadFixtures('clusters/show_cluster.html.raw');
beforeEach(() => {
loadFixtures('clusters/show_cluster.html.raw');
cluster = new Clusters();
});
afterEach(() => {
cluster.destroy();
});
describe('toggle', () => {
2018-10-17 03:13:26 -04:00
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(() => {
2018-10-17 03:13:26 -04:00
expect(toggleButton.classList).not.toContain('is-checked');
2018-10-17 03:13:26 -04:00
expect(toggleInput.getAttribute('value')).toEqual('false');
})
.then(done)
.catch(done.fail);
});
});
2017-11-09 08:59:40 -05:00
describe('showToken', () => {
it('should update token field type', () => {
2017-11-09 08:59:40 -05:00
cluster.showTokenButton.click();
2018-10-17 03:13:26 -04:00
expect(cluster.tokenField.getAttribute('type')).toEqual('text');
2017-11-09 08:59:40 -05:00
cluster.showTokenButton.click();
2018-10-17 03:13:26 -04:00
expect(cluster.tokenField.getAttribute('type')).toEqual('password');
2017-11-09 08:59:40 -05:00
});
it('should update show token button text', () => {
cluster.showTokenButton.click();
2018-10-17 03:13:26 -04:00
expect(cluster.showTokenButton.textContent).toEqual('Hide');
cluster.showTokenButton.click();
2018-10-17 03:13:26 -04:00
expect(cluster.showTokenButton.textContent).toEqual('Show');
});
2017-11-09 08:59:40 -05:00
});
describe('checkForNewInstalls', () => {
const INITIAL_APP_MAP = {
helm: { status: null, title: 'Helm Tiller' },
ingress: { status: null, title: 'Ingress' },
runner: { status: null, title: 'GitLab Runner' },
};
it('does not show alert when things transition from initial null state to something', () => {
cluster.checkForNewInstalls(INITIAL_APP_MAP, {
...INITIAL_APP_MAP,
helm: { status: APPLICATION_STATUS.INSTALLABLE, title: 'Helm Tiller' },
});
const flashMessage = document.querySelector('.js-cluster-application-notice .flash-text');
2018-10-09 14:03:09 -04:00
expect(flashMessage).toBeNull();
});
it('shows an alert when something gets newly installed', () => {
2018-10-17 03:13:26 -04:00
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');
2018-10-09 14:03:09 -04:00
expect(flashMessage).not.toBeNull();
2018-10-17 03:13:26 -04:00
expect(flashMessage.textContent.trim()).toEqual(
'Helm Tiller was successfully installed on your Kubernetes cluster',
);
});
it('shows an alert when multiple things gets newly installed', () => {
2018-10-17 03:13:26 -04:00
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');
2018-10-09 14:03:09 -04:00
expect(flashMessage).not.toBeNull();
2018-10-17 03:13:26 -04:00
expect(flashMessage.textContent.trim()).toEqual(
'Helm Tiller, Ingress was successfully installed on your Kubernetes cluster',
);
});
});
describe('updateContainer', () => {
describe('when creating cluster', () => {
it('should show the creating container', () => {
cluster.updateContainer(null, 'creating');
2018-10-17 03:13:26 -04:00
expect(cluster.creatingContainer.classList.contains('hidden')).toBeFalsy();
2018-10-09 14:03:09 -04:00
2018-10-17 03:13:26 -04:00
expect(cluster.successContainer.classList.contains('hidden')).toBeTruthy();
2018-10-09 14:03:09 -04:00
2018-10-17 03:13:26 -04:00
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');
2018-10-17 03:13:26 -04:00
expect(cluster.creatingContainer.classList.contains('hidden')).toBeFalsy();
2018-10-09 14:03:09 -04:00
2018-10-17 03:13:26 -04:00
expect(cluster.successContainer.classList.contains('hidden')).toBeTruthy();
2018-10-09 14:03:09 -04:00
2018-10-17 03:13:26 -04:00
expect(cluster.errorContainer.classList.contains('hidden')).toBeTruthy();
});
});
describe('when cluster is created', () => {
2017-11-16 07:22:19 -05:00
it('should show the success container and fresh the page', () => {
cluster.updateContainer(null, 'created');
2018-10-17 03:13:26 -04:00
expect(cluster.creatingContainer.classList.contains('hidden')).toBeTruthy();
2018-10-09 14:03:09 -04:00
2018-10-17 03:13:26 -04:00
expect(cluster.successContainer.classList.contains('hidden')).toBeFalsy();
2018-10-09 14:03:09 -04:00
2018-10-17 03:13:26 -04:00
expect(cluster.errorContainer.classList.contains('hidden')).toBeTruthy();
});
it('should not show a banner when status is already `created`', () => {
cluster.updateContainer('created', 'created');
2018-10-17 03:13:26 -04:00
expect(cluster.creatingContainer.classList.contains('hidden')).toBeTruthy();
2018-10-09 14:03:09 -04:00
2018-10-17 03:13:26 -04:00
expect(cluster.successContainer.classList.contains('hidden')).toBeTruthy();
2018-10-09 14:03:09 -04:00
2018-10-17 03:13:26 -04:00
expect(cluster.errorContainer.classList.contains('hidden')).toBeTruthy();
});
});
describe('when cluster has error', () => {
it('should show the error container', () => {
cluster.updateContainer(null, 'errored', 'this is an error');
2018-10-17 03:13:26 -04:00
expect(cluster.creatingContainer.classList.contains('hidden')).toBeTruthy();
2018-10-09 14:03:09 -04:00
2018-10-17 03:13:26 -04:00
expect(cluster.successContainer.classList.contains('hidden')).toBeTruthy();
2018-10-09 14:03:09 -04:00
2018-10-17 03:13:26 -04:00
expect(cluster.errorContainer.classList.contains('hidden')).toBeFalsy();
2018-10-17 03:13:26 -04:00
expect(cluster.errorReasonContainer.textContent).toContain('this is an error');
});
it('should show `error` banner when previously `creating`', () => {
cluster.updateContainer('creating', 'errored');
2018-10-17 03:13:26 -04:00
expect(cluster.creatingContainer.classList.contains('hidden')).toBeTruthy();
2018-10-09 14:03:09 -04:00
2018-10-17 03:13:26 -04:00
expect(cluster.successContainer.classList.contains('hidden')).toBeTruthy();
2018-10-09 14:03:09 -04:00
2018-10-17 03:13:26 -04:00
expect(cluster.errorContainer.classList.contains('hidden')).toBeFalsy();
});
});
});
describe('installApplication', () => {
it('tries to install helm', () => {
spyOn(cluster.service, 'installApplication').and.returnValue(Promise.resolve());
2018-10-09 14:03:09 -04:00
expect(cluster.store.state.applications.helm.requestStatus).toEqual(null);
cluster.installApplication({ id: 'helm' });
expect(cluster.store.state.applications.helm.requestStatus).toEqual(REQUEST_SUBMITTED);
expect(cluster.store.state.applications.helm.requestReason).toEqual(null);
expect(cluster.service.installApplication).toHaveBeenCalledWith('helm', undefined);
});
it('tries to install ingress', () => {
spyOn(cluster.service, 'installApplication').and.returnValue(Promise.resolve());
2018-10-09 14:03:09 -04:00
expect(cluster.store.state.applications.ingress.requestStatus).toEqual(null);
cluster.installApplication({ id: 'ingress' });
expect(cluster.store.state.applications.ingress.requestStatus).toEqual(REQUEST_SUBMITTED);
expect(cluster.store.state.applications.ingress.requestReason).toEqual(null);
expect(cluster.service.installApplication).toHaveBeenCalledWith('ingress', undefined);
});
it('tries to install runner', () => {
spyOn(cluster.service, 'installApplication').and.returnValue(Promise.resolve());
2018-10-09 14:03:09 -04:00
expect(cluster.store.state.applications.runner.requestStatus).toEqual(null);
cluster.installApplication({ id: 'runner' });
expect(cluster.store.state.applications.runner.requestStatus).toEqual(REQUEST_SUBMITTED);
expect(cluster.store.state.applications.runner.requestReason).toEqual(null);
expect(cluster.service.installApplication).toHaveBeenCalledWith('runner', undefined);
});
it('tries to install jupyter', () => {
spyOn(cluster.service, 'installApplication').and.returnValue(Promise.resolve());
2018-10-09 14:03:09 -04:00
expect(cluster.store.state.applications.jupyter.requestStatus).toEqual(null);
2018-10-17 03:13:26 -04:00
cluster.installApplication({
id: 'jupyter',
params: { hostname: cluster.store.state.applications.jupyter.hostname },
});
expect(cluster.store.state.applications.jupyter.requestStatus).toEqual(REQUEST_SUBMITTED);
expect(cluster.store.state.applications.jupyter.requestReason).toEqual(null);
2018-10-17 03:13:26 -04:00
expect(cluster.service.installApplication).toHaveBeenCalledWith('jupyter', {
hostname: cluster.store.state.applications.jupyter.hostname,
});
});
2018-10-17 03:13:26 -04:00
it('sets error request status when the request fails', done => {
spyOn(cluster.service, 'installApplication').and.returnValue(
Promise.reject(new Error('STUBBED ERROR')),
);
2018-10-09 14:03:09 -04:00
expect(cluster.store.state.applications.helm.requestStatus).toEqual(null);
cluster.installApplication({ id: 'helm' });
expect(cluster.store.state.applications.helm.requestStatus).toEqual(REQUEST_SUBMITTED);
expect(cluster.store.state.applications.helm.requestReason).toEqual(null);
expect(cluster.service.installApplication).toHaveBeenCalled();
getSetTimeoutPromise()
.then(() => {
expect(cluster.store.state.applications.helm.requestStatus).toEqual(REQUEST_FAILURE);
expect(cluster.store.state.applications.helm.requestReason).toBeDefined();
})
.then(done)
.catch(done.fail);
});
});
});