chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 12:27:50 +08:00
commit cc8f841fc5
422 changed files with 70222 additions and 0 deletions
@@ -0,0 +1,55 @@
/**
* @jest-environment jsdom
*/
import React from 'react';
import { render, screen, fireEvent } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import Avatar, { avatarFailback } from '../../src/components/Avatar';
describe('Avatar', () => {
it('shoule render without error', async () => {
render(<Avatar src="./1.jpg" />);
const $img = await screen.findByRole('img');
expect($img).toBeInTheDocument();
});
it('should call props handler function when fire event', async () => {
const handleClick = jest.fn();
const handleMouseEnter = jest.fn();
const handleMouseLeave = jest.fn();
render(
<Avatar
src="./1.jpg"
onClick={handleClick}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
/>,
);
const $img = await screen.findByRole('img');
fireEvent.click($img);
expect(handleClick).toBeCalled();
fireEvent.mouseEnter($img);
expect(handleMouseEnter).toBeCalled();
fireEvent.mouseLeave($img);
expect(handleMouseLeave).toBeCalled();
});
it('shoule use failback avatar when fetch error', async () => {
const src = 'origin.jpg';
render(<Avatar src={src} />);
const $img = (await screen.findByRole('img')) as HTMLImageElement;
expect($img.src).toEqual(expect.stringContaining(src));
fireEvent.error($img);
expect($img.src).toEqual(expect.stringContaining(avatarFailback));
fireEvent.error($img);
fireEvent.error($img);
});
it('shoule not add CDN query params', async () => {
const src = 'data:base64/png;xxx';
render(<Avatar src={src} />);
const $img = (await screen.findByRole('img')) as HTMLImageElement;
expect($img.src).not.toEqual(expect.stringContaining('x-oss-process='));
});
});
@@ -0,0 +1,35 @@
/**
* @jest-environment jsdom
*/
import React from 'react';
import { render, screen, fireEvent } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import Button from '../../src/components/Button';
describe('Button', () => {
it('shoule render without error', async () => {
render(<Button>text</Button>);
const $button = screen.getByRole('button');
expect($button).toBeInTheDocument();
});
it('shoule support set custom class name and type', async () => {
render(
<Button className="custom" type="danger">
text
</Button>,
);
const $button = screen.getByRole('button');
expect($button.classList).toContain('custom');
expect($button.classList).toContain('danger');
});
it('shoule call props handler function when fire event', async () => {
const handleClick = jest.fn();
render(<Button onClick={handleClick}>text</Button>);
const $button = screen.getByRole('button');
fireEvent.click($button);
expect(handleClick).toHaveBeenCalled();
});
});