feat: implement AccessDeniedScreen and enhance error handling
- Introduced AccessDeniedScreen component for improved user experience when access is denied, replacing the previous AccessDenied component. - Updated CurrentDutyView and CalendarPage to handle access denied scenarios, displaying the new screen appropriately. - Enhanced tests for CurrentDutyView and AccessDeniedScreen to ensure correct rendering and functionality under access denied conditions. - Refactored localization messages to include new labels for access denied scenarios in both English and Russian.
This commit is contained in:
@@ -127,4 +127,25 @@ describe("CurrentDutyView", () => {
|
||||
expect(buttons[0]).toHaveAccessibleName(/Retry|Повторить/i);
|
||||
vi.mocked(fetchDuties).mockResolvedValue([]);
|
||||
});
|
||||
|
||||
it("403 shows AccessDeniedScreen with Back button and no Retry", async () => {
|
||||
const { fetchDuties, AccessDeniedError } = await import("@/lib/api");
|
||||
vi.mocked(fetchDuties).mockRejectedValue(
|
||||
new AccessDeniedError("ACCESS_DENIED", "Custom 403 message")
|
||||
);
|
||||
const onBack = vi.fn();
|
||||
render(<CurrentDutyView onBack={onBack} />);
|
||||
await screen.findByText(/Access denied|Доступ запрещён/i, {}, { timeout: 3000 });
|
||||
expect(
|
||||
screen.getByText(/Open the app again from Telegram|Откройте приложение снова из Telegram/i)
|
||||
).toBeInTheDocument();
|
||||
expect(screen.getByText("Custom 403 message")).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByRole("button", { name: /Back to calendar|Назад к календарю/i })
|
||||
).toBeInTheDocument();
|
||||
expect(screen.queryByRole("button", { name: /Retry|Повторить/i })).not.toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("button", { name: /Back to calendar|Назад к календарю/i }));
|
||||
expect(onBack).toHaveBeenCalled();
|
||||
vi.mocked(fetchDuties).mockResolvedValue([]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user