You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ha...@apache.org on 2026/10/14 17:56:54 UTC

(superset) branch master updated: test(semantic views): finish selected refreshes before test teardown (#45282)

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

hainenber 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 5cf0b8c6046 test(semantic views): finish selected refreshes before test teardown (#45282)
5cf0b8c6046 is described below

commit 5cf0b8c60462bd0c5d6676b0e7783e13c6b898dd
Author: Mike Bridge <mi...@preset.io>
AuthorDate: Wed Oct 14 13:56:47 2026 -0400

    test(semantic views): finish selected refreshes before test teardown (#45282)
---
 .../semanticViews/AddSemanticViewModal.test.tsx    | 73 ++++++++++++++++------
 1 file changed, 54 insertions(+), 19 deletions(-)

diff --git a/superset-frontend/src/features/semanticViews/AddSemanticViewModal.test.tsx b/superset-frontend/src/features/semanticViews/AddSemanticViewModal.test.tsx
index 0b7d4362bc5..9041c18801a 100644
--- a/superset-frontend/src/features/semanticViews/AddSemanticViewModal.test.tsx
+++ b/superset-frontend/src/features/semanticViews/AddSemanticViewModal.test.tsx
@@ -419,7 +419,6 @@ test('a const array default does not loop updates', async () => {
 });
 
 test('a failed array-only refresh keeps views and Add usable with a bounded retry', async () => {
-  let refreshCount = 0;
   const schemaWithMode = {
     ...dynamicMetricsSchema,
     properties: {
@@ -436,7 +435,6 @@ test('a failed array-only refresh keeps views and Add usable with a bounded retr
   mockLayerWithSchema(schemaWithMode, {
     '/api/v1/semantic_layer/layer-1/schema/runtime': (payload: unknown) => {
       if ((payload as { runtime_data?: unknown })?.runtime_data) {
-        refreshCount += 1;
         return Promise.reject(new Error('refresh boom'));
       }
       return Promise.resolve({ json: { result: schemaWithMode } });
@@ -455,7 +453,18 @@ test('a failed array-only refresh keeps views and Add usable with a bounded retr
     },
     { timeout: 10000 },
   );
-  expect(refreshCount).toBeGreaterThanOrEqual(1);
+  await waitFor(
+    () =>
+      expect(mockedPost).toHaveBeenCalledWith({
+        endpoint: '/api/v1/semantic_layer/layer-1/schema/runtime',
+        jsonPayload: {
+          runtime_data: expect.objectContaining({
+            metrics: expect.arrayContaining(['m1']),
+          }),
+        },
+      }),
+    { timeout: 10000 },
+  );
   // The user's selection is untouched by the failure (spec FR-005).
   expect(selectedTag('m1')).toBeTruthy();
   await waitFor(
@@ -469,7 +478,18 @@ test('a failed array-only refresh keeps views and Add usable with a bounded retr
   await selectOption('Semantic views', 'orders');
   expect(screen.getByRole('button', { name: /Add 1 view/ })).toBeEnabled();
   await pickFromSelect(/metrics/i, 'm2');
-  await waitFor(() => expect(refreshCount).toBe(2), { timeout: 10000 });
+  await waitFor(
+    () =>
+      expect(mockedPost).toHaveBeenCalledWith({
+        endpoint: '/api/v1/semantic_layer/layer-1/schema/runtime',
+        jsonPayload: {
+          runtime_data: expect.objectContaining({
+            metrics: expect.arrayContaining(['m2']),
+          }),
+        },
+      }),
+    { timeout: 10000 },
+  );
 });
 
 test('the save payload carries every selected metric', async () => {
@@ -542,7 +562,20 @@ test('the save payload carries every selected metric', async () => {
 
 test('renders and selects within a 500-metric runtime schema', async () => {
   const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation();
-  mockLayerWithSchema(largeRuntimeSchema as Record<string, unknown>);
+  let resolveSelectedRefresh: (() => void) | undefined;
+  mockLayerWithSchema(largeRuntimeSchema as Record<string, unknown>, {
+    '/api/v1/semantic_layer/layer-1/schema/runtime': (payload: unknown) => {
+      const data = (payload as { runtime_data?: { metrics?: string[] } })
+        ?.runtime_data;
+      if (data?.metrics?.includes(largeMetricEnum[42])) {
+        return new Promise(resolve => {
+          resolveSelectedRefresh = () =>
+            resolve({ json: { result: largeRuntimeSchema } });
+        });
+      }
+      return Promise.resolve({ json: { result: largeRuntimeSchema } });
+    },
+  });
   render(<AddSemanticViewModal {...createProps()} />);
   await selectOption('Semantic layer', 'Snowflake SL');
 
@@ -559,20 +592,22 @@ test('renders and selects within a 500-metric runtime schema', async () => {
   await userEvent.click(option);
   expect(selectedTag(largeMetricEnum[42])).toBeTruthy();
 
-  // largeRuntimeSchema's dimensions field depends on metrics, so the pick
-  // schedules a refresh — wait for it so the dedupe/apply path is exercised
-  // at 500-metric scale rather than ending before the debounce elapses.
-  await waitFor(
-    () => {
-      const refreshes = mockedPost.mock.calls.filter(
-        ([{ endpoint, jsonPayload }]) =>
-          endpoint === '/api/v1/semantic_layer/layer-1/schema/runtime' &&
-          (jsonPayload as { runtime_data?: unknown })?.runtime_data,
-      );
-      expect(refreshes.length).toBeGreaterThanOrEqual(1);
-    },
-    { timeout: 10000 },
-  );
+  // Finish this metric's own refresh before unmounting; an earlier refresh
+  // for empty runtime data does not prove the selected metric was applied.
+  await waitFor(() => {
+    expect(mockedPost).toHaveBeenCalledWith({
+      endpoint: '/api/v1/semantic_layer/layer-1/schema/runtime',
+      jsonPayload: {
+        runtime_data: expect.objectContaining({
+          metrics: [largeMetricEnum[42]],
+        }),
+      },
+    });
+    expect(resolveSelectedRefresh).toBeDefined();
+  });
+  await act(async () => {
+    resolveSelectedRefresh?.();
+  });
   expect(selectedTag(largeMetricEnum[42])).toBeTruthy();
   expect(
     consoleErrorSpy.mock.calls.find(args =>