Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth committed Feb 12, 2020
1 parent 87909a2 commit 58b03ed
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
*/

import { registerTestBed } from '../../../../../test_utils';

/* eslint-disable @kbn/eslint/no-restricted-paths */
import { RemoteClusterAdd } from '../../../public/app/sections/remote_cluster_add';
import { createRemoteClustersStore } from '../../../public/app/store';
import { registerRouter } from '../../../public/app/services/routing';
/* eslint-disable @kbn/eslint/no-restricted-paths */

const testBedConfig = {
store: createRemoteClustersStore,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { registerTestBed } from '../../../../../test_utils';
import { RemoteClusterEdit } from '../../../public/app/sections/remote_cluster_edit';
import { createRemoteClustersStore } from '../../../public/app/store';
import { registerRouter } from '../../../public/app/services/routing';
/* eslint-disable @kbn/eslint/no-restricted-paths */

import { REMOTE_CLUSTER_EDIT_NAME } from './constants';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { registerTestBed, findTestSubject } from '../../../../../test_utils';
import { RemoteClusterList } from '../../../public/app/sections/remote_cluster_list';
import { createRemoteClustersStore } from '../../../public/app/store';
import { registerRouter } from '../../../public/app/services/routing';
/* eslint-disable @kbn/eslint/no-restricted-paths */

const testBedConfig = {
store: createRemoteClustersStore,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,40 @@
* you may not use this file except in compliance with the Elastic License.
*/

import axios from 'axios';
import axiosXhrAdapter from 'axios/lib/adapters/xhr';
import chrome from 'ui/chrome'; // eslint-disable-line import/no-unresolved
import { MANAGEMENT_BREADCRUMB } from 'ui/management'; // eslint-disable-line import/no-unresolved
import { fatalError, toastNotifications } from 'ui/notify'; // eslint-disable-line import/no-unresolved
import {
notificationServiceMock,
fatalErrorsServiceMock,
docLinksServiceMock,
injectedMetadataServiceMock,
} from '../../../../../../src/core/public/mocks';

import { usageCollectionPluginMock } from '../../../../../../src/plugins/usage_collection/public/mocks';

// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { HttpService } from '../../../../../../src/core/public/http';

/* eslint-disable @kbn/eslint/no-restricted-paths */
import { init as initBreadcrumb } from '../../../public/app/services/breadcrumb';
import { init as initHttp } from '../../../public/app/services/http';
import { init as initNotification } from '../../../public/app/services/notification';
import { init as initUiMetric } from '../../../public/app/services/ui_metric';
/* eslint-disable @kbn/eslint/no-restricted-paths */
import { init as initDocumentation } from '../../../public/app/services/documentation';
import { init as initHttpRequests } from './http_requests';

export const setupEnvironment = () => {
chrome.breadcrumbs = {
set: () => {},
};
// axios has a $http like interface so using it to simulate $http
initHttp(axios.create({ adapter: axiosXhrAdapter }), path => path);
initBreadcrumb(() => {}, MANAGEMENT_BREADCRUMB);
initNotification(toastNotifications, fatalError);
initUiMetric(() => () => {});
const httpServiceSetupMock = new HttpService().setup({
injectedMetadata: injectedMetadataServiceMock.createSetupContract(),
fatalErrors: fatalErrorsServiceMock.createSetupContract(),
});

initBreadcrumb(() => {});
initDocumentation(docLinksServiceMock.createStartContract());
initUiMetric(usageCollectionPluginMock.createSetupContract());
initNotification(
notificationServiceMock.createSetupContract().toasts,
fatalErrorsServiceMock.createSetupContract()
);
initHttp(httpServiceSetupMock);

const { server, httpRequestsMockHelpers } = initHttpRequests();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe('Create Remote cluster', () => {
beforeEach(async () => {
({ component, form, actions } = setup());

await nextTick();
await nextTick(100);
component.update();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('Edit Remote cluster', () => {
httpRequestsMockHelpers.setLoadRemoteClustersResponse([REMOTE_CLUSTER_EDIT]);

({ component, find, exists } = setup());
await nextTick();
await nextTick(100);
component.update();
});

Expand All @@ -52,7 +52,7 @@ describe('Edit Remote cluster', () => {
test('should use the same Form component as the "<RemoteClusterEdit />" component', async () => {
const { component: addRemoteClusterComponent } = setupRemoteClustersAdd();

await nextTick();
await nextTick(100);
addRemoteClusterComponent.update();

const formEdit = component.find(RemoteClusterForm);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ describe('<RemoteClusterList />', () => {
describe('on component mount', () => {
let exists;

beforeEach(async () => {
beforeEach(() => {
({ exists } = setup());
});

test('should show a "loading remote clusters" indicator', async () => {
test('should show a "loading remote clusters" indicator', () => {
expect(exists('remoteClustersTableLoading')).toBe(true);
});
});
Expand All @@ -55,7 +55,7 @@ describe('<RemoteClusterList />', () => {
beforeEach(async () => {
({ exists, component } = setup());

await nextTick(); // 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
component.update();
});

Expand Down Expand Up @@ -97,7 +97,7 @@ describe('<RemoteClusterList />', () => {
// Mount the component
({ component, find, exists, table, actions } = setup());

await nextTick(); // Make sure that the Http request is fulfilled
await nextTick(100); // Make sure that the Http request is fulfilled
component.update();

// Read the remote clusters list table
Expand Down Expand Up @@ -206,7 +206,7 @@ describe('<RemoteClusterList />', () => {
actions.clickBulkDeleteButton();
actions.clickConfirmModalDeleteRemoteCluster();

await nextTick(550); // there is a 500ms timeout in the api action
await nextTick(600); // there is a 500ms timeout in the api action
component.update();

({ rows } = table.getMetaData('remoteClusterListTable'));
Expand Down

0 comments on commit 58b03ed

Please sign in to comment.