You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ma...@apache.org on 2026/04/10 19:30:45 UTC

(superset) branch master updated: fix(tests): improve ShareMenuItems test isolation to fix intermittent suite failure (#39280)

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

maximebeauchemin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 98146251c4f fix(tests): improve ShareMenuItems test isolation to fix intermittent suite failure (#39280)
98146251c4f is described below

commit 98146251c4fc16d26e9cb49a80c0d72a25263107
Author: Maxime Beauchemin <ma...@gmail.com>
AuthorDate: Fri Apr 10 12:30:38 2026 -0700

    fix(tests): improve ShareMenuItems test isolation to fix intermittent suite failure (#39280)
    
    Co-authored-by: Claude Opus 4.6 <no...@anthropic.com>
---
 .../menu/ShareMenuItems/ShareMenuItems.test.tsx    | 34 +++++++++-------------
 1 file changed, 14 insertions(+), 20 deletions(-)

diff --git a/superset-frontend/src/dashboard/components/menu/ShareMenuItems/ShareMenuItems.test.tsx b/superset-frontend/src/dashboard/components/menu/ShareMenuItems/ShareMenuItems.test.tsx
index 3e137d2c874..476487563a3 100644
--- a/superset-frontend/src/dashboard/components/menu/ShareMenuItems/ShareMenuItems.test.tsx
+++ b/superset-frontend/src/dashboard/components/menu/ShareMenuItems/ShareMenuItems.test.tsx
@@ -45,13 +45,16 @@ const createProps = () => ({
   submenuKey: 'share',
 });
 
-const { location } = window;
+const originalLocation = window.location;
 
 const postDashboardPermalinkMockUrl = `http://localhost/api/v1/dashboard/${DASHBOARD_ID}/permalink`;
 
-beforeAll((): void => {
+beforeEach(() => {
+  jest.clearAllMocks();
   // @ts-expect-error
   delete window.location;
+  window.location = { href: '' } as any;
+  fetchMock.clearHistory().removeRoutes();
   fetchMock.post(
     postDashboardPermalinkMockUrl,
     { key: '123', url: 'http://localhost/superset/dashboard/p/123/' },
@@ -59,15 +62,10 @@ beforeAll((): void => {
   );
 });
 
-beforeEach(() => {
-  jest.clearAllMocks();
-  window.location = {
-    href: '',
-  } as any;
-});
-
-afterAll((): void => {
-  window.location = location;
+afterEach(() => {
+  window.location = originalLocation;
+  window.featureFlags = {};
+  fetchMock.clearHistory().removeRoutes();
 });
 
 const MenuWrapper = (
@@ -113,7 +111,7 @@ test('Click on "Copy dashboard URL" and succeed', async () => {
     expect(props.addDangerToast).toHaveBeenCalledTimes(0);
   });
 
-  userEvent.click(screen.getByText('Copy dashboard URL'));
+  await userEvent.click(screen.getByText('Copy dashboard URL'));
 
   await waitFor(async () => {
     expect(spy).toHaveBeenCalledTimes(1);
@@ -145,7 +143,7 @@ test('Click on "Copy dashboard URL" and fail', async () => {
     expect(props.addDangerToast).toHaveBeenCalledTimes(0);
   });
 
-  userEvent.click(screen.getByText('Copy dashboard URL'));
+  await userEvent.click(screen.getByText('Copy dashboard URL'));
 
   await waitFor(async () => {
     expect(spy).toHaveBeenCalledTimes(1);
@@ -177,7 +175,7 @@ test('Click on "Share dashboard by email" and succeed', async () => {
     expect(window.location.href).toBe('');
   });
 
-  userEvent.click(screen.getByText('Share dashboard by email'));
+  await userEvent.click(screen.getByText('Share dashboard by email'));
 
   await waitFor(() => {
     expect(props.addDangerToast).toHaveBeenCalledTimes(0);
@@ -189,11 +187,7 @@ test('Click on "Share dashboard by email" and succeed', async () => {
 
 test('Click on "Share dashboard by email" and fail', async () => {
   fetchMock.removeRoute(postDashboardPermalinkMockUrl);
-  fetchMock.post(
-    `http://localhost/api/v1/dashboard/${DASHBOARD_ID}/permalink`,
-    { status: 404 },
-    { name: postDashboardPermalinkMockUrl },
-  );
+  fetchMock.post(postDashboardPermalinkMockUrl, { status: 404 });
   const props = createProps();
   render(
     <MenuWrapper
@@ -211,7 +205,7 @@ test('Click on "Share dashboard by email" and fail', async () => {
     expect(window.location.href).toBe('');
   });
 
-  userEvent.click(screen.getByText('Share dashboard by email'));
+  await userEvent.click(screen.getByText('Share dashboard by email'));
 
   await waitFor(() => {
     expect(window.location.href).toBe('');