From f80125f1269b94c29bfb2f869a10cec120dbc1f2 Mon Sep 17 00:00:00 2001 From: lyndsiWilliams Date: Mon, 30 Jan 2023 17:27:27 -0600 Subject: [PATCH 1/2] Clean up AdhocFilterOption test --- .../AdhocFilterOption.test.tsx | 42 ++++++++++++++----- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/superset-frontend/src/explore/components/controls/FilterControl/AdhocFilterOption/AdhocFilterOption.test.tsx b/superset-frontend/src/explore/components/controls/FilterControl/AdhocFilterOption/AdhocFilterOption.test.tsx index 888eb5a8c3883..73671dd1b1164 100644 --- a/superset-frontend/src/explore/components/controls/FilterControl/AdhocFilterOption/AdhocFilterOption.test.tsx +++ b/superset-frontend/src/explore/components/controls/FilterControl/AdhocFilterOption/AdhocFilterOption.test.tsx @@ -19,14 +19,35 @@ import React from 'react'; import { render, screen, waitFor } from 'spec/helpers/testing-library'; import userEvent from '@testing-library/user-event'; -import { HTML5Backend } from 'react-dnd-html5-backend'; -import { DndProvider } from 'react-dnd'; import AdhocFilter, { EXPRESSION_TYPES, CLAUSES, } from 'src/explore/components/controls/FilterControl/AdhocFilter'; import AdhocFilterOption, { AdhocFilterOptionProps } from '.'; +jest.mock('src/components/Icons/Icon', () => ({ + __esModule: true, + default: ({ + fileName, + role, + iconColor, + ...rest + }: { + fileName: string; + role: string; + iconColor: string; + }) => ( + + ), + StyledIcon: () => , +})); + const simpleAdhocFilter = new AdhocFilter({ expressionType: EXPRESSION_TYPES.SIMPLE, subject: 'value', @@ -56,36 +77,37 @@ const mockedProps = { }; const setup = (props: AdhocFilterOptionProps) => ( - - - + ); test('should render', async () => { - const { container } = render(setup(mockedProps)); + const { container } = render(setup(mockedProps), { + useDnd: true, + useRedux: true, + }); await waitFor(() => expect(container).toBeInTheDocument()); }); test('should render the control label', async () => { - render(setup(mockedProps)); + render(setup(mockedProps), { useDnd: true, useRedux: true }); expect(await screen.findByText('value > 10')).toBeInTheDocument(); }); test('should render the remove button', async () => { - render(setup(mockedProps)); + render(setup(mockedProps), { useDnd: true, useRedux: true }); const removeBtn = await screen.findByRole('button'); expect(removeBtn).toBeInTheDocument(); }); test('should render the right caret', async () => { - render(setup(mockedProps)); + render(setup(mockedProps), { useDnd: true, useRedux: true }); expect( await screen.findByRole('img', { name: 'caret-right' }), ).toBeInTheDocument(); }); test('should render the Popover on clicking the right caret', async () => { - render(setup(mockedProps)); + render(setup(mockedProps), { useDnd: true, useRedux: true }); const rightCaret = await screen.findByRole('img', { name: 'caret-right' }); userEvent.click(rightCaret); expect(screen.getByRole('tooltip')).toBeInTheDocument(); From b4c2371b09bb63ef76021a02faa7d7b1f7968f39 Mon Sep 17 00:00:00 2001 From: lyndsiWilliams Date: Wed, 1 Feb 2023 15:26:47 -0600 Subject: [PATCH 2/2] Fix icon mock in AdhocFilterOption test --- .../AdhocFilterOption.test.tsx | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/superset-frontend/src/explore/components/controls/FilterControl/AdhocFilterOption/AdhocFilterOption.test.tsx b/superset-frontend/src/explore/components/controls/FilterControl/AdhocFilterOption/AdhocFilterOption.test.tsx index 73671dd1b1164..ec7de8d36ed87 100644 --- a/superset-frontend/src/explore/components/controls/FilterControl/AdhocFilterOption/AdhocFilterOption.test.tsx +++ b/superset-frontend/src/explore/components/controls/FilterControl/AdhocFilterOption/AdhocFilterOption.test.tsx @@ -27,23 +27,8 @@ import AdhocFilterOption, { AdhocFilterOptionProps } from '.'; jest.mock('src/components/Icons/Icon', () => ({ __esModule: true, - default: ({ - fileName, - role, - iconColor, - ...rest - }: { - fileName: string; - role: string; - iconColor: string; - }) => ( - + default: ({ fileName, role }: { fileName: string; role: string }) => ( + ), StyledIcon: () => , }));