From 5cdb0153dc3e00a2f93760b0c598584a87c96ae6 Mon Sep 17 00:00:00 2001 From: Yuliia Naumenko Date: Tue, 3 Mar 2020 13:40:51 -0800 Subject: [PATCH] Fixed test (#59208) --- .../sections/alert_add/alert_add.test.tsx | 74 ++++++------------- 1 file changed, 24 insertions(+), 50 deletions(-) diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_add/alert_add.test.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_add/alert_add.test.tsx index cc3b15d37471..d52ca19f5802 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_add/alert_add.test.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_add/alert_add.test.tsx @@ -4,13 +4,12 @@ * you may not use this file except in compliance with the Elastic License. */ import * as React from 'react'; -import { mountWithIntl } from 'test_utils/enzyme_helpers'; +import { mountWithIntl, nextTick } from 'test_utils/enzyme_helpers'; import { act } from 'react-dom/test-utils'; import { coreMock } from '../../../../../../../src/core/public/mocks'; import { AlertAdd } from './alert_add'; import { actionTypeRegistryMock } from '../../action_type_registry.mock'; import { ValidationResult } from '../../../types'; -import { AppDeps } from '../../app'; import { AlertsContextProvider } from '../../context/alerts_context'; import { alertTypeRegistryMock } from '../../alert_type_registry.mock'; import { chartPluginMock } from '../../../../../../../src/plugins/charts/public/mocks'; @@ -19,38 +18,19 @@ import { ReactWrapper } from 'enzyme'; const actionTypeRegistry = actionTypeRegistryMock.create(); const alertTypeRegistry = alertTypeRegistryMock.create(); -// FLAKY: https://github.com/elastic/kibana/issues/58970 -describe.skip('alert_add', () => { - let deps: AppDeps | null; +describe('alert_add', () => { + let deps: any; let wrapper: ReactWrapper; async function setup() { const mockes = coreMock.createSetup(); - const [ - { - chrome, - docLinks, - application: { capabilities }, - }, - ] = await mockes.getStartServices(); deps = { - chrome, - docLinks, toastNotifications: mockes.notifications.toasts, injectedMetadata: mockes.injectedMetadata, http: mockes.http, uiSettings: mockes.uiSettings, dataPlugin: dataPluginMock.createStartContract(), charts: chartPluginMock.createStartContract(), - capabilities: { - ...capabilities, - alerting: { - delete: true, - save: true, - show: true, - }, - }, - setBreadcrumbs: jest.fn(), actionTypeRegistry: actionTypeRegistry as any, alertTypeRegistry: alertTypeRegistry as any, }; @@ -86,29 +66,29 @@ describe.skip('alert_add', () => { actionTypeRegistry.list.mockReturnValue([actionTypeModel]); actionTypeRegistry.has.mockReturnValue(true); + wrapper = mountWithIntl( + {}, + reloadAlerts: () => { + return new Promise(() => {}); + }, + http: deps.http, + actionTypeRegistry: deps.actionTypeRegistry, + alertTypeRegistry: deps.alertTypeRegistry, + toastNotifications: deps.toastNotifications, + uiSettings: deps.uiSettings, + }} + > + + + ); + // Wait for active space to resolve before requesting the component to update await act(async () => { - if (deps) { - wrapper = mountWithIntl( - {}, - reloadAlerts: () => { - return new Promise(() => {}); - }, - http: deps.http, - actionTypeRegistry: deps.actionTypeRegistry, - alertTypeRegistry: deps.alertTypeRegistry, - toastNotifications: deps.toastNotifications, - uiSettings: deps.uiSettings, - }} - > - - - ); - } + await nextTick(); + wrapper.update(); }); - await waitForRender(wrapper); } it('renders alert add flyout', async () => { @@ -117,9 +97,3 @@ describe.skip('alert_add', () => { expect(wrapper.find('[data-test-subj="saveAlertButton"]').exists()).toBeTruthy(); }); }); - -async function waitForRender(wrapper: ReactWrapper) { - await Promise.resolve(); - await Promise.resolve(); - wrapper.update(); -}