diff --git a/docs/de/platform/knowledge/structured-data.md b/docs/de/platform/knowledge/structured-data.md index 3c7eccf22f..8914e4e584 100644 --- a/docs/de/platform/knowledge/structured-data.md +++ b/docs/de/platform/knowledge/structured-data.md @@ -40,6 +40,8 @@ Zum Pflegen der Organisationsdatensätze brauchst du die Rolle Redakteur oder h Vor dem Speichern prüft das Formular jedes Feld gegen das, was Tale speichert: **Name** bis 300 Zeichen, **Telefon** bis 50, **Sprache** bis 20 und bei der **E-Mail** höchstens 64 Zeichen vor dem `@`. Ein Wert über einer Grenze wird unter seinem Feld genannt, und gespeichert wird erst, wenn du ihn korrigiert hast. +Um nur die Kontakte einer Sprache zu sehen, wähle über der Kontaktliste **Filter** und unter **Sprache** die gewünschte Sprache. Eine Sprache schließt ihre regionalen Varianten ein: **FR** zeigt Kontakte mit der Sprache `fr`, `fr-CH` oder `fr_CA`. Ein Kontakt ohne Sprache erscheint nur, solange keine Sprache gewählt ist. + Du kannst einen Kontakt auch beim Schreiben anlegen. Wähle im Bereich **Start** in der Ansicht **Inbox** die Schaltfläche **Neue E-Mail** und tippe eine Adresse in **An**: Trägt sie kein Kontakt, bietet die Liste **„…“ als Kontakt hinzufügen** an und öffnet dasselbe Formular mit bereits ausgefüllter **E-Mail**. Nach dem Speichern ist dieser Kontakt der Empfänger – du verlässt die begonnene Nachricht also nie. Ist die E-Mail-Adresse bereits vorhanden, suche den bestehenden Kontakt und bearbeite ihn über sein Zeilenmenü; aus **Neue E-Mail** heraus wählt Tale den vorhandenen Kontakt für dich aus. Beim Speichern wird nur der Datensatz angelegt; Tale sendet dem Kontakt dabei keine E-Mail. diff --git a/docs/en/platform/knowledge/structured-data.md b/docs/en/platform/knowledge/structured-data.md index facb635a02..9963187a62 100644 --- a/docs/en/platform/knowledge/structured-data.md +++ b/docs/en/platform/knowledge/structured-data.md @@ -40,6 +40,8 @@ You need an Editor role or higher to maintain organization records. Open **Knowl The form holds each field to what Tale stores before it saves: a **Name** of up to 300 characters, a **Phone** of up to 50, a **Locale** of up to 20, and an **Email** with at most 64 characters before the `@`. A value past a limit is named under its field, and nothing is saved until you fix it. +To see only the contacts in one language, choose **Filter** above the Contacts list and pick the language under **Locale**. A language includes its regional variants: **FR** lists contacts whose locale is `fr`, `fr-CH`, or `fr_CA`. A contact without a locale appears only while no language is picked. + You can also add a contact while writing to them. In the **Inbox** view in Home, choose **New email** and type an address into **To**: if no contact carries it, the list offers **Add “…” as a contact**, which opens this same form with the **Email** already filled. Saving makes that contact the recipient, so you never leave the message you are writing. If the email address already exists, find the existing contact and update it through the row menu instead of creating a duplicate; from **New email**, Tale selects the existing contact for you. Saving a contact creates a record; it does not send that person an email. diff --git a/docs/fr/platform/knowledge/structured-data.md b/docs/fr/platform/knowledge/structured-data.md index 3c41f4850d..70ab78e809 100644 --- a/docs/fr/platform/knowledge/structured-data.md +++ b/docs/fr/platform/knowledge/structured-data.md @@ -40,6 +40,8 @@ Le rôle Rédacteur ou un rôle supérieur est nécessaire pour modifier les fic Avant d’enregistrer, le formulaire vérifie chaque champ selon ce que Tale conserve : un **Nom** de 300 caractères au plus, un **Téléphone** de 50 au plus, une **Langue** de 20 au plus et un **Courriel** d’au plus 64 caractères avant le `@`. Une valeur qui dépasse une limite est signalée sous son champ, et rien n’est enregistré tant que tu ne l’as pas corrigée. +Pour n’afficher que les contacts d’une langue, choisis **Filtre** au-dessus de la liste des contacts, puis la langue sous **Langue**. Une langue inclut ses variantes régionales : **FR** affiche les contacts dont la langue est `fr`, `fr-CH` ou `fr_CA`. Un contact sans langue n’apparaît que tant qu’aucune langue n’est choisie. + Tu peux aussi créer une fiche au moment d’écrire. Dans la vue **Réception** d’**Accueil**, choisis **Nouvel e-mail** et saisis une adresse dans **À** : si aucun contact ne la porte, la liste propose **Ajouter « … » comme contact**, ce qui ouvre ce même formulaire avec le **Courriel** déjà renseigné. Une fois la fiche enregistrée, ce contact devient le destinataire : tu ne quittes jamais le message en cours. Si cette adresse existe déjà, retrouve la fiche et modifie-la depuis le menu de sa ligne ; depuis **Nouvel e-mail**, Tale sélectionne pour toi le contact existant. Enregistrer un contact crée uniquement une fiche ; cette opération ne lui envoie aucun e-mail. diff --git a/services/platform/app/features/contacts/components/contact-table.wire.test.tsx b/services/platform/app/features/contacts/components/contact-table.wire.test.tsx new file mode 100644 index 0000000000..c1b32fadff --- /dev/null +++ b/services/platform/app/features/contacts/components/contact-table.wire.test.tsx @@ -0,0 +1,189 @@ +/** + * The Contacts list over its real paginated read: `useListContactsPaginated`, + * the adapter row and `backendFetch` run unchanged, and only `fetch` is + * answered here, by a small model of the contacts door that narrows by the + * facets its address names. The router, the abilities and the column config + * are stubbed as in `contact-table.test.tsx`. + */ +import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; +import type { ColumnDef } from '@tanstack/react-table'; +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; + +import type { ContactDoc } from '@/app/lib/backend/contract/docs'; +import { render, screen, waitFor, within } from '@/tests/utils/render'; +import { + syntheticBackend, + type SyntheticBackend, +} from '@/tests/utils/synthetic-backend'; + +import { ContactsTable } from './contact-table'; + +vi.mock('@tanstack/react-router', () => ({ + useNavigate: () => vi.fn(), +})); +vi.mock('@/app/hooks/use-ability', () => ({ + useAbility: () => ({ can: () => true, cannot: () => false }), +})); +vi.mock('../hooks/mutations', () => ({ + useBulkCreateContacts: () => ({ mutateAsync: vi.fn() }), + useCreateContact: () => ({ mutateAsync: vi.fn() }), + useDeleteContact: () => ({ mutateAsync: vi.fn() }), + useUpdateContact: () => ({ mutateAsync: vi.fn() }), +})); + +const columns: ColumnDef[] = [ + { accessorKey: 'name', header: 'Name', size: 200 }, + { accessorKey: 'locale', header: 'Locale', size: 120 }, +]; + +vi.mock('../hooks/use-contacts-table-config', () => ({ + useContactsTableConfig: () => ({ + columns, + searchPlaceholder: 'Search contacts', + pageSize: 20, + }), +})); + +const ORG = 'org-1'; + +function wireContact(name: string, locale: string, source: string) { + return { + id: `contact-${name.toLowerCase().replaceAll(' ', '-')}`, + organizationId: ORG, + name, + email: `${name.toLowerCase().replaceAll(' ', '.')}@example.test`, + phone: null, + externalId: null, + source, + locale, + address: null, + tags: [], + metadata: null, + notes: null, + lifecycleStatus: null, + createdAt: 1770000000000, + updatedAt: 1770000000000, + }; +} + +const directory = [ + wireContact('Audit en', 'en', 'manual_import'), + wireContact('Audit fr', 'fr', 'manual_import'), + wireContact('Audit fr-CH', 'fr-CH', 'manual_import'), + wireContact('Upload en', 'en', 'file_upload'), +]; + +/** The contacts door as the list reaches it: each facet its address names + * narrows the rows, a language listing its regional tags. */ +function contactsDoor(url: URL): Response { + const source = url.searchParams.get('source'); + const locale = url.searchParams.get('locale')?.toLowerCase(); + const items = directory.filter( + (row) => + (source === null || row.source === source) && + (locale === undefined || + row.locale.toLowerCase() === locale || + row.locale.toLowerCase().startsWith(`${locale}-`)), + ); + return Response.json({ items, nextCursor: null }); +} + +let backend: SyntheticBackend; + +beforeEach(() => { + // The adapters resolve the active organization from the page's address. + window.history.pushState({}, '', `/dashboard/${ORG}/contacts`); + backend = syntheticBackend(); + backend.on(/^GET \/api\/app\/contacts\/count\?/, () => + Response.json({ count: directory.length }), + ); + backend.on(/^GET \/api\/app\/contacts\?/, contactsDoor); +}); + +afterEach(() => { + vi.restoreAllMocks(); +}); + +function contactsTable(props: { source?: string; locale?: string }) { + return ; +} + +function renderTable(props: { source?: string; locale?: string } = {}) { + const client = new QueryClient({ + defaultOptions: { queries: { retry: false } }, + }); + const view = render( + + {contactsTable(props)} + , + ); + return { + rerender: (next: { source?: string; locale?: string }) => + view.rerender( + + {contactsTable(next)} + , + ), + }; +} + +/** The names of the data rows the table renders, in order: each row's first + * cell with text (the selection checkbox has none, Name precedes Locale). */ +function listedNames(): string[] { + return screen + .getAllByRole('row') + .map((row) => + within(row) + .queryAllByRole('cell') + .map((cell) => cell.textContent?.trim() ?? '') + .find((text) => text !== ''), + ) + .filter((name): name is string => name !== undefined); +} + +const listReads = () => + backend.calls.filter((call) => call.startsWith('GET /api/app/contacts?')); + +describe('the Contacts facets over the real list read', () => { + // #3618: the Locale facet showed as active while the list asked for, cached + // and rendered every contact. + it('lists only the French contacts under the French Locale', async () => { + renderTable({ locale: 'fr' }); + + await waitFor(() => + expect(listedNames()).toEqual(['Audit fr', 'Audit fr-CH']), + ); + expect(listReads()).toEqual([ + `GET /api/app/contacts?limit=20&locale=fr&orgId=${ORG}`, + ]); + }); + + it('reads the list again when the Locale changes, and back', async () => { + const view = renderTable(); + await waitFor(() => expect(listedNames()).toHaveLength(4)); + + view.rerender({ locale: 'fr' }); + await waitFor(() => + expect(listedNames()).toEqual(['Audit fr', 'Audit fr-CH']), + ); + + view.rerender({}); + await waitFor(() => expect(listedNames()).toHaveLength(4)); + expect(listReads().slice(0, 2)).toEqual([ + `GET /api/app/contacts?limit=20&orgId=${ORG}`, + `GET /api/app/contacts?limit=20&locale=fr&orgId=${ORG}`, + ]); + }); + + it('still narrows by Source, alone and beside the Locale', async () => { + const view = renderTable({ source: 'file_upload' }); + await waitFor(() => expect(listedNames()).toEqual(['Upload en'])); + + view.rerender({ source: 'manual_import', locale: 'en' }); + await waitFor(() => expect(listedNames()).toEqual(['Audit en'])); + expect(listReads()).toEqual([ + `GET /api/app/contacts?limit=20&source=file_upload&orgId=${ORG}`, + `GET /api/app/contacts?limit=20&source=manual_import&locale=en&orgId=${ORG}`, + ]); + }); +}); diff --git a/services/platform/app/lib/backend/engagement.test.ts b/services/platform/app/lib/backend/engagement.test.ts index 0d6c0bc26c..4a36944a9f 100644 --- a/services/platform/app/lib/backend/engagement.test.ts +++ b/services/platform/app/lib/backend/engagement.test.ts @@ -157,6 +157,74 @@ describe.each([ }); }); +describe('the contacts listing facets', () => { + const listing = (args: Record) => + engagementPaginatedAdapters['contacts/queries:listContactsPaginated']?.( + args, + ctx, + ); + + /** The address of every page the adapter asked for, origin stripped. */ + async function requested( + args: Record, + cursor: string | null = null, + ): Promise { + const fetchSpy = vi + .spyOn(window, 'fetch') + .mockResolvedValue( + new Response(JSON.stringify({ items: [], nextCursor: null })), + ); + await listing(args)?.fetchPage(cursor, 20); + const input = fetchSpy.mock.calls[0]?.[0]; + fetchSpy.mockRestore(); + return typeof input === 'string' ? input : ''; + } + + // #3618: the Locale facet changed neither the request nor the cache key, + // so the list kept every contact under an active filter. + it('asks for the selected Locale and keys its pages apart', async () => { + expect(await requested({ locale: 'fr' })).toBe( + '/api/app/contacts?limit=20&locale=fr&orgId=org1', + ); + expect(listing({ locale: 'fr' })?.queryKey).not.toEqual( + listing({})?.queryKey, + ); + expect(listing({ locale: 'fr' })?.queryKey).not.toEqual( + listing({ locale: 'de' })?.queryKey, + ); + }); + + it('keeps the Locale on every later page', async () => { + expect(await requested({ locale: 'fr' }, '1770003600000|record-1')).toBe( + '/api/app/contacts?limit=20&locale=fr&cursorUpdatedAt=1770003600000&cursorId=record-1&orgId=org1', + ); + }); + + it('still asks for the Source, alone and beside the Locale', async () => { + expect(await requested({ source: 'file_upload' })).toBe( + '/api/app/contacts?limit=20&source=file_upload&orgId=org1', + ); + expect(await requested({ source: 'file_upload', locale: 'fr' })).toBe( + '/api/app/contacts?limit=20&source=file_upload&locale=fr&orgId=org1', + ); + const keys = [ + listing({}), + listing({ source: 'file_upload' }), + listing({ locale: 'file_upload' }), + listing({ source: 'file_upload', locale: 'fr' }), + ].map((adapter) => JSON.stringify(adapter?.queryKey)); + expect(new Set(keys).size).toBe(keys.length); + }); + + it('keys every facet under the contact entity a write invalidates', () => { + expect(listing({ locale: 'fr' })?.queryKey.slice(0, 3)).toEqual([ + 'backend', + 'org1', + 'contact', + ]); + }); +}); + describe('website creation dates', () => { const wireRow = { id: 'website-1', diff --git a/services/platform/app/lib/backend/engagement.ts b/services/platform/app/lib/backend/engagement.ts index d3f979a426..40f4bbd6a3 100644 --- a/services/platform/app/lib/backend/engagement.ts +++ b/services/platform/app/lib/backend/engagement.ts @@ -370,7 +370,7 @@ export const engagementPaginatedAdapters: Record = { typeof args[key] === 'string' && args[key] !== '' ? `&${key}=${encodeURIComponent(args[key])}` : ''; - const qs = qsOf('search') + qsOf('source'); + const qs = qsOf('search') + qsOf('source') + qsOf('locale'); return { queryKey: backendKey( orgId, @@ -378,6 +378,7 @@ export const engagementPaginatedAdapters: Record = { 'page', keyPart(args.search), keyPart(args.source), + keyPart(args.locale), ), fetchPage: (cursor, numItems) => { const split = splitCursor(cursor); diff --git a/services/platform/backend/domains/contacts/routes.test.ts b/services/platform/backend/domains/contacts/routes.test.ts index b9bc92a95e..25a8ba91ca 100644 --- a/services/platform/backend/domains/contacts/routes.test.ts +++ b/services/platform/backend/domains/contacts/routes.test.ts @@ -1,17 +1,22 @@ import type { Context } from 'hono'; import { beforeEach, describe, expect, it, vi } from 'vitest'; -import { CONTACT_IMPORT_ROWS_MAX } from '../../../lib/shared/schemas/common.ts'; +import { + CONTACT_IMPORT_ROWS_MAX, + CONTACT_LOCALE_MAX, +} from '../../../lib/shared/schemas/common.ts'; import type { OrgEnv } from '../../auth/org.ts'; -const { bulkCreateContacts, updateContact } = vi.hoisted(() => ({ +const { bulkCreateContacts, listContacts, updateContact } = vi.hoisted(() => ({ bulkCreateContacts: vi.fn(), + listContacts: vi.fn(), updateContact: vi.fn(), })); vi.mock('./service.ts', async (importOriginal) => ({ ...(await importOriginal()), bulkCreateContacts, + listContacts, updateContact, })); vi.mock('@tale/shared/db/serializable', () => ({ @@ -203,3 +208,37 @@ describe('contact edit', () => { ); }); }); + +describe('contact listing filters', () => { + beforeEach(() => { + vi.clearAllMocks(); + listContacts.mockResolvedValue({ items: [], nextCursor: null }); + }); + + const list = (query: string) => app.request(`/?orgId=o1&${query}`); + + // #3618: the door never read `locale`, so the Contacts Locale facet listed + // every contact. + it('hands the Locale facet to the listing beside the Source', async () => { + expect((await list('limit=20&locale=fr')).status).toBe(200); + expect(listContacts).toHaveBeenLastCalledWith( + expect.anything(), + expect.objectContaining({ organizationId: 'o1' }), + { limit: 20, locale: 'fr', cursor: null }, + ); + expect((await list('source=file_upload&locale=fr')).status).toBe(200); + expect(listContacts).toHaveBeenLastCalledWith( + expect.anything(), + expect.anything(), + { source: 'file_upload', locale: 'fr', cursor: null }, + ); + }); + + it('refuses a Locale longer than any contact stores, as it does a Source', async () => { + expect( + (await list(`locale=${'x'.repeat(CONTACT_LOCALE_MAX + 1)}`)).status, + ).toBe(400); + expect((await list('source=fax')).status).toBe(400); + expect(listContacts).not.toHaveBeenCalled(); + }); +}); diff --git a/services/platform/backend/domains/contacts/routes.ts b/services/platform/backend/domains/contacts/routes.ts index 8033ca5110..9afd62d4ad 100644 --- a/services/platform/backend/domains/contacts/routes.ts +++ b/services/platform/backend/domains/contacts/routes.ts @@ -6,6 +6,7 @@ import { z } from 'zod'; import { CONTACT_EXTERNAL_ID_MAX, CONTACT_IMPORT_ROWS_MAX, + CONTACT_LOCALE_MAX, CONTACT_LOCALE_PATTERN, } from '../../../lib/shared/schemas/common.ts'; import type { Auth } from '../../auth/auth.ts'; @@ -84,6 +85,9 @@ export function createContactRoutes(deps: { .object({ search: z.string().max(200).optional(), source: sourceSchema.optional(), + // An open set, like `search` and `tag`: the REST door stores any + // locale up to the cap, so an unknown one lists nothing. + locale: z.string().max(CONTACT_LOCALE_MAX).optional(), tag: z.string().max(60).optional(), limit: z.coerce.number().int().min(1).max(200).optional(), cursorUpdatedAt: z.coerce.number().int().positive().optional(), @@ -92,6 +96,7 @@ export function createContactRoutes(deps: { .safeParse({ search: c.req.query('search'), source: c.req.query('source'), + locale: c.req.query('locale'), tag: c.req.query('tag'), limit: c.req.query('limit'), cursorUpdatedAt: c.req.query('cursorUpdatedAt'), diff --git a/services/platform/backend/domains/contacts/service.test.ts b/services/platform/backend/domains/contacts/service.test.ts index 2ded388d39..1d2b24fd03 100644 --- a/services/platform/backend/domains/contacts/service.test.ts +++ b/services/platform/backend/domains/contacts/service.test.ts @@ -28,6 +28,7 @@ import { ContactError, createContact, findOrCreateContactByEmail, + listContacts, } from './service.ts'; type Statement = { text: string; values: unknown[] }; @@ -273,3 +274,39 @@ describe('bulkCreateContacts — the import door', () => { expect(createAuditLog).not.toHaveBeenCalled(); }); }); + +describe('listContacts — the Locale facet', () => { + /** The values bound to the listing's three locale comparisons. */ + function localeSlots(statements: Statement[]): unknown[] { + const listing = statements.find((s) => s.text.includes('ORDER BY')); + const segments = listing?.text.split('?') ?? []; + return (listing?.values ?? []).filter((_, index) => { + const after = segments[index + 1] ?? ''; + return ( + after.startsWith('::text IS NULL OR lower(replace(locale') || + after.startsWith(" OR starts_with(lower(replace(locale, '_', '-'))") || + after.startsWith("::text || '-')") + ); + }); + } + + // #3618: the listing had no locale predicate at all. A facet names a + // language (`fr`), the directory stores tags (`fr-CH`, `fr_CA`, `FR`), so + // the range is compared as RFC 4647 basic filtering compares it. + it('compares a lower-case, hyphenated range against the tag and its subtags', async () => { + const { sql, statements } = recordingSql(); + await listContacts(sql, SCOPE, { locale: ' FR_ca ' }); + expect(statements[0]?.text).toContain( + "AND (?::text IS NULL OR lower(replace(locale, '_', '-')) = ? OR starts_with(lower(replace(locale, '_', '-')), ?::text || '-'))", + ); + expect(localeSlots(statements)).toEqual(['fr-ca', 'fr-ca', 'fr-ca']); + }); + + it('filters nothing without a Locale, or with a blank one', async () => { + for (const options of [{}, { locale: ' ' }]) { + const { sql, statements } = recordingSql(); + await listContacts(sql, SCOPE, options); + expect(localeSlots(statements)).toEqual([null, null, null]); + } + }); +}); diff --git a/services/platform/backend/domains/contacts/service.ts b/services/platform/backend/domains/contacts/service.ts index 22230826b8..4a3f21f095 100644 --- a/services/platform/backend/domains/contacts/service.ts +++ b/services/platform/backend/domains/contacts/service.ts @@ -759,12 +759,27 @@ export async function getContact( return contact; } +/** + * A locale filter as the listing compares it: lower case, with `_` read as + * `-`, so `fr_CA` and `fr-ca` name the same tag. Null when blank. + */ +function localeRange(value: string | undefined): string | null { + const trimmed = value?.trim(); + return trimmed ? trimmed.toLowerCase().replaceAll('_', '-') : null; +} + export async function listContacts( sql: Sql, scope: ContactScope, options: { search?: string; source?: ContactSource; + /** A language (`fr`) or a regional tag (`fr-CH`), matched the way + * RFC 4647 basic filtering matches a language range: a tag equal to it, + * or one extending it by further subtags, case-insensitively — `fr` + * lists `fr`, `FR`, `fr-CH` and `fr_CA`, never `en`; `fr-CH` lists only + * `fr-CH`. */ + locale?: string; tag?: string; cursor?: { updatedAt: number; id: string } | null; limit?: number; @@ -776,6 +791,7 @@ export async function listContacts( assertContactAccess(scope, 'read'); const limit = Math.min(options.limit ?? 50, 200); const search = options.search?.trim() ? `%${options.search.trim()}%` : null; + const locale = localeRange(options.locale); const cursor = options.cursor ?? null; const rows = await sql` SELECT ${sql.unsafe(CONTACT_COLUMNS)} FROM app.contacts @@ -784,6 +800,9 @@ export async function listContacts( AND (${search}::text IS NULL OR name ILIKE ${search} OR email ILIKE ${search} OR phone ILIKE ${search}) AND (${options.source ?? null}::text IS NULL OR source = ${options.source ?? null}) + AND (${locale}::text IS NULL + OR lower(replace(locale, '_', '-')) = ${locale} + OR starts_with(lower(replace(locale, '_', '-')), ${locale}::text || '-')) AND (${options.tag ?? null}::text IS NULL OR ${options.tag ?? null} = ANY(tags)) AND (${cursor?.updatedAt ?? null}::bigint IS NULL OR updated_at_ms < ${cursor?.updatedAt ?? null} diff --git a/services/platform/backend/integration-check.ts b/services/platform/backend/integration-check.ts index ff18cc2825..b08b1afc55 100644 --- a/services/platform/backend/integration-check.ts +++ b/services/platform/backend/integration-check.ts @@ -7573,6 +7573,79 @@ async function checkSmallDomains( `listed created=${hopperListed?.createdAt} updated=${hopperListed?.updatedAt}, hit updatedAt=${hopperSearched?.updatedAt} (want = listed updatedAt, > createdAt)`, ); + // The Contacts Locale facet narrows the listing (#3618): a language lists + // its regional tags in any case or separator, a regional tag only itself, + // and the Source facet still narrows beside it. The search pins the + // listing to this probe's rows. + const localeRun = `locale-${Date.now()}`; + const localeEmail = (locale: string): string => + `${localeRun}-${locale.toLowerCase()}@example.com`; + const localeBulk = await send( + 'POST', + `/api/app/contacts/bulk?orgId=${orgId}`, + { + contacts: ['fr-CH', 'FR_ca', 'en-US', 'en'].map((locale) => ({ + email: localeEmail(locale), + name: `Locale ${locale}`, + locale, + source: 'file_upload', + })), + }, + ); + const localeManual = await send('POST', `/api/app/contacts?orgId=${orgId}`, { + email: localeEmail('fr'), + name: 'Locale fr', + locale: 'fr', + source: 'manual_import', + }); + const localeRows = async ( + facets: string, + ): Promise<{ id: string; locale: string | null }[] | null> => { + const page = z + .object({ + items: z.array( + z.object({ id: z.string(), locale: z.string().nullable() }), + ), + }) + .safeParse( + await get( + `/api/app/contacts?orgId=${orgId}&limit=200&search=${localeRun}${facets}`, + ), + ); + return page.success ? page.data.items : null; + }; + const localesOf = (rows: { locale: string | null }[] | null): string => + rows === null + ? 'ERR' + : rows + .map((row) => row.locale ?? '') + .sort() + .join(','); + const localeAll = await localeRows(''); + const localeFacets = { + all: localesOf(localeAll), + fr: localesOf(await localeRows('&locale=fr')), + frCH: localesOf(await localeRows('&locale=fr-CH')), + EN: localesOf(await localeRows('&locale=EN')), + frUploads: localesOf(await localeRows('&locale=fr&source=file_upload')), + de: localesOf(await localeRows('&locale=de')), + }; + for (const row of localeAll ?? []) { + await send('DELETE', `/api/app/contacts/${row.id}?orgId=${orgId}`); + } + record( + 'contacts: the Locale facet lists a language with its regional tags', + localeBulk.ok && + localeManual.ok && + localeFacets.all === 'FR_ca,en,en-US,fr,fr-CH' && + localeFacets.fr === 'FR_ca,fr,fr-CH' && + localeFacets.frCH === 'fr-CH' && + localeFacets.EN === 'en,en-US' && + localeFacets.frUploads === 'FR_ca,fr-CH' && + localeFacets.de === '', + `seeded bulk=${localeBulk.status} manual=${localeManual.status}; ${JSON.stringify(localeFacets)} (want all=FR_ca,en,en-US,fr,fr-CH fr=FR_ca,fr,fr-CH frCH=fr-CH EN=en,en-US frUploads=FR_ca,fr-CH de=)`, + ); + // Message feedback lands on a REAL message the caller can read: a chat // thread this user owns, with one assistant reply in it. const fbNow = Date.now(); diff --git a/services/platform/tests/manual/reference/automation.md b/services/platform/tests/manual/reference/automation.md index b9a7027b17..5330f18f16 100644 --- a/services/platform/tests/manual/reference/automation.md +++ b/services/platform/tests/manual/reference/automation.md @@ -122,6 +122,7 @@ Legend: ✅ fully automated · 🔶 partially automated · ⛔ manual-only (no s | [knowledge](../suites/knowledge.md) | Authenticated image intake, MIME/5 MiB limits, reserved-source refusal, organization/parent/binding access, retention lock, absolute REST URL replay, and explicit UI removal | ✅ automated | `backend/domains/products/images.test.ts`, `backend/domains/products/images.routes.test.ts`, `backend/domains/files/routes.register.test.ts`, `backend/domains/files/service.product-images.test.ts`, `backend/rest/product-images.test.ts`, `backend/rest/v1-core.test.ts`, `backend/rest/v1-core.crm.test.ts`, `app/features/products/hooks/use-product-image-upload.test.ts`, `app/features/products/components/product-edit-dialog.test.tsx` | | [knowledge](../suites/knowledge.md) | Screenshot seeding waits for existing table rows despite loading and notification status regions, and matches active/retired WebDAV device labels exactly | ✅ browser | `tests/e2e/specs/docs-screenshot-seed.spec.ts` (synthetic DOM; no organization writes) | | [knowledge](../suites/knowledge.md) | Native contact and product dates reach list and paginated UI records without losing cursor metadata | ✅ unit | `app/lib/backend/engagement.test.ts` | +| [knowledge](../suites/knowledge.md) | The Contacts **Locale** facet narrows the list on the server (#3618): the paginated read asks for `locale` beside `source` on every page and keys each facet's pages apart, the app door hands it to the listing, and a language lists its regional tags in any case or separator (`fr` → `fr`, `FR`, `fr-CH`, `fr_CA`; `fr-CH` → only itself; a contact without a locale only while none is picked), while the **Source** facet still narrows alone and beside it | ✅ unit + route + component + Postgres | `app/lib/backend/engagement.test.ts`, `backend/domains/contacts/routes.test.ts`, `backend/domains/contacts/service.test.ts`, `app/features/contacts/components/contact-table.wire.test.tsx` (the real list read down to `fetch`), the `contacts: the Locale facet lists a language with its regional tags` probe of `backend:integration` (CI's Backend integration check); picking the facet in a real browser stays manual | | [settings](../suites/settings.md) | WebDAV native null timestamps leave active credentials revocable; revoked credentials have a status and no action | ✅ component | `app/features/settings/webdav/components/webdav-settings.test.tsx` | | [settings](../suites/settings.md) | WebDAV discovery reaches the backend through development and preview proxies without widening CORS origins | ✅ integration | `vite-plugins/webdav-preflight.test.ts` (real Vite servers and HTTP backend) | | [navigation](../suites/navigation.md) | Optional analytics: runtime disablement, safe SPA pageviews, private route templates, DNT/GPC and collector boundary | ✅ automated | `packages/ui/src/analytics/browser.test.ts`, `packages/ui/src/analytics/server.test.ts` |