2019-12-10 04:07:51 -05:00
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
|
|
|
import { loadHTMLFixture } from 'helpers/fixtures';
|
|
|
|
import { setTestTimeout } from 'helpers/timeout';
|
2017-10-24 00:56:39 -04:00
|
|
|
import Clusters from '~/clusters/clusters_bundle';
|
2019-04-08 03:31:27 -04:00
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2019-11-04 04:06:21 -05:00
|
|
|
import initProjectSelectDropdown from '~/project_select';
|
2017-10-24 00:56:39 -04:00
|
|
|
|
2019-09-18 10:02:45 -04:00
|
|
|
jest.mock('~/lib/utils/poll');
|
2019-11-04 04:06:21 -05:00
|
|
|
jest.mock('~/project_select');
|
2019-09-18 10:02:45 -04:00
|
|
|
|
2017-10-24 00:56:39 -04:00
|
|
|
describe('Clusters', () => {
|
2019-04-11 08:52:40 -04:00
|
|
|
setTestTimeout(1000);
|
2019-04-08 03:31:27 -04:00
|
|
|
|
2017-10-24 00:56:39 -04:00
|
|
|
let cluster;
|
2019-04-08 03:31:27 -04:00
|
|
|
let mock;
|
|
|
|
|
|
|
|
const mockGetClusterStatusRequest = () => {
|
|
|
|
const { statusPath } = document.querySelector('.js-edit-cluster-form').dataset;
|
|
|
|
|
|
|
|
mock = new MockAdapter(axios);
|
|
|
|
|
|
|
|
mock.onGet(statusPath).reply(200);
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
loadHTMLFixture('clusters/show_cluster.html');
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
mockGetClusterStatusRequest();
|
|
|
|
});
|
2017-10-24 00:56:39 -04:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
cluster = new Clusters();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
cluster.destroy();
|
2019-04-08 03:31:27 -04:00
|
|
|
mock.restore();
|
2017-10-24 00:56:39 -04:00
|
|
|
});
|
|
|
|
|
2019-09-18 10:02:45 -04:00
|
|
|
describe('class constructor', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.spyOn(Clusters.prototype, 'initPolling');
|
|
|
|
cluster = new Clusters();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should call initPolling on construct', () => {
|
|
|
|
expect(cluster.initPolling).toHaveBeenCalled();
|
2019-11-04 04:06:21 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should call initProjectSelectDropdown on construct', () => {
|
|
|
|
expect(initProjectSelectDropdown).toHaveBeenCalled();
|
2019-09-18 10:02:45 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-10-24 00:56:39 -04:00
|
|
|
describe('updateContainer', () => {
|
2019-08-02 16:08:53 -04:00
|
|
|
const { location } = window;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
delete window.location;
|
|
|
|
window.location = {
|
|
|
|
reload: jest.fn(),
|
|
|
|
hash: location.hash,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
window.location = location;
|
|
|
|
});
|
|
|
|
|
2017-10-24 00:56:39 -04:00
|
|
|
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();
|
|
|
|
expect(cluster.successContainer.classList.contains('hidden')).toBeTruthy();
|
|
|
|
expect(cluster.errorContainer.classList.contains('hidden')).toBeTruthy();
|
2019-08-02 16:08:53 -04:00
|
|
|
expect(window.location.reload).not.toHaveBeenCalled();
|
2017-11-06 11:07:19 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should continue to show `creating` banner with subsequent updates of the same status', () => {
|
2019-08-02 16:08:53 -04:00
|
|
|
cluster.updateContainer(null, 'creating');
|
2017-11-06 11:07:19 -05:00
|
|
|
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();
|
|
|
|
expect(cluster.successContainer.classList.contains('hidden')).toBeTruthy();
|
|
|
|
expect(cluster.errorContainer.classList.contains('hidden')).toBeTruthy();
|
2019-08-02 16:08:53 -04:00
|
|
|
expect(window.location.reload).not.toHaveBeenCalled();
|
2017-10-24 00:56:39 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when cluster is created', () => {
|
2019-08-02 16:08:53 -04:00
|
|
|
it('should hide the "creating" banner and refresh the page', () => {
|
|
|
|
jest.spyOn(cluster, 'setClusterNewlyCreated');
|
|
|
|
cluster.updateContainer(null, 'creating');
|
|
|
|
cluster.updateContainer('creating', 'created');
|
2017-10-24 00:56:39 -04:00
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
expect(cluster.creatingContainer.classList.contains('hidden')).toBeTruthy();
|
2019-08-02 16:08:53 -04:00
|
|
|
expect(cluster.successContainer.classList.contains('hidden')).toBeTruthy();
|
|
|
|
expect(cluster.errorContainer.classList.contains('hidden')).toBeTruthy();
|
|
|
|
expect(window.location.reload).toHaveBeenCalled();
|
|
|
|
expect(cluster.setClusterNewlyCreated).toHaveBeenCalledWith(true);
|
|
|
|
});
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2019-08-02 16:08:53 -04:00
|
|
|
it('when the page is refreshed, it should show the "success" banner', () => {
|
|
|
|
jest.spyOn(cluster, 'setClusterNewlyCreated');
|
|
|
|
jest.spyOn(cluster, 'isClusterNewlyCreated').mockReturnValue(true);
|
|
|
|
|
|
|
|
cluster.updateContainer(null, 'created');
|
|
|
|
cluster.updateContainer('created', 'created');
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2019-08-02 16:08:53 -04:00
|
|
|
expect(cluster.creatingContainer.classList.contains('hidden')).toBeTruthy();
|
|
|
|
expect(cluster.successContainer.classList.contains('hidden')).toBeFalsy();
|
2018-10-17 03:13:26 -04:00
|
|
|
expect(cluster.errorContainer.classList.contains('hidden')).toBeTruthy();
|
2019-08-02 16:08:53 -04:00
|
|
|
expect(window.location.reload).not.toHaveBeenCalled();
|
|
|
|
expect(cluster.setClusterNewlyCreated).toHaveBeenCalledWith(false);
|
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`', () => {
|
2019-08-02 16:08:53 -04:00
|
|
|
jest.spyOn(cluster, 'setClusterNewlyCreated');
|
|
|
|
jest.spyOn(cluster, 'isClusterNewlyCreated').mockReturnValue(false);
|
|
|
|
|
|
|
|
cluster.updateContainer(null, 'created');
|
2017-11-06 11:07:19 -05:00
|
|
|
cluster.updateContainer('created', 'created');
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
expect(cluster.creatingContainer.classList.contains('hidden')).toBeTruthy();
|
|
|
|
expect(cluster.successContainer.classList.contains('hidden')).toBeTruthy();
|
|
|
|
expect(cluster.errorContainer.classList.contains('hidden')).toBeTruthy();
|
2019-08-02 16:08:53 -04:00
|
|
|
expect(window.location.reload).not.toHaveBeenCalled();
|
|
|
|
expect(cluster.setClusterNewlyCreated).not.toHaveBeenCalled();
|
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
|
|
|
});
|
2019-05-27 04:23:17 -04:00
|
|
|
|
|
|
|
describe('when cluster is unreachable', () => {
|
|
|
|
it('should show the unreachable warning container', () => {
|
|
|
|
cluster.updateContainer(null, 'unreachable');
|
|
|
|
|
|
|
|
expect(cluster.unreachableContainer.classList.contains('hidden')).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when cluster has an authentication failure', () => {
|
|
|
|
it('should show the authentication failure warning container', () => {
|
|
|
|
cluster.updateContainer(null, 'authentication_failure');
|
|
|
|
|
|
|
|
expect(cluster.authenticationFailureContainer.classList.contains('hidden')).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
2017-10-24 00:56:39 -04:00
|
|
|
});
|
|
|
|
|
2019-09-18 10:02:45 -04:00
|
|
|
describe('fetch cluster environments success', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.spyOn(cluster.store, 'toggleFetchEnvironments').mockReturnThis();
|
|
|
|
jest.spyOn(cluster.store, 'updateEnvironments').mockReturnThis();
|
|
|
|
|
|
|
|
cluster.handleClusterEnvironmentsSuccess({ data: {} });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('toggles the cluster environments loading icon', () => {
|
|
|
|
expect(cluster.store.toggleFetchEnvironments).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('updates the store when cluster environments is retrieved', () => {
|
|
|
|
expect(cluster.store.updateEnvironments).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('handleClusterStatusSuccess', () => {
|
2019-03-18 15:53:51 -04:00
|
|
|
beforeEach(() => {
|
2019-04-08 03:31:27 -04:00
|
|
|
jest.spyOn(cluster.store, 'updateStateFromServer').mockReturnThis();
|
|
|
|
jest.spyOn(cluster, 'updateContainer').mockReturnThis();
|
2019-09-18 10:02:45 -04:00
|
|
|
cluster.handleClusterStatusSuccess({ data: {} });
|
2019-03-18 15:53:51 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('updates clusters store', () => {
|
|
|
|
expect(cluster.store.updateStateFromServer).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('updates message containers', () => {
|
|
|
|
expect(cluster.updateContainer).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
2017-10-24 00:56:39 -04:00
|
|
|
});
|