From b52a9c840d44f2beacd180c3d811db07d5654224 Mon Sep 17 00:00:00 2001 From: Bree Hall Date: Wed, 28 Sep 2022 20:07:56 -0400 Subject: [PATCH] Updated unit tests in Jest Test Suites 3, 7, 8, 13, and 14. Updated snapshot to account for EuiButton Emotion conversion. Updated tests that target EuiButton to simulate click events. These tests now target a generic button element to prevent undefined click event errors. Updated a few snapshots by adding .render() before checking the snapshot. This will prevent large snapshots coming from recent Emotion conversions --- .../collapsible_nav.test.tsx.snap | 10 +- .../header/__snapshots__/header.test.tsx.snap | 4 +- .../add_from_library.test.tsx.snap | 597 +----------------- .../add_from_library.test.tsx | 2 +- .../__snapshots__/primary.test.tsx.snap | 470 +------------- .../src/buttons/primary/primary.test.tsx | 4 +- .../__snapshots__/toolbar.test.tsx.snap | 215 +------ .../src/toolbar/toolbar.test.tsx | 2 +- .../components/delete_confirm_modal.test.tsx | 6 +- .../components/export_modal.test.tsx | 2 +- .../opted_in_notice_banner.test.tsx.snap | 1 + .../saved_query_management_list.test.tsx | 2 +- .../public/search_bar/search_bar.test.tsx | 6 +- .../field_type_icon/field_type_icon.test.tsx | 2 +- .../confirm_delete_modal.test.js | 2 +- .../__snapshots__/index.test.tsx.snap | 2 + .../components/policy_form_layout.test.tsx | 4 +- .../delete_spaces_button.test.tsx.snap | 1 + 18 files changed, 81 insertions(+), 1251 deletions(-) diff --git a/packages/core/chrome/core-chrome-browser-internal/src/ui/header/__snapshots__/collapsible_nav.test.tsx.snap b/packages/core/chrome/core-chrome-browser-internal/src/ui/header/__snapshots__/collapsible_nav.test.tsx.snap index 63e5e8dd748be..1475e5fbedd01 100644 --- a/packages/core/chrome/core-chrome-browser-internal/src/ui/header/__snapshots__/collapsible_nav.test.tsx.snap +++ b/packages/core/chrome/core-chrome-browser-internal/src/ui/header/__snapshots__/collapsible_nav.test.tsx.snap @@ -136,7 +136,7 @@ Array [ aria-controls="generated-id" aria-expanded="true" aria-labelledby="generated-id" - class="euiButtonIcon euiButtonIcon--text euiButtonIcon--empty euiButtonIcon--xSmall euiAccordion__iconButton euiAccordion__iconButton-isOpen euiAccordion__iconButton--right emotion-euiAccordion__iconButton-isOpen-arrowRight" + class="euiButtonIcon euiButtonIcon--xSmall euiAccordion__iconButton euiAccordion__iconButton-isOpen euiAccordion__iconButton--right emotion-euiButtonIcon-empty-text-hoverStyles-euiAccordion__iconButton-isOpen-arrowRight" tabindex="-1" type="button" > @@ -261,7 +261,7 @@ Array [ aria-controls="generated-id" aria-expanded="true" aria-labelledby="generated-id" - class="euiButtonIcon euiButtonIcon--text euiButtonIcon--empty euiButtonIcon--xSmall euiAccordion__iconButton euiAccordion__iconButton-isOpen euiAccordion__iconButton--right emotion-euiAccordion__iconButton-isOpen-arrowRight" + class="euiButtonIcon euiButtonIcon--xSmall euiAccordion__iconButton euiAccordion__iconButton-isOpen euiAccordion__iconButton--right emotion-euiButtonIcon-empty-text-hoverStyles-euiAccordion__iconButton-isOpen-arrowRight" tabindex="-1" type="button" > @@ -393,7 +393,7 @@ Array [ aria-controls="generated-id" aria-expanded="true" aria-labelledby="generated-id" - class="euiButtonIcon euiButtonIcon--text euiButtonIcon--empty euiButtonIcon--xSmall euiAccordion__iconButton euiAccordion__iconButton-isOpen euiAccordion__iconButton--right emotion-euiAccordion__iconButton-isOpen-arrowRight" + class="euiButtonIcon euiButtonIcon--xSmall euiAccordion__iconButton euiAccordion__iconButton-isOpen euiAccordion__iconButton--right emotion-euiButtonIcon-empty-text-hoverStyles-euiAccordion__iconButton-isOpen-arrowRight" tabindex="-1" type="button" > @@ -508,7 +508,7 @@ Array [ aria-controls="generated-id" aria-expanded="true" aria-labelledby="generated-id" - class="euiButtonIcon euiButtonIcon--text euiButtonIcon--empty euiButtonIcon--xSmall euiAccordion__iconButton euiAccordion__iconButton-isOpen euiAccordion__iconButton--right emotion-euiAccordion__iconButton-isOpen-arrowRight" + class="euiButtonIcon euiButtonIcon--xSmall euiAccordion__iconButton euiAccordion__iconButton-isOpen euiAccordion__iconButton--right emotion-euiButtonIcon-empty-text-hoverStyles-euiAccordion__iconButton-isOpen-arrowRight" tabindex="-1" type="button" > @@ -606,7 +606,7 @@ Array [ aria-controls="generated-id" aria-expanded="true" aria-labelledby="generated-id" - class="euiButtonIcon euiButtonIcon--text euiButtonIcon--empty euiButtonIcon--xSmall euiAccordion__iconButton euiAccordion__iconButton-isOpen euiAccordion__iconButton--right emotion-euiAccordion__iconButton-isOpen-arrowRight" + class="euiButtonIcon euiButtonIcon--xSmall euiAccordion__iconButton euiAccordion__iconButton-isOpen euiAccordion__iconButton--right emotion-euiButtonIcon-empty-text-hoverStyles-euiAccordion__iconButton-isOpen-arrowRight" tabindex="-1" type="button" > diff --git a/packages/core/chrome/core-chrome-browser-internal/src/ui/header/__snapshots__/header.test.tsx.snap b/packages/core/chrome/core-chrome-browser-internal/src/ui/header/__snapshots__/header.test.tsx.snap index 2a42112f30a81..aa77a58ad7202 100644 --- a/packages/core/chrome/core-chrome-browser-internal/src/ui/header/__snapshots__/header.test.tsx.snap +++ b/packages/core/chrome/core-chrome-browser-internal/src/ui/header/__snapshots__/header.test.tsx.snap @@ -83,7 +83,7 @@ exports[`Header renders 1`] = ` aria-expanded="false" aria-haspopup="true" aria-label="Help menu" - class="euiButtonEmpty euiButtonEmpty--text euiHeaderSectionItemButton" + class="euiButtonEmpty euiHeaderSectionItemButton css-wvaqcf-empty-text" type="button" > + + `; diff --git a/packages/shared-ux/button_toolbar/src/buttons/add_from_library/add_from_library.test.tsx b/packages/shared-ux/button_toolbar/src/buttons/add_from_library/add_from_library.test.tsx index f573f6654e664..f59760278cb14 100644 --- a/packages/shared-ux/button_toolbar/src/buttons/add_from_library/add_from_library.test.tsx +++ b/packages/shared-ux/button_toolbar/src/buttons/add_from_library/add_from_library.test.tsx @@ -14,6 +14,6 @@ import { AddFromLibraryButton } from './add_from_library'; describe('', () => { test('is rendered', () => { const component = mountWithIntl(); - expect(component).toMatchSnapshot(); + expect(component.render()).toMatchSnapshot(); }); }); diff --git a/packages/shared-ux/button_toolbar/src/buttons/primary/__snapshots__/primary.test.tsx.snap b/packages/shared-ux/button_toolbar/src/buttons/primary/__snapshots__/primary.test.tsx.snap index 3f00e19ce3a91..94b1fe6d36b6c 100644 --- a/packages/shared-ux/button_toolbar/src/buttons/primary/__snapshots__/primary.test.tsx.snap +++ b/packages/shared-ux/button_toolbar/src/buttons/primary/__snapshots__/primary.test.tsx.snap @@ -1,465 +1,19 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[` is rendered 1`] = ` - - - - - - - + test + + + `; diff --git a/packages/shared-ux/button_toolbar/src/buttons/primary/primary.test.tsx b/packages/shared-ux/button_toolbar/src/buttons/primary/primary.test.tsx index 10cbe7cb4dff0..8478ca1842c41 100644 --- a/packages/shared-ux/button_toolbar/src/buttons/primary/primary.test.tsx +++ b/packages/shared-ux/button_toolbar/src/buttons/primary/primary.test.tsx @@ -14,13 +14,13 @@ import { PrimaryButton } from './primary'; describe('', () => { test('is rendered', () => { const component = mountWithIntl(); - expect(component).toMatchSnapshot(); + expect(component.render()).toMatchSnapshot(); }); test('it can be passed a functional onClick handler', () => { const mockHandler = jest.fn(); const component = mountWithIntl(); - component.simulate('click'); + component.find('button').simulate('click'); expect(mockHandler).toHaveBeenCalled(); }); }); diff --git a/packages/shared-ux/button_toolbar/src/toolbar/__snapshots__/toolbar.test.tsx.snap b/packages/shared-ux/button_toolbar/src/toolbar/__snapshots__/toolbar.test.tsx.snap index 3c58970a94bee..e64f6a228a7f5 100644 --- a/packages/shared-ux/button_toolbar/src/toolbar/__snapshots__/toolbar.test.tsx.snap +++ b/packages/shared-ux/button_toolbar/src/toolbar/__snapshots__/toolbar.test.tsx.snap @@ -1,200 +1,33 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[` is rendered 1`] = ` - - -
- -
- - - - - - - -
-
- -
- -
- -
- -
- - + Create chart + + + +
+
+
+
+
`; diff --git a/packages/shared-ux/button_toolbar/src/toolbar/toolbar.test.tsx b/packages/shared-ux/button_toolbar/src/toolbar/toolbar.test.tsx index 545ed8d4f7b93..729695edab5e8 100644 --- a/packages/shared-ux/button_toolbar/src/toolbar/toolbar.test.tsx +++ b/packages/shared-ux/button_toolbar/src/toolbar/toolbar.test.tsx @@ -18,7 +18,7 @@ describe('', () => { const children = { primaryButton }; const component = mountWithIntl(); - expect(component).toMatchSnapshot(); + expect(component.render()).toMatchSnapshot(); }); test('onClick works as expected when the primary button is clicked', () => { diff --git a/src/plugins/saved_objects_management/public/management_section/objects_table/components/delete_confirm_modal.test.tsx b/src/plugins/saved_objects_management/public/management_section/objects_table/components/delete_confirm_modal.test.tsx index 3c24d68007222..8bcc940514d62 100644 --- a/src/plugins/saved_objects_management/public/management_section/objects_table/components/delete_confirm_modal.test.tsx +++ b/src/plugins/saved_objects_management/public/management_section/objects_table/components/delete_confirm_modal.test.tsx @@ -95,7 +95,7 @@ describe('DeleteConfirmModal', () => { allowedTypes={allowedTypes} /> ); - wrapper.find('EuiButton').simulate('click'); + wrapper.find('button[data-test-subj="confirmModalConfirmButton"]').simulate('click'); expect(onConfirm).toHaveBeenCalledTimes(1); expect(onCancel).not.toHaveBeenCalled(); @@ -176,7 +176,9 @@ describe('DeleteConfirmModal', () => { /> ); - expect(wrapper.find('EuiButton').getDOMNode()).toBeDisabled(); + expect( + wrapper.find('button[data-test-subj="confirmModalConfirmButton"]').getDOMNode() + ).toBeDisabled(); }); }); diff --git a/src/plugins/saved_objects_management/public/management_section/objects_table/components/export_modal.test.tsx b/src/plugins/saved_objects_management/public/management_section/objects_table/components/export_modal.test.tsx index 609338f7aed38..5f39e65cd1e73 100644 --- a/src/plugins/saved_objects_management/public/management_section/objects_table/components/export_modal.test.tsx +++ b/src/plugins/saved_objects_management/public/management_section/objects_table/components/export_modal.test.tsx @@ -81,7 +81,7 @@ describe('ExportModal', () => { onIncludeReferenceChange={onIncludeReferenceChange} /> ); - wrapper.find('EuiButton').simulate('click'); + wrapper.find('EuiButton button').simulate('click'); expect(onExport).toHaveBeenCalledTimes(1); expect(onCancel).not.toHaveBeenCalled(); diff --git a/src/plugins/telemetry/public/components/__snapshots__/opted_in_notice_banner.test.tsx.snap b/src/plugins/telemetry/public/components/__snapshots__/opted_in_notice_banner.test.tsx.snap index 54e1b1ad17dde..122764b27bd29 100644 --- a/src/plugins/telemetry/public/components/__snapshots__/opted_in_notice_banner.test.tsx.snap +++ b/src/plugins/telemetry/public/components/__snapshots__/opted_in_notice_banner.test.tsx.snap @@ -38,6 +38,7 @@ exports[`OptInDetailsComponent renders as expected 1`] = ` size="s" /> diff --git a/src/plugins/unified_search/public/saved_query_management/saved_query_management_list.test.tsx b/src/plugins/unified_search/public/saved_query_management/saved_query_management_list.test.tsx index c7db17ea934d5..84e41d6c6aa4f 100644 --- a/src/plugins/unified_search/public/saved_query_management/saved_query_management_list.test.tsx +++ b/src/plugins/unified_search/public/saved_query_management/saved_query_management_list.test.tsx @@ -126,7 +126,7 @@ describe('Saved query management list component', () => { component.find('[data-test-subj="saved-query-management-apply-changes-button"]').length ).toBeTruthy(); component - .find('[data-test-subj="saved-query-management-apply-changes-button"]') + .find('button[data-test-subj="saved-query-management-apply-changes-button"]') .first() .simulate('click'); expect(onLoadSpy).toBeCalled(); diff --git a/src/plugins/unified_search/public/search_bar/search_bar.test.tsx b/src/plugins/unified_search/public/search_bar/search_bar.test.tsx index b47b2d81b780c..caf62fa3e3cff 100644 --- a/src/plugins/unified_search/public/search_bar/search_bar.test.tsx +++ b/src/plugins/unified_search/public/search_bar/search_bar.test.tsx @@ -273,8 +273,10 @@ describe('SearchBar', () => { expect(component.find(EuiSuperUpdateButton).prop('isDisabled')).toBe(true); expect(component.find(FilterItems).prop('readOnly')).toBe(true); - expect(component.find('[data-test-subj="showQueryBarMenu"]').at(0).getDOMNode()).toBeDisabled(); - expect(component.find('[data-test-subj="addFilter"]').at(0).getDOMNode()).toBeDisabled(); + expect( + component.find('button[data-test-subj="showQueryBarMenu"]').at(0).getDOMNode() + ).toBeDisabled(); + expect(component.find('button[data-test-subj="addFilter"]').at(0).getDOMNode()).toBeDisabled(); expect(component.find(DataViewPicker).prop('isDisabled')).toBe(true); diff --git a/x-pack/plugins/data_visualizer/public/application/common/components/field_type_icon/field_type_icon.test.tsx b/x-pack/plugins/data_visualizer/public/application/common/components/field_type_icon/field_type_icon.test.tsx index 9962937fa80dc..fe92ef0db9826 100644 --- a/x-pack/plugins/data_visualizer/public/application/common/components/field_type_icon/field_type_icon.test.tsx +++ b/x-pack/plugins/data_visualizer/public/application/common/components/field_type_icon/field_type_icon.test.tsx @@ -43,7 +43,7 @@ describe('FieldTypeIcon', () => { jest.runAllTimers(); typeIconComponent.update(); - expect(typeIconComponent.find('EuiToolTip').children()).toHaveLength(1); + expect(typeIconComponent.find('EuiToolTip').children()).toHaveLength(2); // Clearing all mocks will also reset fake timers. jest.clearAllMocks(); diff --git a/x-pack/plugins/logstash/public/application/components/pipeline_list/confirm_delete_modal.test.js b/x-pack/plugins/logstash/public/application/components/pipeline_list/confirm_delete_modal.test.js index 9186d8138c094..ce37d78049081 100644 --- a/x-pack/plugins/logstash/public/application/components/pipeline_list/confirm_delete_modal.test.js +++ b/x-pack/plugins/logstash/public/application/components/pipeline_list/confirm_delete_modal.test.js @@ -43,7 +43,7 @@ describe('ConfirmDeleteModal component', () => { it('calls deleteSelectedPipelines', () => { const wrapper = mountWithIntl(); - wrapper.find('[data-test-subj="confirmModalConfirmButton"]').first().simulate('click'); + wrapper.find('button[data-test-subj="confirmModalConfirmButton"]').first().simulate('click'); expect(props.deleteSelectedPipelines).toHaveBeenCalled(); }); diff --git a/x-pack/plugins/security_solution/public/detections/components/rules/next_step/__snapshots__/index.test.tsx.snap b/x-pack/plugins/security_solution/public/detections/components/rules/next_step/__snapshots__/index.test.tsx.snap index 433b38773c14a..035910b32526b 100644 --- a/x-pack/plugins/security_solution/public/detections/components/rules/next_step/__snapshots__/index.test.tsx.snap +++ b/x-pack/plugins/security_solution/public/detections/components/rules/next_step/__snapshots__/index.test.tsx.snap @@ -15,10 +15,12 @@ exports[`NextStep renders correctly against snapshot 1`] = ` grow={false} > Continue diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_forms/components/policy_form_layout.test.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_forms/components/policy_form_layout.test.tsx index 49a2e8173476a..f63ee1e1bf990 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_forms/components/policy_form_layout.test.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/policy_forms/components/policy_form_layout.test.tsx @@ -144,9 +144,7 @@ describe('Policy Form Layout', () => { beforeEach(async () => { await asyncActions; policyFormLayoutView.update(); - saveButton = policyFormLayoutView.find( - 'EuiButton[data-test-subj="policyDetailsSaveButton"]' - ); + saveButton = policyFormLayoutView.find('button[data-test-subj="policyDetailsSaveButton"]'); saveButton.simulate('click'); policyFormLayoutView.update(); confirmModal = policyFormLayoutView.find( diff --git a/x-pack/plugins/spaces/public/management/edit_space/__snapshots__/delete_spaces_button.test.tsx.snap b/x-pack/plugins/spaces/public/management/edit_space/__snapshots__/delete_spaces_button.test.tsx.snap index 26ef77ebf9da9..598beb539f364 100644 --- a/x-pack/plugins/spaces/public/management/edit_space/__snapshots__/delete_spaces_button.test.tsx.snap +++ b/x-pack/plugins/spaces/public/management/edit_space/__snapshots__/delete_spaces_button.test.tsx.snap @@ -6,6 +6,7 @@ exports[`DeleteSpacesButton renders as expected 1`] = ` aria-label="Delete this space" color="danger" onClick={[Function]} + size="m" >