Embed a versioned local alias overlay and rank exact aliases before legal-name matches and word prefixes. Normalize Unicode consistently, deduplicate by company identity before limiting, and update bilingual search guidance and tests. Refs #24 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
40 lines
2.5 KiB
TypeScript
40 lines
2.5 KiB
TypeScript
import { cleanup, render, screen, waitFor, within } from '@testing-library/react'
|
||
import userEvent from '@testing-library/user-event'
|
||
import { afterEach, beforeEach, expect, it, vi } from 'vitest'
|
||
import { Watchlist } from '../src/pages/Watchlist'
|
||
|
||
const { search, list, add } = vi.hoisted(() => ({ search: vi.fn(), list: vi.fn(), add: vi.fn() }))
|
||
vi.mock('@/api/assets', () => ({ assetsApi: { search, list, add, remove: vi.fn() } }))
|
||
afterEach(cleanup)
|
||
beforeEach(() => {
|
||
vi.clearAllMocks()
|
||
list.mockResolvedValue([])
|
||
search.mockResolvedValue([{ company_id: 'company-ibm', name: 'International Business Machines Corporation', country: 'United States', exchange: 'New York Stock Exchange', mic: 'XNYS', symbol: 'IBM' }])
|
||
})
|
||
|
||
it.each([
|
||
{ language: 'fr', label: 'Nom ou nom courant de l’entreprise', help: /Intel.*IBM/, results: 'Résultats des entreprises', query: 'Intel', empty: 'Aucune entreprise trouvée. Essayez un autre nom ou nom courant, par exemple Intel ou IBM.' },
|
||
{ language: 'en', label: 'Company name or commonly used name', help: /Intel.*IBM/, results: 'Company results', query: 'IBM', empty: 'No company found. Try another name or commonly used name, such as Intel or IBM.' },
|
||
] as const)('affiche les textes accessibles $language et garde la recherche explicite au clavier', async ({ language, label, help, results, query, empty }) => {
|
||
const user = userEvent.setup()
|
||
render(<Watchlist />)
|
||
if (language === 'en') await user.selectOptions(screen.getByLabelText('Langue / Language'), 'en')
|
||
const input = screen.getByRole('textbox', { name: label })
|
||
expect(input).toHaveAccessibleDescription(help)
|
||
expect(input).toHaveAttribute('maxLength', '100')
|
||
await user.type(input, query)
|
||
expect(search).not.toHaveBeenCalled()
|
||
await user.keyboard('{Enter}')
|
||
await waitFor(() => expect(search).toHaveBeenCalledWith(query, 20))
|
||
const region = screen.getByRole('region', { name: results })
|
||
expect(await within(region).findByText('International Business Machines Corporation')).toBeInTheDocument()
|
||
expect(within(region).getByText('United States')).toBeInTheDocument()
|
||
expect(within(region).getByText('New York Stock Exchange')).toBeInTheDocument()
|
||
for (const value of ['IBM', 'XNYS', 'company-ibm']) expect(within(region).queryByText(value, { exact: true })).not.toBeInTheDocument()
|
||
expect(add).not.toHaveBeenCalled()
|
||
search.mockResolvedValueOnce([])
|
||
await user.clear(input)
|
||
await user.type(input, 'Unknown{Enter}')
|
||
expect(await screen.findByText(empty)).toHaveAttribute('role', 'status')
|
||
})
|