2022-12-04 22:38:56 +01:00
|
|
|
import { describe, it, expect } from 'vitest';
|
2024-02-01 22:38:21 +09:00
|
|
|
import { render, cleanup } from '@testing-library/preact';
|
2023-11-24 13:59:12 +01:00
|
|
|
import { Pen, Edit2, Grid, Droplet } from '../src/lucide-preact';
|
2024-04-26 17:59:04 +02:00
|
|
|
import defaultAttributes from '../src/defaultAttributes';
|
2021-05-23 13:13:18 +02:00
|
|
|
|
2024-02-01 22:38:21 +09:00
|
|
|
type AttributesAssertion = { attributes: Record<string, { value: string }> };
|
2023-04-20 16:08:34 +02:00
|
|
|
|
2021-05-23 13:13:18 +02:00
|
|
|
describe('Using lucide icon components', () => {
|
|
|
|
|
it('should render an component', () => {
|
2024-02-01 22:38:21 +09:00
|
|
|
const { container } = render(<Grid />);
|
2021-05-23 13:13:18 +02:00
|
|
|
|
2024-02-01 22:38:21 +09:00
|
|
|
expect(container.innerHTML).toMatchSnapshot();
|
2021-05-23 13:13:18 +02:00
|
|
|
});
|
|
|
|
|
|
2024-04-26 17:59:04 +02:00
|
|
|
it('should render the icon with the default attributes', () => {
|
|
|
|
|
const { container } = render(<Grid />);
|
|
|
|
|
|
|
|
|
|
const SVGElement = container.firstElementChild;
|
|
|
|
|
|
|
|
|
|
expect(SVGElement).toHaveAttribute('xmlns', defaultAttributes.xmlns);
|
|
|
|
|
expect(SVGElement).toHaveAttribute('width', String(defaultAttributes.width));
|
|
|
|
|
expect(SVGElement).toHaveAttribute('height', String(defaultAttributes.height));
|
|
|
|
|
expect(SVGElement).toHaveAttribute('viewBox', defaultAttributes.viewBox);
|
|
|
|
|
expect(SVGElement).toHaveAttribute('fill', defaultAttributes.fill);
|
|
|
|
|
expect(SVGElement).toHaveAttribute('stroke', defaultAttributes.stroke);
|
|
|
|
|
expect(SVGElement).toHaveAttribute('stroke-width', String(defaultAttributes['stroke-width']));
|
|
|
|
|
expect(SVGElement).toHaveAttribute('stroke-linecap', defaultAttributes['stroke-linecap']);
|
|
|
|
|
expect(SVGElement).toHaveAttribute('stroke-linejoin', defaultAttributes['stroke-linejoin']);
|
|
|
|
|
});
|
|
|
|
|
|
2021-05-23 13:13:18 +02:00
|
|
|
it('should adjust the size, stroke color and stroke width', () => {
|
2024-04-26 17:59:04 +02:00
|
|
|
const { container } = render(
|
2021-05-23 13:13:18 +02: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');
|
2024-02-01 22:38:21 +09:00
|
|
|
expect(container.innerHTML).toMatchSnapshot();
|
2021-05-23 13:13:18 +02:00
|
|
|
});
|
2023-01-17 08:04:34 +01:00
|
|
|
|
|
|
|
|
it('should render the alias icon', () => {
|
|
|
|
|
const { container } = render(
|
|
|
|
|
<Pen
|
|
|
|
|
size={48}
|
|
|
|
|
stroke="red"
|
|
|
|
|
strokeWidth={4}
|
|
|
|
|
/>,
|
|
|
|
|
);
|
|
|
|
|
|
2024-02-01 22:38:21 +09:00
|
|
|
const PenIconRenderedHTML = container.innerHTML;
|
2023-01-17 08:04:34 +01:00
|
|
|
|
2024-02-01 22:38:21 +09:00
|
|
|
cleanup();
|
2023-01-17 08:04:34 +01:00
|
|
|
|
|
|
|
|
const { container: Edit2Container } = render(
|
|
|
|
|
<Edit2
|
|
|
|
|
size={48}
|
|
|
|
|
stroke="red"
|
|
|
|
|
strokeWidth={4}
|
|
|
|
|
/>,
|
|
|
|
|
);
|
|
|
|
|
|
2024-02-01 22:38:21 +09:00
|
|
|
expect(PenIconRenderedHTML).toBe(Edit2Container.innerHTML);
|
2023-01-17 08:04:34 +01:00
|
|
|
});
|
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-11-24 13:59:12 +01:00
|
|
|
|
|
|
|
|
it('should apply all classes to the element', () => {
|
|
|
|
|
const testClass = 'my-class';
|
2024-02-01 22:38:21 +09:00
|
|
|
const { container } = render(<Droplet class={testClass} />);
|
2023-11-24 13:59:12 +01:00
|
|
|
|
|
|
|
|
expect(container.firstChild).toHaveClass(testClass);
|
|
|
|
|
expect(container.firstChild).toHaveClass('lucide');
|
|
|
|
|
expect(container.firstChild).toHaveClass('lucide-droplet');
|
|
|
|
|
});
|
2024-02-01 22:38:21 +09:00
|
|
|
});
|