fix: The onRefresh method is missing from the QRCode component's statusRender (#51315)

This commit is contained in:
kiner-tang 2024-10-20 10:39:38 +08:00 committed by GitHub
parent 00a4e2d3c4
commit f4d8a8df0c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 23 additions and 3 deletions

View File

@ -49,5 +49,6 @@ export default function QRcodeStatus({
return mergedStatusRender({
status,
locale,
onRefresh,
});
}

View File

@ -12,7 +12,15 @@ exports[`QRCode test custom status render 1`] = `
<div
class="custom-expired"
>
QR code expired
<span>
QR code expired
</span>
<button
id="refresh"
type="button"
>
refresh
</button>
</div>
</div>
<canvas

View File

@ -99,10 +99,18 @@ describe('QRCode test', () => {
);
});
it('custom status render', () => {
const refreshCb = jest.fn();
const customStatusRender: QRCodeProps['statusRender'] = (info) => {
switch (info.status) {
case 'expired':
return <div className="custom-expired">{info.locale?.expired}</div>;
return (
<div className="custom-expired">
<span>{info.locale?.expired}</span>
<button id="refresh" onClick={info.onRefresh} type="button">
refresh
</button>
</div>
);
case 'loading':
return <div className="custom-loading">Loading</div>;
case 'scanned':
@ -118,6 +126,7 @@ describe('QRCode test', () => {
value="test"
status="expired"
statusRender={customStatusRender}
onRefresh={refreshCb}
/>
<QRCode
className="qrcode-loading"
@ -134,8 +143,10 @@ describe('QRCode test', () => {
</>,
);
expect(
container.querySelector<HTMLDivElement>('.qrcode-expired .custom-expired')?.textContent,
container.querySelector<HTMLDivElement>('.qrcode-expired .custom-expired>span')?.textContent,
).toBe('QR code expired');
fireEvent.click(container?.querySelector<HTMLButtonElement>('#refresh')!);
expect(refreshCb).toHaveBeenCalled();
expect(
container.querySelector<HTMLDivElement>('.qrcode-loading .custom-loading')?.textContent,
).toBe('Loading');