mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[Remote clusters] Reorganize test files (#82362)
* Refactor Remote Clusters client integration tests for readability. - Colocate helpers with test files. - Remove default API responses from HTTP response mocking functions to make behavior clearer at call sites.
This commit is contained in:
parent
adf0e249c7
commit
b770e82106
9 changed files with 28 additions and 54 deletions
|
@ -4,10 +4,9 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { pageHelpers, nextTick, setupEnvironment } from './helpers';
|
||||
import { NON_ALPHA_NUMERIC_CHARS, ACCENTED_CHARS } from './helpers/constants';
|
||||
|
||||
const { setup } = pageHelpers.remoteClustersAdd;
|
||||
import { nextTick, setupEnvironment } from '../helpers';
|
||||
import { NON_ALPHA_NUMERIC_CHARS, ACCENTED_CHARS } from './special_characters';
|
||||
import { setup } from './remote_clusters_add.helpers';
|
||||
|
||||
describe('Create Remote cluster', () => {
|
||||
describe('on component mount', () => {
|
|
@ -4,14 +4,6 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
export const REMOTE_CLUSTER_EDIT_NAME = 'new-york';
|
||||
|
||||
export const REMOTE_CLUSTER_EDIT = {
|
||||
name: REMOTE_CLUSTER_EDIT_NAME,
|
||||
seeds: ['localhost:9400'],
|
||||
skipUnavailable: true,
|
||||
};
|
||||
|
||||
export const NON_ALPHA_NUMERIC_CHARS = [
|
||||
'#',
|
||||
'@',
|
|
@ -11,7 +11,13 @@ import { RemoteClusterEdit } from '../../../public/application/sections/remote_c
|
|||
import { createRemoteClustersStore } from '../../../public/application/store';
|
||||
import { registerRouter } from '../../../public/application/services/routing';
|
||||
|
||||
import { REMOTE_CLUSTER_EDIT_NAME } from './constants';
|
||||
export const REMOTE_CLUSTER_EDIT_NAME = 'new-york';
|
||||
|
||||
export const REMOTE_CLUSTER_EDIT = {
|
||||
name: REMOTE_CLUSTER_EDIT_NAME,
|
||||
seeds: ['localhost:9400'],
|
||||
skipUnavailable: true,
|
||||
};
|
||||
|
||||
const testBedConfig = {
|
||||
store: createRemoteClustersStore,
|
|
@ -6,12 +6,14 @@
|
|||
|
||||
import { act } from 'react-dom/test-utils';
|
||||
|
||||
import { RemoteClusterForm } from '../../public/application/sections/components/remote_cluster_form';
|
||||
import { pageHelpers, setupEnvironment } from './helpers';
|
||||
import { REMOTE_CLUSTER_EDIT, REMOTE_CLUSTER_EDIT_NAME } from './helpers/constants';
|
||||
|
||||
const { setup } = pageHelpers.remoteClustersEdit;
|
||||
const { setup: setupRemoteClustersAdd } = pageHelpers.remoteClustersAdd;
|
||||
import { RemoteClusterForm } from '../../../public/application/sections/components/remote_cluster_form';
|
||||
import { setupEnvironment } from '../helpers';
|
||||
import { setup as setupRemoteClustersAdd } from '../add/remote_clusters_add.helpers';
|
||||
import {
|
||||
setup,
|
||||
REMOTE_CLUSTER_EDIT,
|
||||
REMOTE_CLUSTER_EDIT_NAME,
|
||||
} from './remote_clusters_edit.helpers';
|
||||
|
||||
describe('Edit Remote cluster', () => {
|
||||
let server;
|
|
@ -8,29 +8,22 @@ import sinon from 'sinon';
|
|||
|
||||
// Register helpers to mock HTTP Requests
|
||||
const registerHttpRequestMockHelpers = (server) => {
|
||||
const mockResponse = (defaultResponse, response) => [
|
||||
const mockResponse = (response) => [
|
||||
200,
|
||||
{ 'Content-Type': 'application/json' },
|
||||
JSON.stringify({ ...defaultResponse, ...response }),
|
||||
JSON.stringify(response),
|
||||
];
|
||||
|
||||
const setLoadRemoteClustersResponse = (response) => {
|
||||
const defaultResponse = [];
|
||||
|
||||
server.respondWith('GET', '/api/remote_clusters', [
|
||||
200,
|
||||
{ 'Content-Type': 'application/json' },
|
||||
JSON.stringify(response ? response : defaultResponse),
|
||||
JSON.stringify(response),
|
||||
]);
|
||||
};
|
||||
|
||||
const setDeleteRemoteClusterResponse = (response) => {
|
||||
const defaultResponse = {
|
||||
itemsDeleted: [],
|
||||
errors: [],
|
||||
};
|
||||
|
||||
server.respondWith('DELETE', /api\/remote_clusters/, mockResponse(defaultResponse, response));
|
||||
server.respondWith('DELETE', /api\/remote_clusters/, mockResponse(response));
|
||||
};
|
||||
|
||||
return {
|
||||
|
|
|
@ -4,16 +4,5 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { setup as remoteClustersAddSetup } from './remote_clusters_add.helpers';
|
||||
import { setup as remoteClustersEditSetup } from './remote_clusters_edit.helpers';
|
||||
import { setup as remoteClustersListSetup } from './remote_clusters_list.helpers';
|
||||
|
||||
export { nextTick, getRandomString, findTestSubject } from '../../../../../test_utils';
|
||||
|
||||
export { setupEnvironment } from './setup_environment';
|
||||
|
||||
export const pageHelpers = {
|
||||
remoteClustersAdd: { setup: remoteClustersAddSetup },
|
||||
remoteClustersEdit: { setup: remoteClustersEditSetup },
|
||||
remoteClustersList: { setup: remoteClustersListSetup },
|
||||
};
|
||||
|
|
|
@ -5,20 +5,14 @@
|
|||
*/
|
||||
import { act } from 'react-dom/test-utils';
|
||||
|
||||
import {
|
||||
pageHelpers,
|
||||
setupEnvironment,
|
||||
nextTick,
|
||||
getRandomString,
|
||||
findTestSubject,
|
||||
} from './helpers';
|
||||
import { getRouter } from '../../../public/application/services';
|
||||
import { getRemoteClusterMock } from '../../../fixtures/remote_cluster';
|
||||
|
||||
import { getRouter } from '../../public/application/services';
|
||||
import { getRemoteClusterMock } from '../../fixtures/remote_cluster';
|
||||
import { PROXY_MODE } from '../../../common/constants';
|
||||
|
||||
import { PROXY_MODE } from '../../common/constants';
|
||||
import { setupEnvironment, nextTick, getRandomString, findTestSubject } from '../helpers';
|
||||
|
||||
const { setup } = pageHelpers.remoteClustersList;
|
||||
import { setup } from './remote_clusters_list.helpers';
|
||||
|
||||
describe('<RemoteClusterList />', () => {
|
||||
let server;
|
||||
|
@ -33,8 +27,7 @@ describe('<RemoteClusterList />', () => {
|
|||
});
|
||||
|
||||
beforeEach(() => {
|
||||
// Set "default" mock responses by not providing any arguments
|
||||
httpRequestsMockHelpers.setLoadRemoteClustersResponse();
|
||||
httpRequestsMockHelpers.setLoadRemoteClustersResponse([]);
|
||||
});
|
||||
|
||||
describe('on component mount', () => {
|
Loading…
Add table
Add a link
Reference in a new issue