sadpandajoe commented on code in PR #39461:
URL: https://github.com/apache/superset/pull/39461#discussion_r3191443555


##########
superset-frontend/src/explore/components/SaveModal.test.tsx:
##########
@@ -330,139 +329,43 @@ test('renders InfoTooltip icon next to Dataset Name 
label when datasource type i
   expect(labelContainer).toContainElement(infoTooltip);
 });
 
-test('make sure slice_id in the URLSearchParams before the redirect', () => {
-  const myProps = {
-    ...defaultProps,
-    slice: { slice_id: 1, slice_name: 'title', owners: [1] },
-    actions: {
-      setFormData: jest.fn(),
-      updateSlice: jest.fn(() => Promise.resolve({ id: 1 })),
-      getSliceDashboards: jest.fn(),
-    },
-    user: { userId: 1 },
-    history: {
-      replace: jest.fn(),
-    },
-    dispatch: jest.fn(),
-  };
-
-  const saveModal = new TestSaveModal(myProps);
-  const result = saveModal.handleRedirect(
-    'https://example.com/?name=John&age=30',
+test('createRedirectParams sets slice_id in the URLSearchParams', () => {
+  const result = createRedirectParams(
+    '?name=John&age=30',
     { id: 1 },
+    'overwrite',
   );
   expect(result.get('slice_id')).toEqual('1');
+  expect(result.get('save_action')).toEqual('overwrite');
 });
 
-test('removes form_data_key from URL parameters after save', () => {
-  const myProps = {
-    ...defaultProps,
-    slice: { slice_id: 1, slice_name: 'title', owners: [1] },
-    actions: {
-      setFormData: jest.fn(),
-      updateSlice: jest.fn(() => Promise.resolve({ id: 1 })),
-      getSliceDashboards: jest.fn(),
-    },
-    user: { userId: 1 },
-    history: {
-      replace: jest.fn(),
-    },
-    dispatch: jest.fn(),
-  };
-
-  const saveModal = new TestSaveModal(myProps);
-
+test('createRedirectParams removes form_data_key from URL parameters', () => {
   // Test with form_data_key in the URL
   const urlWithFormDataKey = '?form_data_key=12345&other_param=value';
-  const result = saveModal.handleRedirect(urlWithFormDataKey, { id: 1 });
+  const result = createRedirectParams(
+    urlWithFormDataKey,
+    { id: 1 },
+    'overwrite',
+  );
 
   // form_data_key should be removed
   expect(result.has('form_data_key')).toBe(false);
   // other parameters should remain
   expect(result.get('other_param')).toEqual('value');
   expect(result.get('slice_id')).toEqual('1');
-  expect(result.has('save_action')).toBe(false);
+  expect(result.get('save_action')).toEqual('overwrite');
 });
 
-test('dispatches removeChartState when saving and going to dashboard', async 
() => {
-  // Spy on the removeChartState action creator
-  const removeChartStateSpy = jest.spyOn(
-    dashboardStateActions,
-    'removeChartState',
-  );
-
-  // Mock the dashboard API response
-  const dashboardId = 123;
-  const dashboardUrl = '/superset/dashboard/test-dashboard/';
-  fetchMock.get(`glob:*/api/v1/dashboard/${dashboardId}*`, {
-    result: {
-      id: dashboardId,
-      dashboard_title: 'Test Dashboard',
-      url: dashboardUrl,
-    },
-  });
-
-  const mockDispatch = jest.fn();
-  const mockHistory = {
-    push: jest.fn(),
-    replace: jest.fn(),
-  };
-  const chartId = 42;
-  const mockUpdateSlice = jest.fn(() => Promise.resolve({ id: chartId }));
-  const mockSetFormData = jest.fn();
-
-  const myProps = {
-    ...defaultProps,
-    slice: { slice_id: 1, slice_name: 'title', owners: [1] },
-    actions: {
-      setFormData: mockSetFormData,
-      updateSlice: mockUpdateSlice,
-      getSliceDashboards: jest.fn(() => Promise.resolve([])),
-      saveSliceFailed: jest.fn(),
-    },
-    user: { userId: 1 },
-    history: mockHistory,
-    dispatch: mockDispatch,
-  };
-
-  const saveModal = new TestSaveModal(myProps);
-  saveModal.state = {
-    action: 'overwrite',
-    newSliceName: 'test chart',
-    datasetName: 'test dataset',
-    dashboard: { label: 'Test Dashboard', value: dashboardId },
-    saveStatus: null,
-    isLoading: false,
-    tabsData: [],
-  };
-
-  // Mock onHide to prevent errors
-  saveModal.onHide = jest.fn();
-
-  // Trigger save and go to dashboard (gotodash = true)
-  await saveModal.saveOrOverwrite(true);
-
-  // Wait for async operations
-  await waitFor(() => {
-    expect(mockUpdateSlice).toHaveBeenCalled();
-    expect(mockSetFormData).toHaveBeenCalled();
-  });
-
-  // Verify removeChartState was called with the correct chart ID
-  expect(removeChartStateSpy).toHaveBeenCalledWith(chartId);
-
-  // Verify the action was dispatched (check the action object directly)
-  expect(mockDispatch).toHaveBeenCalled();
-  expect(mockDispatch).toHaveBeenCalledWith({
-    type: 'REMOVE_CHART_STATE',
-    chartId,
-  });
-
-  // Verify navigation happened
-  expect(mockHistory.push).toHaveBeenCalled();
-
-  // Clean up
-  removeChartStateSpy.mockRestore();
+/**
+ * TODO: This test was written for the class component version of SaveModal.
+ * Since SaveModal has been converted to a function component, this test
+ * needs to be rewritten to test through component rendering and user 
interaction.
+ * The test should verify that clicking "Save & go to dashboard" dispatches
+ * removeChartState with the correct chart ID.
+ */
+test('dispatches removeChartState when saving and going to dashboard - 
placeholder', () => {

Review Comment:
   We should either rewrite this test now or skip it. The whole 
`expect(true).toB(true)` is probably not a best practice for this.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to