Files
TradarrV2/frontend/e2e/ticket19-company-watchlist.spec.mjs
Blomios f7b057efa3 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>
2026-11-22 18:08:35 +01:00

68 lines
3.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { expect, test } from '@playwright/test'
import { readStackManifest } from './stack-manifest.mjs'
async function login(page, baseURL, email, password) {
await page.goto(new URL('/login', baseURL).href)
await page.getByLabel('Adresse email').fill(email)
await page.getByLabel('Mot de passe').fill(password)
await page.getByRole('button', { name: 'Se connecter' }).click()
await expect(page).toHaveURL(new URL('/', baseURL).href)
}
test('ticket #19: search companies by name and follow by company_id while preserving legacy assets', async ({ page }) => {
const stack = readStackManifest()
await page.context().route('**/*', async route => {
const host = new URL(route.request().url()).hostname
if (host !== '127.0.0.1' && host !== '[::1]') return route.abort('blockedbyclient')
return route.continue()
})
await login(page, stack.frontendUrl, stack.bootstrapAdmin.email, stack.bootstrapAdmin.password)
const oldAsset = {
id: 'historical-index-19', user_id: 'ticket19-admin', symbol: 'OLDX',
name: 'Historic S&P index', figi: null, created_at: '2025-01-01T00:00:00.000Z',
}
const companies = [
{ company_id: 'isin:CNE100001526', name: 'BYD Company Limited', exchange: 'Shenzhen Stock Exchange', country: 'China', mic: 'XSHE' },
{ company_id: 'isin:HK0285041858', name: 'BYD Electronic (International) Company Limited', exchange: 'Hong Kong Stock Exchange', country: 'China', mic: 'XHKG' },
]
let followedBody
let searchURL
await page.route('**/api/me/assets', async route => {
if (route.request().method() === 'GET') return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ data: [oldAsset] }) })
if (route.request().method() === 'POST') {
followedBody = route.request().postDataJSON()
return route.fulfill({ status: 201, contentType: 'application/json', body: JSON.stringify({ data: { id: 'followed-byd', user_id: oldAsset.user_id, company_id: 'isin:CNE100001526', name: 'BYD Company Limited' } }) })
}
return route.continue()
})
await page.route('**/api/companies/search?**', async route => {
searchURL = new URL(route.request().url())
return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ data: companies }) })
})
await page.goto(new URL('/assets', stack.frontendUrl).href)
await expect(page.getByRole('heading', { name: 'Rechercher une entreprise' })).toBeVisible({ timeout: 3000 })
const query = page.getByRole('textbox', { name: /nom ou nom courant de l’entreprise/i })
await expect(page.getByRole('textbox')).toHaveCount(1)
await query.fill('BYD')
await page.getByRole('button', { name: /rechercher/i }).click()
const results = page.getByRole('region', { name: /résultats des entreprises/i })
const byd = results.getByText('BYD Company Limited').locator('..')
await expect(byd).toContainText('Shenzhen Stock Exchange')
await expect(byd).toContainText('China')
await expect(results.getByText('BYD Electronic (International) Company Limited')).toBeVisible()
for (const privateValue of ['002594.SZ', '0285.HK', 'BBG001QVK2K1', 'BBG000JPLTR7']) {
await expect(results.getByText(privateValue, { exact: false })).toHaveCount(0)
}
await expect(page.getByRole('region', { name: /actifs historiques/i })).toContainText('Historic S&P index')
await byd.getByRole('button', { name: /suivre/i }).click()
await expect.poll(() => followedBody).toEqual({ company_id: 'isin:CNE100001526' })
expect(Object.keys(followedBody)).toEqual(['company_id'])
await expect(page.getByRole('region', { name: /actifs historiques/i })).toContainText('Historic S&P index')
expect(searchURL?.pathname).toBe('/api/companies/search')
expect(searchURL?.searchParams.get('q')).toBe('BYD')
expect(searchURL?.searchParams.get('limit')).toBe('20')
})