Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Remote clusters] Reorganize test files #82362

Merged
merged 5 commits into from
Nov 3, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
'#',
'@',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
};
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,8 +27,7 @@ describe('<RemoteClusterList />', () => {
});

beforeEach(() => {
// Set "default" mock responses by not providing any arguments
httpRequestsMockHelpers.setLoadRemoteClustersResponse();
httpRequestsMockHelpers.setLoadRemoteClustersResponse([]);
});

describe('on component mount', () => {
Expand All @@ -56,7 +49,7 @@ describe('<RemoteClusterList />', () => {
beforeEach(async () => {
({ exists, component } = setup());

await nextTick(100); // We need to wait next tick for the mock server response to kick in
// await nextTick(100); // We need to wait next tick for the mock server response to kick in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you uncomment this line for now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, that was a leftover!

component.update();
});

Expand Down