From 8325b0d01451bce2ddbe1418fbb751a744eff96d Mon Sep 17 00:00:00 2001 From: Julian Gernun <17549662+jcger@users.noreply.github.com> Date: Fri, 5 May 2023 17:04:20 +0200 Subject: [PATCH] Fix skipped Bulk Actions in Alerts Table tests (#156795) ## Summary Fixes https://github.com/elastic/kibana/issues/154970 Fixes https://github.com/elastic/kibana/issues/152176 Run times before: ![Screenshot 12](https://user-images.githubusercontent.com/17549662/236402240-5be77baa-c35b-44f2-bbe1-f49d7cd6accc.png) Run times after: ![Screenshot](https://user-images.githubusercontent.com/17549662/236402290-0d7377b2-1db3-4c62-8164-ff40358aea63.png) --- .../bulk_actions/bulk_actions.test.tsx | 51 +++++++++++++++++-- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_table/bulk_actions/bulk_actions.test.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_table/bulk_actions/bulk_actions.test.tsx index 23fac59fca2081..e1b630d56a5d7a 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_table/bulk_actions/bulk_actions.test.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_table/bulk_actions/bulk_actions.test.tsx @@ -61,7 +61,44 @@ jest.mock('@kbn/kibana-react-plugin/public', () => { }; }); +const originalGetComputedStyle = Object.assign({}, window.getComputedStyle); + describe('AlertsTable.BulkActions', () => { + beforeAll(() => { + // The JSDOM implementation is too slow + // Especially for dropdowns that try to position themselves + // perf issue - https://github.com/jsdom/jsdom/issues/3234 + Object.defineProperty(window, 'getComputedStyle', { + value: (el: HTMLElement) => { + /** + * This is based on the jsdom implementation of getComputedStyle + * https://github.com/jsdom/jsdom/blob/9dae17bf0ad09042cfccd82e6a9d06d3a615d9f4/lib/jsdom/browser/Window.js#L779-L820 + * + * It is missing global style parsing and will only return styles applied directly to an element. + * Will not return styles that are global or from emotion + */ + const declaration = new CSSStyleDeclaration(); + const { style } = el; + + Array.prototype.forEach.call(style, (property: string) => { + declaration.setProperty( + property, + style.getPropertyValue(property), + style.getPropertyPriority(property) + ); + }); + + return declaration; + }, + configurable: true, + writable: true, + }); + }); + + afterAll(() => { + Object.defineProperty(window, 'getComputedStyle', originalGetComputedStyle); + }); + const alerts = [ { [AlertsField.name]: ['one'], @@ -691,8 +728,7 @@ describe('AlertsTable.BulkActions', () => { ).toBeTruthy(); }); - // FLAKY: https://github.com/elastic/kibana/issues/154970 - describe.skip('and clear the selection is clicked', () => { + describe('and clear the selection is clicked', () => { it('should turn off the toolbar', async () => { const props = { ...tablePropsWithBulkActions, @@ -731,8 +767,7 @@ describe('AlertsTable.BulkActions', () => { }); }); - // FLAKY: https://github.com/elastic/kibana/issues/152176 - describe.skip('and executing a bulk action', () => { + describe('and executing a bulk action', () => { it('should return the are all selected flag set to true', async () => { const mockedFn = jest.fn(); const props = { @@ -781,6 +816,10 @@ describe('AlertsTable.BulkActions', () => { field: 'kibana.alert.rule.uuid', value: ['uuidone'], }, + { + field: 'kibana.alert.case_ids', + value: [], + }, ], ecs: { _id: 'alert0', @@ -799,6 +838,10 @@ describe('AlertsTable.BulkActions', () => { field: 'kibana.alert.rule.uuid', value: ['uuidtwo'], }, + { + field: 'kibana.alert.case_ids', + value: [], + }, ], ecs: { _id: 'alert1',