test: improve coverage for some files (#33218)

This commit is contained in:
Saumya Talwani
2026-03-12 12:39:10 +05:30
committed by GitHub
parent 68982f910e
commit ed5511ce28
61 changed files with 3191 additions and 304 deletions

View File

@ -90,5 +90,45 @@ describe('ShareQRCode', () => {
HTMLCanvasElement.prototype.toDataURL = originalToDataURL
}
})
it('does not call downloadUrl when canvas is not found', async () => {
const user = userEvent.setup()
render(<ShareQRCode content={content} />)
const trigger = screen.getByTestId('qrcode-container')
await user.click(trigger)
// Override querySelector on the panel to simulate canvas not being found
const panel = screen.getByRole('img').parentElement!
const origQuerySelector = panel.querySelector.bind(panel)
panel.querySelector = ((sel: string) => {
if (sel === 'canvas')
return null
return origQuerySelector(sel)
}) as typeof panel.querySelector
try {
const downloadBtn = screen.getByText('appOverview.overview.appInfo.qrcode.download')
await user.click(downloadBtn)
expect(downloadUrl).not.toHaveBeenCalled()
}
finally {
panel.querySelector = origQuerySelector
}
})
it('does not close when clicking inside the qrcode ref area', async () => {
const user = userEvent.setup()
render(<ShareQRCode content={content} />)
const trigger = screen.getByTestId('qrcode-container')
await user.click(trigger)
// Click on the scan text inside the panel — panel should remain open
const scanText = screen.getByText('appOverview.overview.appInfo.qrcode.scan')
await user.click(scanText)
expect(screen.getByRole('img')).toBeInTheDocument()
})
})
})

View File

@ -25,6 +25,7 @@ const ShareQRCode = ({ content }: Props) => {
useEffect(() => {
const handleClickOutside = (event: MouseEvent) => {
/* v8 ignore next 2 -- this handler can fire during open/close transitions where the panel ref is temporarily null; guard is defensive. @preserve */
if (qrCodeRef.current && !qrCodeRef.current.contains(event.target as Node))
setIsShow(false)
}
@ -48,9 +49,13 @@ const ShareQRCode = ({ content }: Props) => {
event.stopPropagation()
}
const tooltipText = t(`${prefixEmbedded}`, { ns: 'appOverview' })
/* v8 ignore next -- react-i18next returns a non-empty key/string in configured runtime; empty fallback protects against missing i18n payloads. @preserve */
const safeTooltipText = tooltipText || ''
return (
<Tooltip
popupContent={t(`${prefixEmbedded}`, { ns: 'appOverview' }) || ''}
popupContent={safeTooltipText}
>
<div className="relative h-6 w-6" onClick={toggleQRCode} data-testid="qrcode-container">
<ActionButton>