feat(search): find companies by stock symbol

Index exact symbols from selected primary listings, preserve canonical company identities, and add BABA as an explicit alias for Alibaba's primary identity. Update bilingual help and cover symbol collisions, aliases, and DTO stability.

Refs #25

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-11-22 18:31:46 +01:00
parent f7b057efa3
commit f97ae18d6c
10 changed files with 354 additions and 19 deletions

View File

@ -10,9 +10,9 @@ const copy = {
fr: {
title: 'Entreprises suivies', intro: 'Recherchez une entreprise par son nom, choisissez le bon résultat puis suivez-la. Aucune synthèse n’est générée automatiquement.',
searchTitle: 'Rechercher une entreprise', query: 'Nom ou nom courant de l’entreprise', search: 'Rechercher',
help: 'Saisissez le nom ou le nom courant d’une entreprise, par exemple Intel ou IBM. La recherche se lance au clic sur Rechercher ou avec Entrée. Jusqu’à 20 résultats, sans sélection automatique.',
help: 'Saisissez le nom, le sigle courant ou le symbole boursier d’une entreprise, par exemple Intel, IBM, AMZN ou BABA. La recherche se lance au clic sur Rechercher ou avec Entrée. Jusqu’à 20 résultats, sans sélection automatique.',
results: 'Résultats des entreprises', before: 'Saisissez le nom d’une entreprise, puis lancez la recherche.',
searching: 'Recherche en cours…', empty: 'Aucune entreprise trouvée. Essayez un autre nom ou nom courant, par exemple Intel ou IBM.',
searching: 'Recherche en cours…', empty: 'Aucune entreprise trouvée. Essayez un autre nom, sigle courant ou symbole boursier.',
quota: 'Quota de recherche atteint. Réessayez plus tard.', timeout: 'Le délai de recherche est dépassé. Vous pouvez relancer la recherche.',
unavailable: 'Le service de recherche est indisponible. Réessayez plus tard.', searchError: 'Impossible de rechercher des entreprises. Vous pouvez relancer la recherche.',
retry: 'Réessayer', follow: 'Suivre cette entreprise', tracked: 'Déjà suivie', unfollow: 'Ne plus suivre',
@ -28,8 +28,8 @@ const copy = {
en: {
title: 'Followed companies', intro: 'Search for a company by name, choose the correct result, then follow it. No summary is generated automatically.',
searchTitle: 'Search for a company', query: 'Company name or commonly used name', search: 'Search',
help: 'Enter a company name or commonly used name, such as Intel or IBM. Search by clicking Search or pressing Enter. Up to 20 results, with no automatic selection.',
results: 'Company results', before: 'Enter a company name, then search.', searching: 'Searching…', empty: 'No company found. Try another name or commonly used name, such as Intel or IBM.',
help: 'Enter a company name, commonly used acronym or stock symbol, such as Intel, IBM, AMZN or BABA. Search by clicking Search or pressing Enter. Up to 20 results, with no automatic selection.',
results: 'Company results', before: 'Enter a company name, then search.', searching: 'Searching…', empty: 'No company found. Try another name, commonly used acronym or stock symbol.',
quota: 'Search quota reached. Please try again later.', timeout: 'The search timed out. You can search again.',
unavailable: 'The search service is unavailable. Please try again later.', searchError: 'Unable to search for companies. You can search again.',
retry: 'Try again', follow: 'Follow this company', tracked: 'Already followed', unfollow: 'Unfollow',

View File

@ -13,8 +13,8 @@ beforeEach(() => {
})
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.' },
{ 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, sigle courant ou symbole boursier.' },
{ language: 'en', label: 'Company name or commonly used name', help: /Intel.*IBM/, results: 'Company results', query: 'IBM', empty: 'No company found. Try another name, commonly used acronym or stock symbol.' },
] 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 />)

View File

@ -0,0 +1,44 @@
import { cleanup, render, screen, within, waitFor } 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 { list, search, add } = vi.hoisted(() => ({ list: vi.fn(), search: vi.fn(), add: vi.fn() }))
vi.mock('@/api/assets', () => ({ assetsApi: { list, search, add, remove: vi.fn() } }))
afterEach(cleanup)
beforeEach(() => { vi.clearAllMocks(); list.mockResolvedValue([]) })
it.each([
{ language: 'fr', symbol: 'AMZN', name: 'Amazon.com, Inc.' },
{ language: 'fr', symbol: 'BABA', name: 'Alibaba Group Holding Limited' },
{ language: 'en', symbol: 'AMZN', name: 'Amazon.com, Inc.' },
{ language: 'en', symbol: 'BABA', name: 'Alibaba Group Holding Limited' },
] as const)('$language explique la recherche par symbole $symbol sans le rendre dans les résultats', async ({ language, symbol, name }) => {
const company = { company_id: `company-${symbol}`, name, country: 'United States', exchange: 'Nasdaq', mic: 'XNAS', symbol }
search.mockResolvedValueOnce([company]).mockResolvedValueOnce([])
add.mockResolvedValueOnce({ id: 'followed-company', ...company })
const user = userEvent.setup()
render(<Watchlist />)
if (language === 'en') await user.selectOptions(screen.getByLabelText('Langue / Language'), 'en')
const input = screen.getByRole('textbox')
expect(input).toHaveAccessibleDescription(language === 'fr' ? /nom,.*sigle courant.*symbole boursier/ : /name,.*commonly used acronym.*stock symbol/)
await user.type(input, symbol)
expect(search).not.toHaveBeenCalled()
await user.keyboard('{Enter}')
await waitFor(() => expect(search).toHaveBeenCalledWith(symbol, 20))
const results = screen.getByRole('region', { name: language === 'fr' ? 'Résultats des entreprises' : 'Company results' })
expect(await within(results).findByText(name)).toBeInTheDocument()
for (const hidden of [symbol, company.company_id, company.mic]) expect(within(results).queryByText(hidden, { exact: true })).not.toBeInTheDocument()
expect(add).not.toHaveBeenCalled()
await user.click(within(results).getByRole('button', { name: language === 'fr' ? 'Suivre cette entreprise' : 'Follow this company' }))
await waitFor(() => expect(add).toHaveBeenCalledWith({ company_id: company.company_id }))
const followed = screen.getByRole('region', { name: language === 'fr' ? 'Entreprises suivies' : 'Followed companies' })
expect(within(followed).getByText(name)).toBeInTheDocument()
expect(within(followed).queryByText(symbol, { exact: true })).not.toBeInTheDocument()
expect(within(followed).queryByText(company.mic)).not.toBeInTheDocument()
await user.clear(input)
await user.type(input, 'Unknown{Enter}')
expect(await screen.findByText(language === 'fr'
? 'Aucune entreprise trouvée. Essayez un autre nom, sigle courant ou symbole boursier.'
: 'No company found. Try another name, commonly used acronym or stock symbol.')).toHaveAttribute('role', 'status')
})