From 48b98f4f8b710ca6b25701047e2fb4752fcf9b32 Mon Sep 17 00:00:00 2001 From: yannickmonney <102406702+yannickmonney@users.noreply.github.com> Date: Mon, 5 Oct 2026 12:47:07 +0000 Subject: [PATCH 1/2] fix(platform): allow retry after failed website status sync --- .../components/websites-table.test.tsx | 157 +++++++++++++++++- .../websites/components/websites-table.tsx | 43 ++++- services/platform/messages/de.yml | 4 + services/platform/messages/en.yml | 4 + services/platform/messages/fr.yml | 4 + .../tests/manual/reference/automation.md | 7 + 6 files changed, 212 insertions(+), 7 deletions(-) diff --git a/services/platform/app/features/websites/components/websites-table.test.tsx b/services/platform/app/features/websites/components/websites-table.test.tsx index 3c612b2a1a..3a7ad3927a 100644 --- a/services/platform/app/features/websites/components/websites-table.test.tsx +++ b/services/platform/app/features/websites/components/websites-table.test.tsx @@ -1,14 +1,29 @@ // @vitest-environment jsdom import '@testing-library/jest-dom/vitest'; -import { screen } from '@testing-library/react'; -import { describe, expect, it, vi } from 'vitest'; +import { QueryClient, useMutation } from '@tanstack/react-query'; +import { act, fireEvent, screen, waitFor } from '@testing-library/react'; +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import deMessages from '@/messages/de.yml'; +import enMessages from '@/messages/en.yml'; +import frMessages from '@/messages/fr.yml'; import { checkAccessibility } from '@/tests/utils/a11y'; import { render } from '@/tests/utils/render'; +const { locale } = vi.hoisted(() => ({ + locale: { value: 'en' as 'en' | 'de' | 'fr' }, +})); +const catalogs = { en: enMessages, de: deMessages, fr: frMessages }; + vi.mock('@tale/ui/i18n/client', () => ({ useT: (ns: string) => ({ t: (key: string, params?: Record) => { + if (ns === 'websites') { + const copy = catalogs[locale.value].websites.syncError; + if (key === 'syncError.title') return copy.title; + if (key === 'syncError.description') return copy.description; + if (key === 'syncError.retry') return copy.retry; + } if (params) { return Object.entries(params).reduce( (acc, [k, v]) => acc.replace(`{${k}}`, v), @@ -34,8 +49,15 @@ vi.mock('@tanstack/react-router', () => ({ useLocation: () => ({ pathname: '/dashboard/test-org/websites' }), })); +const { syncStatuses } = vi.hoisted(() => ({ + syncStatuses: vi.fn<(args: { organizationId: string }) => Promise>(), +})); + +let queryClient: QueryClient; + vi.mock('../hooks/mutations', () => ({ - useSyncWebsiteStatuses: () => ({ mutate: vi.fn() }), + useSyncWebsiteStatuses: () => + useMutation({ mutationFn: syncStatuses }, queryClient), useCreateWebsite: () => ({ mutate: vi.fn(), isPending: false }), useDeleteWebsite: () => ({ mutateAsync: vi.fn() }), })); @@ -73,6 +95,110 @@ vi.mock('./website-search-notice', () => ({ import { WebsitesTable } from './websites-table'; describe('WebsitesTable', () => { + beforeEach(() => { + queryClient = new QueryClient(); + locale.value = 'en'; + sessionStorage.clear(); + syncStatuses.mockReset().mockResolvedValue(undefined); + vi.spyOn(Date, 'now').mockReturnValue(1_800_000_000_000); + }); + + afterEach(() => { + vi.restoreAllMocks(); + }); + + it('retries on remount within five minutes after the first sync rejects', async () => { + syncStatuses.mockRejectedValueOnce(new Error('Unavailable')); + const first = render(); + await waitFor(() => expect(syncStatuses).toHaveBeenCalledTimes(1)); + await act(async () => {}); + first.unmount(); + + render(); + await waitFor(() => expect(syncStatuses).toHaveBeenCalledTimes(2)); + await waitFor(() => + expect(sessionStorage.getItem('websites-sync-org-sync')).toBe( + String(Date.now()), + ), + ); + }); + + it('records completion time only after success and throttles successful remounts', async () => { + let finishSync: (() => void) | undefined; + syncStatuses.mockImplementationOnce( + () => + new Promise((resolve) => { + finishSync = resolve; + }), + ); + const first = render(); + await waitFor(() => expect(syncStatuses).toHaveBeenCalledTimes(1)); + expect(sessionStorage.getItem('websites-sync-org-sync')).toBeNull(); + first.unmount(); + vi.mocked(Date.now).mockReturnValue(1_800_000_010_000); + await act(async () => finishSync?.()); + expect(sessionStorage.getItem('websites-sync-org-sync')).toBe( + String(Date.now()), + ); + + const second = render(); + await act(async () => {}); + expect(syncStatuses).toHaveBeenCalledTimes(1); + second.unmount(); + + vi.mocked(Date.now).mockReturnValue(1_800_000_310_000); + render(); + await waitFor(() => expect(syncStatuses).toHaveBeenCalledTimes(2)); + }); + + it('keeps a retryable alert until Retry succeeds and prevents duplicate retries', async () => { + syncStatuses.mockRejectedValueOnce(new Error('Unavailable')); + render(); + const alert = await screen.findByRole('alert'); + expect(alert).toHaveTextContent(enMessages.websites.syncError.description); + let finishRetry: (() => void) | undefined; + syncStatuses.mockImplementationOnce( + () => + new Promise((resolve) => { + finishRetry = resolve; + }), + ); + const retry = screen.getByRole('button', { + name: enMessages.websites.syncError.retry, + }); + fireEvent.click(retry); + await waitFor(() => expect(retry).toBeDisabled()); + fireEvent.click(retry); + expect(syncStatuses).toHaveBeenCalledTimes(2); + expect(alert).toBeInTheDocument(); + expect(sessionStorage.getItem('websites-sync-org-sync')).toBeNull(); + await act(async () => finishRetry?.()); + await waitFor(() => + expect(screen.queryByRole('alert')).not.toBeInTheDocument(), + ); + expect(sessionStorage.getItem('websites-sync-org-sync')).toBe( + String(Date.now()), + ); + }); + + it('clears an expired timestamp on failure without touching another organization', async () => { + sessionStorage.setItem( + 'websites-sync-org-sync', + String(Date.now() - 300_000), + ); + sessionStorage.setItem('websites-sync-other-org', String(Date.now())); + syncStatuses.mockRejectedValueOnce(new Error('Unavailable')); + const view = render(); + await screen.findByRole('alert'); + expect(sessionStorage.getItem('websites-sync-org-sync')).toBeNull(); + expect(sessionStorage.getItem('websites-sync-other-org')).toBe( + String(Date.now()), + ); + view.rerender(); + expect(screen.queryByRole('alert')).not.toBeInTheDocument(); + expect(syncStatuses).toHaveBeenCalledTimes(1); + }); + it('stacks the search notice above the table inside the list frame', () => { render(); const notice = screen.getByTestId('website-search-notice'); @@ -86,6 +212,31 @@ describe('WebsitesTable', () => { }); describe('accessibility', () => { + it.each(['en', 'de', 'fr'] as const)( + 'shows an accessible, localized retry error in %s', + async (language) => { + locale.value = language; + syncStatuses.mockRejectedValueOnce(new Error('Unavailable')); + const { container, user } = render( + , + ); + const alert = await screen.findByRole('alert'); + const copy = catalogs[language].websites.syncError; + expect(alert).toHaveTextContent(copy.title); + expect(alert).toHaveTextContent(copy.description); + const retry = screen.getByRole('button', { name: copy.retry }); + await checkAccessibility(container, { + rules: { 'aria-allowed-attr': { enabled: false } }, + }); + retry.focus(); + await user.keyboard('{Enter}'); + await waitFor(() => + expect(screen.queryByRole('alert')).not.toBeInTheDocument(), + ); + expect(syncStatuses).toHaveBeenCalledTimes(2); + }, + ); + it('passes axe audit', async () => { const { container } = render( , diff --git a/services/platform/app/features/websites/components/websites-table.tsx b/services/platform/app/features/websites/components/websites-table.tsx index a6aa62367c..ac57fe2f4b 100644 --- a/services/platform/app/features/websites/components/websites-table.tsx +++ b/services/platform/app/features/websites/components/websites-table.tsx @@ -1,5 +1,7 @@ 'use client'; +import { Alert } from '@tale/ui/alert'; +import { Button } from '@tale/ui/button'; import { DataTable } from '@tale/ui/data-table/data-table'; import { BulkDeleteBar } from '@tale/ui/data-table/data-table-bulk-actions'; import { useListPage } from '@tale/ui/use-list-page'; @@ -41,18 +43,33 @@ export function WebsitesTable({ const { t: tEmpty } = useT('emptyStates'); const { t: tWebsites } = useT('websites'); const [createOpen, setCreateOpen] = useState(false); + const [syncErrors, setSyncErrors] = useState>({}); const { data: count } = useApproxWebsiteCount(organizationId); - const { mutate: syncStatuses } = useSyncWebsiteStatuses(); + const { mutateAsync: syncStatuses, isPending: isSyncPending } = + useSyncWebsiteStatuses(); + + const handleSync = useCallback(() => { + const key = `websites-sync-${organizationId}`; + void syncStatuses({ organizationId }).then( + () => { + sessionStorage.setItem(key, String(Date.now())); + setSyncErrors((previous) => ({ ...previous, [organizationId]: false })); + }, + () => { + sessionStorage.removeItem(key); + setSyncErrors((previous) => ({ ...previous, [organizationId]: true })); + }, + ); + }, [organizationId, syncStatuses]); useEffect(() => { const key = `websites-sync-${organizationId}`; const lastSync = sessionStorage.getItem(key); const fiveMinutes = 5 * 60 * 1000; if (lastSync && Date.now() - Number(lastSync) < fiveMinutes) return; - sessionStorage.setItem(key, String(Date.now())); - syncStatuses({ organizationId }); - }, [organizationId, syncStatuses]); + handleSync(); + }, [organizationId, handleSync]); const { columns, searchPlaceholder, pageSize } = useWebsitesTableConfig(); const paginatedResult = useListWebsitesPaginated({ organizationId, @@ -193,6 +210,24 @@ export function WebsitesTable({ keeps the page inset and the table keeps the remaining height. */}
+ {syncErrors[organizationId] && ( + + + + )} Date: Mon, 5 Oct 2026 14:38:46 +0000 Subject: [PATCH 2/2] docs(manual): move website status sync coverage paragraph --- .../platform/tests/manual/reference/automation.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/services/platform/tests/manual/reference/automation.md b/services/platform/tests/manual/reference/automation.md index 4c59084c3c..9cd0ba2065 100644 --- a/services/platform/tests/manual/reference/automation.md +++ b/services/platform/tests/manual/reference/automation.md @@ -6,13 +6,6 @@ suite alongside the automated ones — they drive the same stack. ## Coverage map -Website status sync records the five-minute throttle only after success. Failed -syncs retry on remount, clear expired timestamps and expose an accessible Retry -alert that stays visible during retry and clears on success. Organization-scoped -storage and errors, completion after unmount and successful throttle expiry are -covered by `app/features/websites/components/websites-table.test.tsx`. -Real-browser layout, focus and screen-reader announcements remain manual. - Website content search clears submitted results when the input changes to a different query, without issuing another request until Enter. Whitespace-only edits retain results; clearing the input and late responses after edits are @@ -28,6 +21,13 @@ in EN/DE/FR that clear after correction: covers the component boundary and axe audit; real API persistence and browser layout remain manual. +Website status sync records the five-minute throttle only after success. Failed +syncs retry on remount, clear expired timestamps and expose an accessible Retry +alert that stays visible during retry and clears on success. Organization-scoped +storage and errors, completion after unmount and successful throttle expiry are +covered by `app/features/websites/components/websites-table.test.tsx`. +Real-browser layout, focus and screen-reader announcements remain manual. + Failed single-notification and bulk reads restore unread rows and retry controls in both organization and personal streams, including body activation and a fresh unread response. Bulk failures restore only the failed stream's captured