gabotorresruiz commented on code in PR #44096:
URL: https://github.com/apache/superset/pull/44096#discussion_r4020389718


##########
superset-frontend/src/components/MessageToasts/Toast.test.tsx:
##########
@@ -127,3 +127,34 @@ test('a link requested through the action creator survives 
to the rendered toast
   expect(link).not.toBeNull();
   expect(link).toHaveAttribute('href', '/explore/?slice_id=1');
 });
+
+test('an action button invokes its callback and dismisses the toast', async () 
=> {
+  const onClick = jest.fn();
+  const onCloseToast = jest.fn();
+  const { getByRole } = setup({
+    toast: { ...props.toast, action: { label: 'Undo', onClick } },
+    onCloseToast,
+  });
+  fireEvent.click(getByRole('button', { name: 'Undo' }));
+  expect(onClick).toHaveBeenCalledTimes(1);
+  await waitFor(() =>
+    expect(onCloseToast).toHaveBeenCalledWith(props.toast.id),
+  );
+});
+
+test('an actionable toast remains until it is explicitly dismissed', () => {
+  jest.useFakeTimers();
+  const onCloseToast = jest.fn();
+  setup({
+    toast: {
+      ...props.toast,
+      duration: 100,
+      action: { label: 'Undo', onClick: jest.fn() },
+    },
+    onCloseToast,
+  });
+
+  act(() => jest.advanceTimersByTime(1000));
+  expect(onCloseToast).not.toHaveBeenCalled();

Review Comment:
   Just a small NIT, but worth locking in: I verified this test also passes 
against the pre fix `Toast.tsx`, so it does not actually pin the no auto 
dismiss behavior. Pre fix, the 100ms hide timer fires inside the `act` block, 
but `handleClosePress` schedules `onCloseToast` through a 150ms timeout inside 
the `setVisible` updater, which React only flushes when the `act` block ends, 
after `advanceTimersByTime(1000)` already ran. So the assertion holds either 
way. Adding a second advance turns it into a real regression test:
   
   ```tsx
   act(() => jest.advanceTimersByTime(1000));
   act(() => jest.advanceTimersByTime(200));
   expect(onCloseToast).not.toHaveBeenCalled();
   ```
   
   I ran that variant on this branch: it fails against the previous `Toast.tsx` 
and passes against the current one. The other two new tests (`inherited 
properties` and `preserves filters edited`) do fail pre fix, so they are solid.



-- 
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