feat: Add dismissible warning UI for threshold loading errors
- Replace console.warn with visible MessageBar warning when map color thresholds fail to load - Add DismissRegular icon button to allow users to dismiss the warning - Add dismissedThresholdWarning state to manage warning visibility - Add mock and test for useMapColorThresholds hook - Add test case verifying warning displays and can be dismissed - Remove TASK-QUALITY-04 from Tasks.md (completed) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -31,6 +31,20 @@ vi.mock("../../hooks/useMapData", () => ({
|
||||
},
|
||||
}));
|
||||
|
||||
let thresholdState: { thresholds: unknown; error: string | null } = {
|
||||
thresholds: { threshold_low: 10, threshold_medium: 50, threshold_high: 100 },
|
||||
error: null,
|
||||
};
|
||||
|
||||
vi.mock("../../hooks/useMapColorThresholds", () => ({
|
||||
useMapColorThresholds: () => ({
|
||||
...thresholdState,
|
||||
loading: false,
|
||||
refresh: () => {},
|
||||
updateThresholds: () => {},
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock("../../api/config", () => ({
|
||||
fetchMapColorThresholds: vi.fn(() => ({
|
||||
threshold_low: 10,
|
||||
@@ -113,4 +127,36 @@ describe("MapPage", () => {
|
||||
expect(getLastArgs().origin).toBe("blocklist");
|
||||
expect(await screen.findByText(/Page 1 of 5/i)).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
it("displays warning when map color thresholds fail to load", async () => {
|
||||
const user = userEvent.setup();
|
||||
|
||||
setMapData({
|
||||
countries: { US: 10 },
|
||||
countryNames: { US: "United States" },
|
||||
bans: [],
|
||||
total: 0,
|
||||
loading: false,
|
||||
error: null,
|
||||
});
|
||||
|
||||
thresholdState = {
|
||||
thresholds: null,
|
||||
error: "Failed to fetch thresholds",
|
||||
};
|
||||
|
||||
render(
|
||||
<FluentProvider theme={webLightTheme}>
|
||||
<MapPage />
|
||||
</FluentProvider>,
|
||||
);
|
||||
|
||||
expect(screen.getByText(/Map color thresholds could not be loaded/i)).toBeInTheDocument();
|
||||
expect(screen.getByText(/Using default thresholds/i)).toBeInTheDocument();
|
||||
|
||||
// User can dismiss the warning
|
||||
const dismissButton = screen.getByRole("button", { name: "" });
|
||||
await user.click(dismissButton);
|
||||
expect(screen.queryByText(/Map color thresholds could not be loaded/i)).not.toBeInTheDocument();
|
||||
});
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user