fix(journey): add localized error messages for dismissing suggestions

This commit is contained in:
Luffy
2026-10-16 15:29:41 +08:00
committed by Maurice
parent 5622113348
commit d229613e0e
27 changed files with 34 additions and 8 deletions
+8 -5
View File
@@ -12,6 +12,8 @@ import { useAddonStore } from '../store/addonStore';
import { usePermissionsStore } from '../store/permissionsStore';
import JourneyPage from './JourneyPage';
const { mockToastError } = vi.hoisted(() => ({ mockToastError: vi.fn() }));
// ── Mocks ────────────────────────────────────────────────────────────────────
const mockNavigate = vi.fn();
@@ -24,6 +26,10 @@ vi.mock('../components/Layout/Navbar', () => ({
default: () => <nav data-testid="navbar" />,
}));
vi.mock('../components/shared/Toast', () => ({
useToast: () => ({ error: mockToastError }),
}));
// ── Helpers ──────────────────────────────────────────────────────────────────
let _seq = 500;
@@ -79,7 +85,6 @@ function setupDefaultHandlers(journeys: ReturnType<typeof buildJourneyListItem>[
beforeEach(() => {
vi.clearAllMocks();
window.localStorage.clear();
delete window.__addToast;
mockNavigate.mockReset();
resetAllStores();
seedDefaults();
@@ -223,8 +228,7 @@ describe('JourneyPage', () => {
it('FE-PAGE-JOURNEY-007d: keeps the suggestion visible and reports a storage failure', async () => {
const user = userEvent.setup();
const suggestion = { id: 992, title: 'Coast Trip', start_date: '2026-03-01', end_date: '2026-03-02', place_count: 2 };
const addToast = vi.fn();
window.__addToast = addToast;
mockToastError.mockClear();
const setItem = vi.spyOn(Storage.prototype, 'setItem').mockImplementation(() => {
throw new DOMException('Storage is full', 'QuotaExceededError');
});
@@ -236,10 +240,9 @@ describe('JourneyPage', () => {
render(<JourneyPage />);
await user.click(await screen.findByRole('button', { name: 'Dismiss' }));
expect(addToast).toHaveBeenCalledWith('Could not dismiss this suggestion', 'error', undefined);
expect(mockToastError).toHaveBeenCalledWith('Could not dismiss this suggestion');
expect(screen.getByText(/Trip just ended/i)).toBeInTheDocument();
setItem.mockRestore();
delete window.__addToast;
});
it('FE-PAGE-JOURNEY-007e: deletes dismissed IDs absent from the suggestions response', async () => {
+1 -3
View File
@@ -78,8 +78,6 @@ export function useJourney() {
useEffect(() => {
let cancelled = false
setSuggestions([])
setDismissedSuggestions(readDismissedSuggestions(userId))
journeyApi.suggestions().then(d => {
if (cancelled) return
const trips = d.trips || []
@@ -92,7 +90,7 @@ export function useJourney() {
try {
saveDismissedSuggestions(userId, retained)
} catch {
toast.error(t('journey.frontpage.dismissError'))
// Pruning is best effort; a failed write leaves the old IDs to retry later.
}
}
}).catch(() => {})