Copilot commented on code in PR #42250:
URL: https://github.com/apache/superset/pull/42250#discussion_r3679055543
##########
superset-frontend/src/dashboard/actions/dashboardState.test.ts:
##########
@@ -298,6 +298,73 @@ describe('dashboardState actions', () => {
{ event: 'dashboard_properties_changed' },
);
});
+
+ // The save-error toast mapping lives inline in `onError`, not behind
+ // `getErrorText`, so these exercise the thunk itself. A 403 whose body is
+ // the API's `{"message": "Forbidden"}` shape must surface the
+ // permission-denied copy, while a 403 from outside Superset (reverse
proxy,
+ // WAF, SSO gateway) carries a non-JSON body and must fall back to the
+ // generic status-derived toast. See #42239.
+ const findDangerToast = (dispatch: jest.Mock) =>
+ dispatch.mock.calls
+ .map(call => call[0])
+ .find(
+ action =>
+ action?.type === ADD_TOAST &&
+ action.payload.toastType === ToastType.Danger,
+ );
+
+ test('maps a non-JSON 403 save failure to the generic error toast', async
() => {
+ const { getState, dispatch } = setup();
+ putStub.mockRestore();
+ putStub = jest.spyOn(SupersetClient, 'put').mockRejectedValue(
+ new Response(
+ '<html><head><title>403
Forbidden</title></head><body>Forbidden</body></html>',
+ {
+ status: 403,
+ statusText: 'Forbidden',
+ headers: { 'Content-Type': 'text/html' },
+ },
+ ),
+ );
+
+ const thunk = saveDashboardRequest(
+ newDashboardData,
+ 192,
+ SAVE_TYPE_OVERWRITE,
+ );
Review Comment:
These error-mapping tests are placed inside the
`FeatureFlag.CONFIRM_DASHBOARD_DIFF` describe (where the overwrite precheck can
short-circuit before `SupersetClient.put` is called). That makes the assertions
brittle: if `getOverwriteItems(...)` ever starts returning items for this
payload, the tests will fail even though the toast mapping in `onError` is
unchanged. Using `SAVE_TYPE_OVERWRITE_CONFIRMED` here bypasses the precheck and
isolates the behavior under test.
This issue also appears on line 355 of the same file.
--
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]