debian-mirror-gitlab/spec/javascripts/clusters/clusters_bundle_spec.js

306 lines
11 KiB
JavaScript
Raw Normal View History

2018-03-17 18:26:18 +05:30
import Clusters from '~/clusters/clusters_bundle';
import {
REQUEST_LOADING,
REQUEST_SUCCESS,
REQUEST_FAILURE,
2018-11-18 11:00:15 +05:30
APPLICATION_STATUS,
2018-03-17 18:26:18 +05:30
} from '~/clusters/constants';
2018-03-27 19:54:05 +05:30
import getSetTimeoutPromise from 'spec/helpers/set_timeout_promise_helper';
2018-03-17 18:26:18 +05:30
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-12-13 13:39:08 +05:30
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',
);
2018-03-17 18:26:18 +05:30
toggleButton.click();
getSetTimeoutPromise()
.then(() => {
2018-12-13 13:39:08 +05:30
expect(toggleButton.classList).not.toContain('is-checked');
2018-03-17 18:26:18 +05:30
2018-12-13 13:39:08 +05:30
expect(toggleInput.getAttribute('value')).toEqual('false');
2018-03-17 18:26:18 +05:30
})
.then(done)
.catch(done.fail);
});
});
describe('showToken', () => {
2018-11-18 11:00:15 +05:30
it('should update token field type', () => {
2018-03-17 18:26:18 +05:30
cluster.showTokenButton.click();
2018-11-18 11:00:15 +05:30
2018-12-13 13:39:08 +05:30
expect(cluster.tokenField.getAttribute('type')).toEqual('text');
2018-03-17 18:26:18 +05:30
cluster.showTokenButton.click();
2018-11-18 11:00:15 +05:30
2018-12-13 13:39:08 +05:30
expect(cluster.tokenField.getAttribute('type')).toEqual('password');
2018-03-17 18:26:18 +05:30
});
2018-11-18 11:00:15 +05:30
it('should update show token button text', () => {
cluster.showTokenButton.click();
2018-12-13 13:39:08 +05:30
expect(cluster.showTokenButton.textContent).toEqual('Hide');
2018-11-18 11:00:15 +05:30
cluster.showTokenButton.click();
2018-12-13 13:39:08 +05:30
expect(cluster.showTokenButton.textContent).toEqual('Show');
2018-11-18 11:00:15 +05:30
});
2018-03-17 18:26:18 +05:30
});
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,
2018-11-18 11:00:15 +05:30
helm: { status: APPLICATION_STATUS.INSTALLABLE, title: 'Helm Tiller' },
2018-03-17 18:26:18 +05:30
});
const flashMessage = document.querySelector('.js-cluster-application-notice .flash-text');
2018-12-13 13:39:08 +05:30
2018-03-17 18:26:18 +05:30
expect(flashMessage).toBeNull();
});
it('shows an alert when something gets newly installed', () => {
2018-12-13 13:39:08 +05:30
cluster.checkForNewInstalls(
{
...INITIAL_APP_MAP,
helm: { status: APPLICATION_STATUS.INSTALLING, title: 'Helm Tiller' },
},
{
...INITIAL_APP_MAP,
helm: { status: APPLICATION_STATUS.INSTALLED, title: 'Helm Tiller' },
},
);
2018-03-17 18:26:18 +05:30
const flashMessage = document.querySelector('.js-cluster-application-notice .flash-text');
2018-12-13 13:39:08 +05:30
2018-03-17 18:26:18 +05:30
expect(flashMessage).not.toBeNull();
2018-12-13 13:39:08 +05:30
expect(flashMessage.textContent.trim()).toEqual(
'Helm Tiller was successfully installed on your Kubernetes cluster',
);
2018-03-17 18:26:18 +05:30
});
it('shows an alert when multiple things gets newly installed', () => {
2018-12-13 13:39:08 +05:30
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' },
},
);
2018-03-17 18:26:18 +05:30
const flashMessage = document.querySelector('.js-cluster-application-notice .flash-text');
2018-12-13 13:39:08 +05:30
2018-03-17 18:26:18 +05:30
expect(flashMessage).not.toBeNull();
2018-12-13 13:39:08 +05:30
expect(flashMessage.textContent.trim()).toEqual(
'Helm Tiller, Ingress was successfully installed on your Kubernetes cluster',
);
2018-03-17 18:26:18 +05:30
});
});
describe('updateContainer', () => {
describe('when creating cluster', () => {
it('should show the creating container', () => {
cluster.updateContainer(null, 'creating');
2018-12-13 13:39:08 +05:30
expect(cluster.creatingContainer.classList.contains('hidden')).toBeFalsy();
expect(cluster.successContainer.classList.contains('hidden')).toBeTruthy();
expect(cluster.errorContainer.classList.contains('hidden')).toBeTruthy();
2018-03-17 18:26:18 +05:30
});
it('should continue to show `creating` banner with subsequent updates of the same status', () => {
cluster.updateContainer('creating', 'creating');
2018-12-13 13:39:08 +05:30
expect(cluster.creatingContainer.classList.contains('hidden')).toBeFalsy();
expect(cluster.successContainer.classList.contains('hidden')).toBeTruthy();
expect(cluster.errorContainer.classList.contains('hidden')).toBeTruthy();
2018-03-17 18:26:18 +05:30
});
});
describe('when cluster is created', () => {
it('should show the success container and fresh the page', () => {
cluster.updateContainer(null, 'created');
2018-12-13 13:39:08 +05:30
expect(cluster.creatingContainer.classList.contains('hidden')).toBeTruthy();
expect(cluster.successContainer.classList.contains('hidden')).toBeFalsy();
expect(cluster.errorContainer.classList.contains('hidden')).toBeTruthy();
2018-03-17 18:26:18 +05:30
});
it('should not show a banner when status is already `created`', () => {
cluster.updateContainer('created', 'created');
2018-12-13 13:39:08 +05:30
expect(cluster.creatingContainer.classList.contains('hidden')).toBeTruthy();
expect(cluster.successContainer.classList.contains('hidden')).toBeTruthy();
expect(cluster.errorContainer.classList.contains('hidden')).toBeTruthy();
2018-03-17 18:26:18 +05:30
});
});
describe('when cluster has error', () => {
it('should show the error container', () => {
cluster.updateContainer(null, 'errored', 'this is an error');
2018-12-13 13:39:08 +05:30
expect(cluster.creatingContainer.classList.contains('hidden')).toBeTruthy();
expect(cluster.successContainer.classList.contains('hidden')).toBeTruthy();
expect(cluster.errorContainer.classList.contains('hidden')).toBeFalsy();
expect(cluster.errorReasonContainer.textContent).toContain('this is an error');
2018-03-17 18:26:18 +05:30
});
it('should show `error` banner when previously `creating`', () => {
cluster.updateContainer('creating', 'errored');
2018-12-13 13:39:08 +05:30
expect(cluster.creatingContainer.classList.contains('hidden')).toBeTruthy();
expect(cluster.successContainer.classList.contains('hidden')).toBeTruthy();
expect(cluster.errorContainer.classList.contains('hidden')).toBeFalsy();
2018-03-17 18:26:18 +05:30
});
});
});
describe('installApplication', () => {
2018-12-13 13:39:08 +05:30
it('tries to install helm', done => {
2018-03-17 18:26:18 +05:30
spyOn(cluster.service, 'installApplication').and.returnValue(Promise.resolve());
2018-12-13 13:39:08 +05:30
2018-03-17 18:26:18 +05:30
expect(cluster.store.state.applications.helm.requestStatus).toEqual(null);
2018-11-08 19:23:39 +05:30
cluster.installApplication({ id: 'helm' });
2018-03-17 18:26:18 +05:30
expect(cluster.store.state.applications.helm.requestStatus).toEqual(REQUEST_LOADING);
expect(cluster.store.state.applications.helm.requestReason).toEqual(null);
2018-11-08 19:23:39 +05:30
expect(cluster.service.installApplication).toHaveBeenCalledWith('helm', undefined);
2018-03-17 18:26:18 +05:30
getSetTimeoutPromise()
.then(() => {
expect(cluster.store.state.applications.helm.requestStatus).toEqual(REQUEST_SUCCESS);
expect(cluster.store.state.applications.helm.requestReason).toEqual(null);
})
.then(done)
.catch(done.fail);
});
2018-12-13 13:39:08 +05:30
it('tries to install ingress', done => {
2018-03-17 18:26:18 +05:30
spyOn(cluster.service, 'installApplication').and.returnValue(Promise.resolve());
2018-12-13 13:39:08 +05:30
2018-03-17 18:26:18 +05:30
expect(cluster.store.state.applications.ingress.requestStatus).toEqual(null);
2018-11-08 19:23:39 +05:30
cluster.installApplication({ id: 'ingress' });
2018-03-17 18:26:18 +05:30
expect(cluster.store.state.applications.ingress.requestStatus).toEqual(REQUEST_LOADING);
expect(cluster.store.state.applications.ingress.requestReason).toEqual(null);
2018-11-08 19:23:39 +05:30
expect(cluster.service.installApplication).toHaveBeenCalledWith('ingress', undefined);
2018-03-17 18:26:18 +05:30
getSetTimeoutPromise()
.then(() => {
expect(cluster.store.state.applications.ingress.requestStatus).toEqual(REQUEST_SUCCESS);
expect(cluster.store.state.applications.ingress.requestReason).toEqual(null);
})
.then(done)
.catch(done.fail);
});
2018-12-13 13:39:08 +05:30
it('tries to install runner', done => {
2018-03-17 18:26:18 +05:30
spyOn(cluster.service, 'installApplication').and.returnValue(Promise.resolve());
2018-12-13 13:39:08 +05:30
2018-03-17 18:26:18 +05:30
expect(cluster.store.state.applications.runner.requestStatus).toEqual(null);
2018-11-08 19:23:39 +05:30
cluster.installApplication({ id: 'runner' });
2018-03-17 18:26:18 +05:30
expect(cluster.store.state.applications.runner.requestStatus).toEqual(REQUEST_LOADING);
expect(cluster.store.state.applications.runner.requestReason).toEqual(null);
2018-11-08 19:23:39 +05:30
expect(cluster.service.installApplication).toHaveBeenCalledWith('runner', undefined);
2018-03-17 18:26:18 +05:30
getSetTimeoutPromise()
.then(() => {
expect(cluster.store.state.applications.runner.requestStatus).toEqual(REQUEST_SUCCESS);
expect(cluster.store.state.applications.runner.requestReason).toEqual(null);
})
.then(done)
.catch(done.fail);
});
2018-12-13 13:39:08 +05:30
it('tries to install jupyter', done => {
2018-11-08 19:23:39 +05:30
spyOn(cluster.service, 'installApplication').and.returnValue(Promise.resolve());
2018-12-13 13:39:08 +05:30
2018-11-08 19:23:39 +05:30
expect(cluster.store.state.applications.jupyter.requestStatus).toEqual(null);
2018-12-13 13:39:08 +05:30
cluster.installApplication({
id: 'jupyter',
params: { hostname: cluster.store.state.applications.jupyter.hostname },
});
2018-11-08 19:23:39 +05:30
expect(cluster.store.state.applications.jupyter.requestStatus).toEqual(REQUEST_LOADING);
expect(cluster.store.state.applications.jupyter.requestReason).toEqual(null);
2018-12-13 13:39:08 +05:30
expect(cluster.service.installApplication).toHaveBeenCalledWith('jupyter', {
hostname: cluster.store.state.applications.jupyter.hostname,
});
2018-11-08 19:23:39 +05:30
getSetTimeoutPromise()
2018-12-13 13:39:08 +05:30
.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);
2018-11-08 19:23:39 +05:30
});
2018-12-13 13:39:08 +05:30
it('sets error request status when the request fails', done => {
spyOn(cluster.service, 'installApplication').and.returnValue(
Promise.reject(new Error('STUBBED ERROR')),
);
2018-03-17 18:26:18 +05:30
expect(cluster.store.state.applications.helm.requestStatus).toEqual(null);
2018-11-08 19:23:39 +05:30
cluster.installApplication({ id: 'helm' });
2018-03-17 18:26:18 +05:30
expect(cluster.store.state.applications.helm.requestStatus).toEqual(REQUEST_LOADING);
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);
});
});
});