test: couverture JS - renderHit branches, globalSearch Escape, SIRET fallbacks
- 7 nouveaux tests JS (80 total) : renderHit avec customerName, email, sans subtitle Global search Escape key SIRET nom_raison_sociale fallback, missing siege fields, no parent form Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -506,6 +506,211 @@ describe('app.js DOMContentLoaded', () => {
|
||||
const results = document.getElementById('search-results')
|
||||
expect(results.innerHTML).toContain('Marie Martin')
|
||||
})
|
||||
|
||||
it('renders hit with customerName subtitle', async () => {
|
||||
document.body.innerHTML = `
|
||||
<input id="search-customers" value="">
|
||||
<div id="search-results" class="hidden"></div>
|
||||
`
|
||||
|
||||
globalThis.fetch = vi.fn(() =>
|
||||
Promise.resolve({
|
||||
json: () => Promise.resolve([
|
||||
{ id: 10, fullName: 'Test User', customerName: 'ACME Corp' }
|
||||
])
|
||||
})
|
||||
)
|
||||
|
||||
await loadApp()
|
||||
|
||||
const input = document.getElementById('search-customers')
|
||||
input.value = 'test'
|
||||
input.dispatchEvent(new Event('input'))
|
||||
await new Promise(r => setTimeout(r, 400))
|
||||
|
||||
const results = document.getElementById('search-results')
|
||||
expect(results.innerHTML).toContain('ACME Corp')
|
||||
expect(results.innerHTML).toContain('text-gray-400')
|
||||
})
|
||||
|
||||
it('renders hit with email subtitle when no customerName', async () => {
|
||||
document.body.innerHTML = `
|
||||
<input id="search-customers" value="">
|
||||
<div id="search-results" class="hidden"></div>
|
||||
`
|
||||
|
||||
globalThis.fetch = vi.fn(() =>
|
||||
Promise.resolve({
|
||||
json: () => Promise.resolve([
|
||||
{ id: 11, fullName: 'Test User', email: 'test@example.com' }
|
||||
])
|
||||
})
|
||||
)
|
||||
|
||||
await loadApp()
|
||||
|
||||
const input = document.getElementById('search-customers')
|
||||
input.value = 'test'
|
||||
input.dispatchEvent(new Event('input'))
|
||||
await new Promise(r => setTimeout(r, 400))
|
||||
|
||||
const results = document.getElementById('search-results')
|
||||
expect(results.innerHTML).toContain('test@example.com')
|
||||
})
|
||||
|
||||
it('renders hit with no subtitle when no customerName and no email', async () => {
|
||||
document.body.innerHTML = `
|
||||
<input id="search-customers" value="">
|
||||
<div id="search-results" class="hidden"></div>
|
||||
`
|
||||
|
||||
globalThis.fetch = vi.fn(() =>
|
||||
Promise.resolve({
|
||||
json: () => Promise.resolve([
|
||||
{ id: 12, fullName: 'No Sub User' }
|
||||
])
|
||||
})
|
||||
)
|
||||
|
||||
await loadApp()
|
||||
|
||||
const input = document.getElementById('search-customers')
|
||||
input.value = 'nosub'
|
||||
input.dispatchEvent(new Event('input'))
|
||||
await new Promise(r => setTimeout(r, 400))
|
||||
|
||||
const results = document.getElementById('search-results')
|
||||
expect(results.innerHTML).toContain('No Sub User')
|
||||
expect(results.innerHTML).not.toContain('text-gray-400 ml-2')
|
||||
})
|
||||
})
|
||||
|
||||
describe('Global search', () => {
|
||||
it('hides global results on Escape', async () => {
|
||||
document.body.innerHTML = `
|
||||
<input id="global-search" value="">
|
||||
<div id="global-search-results"><div>Result</div></div>
|
||||
`
|
||||
await loadApp()
|
||||
|
||||
const results = document.getElementById('global-search-results')
|
||||
results.classList.remove('hidden')
|
||||
expect(results.classList.contains('hidden')).toBe(false)
|
||||
|
||||
const input = document.getElementById('global-search')
|
||||
input.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true }))
|
||||
|
||||
expect(results.classList.contains('hidden')).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('SIRET search fallback branches', () => {
|
||||
it('renders result with nom_raison_sociale fallback', async () => {
|
||||
document.body.innerHTML = `
|
||||
<form>
|
||||
<input type="text" id="siret-search-input" value="">
|
||||
<button type="button" id="siret-search-btn">Search</button>
|
||||
<div id="siret-search-results" class="hidden"></div>
|
||||
<input name="raisonSociale">
|
||||
<input name="siret">
|
||||
<input name="address">
|
||||
<input name="zipCode">
|
||||
<input name="city">
|
||||
</form>
|
||||
`
|
||||
|
||||
globalThis.fetch = vi.fn(() =>
|
||||
Promise.resolve({
|
||||
json: () => Promise.resolve({
|
||||
results: [
|
||||
{ nom_raison_sociale: 'Fallback SA', siege: { siret: '12345678901234' } }
|
||||
]
|
||||
})
|
||||
})
|
||||
)
|
||||
|
||||
await loadApp()
|
||||
|
||||
const input = document.getElementById('siret-search-input')
|
||||
input.value = 'fallback'
|
||||
document.getElementById('siret-search-btn').click()
|
||||
await new Promise(r => setTimeout(r, 200))
|
||||
|
||||
const results = document.getElementById('siret-search-results')
|
||||
expect(results.innerHTML).toContain('Fallback SA')
|
||||
expect(results.innerHTML).toContain('12345678901234')
|
||||
})
|
||||
|
||||
it('fills form fields and handles missing siege fields', async () => {
|
||||
document.body.innerHTML = `
|
||||
<form>
|
||||
<input type="text" id="siret-search-input" value="">
|
||||
<button type="button" id="siret-search-btn">Search</button>
|
||||
<div id="siret-search-results" class="hidden"></div>
|
||||
<input name="raisonSociale">
|
||||
<input name="siret">
|
||||
<input name="address">
|
||||
<input name="zipCode">
|
||||
<input name="city">
|
||||
</form>
|
||||
`
|
||||
|
||||
globalThis.fetch = vi.fn(() =>
|
||||
Promise.resolve({
|
||||
json: () => Promise.resolve({
|
||||
results: [
|
||||
{ nom_complet: 'Complete SAS', siege: {} }
|
||||
]
|
||||
})
|
||||
})
|
||||
)
|
||||
|
||||
await loadApp()
|
||||
|
||||
const input = document.getElementById('siret-search-input')
|
||||
input.value = 'complete'
|
||||
document.getElementById('siret-search-btn').click()
|
||||
await new Promise(r => setTimeout(r, 200))
|
||||
|
||||
// Click the result to fill form
|
||||
const resultItem = document.querySelector('.siret-result-item')
|
||||
expect(resultItem).not.toBeNull()
|
||||
resultItem.click()
|
||||
|
||||
expect(document.querySelector('[name="raisonSociale"]').value).toBe('Complete SAS')
|
||||
expect(document.querySelector('[name="siret"]').value).toBe('')
|
||||
})
|
||||
|
||||
it('handles click on result when no parent form', async () => {
|
||||
document.body.innerHTML = `
|
||||
<div>
|
||||
<input type="text" id="siret-search-input" value="">
|
||||
<button type="button" id="siret-search-btn">Search</button>
|
||||
<div id="siret-search-results" class="hidden"></div>
|
||||
</div>
|
||||
`
|
||||
|
||||
globalThis.fetch = vi.fn(() =>
|
||||
Promise.resolve({
|
||||
json: () => Promise.resolve({
|
||||
results: [
|
||||
{ nom_complet: 'No Form', siege: { siret: '999' } }
|
||||
]
|
||||
})
|
||||
})
|
||||
)
|
||||
|
||||
await loadApp()
|
||||
|
||||
document.getElementById('siret-search-input').value = 'noform'
|
||||
document.getElementById('siret-search-btn').click()
|
||||
await new Promise(r => setTimeout(r, 200))
|
||||
|
||||
const resultItem = document.querySelector('.siret-result-item')
|
||||
expect(resultItem).not.toBeNull()
|
||||
// Should not throw when no parent form
|
||||
resultItem.click()
|
||||
})
|
||||
})
|
||||
|
||||
describe('Modal open/close (data-modal-open / data-modal-close)', () => {
|
||||
|
||||
Reference in New Issue
Block a user