This is an automated email from the ASF dual-hosted git repository.

rusackas pushed a commit to branch replace-jest-enzyme
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/replace-jest-enzyme by this 
push:
     new d878072969 fixing borked test
d878072969 is described below

commit d8780729691f3edb9bd282afadd05983d8d707c1
Author: Evan Rusackas <[email protected]>
AuthorDate: Mon Feb 10 14:08:25 2025 -0700

    fixing borked test
---
 .../FilterBarSettings/FilterBarSettings.test.tsx   | 108 +++++++--------------
 1 file changed, 37 insertions(+), 71 deletions(-)

diff --git 
a/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterBarSettings/FilterBarSettings.test.tsx
 
b/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterBarSettings/FilterBarSettings.test.tsx
index caae82fe1d..24fbfe21a0 100644
--- 
a/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterBarSettings/FilterBarSettings.test.tsx
+++ 
b/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterBarSettings/FilterBarSettings.test.tsx
@@ -18,14 +18,9 @@
  */
 
 import fetchMock from 'fetch-mock';
-import {
-  cleanup,
-  userEvent,
-  waitFor,
-  render,
-  screen,
-  within,
-} from 'spec/helpers/testing-library';
+import { waitFor } from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
+import { render, screen, within } from 'spec/helpers/testing-library';
 import { DashboardInfo, FilterBarOrientation } from 'src/dashboard/types';
 import * as mockedMessageActions from 'src/components/MessageToasts/actions';
 import { FeatureFlag } from '@superset-ui/core';
@@ -81,14 +76,6 @@ beforeEach(() => {
   fetchMock.restore();
 });
 
-// Add cleanup after each test
-afterEach(async () => {
-  cleanup();
-  fetchMock.restore();
-  // Wait for any pending effects to complete
-  await new Promise(resolve => setTimeout(resolve, 0));
-});
-
 test('Dropdown trigger renders with FF HORIZONTAL_FILTER_BAR on', async () => {
   // @ts-ignore
   global.featureFlags = {
@@ -149,27 +136,13 @@ test('Popover opens with "Vertical" selected', async () 
=> {
     [FeatureFlag.HorizontalFilterBar]: true,
   };
   await setup();
-
-  // Wait for gear icon to be visible and click it
-  const gearIcon = await waitFor(() => screen.getByLabelText('gear'));
-  userEvent.click(gearIcon);
-
-  // Wait for orientation text and hover
-  const orientationText = await waitFor(() =>
-    screen.getByText('Orientation of filter bar'),
-  );
-  userEvent.hover(orientationText);
-
-  // Wait for submenu to appear and verify options
-  await waitFor(
-    () => {
-      expect(screen.getByText('Vertical (Left)')).toBeInTheDocument();
-      expect(screen.getByText('Horizontal (Top)')).toBeInTheDocument();
-      const menuItems = screen.getAllByRole('menuitem');
-      expect(within(menuItems[4]).getByLabelText('check')).toBeInTheDocument();
-    },
-    { timeout: 3000 },
-  );
+  userEvent.click(screen.getByLabelText('gear'));
+  userEvent.hover(screen.getByText('Orientation of filter bar'));
+  expect(await screen.findByText('Vertical (Left)')).toBeInTheDocument();
+  expect(screen.getByText('Horizontal (Top)')).toBeInTheDocument();
+  expect(
+    within(screen.getAllByRole('menuitem')[4]).getByLabelText('check'),
+  ).toBeInTheDocument();
 });
 
 test('Popover opens with "Horizontal" selected', async () => {
@@ -242,20 +215,7 @@ test('On selection change, send request and update checked 
value', async () => {
       within(verticalItem.closest('li')!).queryByLabelText('check'),
     ).not.toBeInTheDocument();
   });
-
-  userEvent.click(screen.getByLabelText('gear'));
-  userEvent.hover(screen.getByText('Orientation of filter bar'));
-  expect(await screen.findByText('Vertical (Left)')).toBeInTheDocument();
-  expect(screen.getByText('Horizontal (Top)')).toBeInTheDocument();
-
-  // 2nd check - checkmark stays after successful query
-  expect(
-    await within(screen.getAllByRole('menuitem')[5]).findByLabelText('check'),
-  ).toBeInTheDocument();
-  expect(
-    within(screen.getAllByRole('menuitem')[4]).queryByLabelText('check'),
-  ).not.toBeInTheDocument();
-}, 10000);
+});
 
 test('On failed request, restore previous selection', async () => {
   // @ts-ignore
@@ -267,41 +227,47 @@ test('On failed request, restore previous selection', 
async () => {
   const dangerToastSpy = jest.spyOn(mockedMessageActions, 'addDangerToast');
 
   await setup();
-  userEvent.click(screen.getByLabelText('gear'));
-  userEvent.hover(screen.getByText('Orientation of filter bar'));
+  const gearIcon = await screen.findByLabelText('gear');
+  userEvent.click(gearIcon);
 
-  expect(await screen.findByText('Vertical (Left)')).toBeInTheDocument();
-  expect(screen.getByText('Horizontal (Top)')).toBeInTheDocument();
+  const orientationMenu = await screen.findByText('Orientation of filter bar');
+  userEvent.hover(orientationMenu);
+
+  // Wait for menu items to be visible
+  const verticalItem = await screen.findByText('Vertical (Left)');
+  const horizontalItem = await screen.findByText('Horizontal (Top)');
 
+  // Verify initial state
   expect(
-    within(screen.getAllByRole('menuitem')[4]).getByLabelText('check'),
+    within(verticalItem.closest('li')!).getByLabelText('check'),
   ).toBeInTheDocument();
   expect(
-    within(screen.getAllByRole('menuitem')[5]).queryByLabelText('check'),
+    within(horizontalItem.closest('li')!).queryByLabelText('check'),
   ).not.toBeInTheDocument();
 
-  userEvent.click(await screen.findByText('Horizontal (Top)'));
+  // Click horizontal option
+  userEvent.click(horizontalItem);
 
+  // Verify error toast
   await waitFor(() => {
     expect(dangerToastSpy).toHaveBeenCalledWith(
       'Sorry, there was an error saving this dashboard: Unknown Error',
     );
   });
 
-  userEvent.click(screen.getByLabelText('gear'));
-  userEvent.hover(screen.getByText('Orientation of filter bar'));
+  // Reopen menu and verify selection rolled back
+  userEvent.click(gearIcon);
+  userEvent.hover(orientationMenu);
 
+  // Wait for menu items and verify state
   await waitFor(() => {
-    expect(screen.getByText('Vertical (Left)')).toBeInTheDocument();
-    const menuitems = screen.getAllByRole('menuitem');
-    expect(menuitems.length).toBeGreaterThanOrEqual(6);
+    const verticalItemAfter = screen.getByText('Vertical (Left)');
+    const horizontalItemAfter = screen.getByText('Horizontal (Top)');
+    expect(
+      within(verticalItemAfter.closest('li')!).getByLabelText('check'),
+    ).toBeInTheDocument();
+    expect(
+      within(horizontalItemAfter.closest('li')!).queryByLabelText('check'),
+    ).not.toBeInTheDocument();
   });
-
-  // checkmark gets rolled back to the original selection after successful 
query
-  expect(
-    await within(screen.getAllByRole('menuitem')[4]).findByLabelText('check'),
-  ).toBeInTheDocument();
-  expect(
-    within(screen.getAllByRole('menuitem')[5]).queryByLabelText('check'),
-  ).not.toBeInTheDocument();
 });

Reply via email to