Skip to content

Commit

Permalink
cleanup react warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
legrego committed Dec 17, 2019
1 parent 2b1cb06 commit f24c65f
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class EditRolePageUI extends Component<Props, State> {
};
}

public UNSAFE_componentWillMount() {
public componentDidMount() {
if (this.props.action === 'clone' && isReservedRole(this.props.role)) {
this.backToRoleList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const buildProps = (customProps: any = {}) => {
id: 'feature1',
name: 'Feature 1',
app: ['app'],
icon: 'spacesApp',
privileges: {
all: {
app: ['app'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
* you may not use this file except in compliance with the Elastic License.
*/
import React from 'react';
import { mountWithIntl } from 'test_utils/enzyme_helpers';
import { mountWithIntl, nextTick } from 'test_utils/enzyme_helpers';
import { AdvancedSettingsSubtitle } from './advanced_settings_subtitle';
import { EuiCallOut } from '@elastic/eui';
import { act } from '@testing-library/react';

describe('AdvancedSettingsSubtitle', () => {
it('renders as expected', async () => {
Expand All @@ -21,10 +22,10 @@ describe('AdvancedSettingsSubtitle', () => {
);

// Wait for active space to resolve before requesting the component to update
await Promise.resolve();
await Promise.resolve();

wrapper.update();
await act(async () => {
await nextTick();
wrapper.update();
});

expect(wrapper.find(EuiCallOut)).toHaveLength(1);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
* you may not use this file except in compliance with the Elastic License.
*/
import React from 'react';
import { mountWithIntl } from 'test_utils/enzyme_helpers';
import { mountWithIntl, nextTick } from 'test_utils/enzyme_helpers';
import { AdvancedSettingsTitle } from './advanced_settings_title';
import { SpaceAvatar } from '../../../../components';
import { act } from '@testing-library/react';

describe('AdvancedSettingsTitle', () => {
it('renders without crashing', async () => {
Expand All @@ -20,9 +21,11 @@ describe('AdvancedSettingsTitle', () => {
<AdvancedSettingsTitle getActiveSpace={() => Promise.resolve(space)} />
);

await Promise.resolve();
await Promise.resolve();
wrapper.update();
await act(async () => {
await nextTick();
wrapper.update();
});

expect(wrapper.find(SpaceAvatar)).toHaveLength(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
import React from 'react';
import Boom from 'boom';
import { mountWithIntl } from 'test_utils/enzyme_helpers';
import { mountWithIntl, nextTick } from 'test_utils/enzyme_helpers';
import { mockManagementPlugin } from '../../../../../../../../../src/legacy/core_plugins/management/public/np_ready/mocks';
import { CopySavedObjectsToSpaceFlyout } from './copy_to_space_flyout';
import { CopyToSpaceForm } from './copy_to_space_form';
Expand Down Expand Up @@ -93,9 +93,10 @@ const setup = async (opts: SetupOpts = {}) => {

if (!opts.returnBeforeSpacesLoad) {
// Wait for spaces manager to complete and flyout to rerender
await Promise.resolve();
await Promise.resolve();
wrapper.update();
await act(async () => {
await nextTick();
wrapper.update();
});
}

return { wrapper, onClose, mockSpacesManager, mockToastNotifications, savedObjectToCopy };
Expand All @@ -113,8 +114,10 @@ describe('CopyToSpaceFlyout', () => {
expect(wrapper.find(EuiEmptyPrompt)).toHaveLength(0);
expect(wrapper.find(EuiLoadingSpinner)).toHaveLength(1);

await Promise.resolve();
wrapper.update();
await act(async () => {
await nextTick();
wrapper.update();
});

expect(wrapper.find(CopyToSpaceForm)).toHaveLength(1);
expect(wrapper.find(EuiLoadingSpinner)).toHaveLength(0);
Expand Down Expand Up @@ -160,14 +163,13 @@ describe('CopyToSpaceFlyout', () => {
});

const startButton = findTestSubject(wrapper, 'cts-initiate-button');
act(() => {

await act(async () => {
startButton.simulate('click');
await nextTick();
wrapper.update();
});

await Promise.resolve();

wrapper.update();

expect(mockSpacesManager.copySavedObjects).toHaveBeenCalled();
expect(mockToastNotifications.addError).toHaveBeenCalled();
});
Expand Down Expand Up @@ -214,13 +216,13 @@ describe('CopyToSpaceFlyout', () => {
});

const startButton = findTestSubject(wrapper, 'cts-initiate-button');
act(() => {

await act(async () => {
startButton.simulate('click');
await nextTick();
wrapper.update();
});

await Promise.resolve();
wrapper.update();

expect(mockSpacesManager.copySavedObjects).toHaveBeenCalled();
expect(mockToastNotifications.addError).not.toHaveBeenCalled();

Expand All @@ -231,13 +233,13 @@ describe('CopyToSpaceFlyout', () => {
overwriteButton.simulate('click');

const finishButton = findTestSubject(wrapper, 'cts-finish-button');
act(() => {

await act(async () => {
finishButton.simulate('click');
await nextTick();
wrapper.update();
});

await Promise.resolve();
wrapper.update();

expect(mockSpacesManager.resolveCopySavedObjectsErrors).toHaveBeenCalled();
expect(mockToastNotifications.addError).toHaveBeenCalled();
});
Expand Down Expand Up @@ -275,14 +277,13 @@ describe('CopyToSpaceFlyout', () => {
});

const startButton = findTestSubject(wrapper, 'cts-initiate-button');
act(() => {

await act(async () => {
startButton.simulate('click');
await nextTick();
wrapper.update();
});

await Promise.resolve();

wrapper.update();

expect(mockSpacesManager.copySavedObjects).toHaveBeenCalledWith(
[{ type: savedObjectToCopy.type, id: savedObjectToCopy.id }],
['space-1', 'space-2'],
Expand Down Expand Up @@ -350,14 +351,13 @@ describe('CopyToSpaceFlyout', () => {
});

const startButton = findTestSubject(wrapper, 'cts-initiate-button');
act(() => {

await act(async () => {
startButton.simulate('click');
await nextTick();
wrapper.update();
});

await Promise.resolve();

wrapper.update();

expect(wrapper.find(CopyToSpaceForm)).toHaveLength(0);
expect(wrapper.find(ProcessingCopyToSpace)).toHaveLength(1);

Expand All @@ -368,13 +368,13 @@ describe('CopyToSpaceFlyout', () => {
overwriteButton.simulate('click');

const finishButton = findTestSubject(wrapper, 'cts-finish-button');
act(() => {

await act(async () => {
finishButton.simulate('click');
await nextTick();
wrapper.update();
});

await Promise.resolve();
wrapper.update();

expect(mockSpacesManager.resolveCopySavedObjectsErrors).toHaveBeenCalledWith(
[{ type: savedObjectToCopy.type, id: savedObjectToCopy.id }],
{
Expand Down Expand Up @@ -420,14 +420,13 @@ describe('CopyToSpaceFlyout', () => {
});

const startButton = findTestSubject(wrapper, 'cts-initiate-button');
act(() => {

await act(async () => {
startButton.simulate('click');
await nextTick();
wrapper.update();
});

await Promise.resolve();

wrapper.update();

expect(wrapper.find(CopyToSpaceForm)).toHaveLength(0);
expect(wrapper.find(ProcessingCopyToSpace)).toHaveLength(1);

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ const features: Feature[] = [
{
id: 'feature-1',
name: 'Feature 1',
icon: 'spacesApp',
app: [],
privileges: {},
},
{
id: 'feature-2',
name: 'Feature 2',
icon: 'spacesApp',
app: [],
privileges: {},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
jest.mock('ui/kfetch', () => ({
kfetch: () => Promise.resolve([{ id: 'feature-1', name: 'feature 1' }]),
kfetch: () => Promise.resolve([{ id: 'feature-1', name: 'feature 1', icon: 'spacesApp' }]),
}));
import '../../../__mocks__/xpack_info';
import { EuiButton, EuiLink, EuiSwitch } from '@elastic/eui';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class NavControlPopover extends Component<Props, State> {
};
}

public componentWillMount() {
public componentDidMount() {
this.activeSpace$ = this.props.spacesManager.onActiveSpaceChange$.subscribe({
next: activeSpace => {
this.setState({
Expand Down

0 comments on commit f24c65f

Please sign in to comment.