2022-12-04 22:38:56 +01:00
|
|
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
2024-02-01 22:38:21 +09:00
|
|
|
import { cleanup, render } from '@testing-library/react';
|
|
|
|
|
import { Edit2, Grid, Pen } from '../src/lucide-react-native';
|
2020-12-02 13:48:39 +01:00
|
|
|
|
2024-02-01 22:38:21 +09:00
|
|
|
vi.mock('react-native-svg');
|
2022-12-04 22:38:56 +01:00
|
|
|
|
2024-02-01 22:38:21 +09:00
|
|
|
type Attributes = Record<string, { value: unknown }>;
|
2022-12-04 22:38:56 +01:00
|
|
|
|
2020-12-02 13:48:39 +01:00
|
|
|
describe('Using lucide icon components', () => {
|
|
|
|
|
it('should render an component', () => {
|
2024-02-01 22:38:21 +09:00
|
|
|
const { container } = render(<Grid />);
|
2020-12-02 13:48:39 +01:00
|
|
|
|
2024-02-01 22:38:21 +09:00
|
|
|
expect(container.innerHTML).toMatchSnapshot();
|
2020-12-02 13:48:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should adjust the size, stroke color and stroke width', () => {
|
2024-04-26 17:59:04 +02:00
|
|
|
const { container } = render(
|
2020-12-02 13:48:39 +01:00
|
|
|
<Grid
|
|
|
|
|
size={48}
|
|
|
|
|
stroke="red"
|
|
|
|
|
strokeWidth={4}
|
|
|
|
|
/>,
|
|
|
|
|
);
|
|
|
|
|
|
2024-04-26 17:59:04 +02:00
|
|
|
const SVGElement = container.firstElementChild;
|
|
|
|
|
|
|
|
|
|
expect(SVGElement).toHaveAttribute('stroke', 'red');
|
|
|
|
|
expect(SVGElement).toHaveAttribute('width', '48');
|
|
|
|
|
expect(SVGElement).toHaveAttribute('height', '48');
|
|
|
|
|
expect(SVGElement).toHaveAttribute('stroke-width', '4');
|
2021-05-23 13:13:18 +02:00
|
|
|
|
2024-02-01 22:38:21 +09:00
|
|
|
expect(container.innerHTML).toMatchSnapshot();
|
2020-12-02 13:48:39 +01:00
|
|
|
});
|
2023-04-20 16:08:34 +02:00
|
|
|
|
|
|
|
|
it('should render the alias icon', () => {
|
|
|
|
|
const testId = 'pen-icon';
|
|
|
|
|
const { container } = render(
|
|
|
|
|
<Pen
|
|
|
|
|
data-testid={testId}
|
|
|
|
|
size={48}
|
|
|
|
|
stroke="red"
|
|
|
|
|
strokeWidth={4}
|
|
|
|
|
/>,
|
|
|
|
|
);
|
|
|
|
|
|
2024-02-01 22:38:21 +09:00
|
|
|
const PenIconRenderedHTML = container.innerHTML;
|
2023-04-20 16:08:34 +02:00
|
|
|
|
2024-02-01 22:38:21 +09:00
|
|
|
cleanup();
|
2023-04-20 16:08:34 +02:00
|
|
|
|
|
|
|
|
const { container: Edit2Container } = render(
|
|
|
|
|
<Edit2
|
|
|
|
|
data-testid={testId}
|
|
|
|
|
size={48}
|
|
|
|
|
stroke="red"
|
|
|
|
|
strokeWidth={4}
|
|
|
|
|
/>,
|
|
|
|
|
);
|
|
|
|
|
|
2024-02-01 22:38:21 +09:00
|
|
|
expect(PenIconRenderedHTML).toBe(Edit2Container.innerHTML);
|
2023-04-20 16:08:34 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should not scale the strokeWidth when absoluteStrokeWidth is set', () => {
|
2024-04-26 17:59:04 +02:00
|
|
|
const { container } = render(
|
2023-04-20 16:08:34 +02:00
|
|
|
<Grid
|
|
|
|
|
size={48}
|
|
|
|
|
stroke="red"
|
|
|
|
|
absoluteStrokeWidth
|
|
|
|
|
/>,
|
|
|
|
|
);
|
|
|
|
|
|
2024-04-26 17:59:04 +02:00
|
|
|
const SVGElement = container.firstElementChild;
|
|
|
|
|
|
|
|
|
|
expect(SVGElement).toHaveAttribute('stroke', 'red');
|
|
|
|
|
expect(SVGElement).toHaveAttribute('width', '48');
|
|
|
|
|
expect(SVGElement).toHaveAttribute('height', '48');
|
|
|
|
|
expect(SVGElement).toHaveAttribute('stroke-width', '1');
|
2023-04-20 16:08:34 +02:00
|
|
|
|
2024-02-01 22:38:21 +09:00
|
|
|
expect(container.innerHTML).toMatchSnapshot();
|
2023-04-20 16:08:34 +02:00
|
|
|
});
|
2023-04-30 16:06:49 -04:00
|
|
|
|
|
|
|
|
it('should work with a single child component', () => {
|
2024-02-01 22:38:21 +09:00
|
|
|
const testId = 'single-child';
|
|
|
|
|
const childId = 'child';
|
2023-04-30 16:06:49 -04:00
|
|
|
|
|
|
|
|
const { container, getByTestId } = render(
|
|
|
|
|
<Grid data-testid={testId}>
|
2024-02-01 22:38:21 +09:00
|
|
|
<Grid data-testid={childId} />
|
|
|
|
|
</Grid>,
|
2023-04-30 16:06:49 -04:00
|
|
|
);
|
2024-04-26 17:59:04 +02:00
|
|
|
const { children } = container.firstElementChild ?? {};
|
|
|
|
|
const lastChild = children?.[children.length - 1];
|
2023-04-30 16:06:49 -04:00
|
|
|
|
|
|
|
|
expect(lastChild).toEqual(getByTestId(childId));
|
|
|
|
|
expect(container.innerHTML).toMatchSnapshot();
|
2024-02-01 22:38:21 +09:00
|
|
|
});
|
2023-04-30 16:06:49 -04:00
|
|
|
|
|
|
|
|
it('should work with several children components', () => {
|
2024-02-01 22:38:21 +09:00
|
|
|
const testId = 'multiple-children';
|
|
|
|
|
const childId1 = 'child1';
|
|
|
|
|
const childId2 = 'child2';
|
2023-04-30 16:06:49 -04:00
|
|
|
|
|
|
|
|
const { container, getByTestId } = render(
|
|
|
|
|
<Grid data-testid={testId}>
|
2024-02-01 22:38:21 +09:00
|
|
|
<Grid data-testid={childId1} />
|
|
|
|
|
<Grid data-testid={childId2} />
|
|
|
|
|
</Grid>,
|
2023-04-30 16:06:49 -04:00
|
|
|
);
|
2024-02-01 22:38:21 +09:00
|
|
|
const { children } = getByTestId(testId) as unknown as { children: HTMLCollection };
|
2023-04-30 16:06:49 -04:00
|
|
|
const child1 = children[children.length - 2];
|
|
|
|
|
const child2 = children[children.length - 1];
|
|
|
|
|
|
|
|
|
|
expect(child1).toEqual(getByTestId(childId1));
|
|
|
|
|
expect(child2).toEqual(getByTestId(childId2));
|
|
|
|
|
expect(container.innerHTML).toMatchSnapshot();
|
2024-02-01 22:38:21 +09:00
|
|
|
});
|
2023-08-16 17:01:41 -04:00
|
|
|
|
|
|
|
|
it('should duplicate properties to children components', () => {
|
|
|
|
|
const testId = 'multiple-children';
|
|
|
|
|
|
|
|
|
|
const fill = 'red';
|
|
|
|
|
const color = 'white';
|
|
|
|
|
const strokeWidth = 10;
|
|
|
|
|
|
|
|
|
|
const { container, getByTestId } = render(
|
2024-02-01 22:38:21 +09:00
|
|
|
<Grid
|
|
|
|
|
data-testid={testId}
|
|
|
|
|
fill={fill}
|
|
|
|
|
color={color}
|
|
|
|
|
strokeWidth={strokeWidth}
|
|
|
|
|
/>,
|
2023-08-16 17:01:41 -04:00
|
|
|
);
|
|
|
|
|
const { children = [] } = getByTestId(testId) as unknown as { children: HTMLCollection };
|
|
|
|
|
for (let i = 0; i < children.length; i++) {
|
|
|
|
|
const child = children[i];
|
|
|
|
|
expect(child.getAttribute('fill')).toBe(fill);
|
|
|
|
|
expect(child.getAttribute('stroke')).toBe(color);
|
|
|
|
|
expect(child.getAttribute('stroke-width')).toBe(`${strokeWidth}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expect(container.innerHTML).toMatchSnapshot();
|
2024-02-01 22:38:21 +09:00
|
|
|
});
|
|
|
|
|
});
|