rusackas commented on code in PR #37625:
URL: https://github.com/apache/superset/pull/37625#discussion_r2766052170
##########
superset-frontend/src/components/MessageToasts/reducers.test.ts:
##########
@@ -18,26 +18,51 @@
*/
import { ADD_TOAST, REMOVE_TOAST } from 'src/components/MessageToasts/actions';
import messageToastsReducer from 'src/components/MessageToasts/reducers';
+import { ToastMeta, ToastType } from 'src/components/MessageToasts/types';
// messageToasts reducer
test('messageToasts reducer should return initial state', () => {
- expect(messageToastsReducer(undefined, {})).toEqual([]);
+ expect(
+ messageToastsReducer(undefined, { type: '' } as unknown as Parameters<
+ typeof messageToastsReducer
+ >[1]),
+ ).toEqual([]);
});
test('messageToasts reducer should add a toast', () => {
expect(
messageToastsReducer([], {
type: ADD_TOAST,
- payload: { text: 'test', id: 'id', type: 'test_type' },
+ payload: {
+ text: 'test',
+ id: 'id',
+ toastType: ToastType.Info,
+ duration: 4000,
+ },
Review Comment:
The previous test (lines 24-29) was testing the initial state /
default case — the payload {} was irrelevant because the action type ''
doesn't match any case in the switch, so the reducer just returns the default
[]. That test was about verifying the reducer returns [] for an unknown action,
not about handling incomplete toast payloads.
The new test (lines 32-46) correctly provides a complete ToastMeta payload
because the ADD_TOAST case actually uses the payload. The toastType and
duration fields were added because ToastMeta requires them — this is just type
correctness.
Adding a test for incomplete/invalid payloads would be testing a scenario
that TypeScript prevents at compile time. There's no value in testing runtime
behavior for payloads the type system won't allow.
--
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]