From f24c65f3eaed01befb8185c068f0a47266887b9a Mon Sep 17 00:00:00 2001 From: Larry Gregory Date: Tue, 17 Dec 2019 09:26:45 -0500 Subject: [PATCH] cleanup react warnings --- .../edit_role/components/edit_role_page.tsx | 2 +- .../simple_privilege_section.test.tsx | 1 + .../advanced_settings_subtitle.test.tsx | 11 +-- .../advanced_settings_title.test.tsx | 11 ++- .../copy_to_space_flyout.test.tsx | 75 +++++++++---------- .../enabled_features.test.tsx.snap | 2 + .../enabled_features.test.tsx | 2 + .../edit_space/manage_space_page.test.tsx | 2 +- .../views/nav_control/nav_control_popover.tsx | 2 +- 9 files changed, 58 insertions(+), 50 deletions(-) diff --git a/x-pack/legacy/plugins/security/public/views/management/edit_role/components/edit_role_page.tsx b/x-pack/legacy/plugins/security/public/views/management/edit_role/components/edit_role_page.tsx index 7637d28dd4229..2ba012afa689d 100644 --- a/x-pack/legacy/plugins/security/public/views/management/edit_role/components/edit_role_page.tsx +++ b/x-pack/legacy/plugins/security/public/views/management/edit_role/components/edit_role_page.tsx @@ -86,7 +86,7 @@ class EditRolePageUI extends Component { }; } - public UNSAFE_componentWillMount() { + public componentDidMount() { if (this.props.action === 'clone' && isReservedRole(this.props.role)) { this.backToRoleList(); } diff --git a/x-pack/legacy/plugins/security/public/views/management/edit_role/components/privileges/kibana/simple_privilege_section/simple_privilege_section.test.tsx b/x-pack/legacy/plugins/security/public/views/management/edit_role/components/privileges/kibana/simple_privilege_section/simple_privilege_section.test.tsx index 1f29f774fd6cc..f97fa93294ff5 100644 --- a/x-pack/legacy/plugins/security/public/views/management/edit_role/components/privileges/kibana/simple_privilege_section/simple_privilege_section.test.tsx +++ b/x-pack/legacy/plugins/security/public/views/management/edit_role/components/privileges/kibana/simple_privilege_section/simple_privilege_section.test.tsx @@ -46,6 +46,7 @@ const buildProps = (customProps: any = {}) => { id: 'feature1', name: 'Feature 1', app: ['app'], + icon: 'spacesApp', privileges: { all: { app: ['app'], diff --git a/x-pack/legacy/plugins/spaces/public/views/management/components/advanced_settings_subtitle/advanced_settings_subtitle.test.tsx b/x-pack/legacy/plugins/spaces/public/views/management/components/advanced_settings_subtitle/advanced_settings_subtitle.test.tsx index 49f5233db44e2..7134049c4cf8f 100644 --- a/x-pack/legacy/plugins/spaces/public/views/management/components/advanced_settings_subtitle/advanced_settings_subtitle.test.tsx +++ b/x-pack/legacy/plugins/spaces/public/views/management/components/advanced_settings_subtitle/advanced_settings_subtitle.test.tsx @@ -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 () => { @@ -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); }); diff --git a/x-pack/legacy/plugins/spaces/public/views/management/components/advanced_settings_title/advanced_settings_title.test.tsx b/x-pack/legacy/plugins/spaces/public/views/management/components/advanced_settings_title/advanced_settings_title.test.tsx index 7f2b6eee62c45..bf792ca2cdacf 100644 --- a/x-pack/legacy/plugins/spaces/public/views/management/components/advanced_settings_title/advanced_settings_title.test.tsx +++ b/x-pack/legacy/plugins/spaces/public/views/management/components/advanced_settings_title/advanced_settings_title.test.tsx @@ -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 () => { @@ -20,9 +21,11 @@ describe('AdvancedSettingsTitle', () => { Promise.resolve(space)} /> ); - await Promise.resolve(); - await Promise.resolve(); - wrapper.update(); + await act(async () => { + await nextTick(); + wrapper.update(); + }); + expect(wrapper.find(SpaceAvatar)).toHaveLength(1); }); }); diff --git a/x-pack/legacy/plugins/spaces/public/views/management/components/copy_saved_objects_to_space/copy_to_space_flyout.test.tsx b/x-pack/legacy/plugins/spaces/public/views/management/components/copy_saved_objects_to_space/copy_to_space_flyout.test.tsx index 590c0edc0073b..b3fd345b1d2b4 100644 --- a/x-pack/legacy/plugins/spaces/public/views/management/components/copy_saved_objects_to_space/copy_to_space_flyout.test.tsx +++ b/x-pack/legacy/plugins/spaces/public/views/management/components/copy_saved_objects_to_space/copy_to_space_flyout.test.tsx @@ -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'; @@ -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 }; @@ -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); @@ -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(); }); @@ -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(); @@ -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(); }); @@ -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'], @@ -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); @@ -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 }], { @@ -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); diff --git a/x-pack/legacy/plugins/spaces/public/views/management/edit_space/enabled_features/__snapshots__/enabled_features.test.tsx.snap b/x-pack/legacy/plugins/spaces/public/views/management/edit_space/enabled_features/__snapshots__/enabled_features.test.tsx.snap index 5e91c1bd0e36c..5879ff621d64a 100644 --- a/x-pack/legacy/plugins/spaces/public/views/management/edit_space/enabled_features/__snapshots__/enabled_features.test.tsx.snap +++ b/x-pack/legacy/plugins/spaces/public/views/management/edit_space/enabled_features/__snapshots__/enabled_features.test.tsx.snap @@ -190,12 +190,14 @@ exports[`EnabledFeatures renders as expected 1`] = ` Array [ Object { "app": Array [], + "icon": "spacesApp", "id": "feature-1", "name": "Feature 1", "privileges": Object {}, }, Object { "app": Array [], + "icon": "spacesApp", "id": "feature-2", "name": "Feature 2", "privileges": Object {}, diff --git a/x-pack/legacy/plugins/spaces/public/views/management/edit_space/enabled_features/enabled_features.test.tsx b/x-pack/legacy/plugins/spaces/public/views/management/edit_space/enabled_features/enabled_features.test.tsx index 8f82e6d413350..f8bd4b889394a 100644 --- a/x-pack/legacy/plugins/spaces/public/views/management/edit_space/enabled_features/enabled_features.test.tsx +++ b/x-pack/legacy/plugins/spaces/public/views/management/edit_space/enabled_features/enabled_features.test.tsx @@ -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: {}, }, diff --git a/x-pack/legacy/plugins/spaces/public/views/management/edit_space/manage_space_page.test.tsx b/x-pack/legacy/plugins/spaces/public/views/management/edit_space/manage_space_page.test.tsx index 1597e4684222c..c69a885ae0587 100644 --- a/x-pack/legacy/plugins/spaces/public/views/management/edit_space/manage_space_page.test.tsx +++ b/x-pack/legacy/plugins/spaces/public/views/management/edit_space/manage_space_page.test.tsx @@ -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'; diff --git a/x-pack/legacy/plugins/spaces/public/views/nav_control/nav_control_popover.tsx b/x-pack/legacy/plugins/spaces/public/views/nav_control/nav_control_popover.tsx index 98ce64715f325..b37458aace2a2 100644 --- a/x-pack/legacy/plugins/spaces/public/views/nav_control/nav_control_popover.tsx +++ b/x-pack/legacy/plugins/spaces/public/views/nav_control/nav_control_popover.tsx @@ -45,7 +45,7 @@ export class NavControlPopover extends Component { }; } - public componentWillMount() { + public componentDidMount() { this.activeSpace$ = this.props.spacesManager.onActiveSpaceChange$.subscribe({ next: activeSpace => { this.setState({