feat(search): add exact company aliases

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>
This commit is contained in:
2026-11-22 18:08:35 +01:00
parent 64a7124889
commit f7b057efa3
13 changed files with 413 additions and 43 deletions

View File

@ -49,7 +49,7 @@ describe('Ticket #19 — company-first watchlist search', () => {
const history = await screen.findByRole('region', { name: /actifs historiques/i })
expect(within(history).getByText('Historic S&P index')).toBeInTheDocument()
const query = await screen.findByRole('textbox', { name: /nom de l'entreprise/i })
const query = await screen.findByRole('textbox', { name: /nom ou nom courant de l’entreprise/i })
expect(screen.getAllByRole('textbox')).toHaveLength(1)
await user.type(query, 'BYD')
expect(searchCompanies).not.toHaveBeenCalled()
@ -79,7 +79,7 @@ describe('Ticket #19 — company-first watchlist search', () => {
const history = await screen.findByRole('region', { name: /autres suivis existants/i })
expect(within(history).getByText('Existing index')).toBeInTheDocument()
expect(within(history).queryByRole('button')).not.toBeInTheDocument()
await user.type(screen.getByLabelText("Nom de l'entreprise"), 'BYD{Enter}')
await user.type(screen.getByLabelText('Nom ou nom courant de l’entreprise'), 'BYD{Enter}')
const results = await screen.findByRole('region', { name: /résultats des entreprises/i })
expect(await within(results).findByText('Shenzhen Stock Exchange')).toBeInTheDocument()
expect(within(results).getByText('China')).toBeInTheDocument()
@ -95,7 +95,7 @@ describe('Ticket #19 — company-first watchlist search', () => {
render(<Watchlist />)
await user.selectOptions(screen.getByLabelText('Langue / Language'), 'en')
await screen.findByText('BYD Company Limited')
expect(screen.getByLabelText('Company name')).toBeInTheDocument()
expect(screen.getByLabelText('Company name or commonly used name')).toBeInTheDocument()
expect(screen.queryByText('002594.SZ')).not.toBeInTheDocument()
await user.click(screen.getByRole('button', { name: 'Unfollow BYD Company Limited' }))
expect(await screen.findByText('Company unfollowed.')).toBeInTheDocument()
@ -110,9 +110,9 @@ describe('Ticket #19 — company-first watchlist search', () => {
searchCompanies.mockRejectedValueOnce(new Error('offline'))
const user = userEvent.setup()
render(<Watchlist />)
await user.type(screen.getByLabelText("Nom de l'entreprise"), 'BYD{Enter}')
await user.type(screen.getByLabelText('Nom ou nom courant de l’entreprise'), 'BYD{Enter}')
expect(await screen.findByRole('alert')).toHaveTextContent('Impossible de rechercher des entreprises')
expect(screen.getByLabelText("Nom de l'entreprise")).toHaveValue('BYD')
expect(screen.getByLabelText('Nom ou nom courant de l’entreprise')).toHaveValue('BYD')
expect(searchCompanies).toHaveBeenCalledTimes(1)
await user.click(screen.getByRole('button', { name: 'Réessayer' }))
expect(await screen.findByText('BYD Company Limited')).toBeInTheDocument()
@ -126,7 +126,7 @@ describe('Ticket #19 — company-first watchlist search', () => {
] satisfies CompanySearchResult[])
const user = userEvent.setup()
render(<Watchlist />)
await user.type(screen.getByLabelText("Nom de l'entreprise"), 'Example{Enter}')
await user.type(screen.getByLabelText('Nom ou nom courant de l’entreprise'), 'Example{Enter}')
const results = screen.getByRole('region', { name: /résultats des entreprises/i })
const names = await within(results).findAllByText('Example Company')
expect(names).toHaveLength(2)
@ -145,7 +145,7 @@ describe('Ticket #19 — company-first watchlist search', () => {
searchCompanies.mockResolvedValueOnce([{ company_id: 'company-unknown', name: 'Example Company', country: '', exchange: '', mic: 'XNAS' }] satisfies CompanySearchResult[])
const user = userEvent.setup()
render(<Watchlist />)
await user.type(screen.getByLabelText("Nom de l'entreprise"), 'Example{Enter}')
await user.type(screen.getByLabelText('Nom ou nom courant de l’entreprise'), 'Example{Enter}')
const name = await screen.findByText('Example Company')
expect(name).toHaveClass('font-semibold')
expect(screen.queryByText('XNAS')).not.toBeInTheDocument()