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

193 lines
7 KiB
JavaScript
Raw Normal View History

2020-01-01 13:55:28 +05:30
import MockAdapter from 'axios-mock-adapter';
2022-07-16 23:28:13 +05:30
import { loadHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
2021-10-27 15:23:28 +05:30
import { useMockLocationHelper } from 'helpers/mock_window_location_helper';
2018-03-17 18:26:18 +05:30
import Clusters from '~/clusters/clusters_bundle';
2019-07-07 11:18:12 +05:30
import axios from '~/lib/utils/axios_utils';
2019-12-26 22:10:19 +05:30
import initProjectSelectDropdown from '~/project_select';
2018-03-17 18:26:18 +05:30
2019-12-04 20:38:33 +05:30
jest.mock('~/lib/utils/poll');
2019-12-26 22:10:19 +05:30
jest.mock('~/project_select');
2019-12-04 20:38:33 +05:30
2021-10-27 15:23:28 +05:30
useMockLocationHelper();
2018-03-17 18:26:18 +05:30
describe('Clusters', () => {
let cluster;
2019-07-07 11:18:12 +05:30
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');
mockGetClusterStatusRequest();
2018-03-17 18:26:18 +05:30
cluster = new Clusters();
});
afterEach(() => {
cluster.destroy();
2019-07-07 11:18:12 +05:30
mock.restore();
2022-07-16 23:28:13 +05:30
resetHTMLFixture();
2018-03-17 18:26:18 +05:30
});
2019-12-04 20:38:33 +05:30
describe('class constructor', () => {
beforeEach(() => {
jest.spyOn(Clusters.prototype, 'initPolling');
cluster = new Clusters();
});
it('should call initPolling on construct', () => {
expect(cluster.initPolling).toHaveBeenCalled();
});
2019-12-26 22:10:19 +05:30
it('should call initProjectSelectDropdown on construct', () => {
expect(initProjectSelectDropdown).toHaveBeenCalled();
});
2019-12-04 20:38:33 +05:30
});
2018-03-17 18:26:18 +05:30
describe('updateContainer', () => {
describe('when creating cluster', () => {
it('should show the creating container', () => {
cluster.updateContainer(null, 'creating');
2022-08-27 11:52:29 +05:30
expect(cluster.creatingContainer.classList.contains('hidden')).toBe(false);
expect(cluster.successContainer.classList.contains('hidden')).toBe(true);
expect(cluster.errorContainer.classList.contains('hidden')).toBe(true);
2019-10-12 21:52:04 +05:30
expect(window.location.reload).not.toHaveBeenCalled();
2018-03-17 18:26:18 +05:30
});
it('should continue to show `creating` banner with subsequent updates of the same status', () => {
2019-10-12 21:52:04 +05:30
cluster.updateContainer(null, 'creating');
2018-03-17 18:26:18 +05:30
cluster.updateContainer('creating', 'creating');
2022-08-27 11:52:29 +05:30
expect(cluster.creatingContainer.classList.contains('hidden')).toBe(false);
expect(cluster.successContainer.classList.contains('hidden')).toBe(true);
expect(cluster.errorContainer.classList.contains('hidden')).toBe(true);
2019-10-12 21:52:04 +05:30
expect(window.location.reload).not.toHaveBeenCalled();
2018-03-17 18:26:18 +05:30
});
});
describe('when cluster is created', () => {
2019-10-12 21:52:04 +05:30
it('should hide the "creating" banner and refresh the page', () => {
jest.spyOn(cluster, 'setClusterNewlyCreated');
cluster.updateContainer(null, 'creating');
cluster.updateContainer('creating', 'created');
2018-03-17 18:26:18 +05:30
2022-08-27 11:52:29 +05:30
expect(cluster.creatingContainer.classList.contains('hidden')).toBe(true);
expect(cluster.successContainer.classList.contains('hidden')).toBe(true);
expect(cluster.errorContainer.classList.contains('hidden')).toBe(true);
2019-10-12 21:52:04 +05:30
expect(window.location.reload).toHaveBeenCalled();
expect(cluster.setClusterNewlyCreated).toHaveBeenCalledWith(true);
});
2018-12-13 13:39:08 +05:30
2019-10-12 21:52:04 +05:30
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-12-13 13:39:08 +05:30
2022-08-27 11:52:29 +05:30
expect(cluster.creatingContainer.classList.contains('hidden')).toBe(true);
expect(cluster.successContainer.classList.contains('hidden')).toBe(false);
expect(cluster.errorContainer.classList.contains('hidden')).toBe(true);
2019-10-12 21:52:04 +05:30
expect(window.location.reload).not.toHaveBeenCalled();
expect(cluster.setClusterNewlyCreated).toHaveBeenCalledWith(false);
2018-03-17 18:26:18 +05:30
});
it('should not show a banner when status is already `created`', () => {
2019-10-12 21:52:04 +05:30
jest.spyOn(cluster, 'setClusterNewlyCreated');
jest.spyOn(cluster, 'isClusterNewlyCreated').mockReturnValue(false);
cluster.updateContainer(null, 'created');
2018-03-17 18:26:18 +05:30
cluster.updateContainer('created', 'created');
2022-08-27 11:52:29 +05:30
expect(cluster.creatingContainer.classList.contains('hidden')).toBe(true);
expect(cluster.successContainer.classList.contains('hidden')).toBe(true);
expect(cluster.errorContainer.classList.contains('hidden')).toBe(true);
2019-10-12 21:52:04 +05:30
expect(window.location.reload).not.toHaveBeenCalled();
expect(cluster.setClusterNewlyCreated).not.toHaveBeenCalled();
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');
2022-08-27 11:52:29 +05:30
expect(cluster.creatingContainer.classList.contains('hidden')).toBe(true);
2018-12-13 13:39:08 +05:30
2022-08-27 11:52:29 +05:30
expect(cluster.successContainer.classList.contains('hidden')).toBe(true);
2018-12-13 13:39:08 +05:30
2022-08-27 11:52:29 +05:30
expect(cluster.errorContainer.classList.contains('hidden')).toBe(false);
2018-12-13 13:39:08 +05:30
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');
2022-08-27 11:52:29 +05:30
expect(cluster.creatingContainer.classList.contains('hidden')).toBe(true);
2018-12-13 13:39:08 +05:30
2022-08-27 11:52:29 +05:30
expect(cluster.successContainer.classList.contains('hidden')).toBe(true);
2018-12-13 13:39:08 +05:30
2022-08-27 11:52:29 +05:30
expect(cluster.errorContainer.classList.contains('hidden')).toBe(false);
2018-03-17 18:26:18 +05:30
});
});
2019-09-04 21:01:54 +05:30
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);
});
});
2018-03-17 18:26:18 +05:30
});
2019-12-04 20:38:33 +05:30
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-07-07 11:18:12 +05:30
beforeEach(() => {
jest.spyOn(cluster.store, 'updateStateFromServer').mockReturnThis();
jest.spyOn(cluster, 'updateContainer').mockReturnThis();
2019-12-04 20:38:33 +05:30
cluster.handleClusterStatusSuccess({ data: {} });
2019-07-07 11:18:12 +05:30
});
it('updates clusters store', () => {
expect(cluster.store.updateStateFromServer).toHaveBeenCalled();
});
it('updates message containers', () => {
expect(cluster.updateContainer).toHaveBeenCalled();
});
});
2018-03-17 18:26:18 +05:30
});