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/store')
-rw-r--r--spec/frontend/clusters_list/store/actions_spec.js63
-rw-r--r--spec/frontend/clusters_list/store/mutations_spec.js60
2 files changed, 113 insertions, 10 deletions
diff --git a/spec/frontend/clusters_list/store/actions_spec.js b/spec/frontend/clusters_list/store/actions_spec.js
index 74e351a3704..c8556350747 100644
--- a/spec/frontend/clusters_list/store/actions_spec.js
+++ b/spec/frontend/clusters_list/store/actions_spec.js
@@ -13,6 +13,28 @@ import * as Sentry from '@sentry/browser';
jest.mock('~/flash.js');
describe('Clusters store actions', () => {
+ let captureException;
+
+ describe('reportSentryError', () => {
+ beforeEach(() => {
+ captureException = jest.spyOn(Sentry, 'captureException');
+ });
+
+ afterEach(() => {
+ captureException.mockRestore();
+ });
+
+ it('should report sentry error', done => {
+ const sentryError = new Error('New Sentry Error');
+ const tag = 'sentryErrorTag';
+
+ testAction(actions.reportSentryError, { error: sentryError, tag }, {}, [], [], () => {
+ expect(captureException).toHaveBeenCalledWith(sentryError);
+ done();
+ });
+ });
+ });
+
describe('fetchClusters', () => {
let mock;
@@ -48,8 +70,9 @@ describe('Clusters store actions', () => {
{ endpoint: apiData.endpoint },
{},
[
+ { type: types.SET_LOADING_NODES, payload: true },
{ type: types.SET_CLUSTERS_DATA, payload: { data: apiData, paginationInformation } },
- { type: types.SET_LOADING_STATE, payload: false },
+ { type: types.SET_LOADING_CLUSTERS, payload: false },
],
[],
() => done(),
@@ -63,8 +86,20 @@ describe('Clusters store actions', () => {
actions.fetchClusters,
{ endpoint: apiData.endpoint },
{},
- [{ type: types.SET_LOADING_STATE, payload: false }],
- [],
+ [
+ { type: types.SET_LOADING_NODES, payload: true },
+ { type: types.SET_LOADING_CLUSTERS, payload: false },
+ { type: types.SET_LOADING_NODES, payload: false },
+ ],
+ [
+ {
+ type: 'reportSentryError',
+ payload: {
+ error: new Error('Request failed with status code 400'),
+ tag: 'fetchClustersErrorCallback',
+ },
+ },
+ ],
() => {
expect(flashError).toHaveBeenCalledWith(expect.stringMatching('error'));
done();
@@ -73,7 +108,6 @@ describe('Clusters store actions', () => {
});
describe('multiple api requests', () => {
- let captureException;
let pollRequest;
let pollStop;
@@ -81,7 +115,6 @@ describe('Clusters store actions', () => {
const pollHeaders = { 'poll-interval': pollInterval, ...headers };
beforeEach(() => {
- captureException = jest.spyOn(Sentry, 'captureException');
pollRequest = jest.spyOn(Poll.prototype, 'makeRequest');
pollStop = jest.spyOn(Poll.prototype, 'stop');
@@ -89,7 +122,6 @@ describe('Clusters store actions', () => {
});
afterEach(() => {
- captureException.mockRestore();
pollRequest.mockRestore();
pollStop.mockRestore();
});
@@ -100,8 +132,9 @@ describe('Clusters store actions', () => {
{ endpoint: apiData.endpoint },
{},
[
+ { type: types.SET_LOADING_NODES, payload: true },
{ type: types.SET_CLUSTERS_DATA, payload: { data: apiData, paginationInformation } },
- { type: types.SET_LOADING_STATE, payload: false },
+ { type: types.SET_LOADING_CLUSTERS, payload: false },
],
[],
() => {
@@ -149,17 +182,27 @@ describe('Clusters store actions', () => {
{ endpoint: apiData.endpoint },
{},
[
+ { type: types.SET_LOADING_NODES, payload: true },
{
type: types.SET_CLUSTERS_DATA,
payload: { data: badApiResponse, paginationInformation },
},
- { type: types.SET_LOADING_STATE, payload: false },
+ { type: types.SET_LOADING_CLUSTERS, payload: false },
+ { type: types.SET_LOADING_CLUSTERS, payload: false },
+ { type: types.SET_LOADING_NODES, payload: false },
+ ],
+ [
+ {
+ type: 'reportSentryError',
+ payload: {
+ error: new Error('clusters.every is not a function'),
+ tag: 'fetchClustersSuccessCallback',
+ },
+ },
],
- [],
() => {
expect(pollRequest).toHaveBeenCalledTimes(1);
expect(pollStop).toHaveBeenCalledTimes(1);
- expect(captureException).toHaveBeenCalledTimes(1);
done();
},
);
diff --git a/spec/frontend/clusters_list/store/mutations_spec.js b/spec/frontend/clusters_list/store/mutations_spec.js
new file mode 100644
index 00000000000..df0dfe587b6
--- /dev/null
+++ b/spec/frontend/clusters_list/store/mutations_spec.js
@@ -0,0 +1,60 @@
+import * as types from '~/clusters_list/store/mutation_types';
+import { apiData } from '../mock_data';
+import getInitialState from '~/clusters_list/store/state';
+import mutations from '~/clusters_list/store/mutations';
+
+describe('Admin statistics panel mutations', () => {
+ let state;
+
+ const paginationInformation = {
+ nextPage: 1,
+ page: 1,
+ perPage: 20,
+ previousPage: 1,
+ total: apiData.clusters.length,
+ totalPages: 1,
+ };
+
+ beforeEach(() => {
+ state = getInitialState();
+ });
+
+ describe(`${types.SET_CLUSTERS_DATA}`, () => {
+ it('sets clusters and pagination values', () => {
+ mutations[types.SET_CLUSTERS_DATA](state, { data: apiData, paginationInformation });
+
+ expect(state.clusters).toBe(apiData.clusters);
+ expect(state.clustersPerPage).toBe(paginationInformation.perPage);
+ expect(state.hasAncestorClusters).toBe(apiData.has_ancestor_clusters);
+ expect(state.totalCulsters).toBe(paginationInformation.total);
+ });
+ });
+
+ describe(`${types.SET_LOADING_CLUSTERS}`, () => {
+ it('sets value to false', () => {
+ expect(state.loadingClusters).toBe(true);
+
+ mutations[types.SET_LOADING_CLUSTERS](state, false);
+
+ expect(state.loadingClusters).toBe(false);
+ });
+ });
+
+ describe(`${types.SET_LOADING_NODES}`, () => {
+ it('sets value to false', () => {
+ expect(state.loadingNodes).toBe(true);
+
+ mutations[types.SET_LOADING_NODES](state, false);
+
+ expect(state.loadingNodes).toBe(false);
+ });
+ });
+
+ describe(`${types.SET_PAGE}`, () => {
+ it('changes page value', () => {
+ mutations[types.SET_PAGE](state, 123);
+
+ expect(state.page).toBe(123);
+ });
+ });
+});