You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
3.3 KiB

feat: New Component QRCode (#38948) * feat: qrcode * chore: code clean * feat: New Component Qr-Code (#38891) * feat: QrCode * fix * fix * fix: fix bug * fix: fix bug * fix * fix * fix * delete * delete * test case * fix lint * bundlesize * demo * fix: fix test * remove dep * update snap * en docs * refactor: rename tests dir * Update components/qr-code/demo/base.md Co-authored-by: MadCcc <1075746765@qq.com> * Update components/qr-code/demo/base.md Co-authored-by: MadCcc <1075746765@qq.com> * Update components/qr-code/demo/download.md Co-authored-by: MadCcc <1075746765@qq.com> * Update components/qr-code/demo/download.md Co-authored-by: MadCcc <1075746765@qq.com> * Update components/qr-code/demo/download.tsx Co-authored-by: MadCcc <1075746765@qq.com> * Update components/qr-code/demo/logo.md Co-authored-by: MadCcc <1075746765@qq.com> * Update components/qr-code/index.tsx Co-authored-by: MadCcc <1075746765@qq.com> * Update components/qr-code/style/index.ts Co-authored-by: MadCcc <1075746765@qq.com> * Update components/qr-code/style/index.ts Co-authored-by: MadCcc <1075746765@qq.com> * Update components/qr-code/demo/logo.md Co-authored-by: MadCcc <1075746765@qq.com> * rename * fix * adjust text * rename * fix title * rename * rename * fix: snap * fix * bundlesize * update demo * update docs * add demo * add docs * add docs * test: add warning * update demo * bundlesize * update test case * update demo * feat: add onRefresh、add status * fix: fix demo * fix: fix demo * add locale * add locale * add test case * update snap * fix demo * update demo * update demo * update demo * Update components/qrcode/style/index.ts Co-authored-by: MadCcc <1075746765@qq.com> * Update components/qrcode/style/index.ts Co-authored-by: MadCcc <1075746765@qq.com> * Update components/qrcode/style/index.ts Co-authored-by: MadCcc <1075746765@qq.com> * Update components/qrcode/style/index.ts Co-authored-by: MadCcc <1075746765@qq.com> * Update components/qrcode/style/index.ts Co-authored-by: MadCcc <1075746765@qq.com> * Update components/qrcode/interface.ts Co-authored-by: MadCcc <1075746765@qq.com> * Update components/qrcode/style/index.ts Co-authored-by: MadCcc <1075746765@qq.com> * fix * Update components/qrcode/index.tsx Co-authored-by: MadCcc <1075746765@qq.com> * fix * fix * fix * add decs * fix * fix * fix type * fix * fix demo * fix lint * fix lint * add test case for bordered * prettier-ignore Co-authored-by: MadCcc <1075746765@qq.com> Co-authored-by: 栗嘉男 <lijianan@lijianandeMacBook-Pro.local>
2 years ago
import React, { useState } from 'react';
import QRCode from '..';
import mountTest from '../../../tests/shared/mountTest';
import rtlTest from '../../../tests/shared/rtlTest';
import { fireEvent, render } from '../../../tests/utils';
import type { QRCodeProps } from '../interface';
describe('QRCode test', () => {
mountTest(QRCode);
rtlTest(QRCode);
it('should correct render', () => {
const { container } = render(<QRCode value="test" />);
expect(
container
?.querySelector<HTMLDivElement>('.ant-qrcode')
?.querySelector<HTMLCanvasElement>('canvas'),
).toBeTruthy();
expect(container).toMatchSnapshot();
});
it('should render `null` and console Error when value not exist', () => {
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
const { container } = render(<QRCode value={undefined as unknown as string} />);
expect(container.firstChild).toBe(null);
expect(container.firstChild).toMatchSnapshot();
expect(errSpy).toHaveBeenCalledWith('Warning: [antd: QRCode] need to receive `value` props');
errSpy.mockRestore();
});
it('support custom icon', () => {
const { container } = render(<QRCode value="test" icon="test" />);
expect(
container
?.querySelector<HTMLDivElement>('.ant-qrcode')
?.querySelector<HTMLImageElement>('img'),
).toBeTruthy();
});
it('support custom size', () => {
const { container } = render(<QRCode value="test" size={100} />);
const wrapper = container.querySelector<HTMLDivElement>('.ant-qrcode');
expect(wrapper?.style?.width).toBe('100px');
expect(wrapper?.style?.height).toBe('100px');
feat: New Component QRCode (#38948) * feat: qrcode * chore: code clean * feat: New Component Qr-Code (#38891) * feat: QrCode * fix * fix * fix: fix bug * fix: fix bug * fix * fix * fix * delete * delete * test case * fix lint * bundlesize * demo * fix: fix test * remove dep * update snap * en docs * refactor: rename tests dir * Update components/qr-code/demo/base.md Co-authored-by: MadCcc &lt;1075746765@qq.com&gt; * Update components/qr-code/demo/base.md Co-authored-by: MadCcc &lt;1075746765@qq.com&gt; * Update components/qr-code/demo/download.md Co-authored-by: MadCcc &lt;1075746765@qq.com&gt; * Update components/qr-code/demo/download.md Co-authored-by: MadCcc &lt;1075746765@qq.com&gt; * Update components/qr-code/demo/download.tsx Co-authored-by: MadCcc &lt;1075746765@qq.com&gt; * Update components/qr-code/demo/logo.md Co-authored-by: MadCcc &lt;1075746765@qq.com&gt; * Update components/qr-code/index.tsx Co-authored-by: MadCcc &lt;1075746765@qq.com&gt; * Update components/qr-code/style/index.ts Co-authored-by: MadCcc &lt;1075746765@qq.com&gt; * Update components/qr-code/style/index.ts Co-authored-by: MadCcc &lt;1075746765@qq.com&gt; * Update components/qr-code/demo/logo.md Co-authored-by: MadCcc &lt;1075746765@qq.com&gt; * rename * fix * adjust text * rename * fix title * rename * rename * fix: snap * fix * bundlesize * update demo * update docs * add demo * add docs * add docs * test: add warning * update demo * bundlesize * update test case * update demo * feat: add onRefresh、add status * fix: fix demo * fix: fix demo * add locale * add locale * add test case * update snap * fix demo * update demo * update demo * update demo * Update components/qrcode/style/index.ts Co-authored-by: MadCcc &lt;1075746765@qq.com&gt; * Update components/qrcode/style/index.ts Co-authored-by: MadCcc &lt;1075746765@qq.com&gt; * Update components/qrcode/style/index.ts Co-authored-by: MadCcc &lt;1075746765@qq.com&gt; * Update components/qrcode/style/index.ts Co-authored-by: MadCcc &lt;1075746765@qq.com&gt; * Update components/qrcode/style/index.ts Co-authored-by: MadCcc &lt;1075746765@qq.com&gt; * Update components/qrcode/interface.ts Co-authored-by: MadCcc &lt;1075746765@qq.com&gt; * Update components/qrcode/style/index.ts Co-authored-by: MadCcc &lt;1075746765@qq.com&gt; * fix * Update components/qrcode/index.tsx Co-authored-by: MadCcc &lt;1075746765@qq.com&gt; * fix * fix * fix * add decs * fix * fix * fix type * fix * fix demo * fix lint * fix lint * add test case for bordered * prettier-ignore Co-authored-by: MadCcc &lt;1075746765@qq.com&gt; Co-authored-by: 栗嘉男 &lt;lijianan@lijianandeMacBook-Pro.local&gt;
2 years ago
});
it('support refresh', () => {
const refresh = jest.fn();
const { container } = render(<QRCode value="test" status="expired" onRefresh={refresh} />);
fireEvent.click(
container
?.querySelector<HTMLDivElement>('.ant-qrcode')
?.querySelector<HTMLButtonElement>('button.ant-btn-link')!,
);
expect(refresh).toHaveBeenCalled();
});
it('support loading', () => {
const Demo: React.FC = () => {
const [status, setStatus] = useState<QRCodeProps['status']>('active');
return (
<>
<QRCode value="test" status={status} />
<button type="button" onClick={() => setStatus('loading')}>
set loading
</button>
</>
);
};
const { container } = render(<Demo />);
expect(container.querySelector<HTMLDivElement>('.ant-spin-spinning')).toBeFalsy();
fireEvent.click(container?.querySelector<HTMLButtonElement>('button')!);
expect(container.querySelector<HTMLDivElement>('.ant-spin-spinning')).toBeTruthy();
});
it('support bordered', () => {
const { container } = render(<QRCode value="test" bordered={false} />);
expect(container?.querySelector<HTMLDivElement>('.ant-qrcode')).toHaveClass(
'ant-qrcode-borderless',
);
});
it('should console Error when icon exist && errorLevel is `L`', () => {
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
render(<QRCode value="test" icon="test" errorLevel="L" />);
expect(errSpy).toHaveBeenCalledWith(
'Warning: [antd: QRCode] ErrorLevel `L` is not recommended to be used with `icon`, for scanning result would be affected by low level.',
);
errSpy.mockRestore();
});
feat: New Component QRCode (#38948) * feat: qrcode * chore: code clean * feat: New Component Qr-Code (#38891) * feat: QrCode * fix * fix * fix: fix bug * fix: fix bug * fix * fix * fix * delete * delete * test case * fix lint * bundlesize * demo * fix: fix test * remove dep * update snap * en docs * refactor: rename tests dir * Update components/qr-code/demo/base.md Co-authored-by: MadCcc &lt;1075746765@qq.com&gt; * Update components/qr-code/demo/base.md Co-authored-by: MadCcc &lt;1075746765@qq.com&gt; * Update components/qr-code/demo/download.md Co-authored-by: MadCcc &lt;1075746765@qq.com&gt; * Update components/qr-code/demo/download.md Co-authored-by: MadCcc &lt;1075746765@qq.com&gt; * Update components/qr-code/demo/download.tsx Co-authored-by: MadCcc &lt;1075746765@qq.com&gt; * Update components/qr-code/demo/logo.md Co-authored-by: MadCcc &lt;1075746765@qq.com&gt; * Update components/qr-code/index.tsx Co-authored-by: MadCcc &lt;1075746765@qq.com&gt; * Update components/qr-code/style/index.ts Co-authored-by: MadCcc &lt;1075746765@qq.com&gt; * Update components/qr-code/style/index.ts Co-authored-by: MadCcc &lt;1075746765@qq.com&gt; * Update components/qr-code/demo/logo.md Co-authored-by: MadCcc &lt;1075746765@qq.com&gt; * rename * fix * adjust text * rename * fix title * rename * rename * fix: snap * fix * bundlesize * update demo * update docs * add demo * add docs * add docs * test: add warning * update demo * bundlesize * update test case * update demo * feat: add onRefresh、add status * fix: fix demo * fix: fix demo * add locale * add locale * add test case * update snap * fix demo * update demo * update demo * update demo * Update components/qrcode/style/index.ts Co-authored-by: MadCcc &lt;1075746765@qq.com&gt; * Update components/qrcode/style/index.ts Co-authored-by: MadCcc &lt;1075746765@qq.com&gt; * Update components/qrcode/style/index.ts Co-authored-by: MadCcc &lt;1075746765@qq.com&gt; * Update components/qrcode/style/index.ts Co-authored-by: MadCcc &lt;1075746765@qq.com&gt; * Update components/qrcode/style/index.ts Co-authored-by: MadCcc &lt;1075746765@qq.com&gt; * Update components/qrcode/interface.ts Co-authored-by: MadCcc &lt;1075746765@qq.com&gt; * Update components/qrcode/style/index.ts Co-authored-by: MadCcc &lt;1075746765@qq.com&gt; * fix * Update components/qrcode/index.tsx Co-authored-by: MadCcc &lt;1075746765@qq.com&gt; * fix * fix * fix * add decs * fix * fix * fix type * fix * fix demo * fix lint * fix lint * add test case for bordered * prettier-ignore Co-authored-by: MadCcc &lt;1075746765@qq.com&gt; Co-authored-by: 栗嘉男 &lt;lijianan@lijianandeMacBook-Pro.local&gt;
2 years ago
});