2017-10-24 00:56:39 -04:00
|
|
|
import Clusters from '~/clusters/clusters_bundle';
|
2019-02-01 05:44:49 -05:00
|
|
|
import { REQUEST_SUBMITTED, REQUEST_FAILURE, APPLICATION_STATUS } from '~/clusters/constants';
|
2018-02-26 14:43:34 -05:00
|
|
|
import getSetTimeoutPromise from 'spec/helpers/set_timeout_promise_helper';
|
2017-10-24 00:56:39 -04:00
|
|
|
|
|
|
|
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',
|
|
|
|
);
|
2017-10-24 00:56:39 -04:00
|
|
|
|
2018-01-24 16:54:33 -05:00
|
|
|
toggleButton.click();
|
2017-10-24 00:56:39 -04:00
|
|
|
|
2018-01-24 16:54:33 -05:00
|
|
|
getSetTimeoutPromise()
|
|
|
|
.then(() => {
|
2018-10-17 03:13:26 -04:00
|
|
|
expect(toggleButton.classList).not.toContain('is-checked');
|
2018-01-24 16:54:33 -05:00
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
expect(toggleInput.getAttribute('value')).toEqual('false');
|
2018-01-24 16:54:33 -05:00
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2017-10-24 00:56:39 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-11-09 08:59:40 -05:00
|
|
|
describe('showToken', () => {
|
2018-07-16 16:59:37 -04:00
|
|
|
it('should update token field type', () => {
|
2017-11-09 08:59:40 -05:00
|
|
|
cluster.showTokenButton.click();
|
2018-07-16 16:59:37 -04:00
|
|
|
|
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-07-16 16:59:37 -04:00
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
expect(cluster.tokenField.getAttribute('type')).toEqual('password');
|
2017-11-09 08:59:40 -05:00
|
|
|
});
|
2018-07-16 16:59:37 -04: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');
|
2018-07-16 16:59:37 -04:00
|
|
|
|
|
|
|
cluster.showTokenButton.click();
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
expect(cluster.showTokenButton.textContent).toEqual('Show');
|
2018-07-16 16:59:37 -04:00
|
|
|
});
|
2017-11-09 08:59:40 -05:00
|
|
|
});
|
|
|
|
|
2017-10-24 00:56:39 -04: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,
|
2018-08-07 15:05:43 -04:00
|
|
|
helm: { status: APPLICATION_STATUS.INSTALLABLE, title: 'Helm Tiller' },
|
2017-10-24 00:56:39 -04:00
|
|
|
});
|
|
|
|
|
2018-01-29 14:49:00 -05:00
|
|
|
const flashMessage = document.querySelector('.js-cluster-application-notice .flash-text');
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2018-01-29 14:49:00 -05:00
|
|
|
expect(flashMessage).toBeNull();
|
2017-10-24 00:56:39 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
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' },
|
|
|
|
},
|
|
|
|
);
|
2017-10-24 00:56:39 -04:00
|
|
|
|
2018-01-29 14:49:00 -05:00
|
|
|
const flashMessage = document.querySelector('.js-cluster-application-notice .flash-text');
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2018-01-29 14:49:00 -05: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',
|
|
|
|
);
|
2017-10-24 00:56:39 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
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' },
|
|
|
|
},
|
|
|
|
);
|
2017-10-24 00:56:39 -04:00
|
|
|
|
2018-01-29 14:49:00 -05:00
|
|
|
const flashMessage = document.querySelector('.js-cluster-application-notice .flash-text');
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2018-01-29 14:49:00 -05: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',
|
|
|
|
);
|
2017-10-24 00:56:39 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('updateContainer', () => {
|
|
|
|
describe('when creating cluster', () => {
|
|
|
|
it('should show the creating container', () => {
|
2017-11-06 11:07:19 -05:00
|
|
|
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();
|
2017-11-06 11:07:19 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should continue to show `creating` banner with subsequent updates of the same status', () => {
|
|
|
|
cluster.updateContainer('creating', 'creating');
|
2017-10-24 00:56:39 -04:00
|
|
|
|
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();
|
2017-10-24 00:56:39 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when cluster is created', () => {
|
2017-11-16 07:22:19 -05:00
|
|
|
it('should show the success container and fresh the page', () => {
|
2017-11-06 11:07:19 -05:00
|
|
|
cluster.updateContainer(null, 'created');
|
2017-10-24 00:56:39 -04:00
|
|
|
|
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();
|
2017-10-24 00:56:39 -04:00
|
|
|
});
|
2017-11-06 11:07:19 -05:00
|
|
|
|
|
|
|
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();
|
2017-11-06 11:07:19 -05:00
|
|
|
});
|
2017-10-24 00:56:39 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('when cluster has error', () => {
|
|
|
|
it('should show the error container', () => {
|
2017-11-06 11:07:19 -05:00
|
|
|
cluster.updateContainer(null, 'errored', 'this is an error');
|
2017-10-24 00:56:39 -04:00
|
|
|
|
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();
|
2017-10-24 00:56:39 -04:00
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
expect(cluster.errorReasonContainer.textContent).toContain('this is an error');
|
2017-10-24 00:56:39 -04:00
|
|
|
});
|
2017-11-06 11:07:19 -05:00
|
|
|
|
|
|
|
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();
|
2017-11-06 11:07:19 -05:00
|
|
|
});
|
2017-10-24 00:56:39 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('installApplication', () => {
|
2019-02-01 05:44:49 -05:00
|
|
|
it('tries to install helm', () => {
|
2017-10-24 00:56:39 -04:00
|
|
|
spyOn(cluster.service, 'installApplication').and.returnValue(Promise.resolve());
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-10-24 00:56:39 -04:00
|
|
|
expect(cluster.store.state.applications.helm.requestStatus).toEqual(null);
|
|
|
|
|
2018-05-24 16:00:21 -04:00
|
|
|
cluster.installApplication({ id: 'helm' });
|
2017-10-24 00:56:39 -04:00
|
|
|
|
2019-02-01 05:44:49 -05:00
|
|
|
expect(cluster.store.state.applications.helm.requestStatus).toEqual(REQUEST_SUBMITTED);
|
2017-10-24 00:56:39 -04:00
|
|
|
expect(cluster.store.state.applications.helm.requestReason).toEqual(null);
|
2018-05-24 16:00:21 -04:00
|
|
|
expect(cluster.service.installApplication).toHaveBeenCalledWith('helm', undefined);
|
2017-10-24 00:56:39 -04:00
|
|
|
});
|
|
|
|
|
2019-02-01 05:44:49 -05:00
|
|
|
it('tries to install ingress', () => {
|
2017-10-24 00:56:39 -04:00
|
|
|
spyOn(cluster.service, 'installApplication').and.returnValue(Promise.resolve());
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-10-24 00:56:39 -04:00
|
|
|
expect(cluster.store.state.applications.ingress.requestStatus).toEqual(null);
|
|
|
|
|
2018-05-24 16:00:21 -04:00
|
|
|
cluster.installApplication({ id: 'ingress' });
|
2017-10-24 00:56:39 -04:00
|
|
|
|
2019-02-01 05:44:49 -05:00
|
|
|
expect(cluster.store.state.applications.ingress.requestStatus).toEqual(REQUEST_SUBMITTED);
|
2017-10-24 00:56:39 -04:00
|
|
|
expect(cluster.store.state.applications.ingress.requestReason).toEqual(null);
|
2018-05-24 16:00:21 -04:00
|
|
|
expect(cluster.service.installApplication).toHaveBeenCalledWith('ingress', undefined);
|
2017-10-24 00:56:39 -04:00
|
|
|
});
|
|
|
|
|
2019-02-01 05:44:49 -05:00
|
|
|
it('tries to install runner', () => {
|
2017-10-24 00:56:39 -04:00
|
|
|
spyOn(cluster.service, 'installApplication').and.returnValue(Promise.resolve());
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-10-24 00:56:39 -04:00
|
|
|
expect(cluster.store.state.applications.runner.requestStatus).toEqual(null);
|
|
|
|
|
2018-05-24 16:00:21 -04:00
|
|
|
cluster.installApplication({ id: 'runner' });
|
2017-10-24 00:56:39 -04:00
|
|
|
|
2019-02-01 05:44:49 -05:00
|
|
|
expect(cluster.store.state.applications.runner.requestStatus).toEqual(REQUEST_SUBMITTED);
|
2017-10-24 00:56:39 -04:00
|
|
|
expect(cluster.store.state.applications.runner.requestReason).toEqual(null);
|
2018-05-24 16:00:21 -04:00
|
|
|
expect(cluster.service.installApplication).toHaveBeenCalledWith('runner', undefined);
|
2017-10-24 00:56:39 -04:00
|
|
|
});
|
|
|
|
|
2019-02-01 05:44:49 -05:00
|
|
|
it('tries to install jupyter', () => {
|
2018-05-24 16:00:21 -04:00
|
|
|
spyOn(cluster.service, 'installApplication').and.returnValue(Promise.resolve());
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2018-05-24 16:00:21 -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 },
|
|
|
|
});
|
2018-05-24 16:00:21 -04:00
|
|
|
|
2019-02-01 05:44:49 -05:00
|
|
|
expect(cluster.store.state.applications.jupyter.requestStatus).toEqual(REQUEST_SUBMITTED);
|
2018-05-24 16:00:21 -04:00
|
|
|
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-05-24 16:00:21 -04:00
|
|
|
});
|
|
|
|
|
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
|
|
|
|
2017-10-24 00:56:39 -04:00
|
|
|
expect(cluster.store.state.applications.helm.requestStatus).toEqual(null);
|
|
|
|
|
2018-05-24 16:00:21 -04:00
|
|
|
cluster.installApplication({ id: 'helm' });
|
2017-10-24 00:56:39 -04:00
|
|
|
|
2019-02-01 05:44:49 -05:00
|
|
|
expect(cluster.store.state.applications.helm.requestStatus).toEqual(REQUEST_SUBMITTED);
|
2017-10-24 00:56:39 -04:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|