Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/clusters_list/components/clusters_spec.js')
-rw-r--r--spec/frontend/clusters_list/components/clusters_spec.js158
1 files changed, 125 insertions, 33 deletions
diff --git a/spec/frontend/clusters_list/components/clusters_spec.js b/spec/frontend/clusters_list/components/clusters_spec.js
index e2d2e4b73b3..07faee7e50b 100644
--- a/spec/frontend/clusters_list/components/clusters_spec.js
+++ b/spec/frontend/clusters_list/components/clusters_spec.js
@@ -5,6 +5,7 @@ import MockAdapter from 'axios-mock-adapter';
import { apiData } from '../mock_data';
import { mount } from '@vue/test-utils';
import { GlLoadingIcon, GlTable, GlPagination } from '@gitlab/ui';
+import * as Sentry from '@sentry/browser';
describe('Clusters', () => {
let mock;
@@ -13,6 +14,13 @@ describe('Clusters', () => {
const endpoint = 'some/endpoint';
+ const entryData = {
+ endpoint,
+ imgTagsAwsText: 'AWS Icon',
+ imgTagsDefaultText: 'Default Icon',
+ imgTagsGcpText: 'GCP Icon',
+ };
+
const findLoader = () => wrapper.find(GlLoadingIcon);
const findPaginatedButtons = () => wrapper.find(GlPagination);
const findTable = () => wrapper.find(GlTable);
@@ -23,18 +31,26 @@ describe('Clusters', () => {
};
const mountWrapper = () => {
- store = ClusterStore({ endpoint });
+ store = ClusterStore(entryData);
wrapper = mount(Clusters, { store });
return axios.waitForAll();
};
+ const paginationHeader = (total = apiData.clusters.length, perPage = 20, currentPage = 1) => {
+ return {
+ 'x-total': total,
+ 'x-per-page': perPage,
+ 'x-page': currentPage,
+ };
+ };
+
+ let captureException;
+
beforeEach(() => {
+ captureException = jest.spyOn(Sentry, 'captureException');
+
mock = new MockAdapter(axios);
- mockPollingApi(200, apiData, {
- 'x-total': apiData.clusters.length,
- 'x-per-page': 20,
- 'x-page': 1,
- });
+ mockPollingApi(200, apiData, paginationHeader());
return mountWrapper();
});
@@ -42,6 +58,7 @@ describe('Clusters', () => {
afterEach(() => {
wrapper.destroy();
mock.restore();
+ captureException.mockRestore();
});
describe('clusters table', () => {
@@ -77,25 +94,108 @@ describe('Clusters', () => {
});
});
+ describe('cluster icon', () => {
+ it.each`
+ providerText | lineNumber
+ ${'GCP Icon'} | ${0}
+ ${'AWS Icon'} | ${1}
+ ${'Default Icon'} | ${2}
+ ${'Default Icon'} | ${3}
+ ${'Default Icon'} | ${4}
+ ${'Default Icon'} | ${5}
+ `('renders provider image and alt text for each cluster', ({ providerText, lineNumber }) => {
+ const images = findTable().findAll('.js-status img');
+ const image = images.at(lineNumber);
+
+ expect(image.attributes('alt')).toBe(providerText);
+ });
+ });
+
describe('cluster status', () => {
it.each`
- statusName | className | lineNumber
- ${'disabled'} | ${'disabled'} | ${0}
- ${'unreachable'} | ${'bg-danger'} | ${1}
- ${'authentication_failure'} | ${'bg-warning'} | ${2}
- ${'deleting'} | ${null} | ${3}
- ${'created'} | ${'bg-success'} | ${4}
- ${'default'} | ${'bg-white'} | ${5}
- `('renders a status for each cluster', ({ statusName, className, lineNumber }) => {
- const statuses = findStatuses();
- const status = statuses.at(lineNumber);
- if (statusName !== 'deleting') {
- const statusIndicator = status.find('.cluster-status-indicator');
- expect(statusIndicator.exists()).toBe(true);
- expect(statusIndicator.classes()).toContain(className);
- } else {
- expect(status.find(GlLoadingIcon).exists()).toBe(true);
- }
+ statusName | lineNumber | result
+ ${'creating'} | ${0} | ${true}
+ ${null} | ${1} | ${false}
+ ${null} | ${2} | ${false}
+ ${'deleting'} | ${3} | ${true}
+ ${null} | ${4} | ${false}
+ ${null} | ${5} | ${false}
+ `(
+ 'renders $result when status=$statusName and lineNumber=$lineNumber',
+ ({ lineNumber, result }) => {
+ const statuses = findStatuses();
+ const status = statuses.at(lineNumber);
+ expect(status.find(GlLoadingIcon).exists()).toBe(result);
+ },
+ );
+ });
+
+ describe('nodes present', () => {
+ it.each`
+ nodeSize | lineNumber
+ ${'Unknown'} | ${0}
+ ${'1'} | ${1}
+ ${'2'} | ${2}
+ ${'1'} | ${3}
+ ${'1'} | ${4}
+ ${'Unknown'} | ${5}
+ `('renders node size for each cluster', ({ nodeSize, lineNumber }) => {
+ const sizes = findTable().findAll('td:nth-child(3)');
+ const size = sizes.at(lineNumber);
+
+ expect(size.text()).toBe(nodeSize);
+ });
+
+ describe('nodes with unknown quantity', () => {
+ it('notifies Sentry about all missing quantity types', () => {
+ expect(captureException).toHaveBeenCalledTimes(8);
+ });
+
+ it('notifies Sentry about CPU missing quantity types', () => {
+ const missingCpuTypeError = new Error('UnknownK8sCpuQuantity:1missingCpuUnit');
+
+ expect(captureException).toHaveBeenCalledWith(missingCpuTypeError);
+ });
+
+ it('notifies Sentry about Memory missing quantity types', () => {
+ const missingMemoryTypeError = new Error('UnknownK8sMemoryQuantity:1missingMemoryUnit');
+
+ expect(captureException).toHaveBeenCalledWith(missingMemoryTypeError);
+ });
+ });
+ });
+
+ describe('cluster CPU', () => {
+ it.each`
+ clusterCpu | lineNumber
+ ${''} | ${0}
+ ${'1.93 (87% free)'} | ${1}
+ ${'3.87 (86% free)'} | ${2}
+ ${'(% free)'} | ${3}
+ ${'(% free)'} | ${4}
+ ${''} | ${5}
+ `('renders total cpu for each cluster', ({ clusterCpu, lineNumber }) => {
+ const clusterCpus = findTable().findAll('td:nth-child(4)');
+ const cpuData = clusterCpus.at(lineNumber);
+
+ expect(cpuData.text()).toBe(clusterCpu);
+ });
+ });
+
+ describe('cluster Memory', () => {
+ it.each`
+ clusterMemory | lineNumber
+ ${''} | ${0}
+ ${'5.92 (78% free)'} | ${1}
+ ${'12.86 (79% free)'} | ${2}
+ ${'(% free)'} | ${3}
+ ${'(% free)'} | ${4}
+ ${''} | ${5}
+ `('renders total memory for each cluster', ({ clusterMemory, lineNumber }) => {
+ const clusterMemories = findTable().findAll('td:nth-child(5)');
+ const memoryData = clusterMemories.at(lineNumber);
+
+ expect(memoryData.text()).toBe(clusterMemory);
});
});
@@ -105,11 +205,7 @@ describe('Clusters', () => {
const totalSecondPage = 500;
beforeEach(() => {
- mockPollingApi(200, apiData, {
- 'x-total': totalFirstPage,
- 'x-per-page': perPage,
- 'x-page': 1,
- });
+ mockPollingApi(200, apiData, paginationHeader(totalFirstPage, perPage, 1));
return mountWrapper();
});
@@ -123,11 +219,7 @@ describe('Clusters', () => {
describe('when updating currentPage', () => {
beforeEach(() => {
- mockPollingApi(200, apiData, {
- 'x-total': totalSecondPage,
- 'x-per-page': perPage,
- 'x-page': 2,
- });
+ mockPollingApi(200, apiData, paginationHeader(totalSecondPage, perPage, 2));
wrapper.setData({ currentPage: 2 });
return axios.waitForAll();
});