2022-12-04 22:38:56 +01:00
|
|
|
import { describe, it, expect, afterEach } from 'vitest';
|
2023-04-20 16:08:34 +02:00
|
|
|
import { render, cleanup, logDOM } from '@testing-library/svelte';
|
|
|
|
|
import { Smile, Pen, Edit2 } from '../src/lucide-svelte'
|
2022-02-17 17:46:55 +01:00
|
|
|
import TestSlots from './TestSlots.svelte'
|
|
|
|
|
|
|
|
|
|
describe('Using lucide icon components', () => {
|
2022-12-04 22:38:56 +01:00
|
|
|
afterEach(() => cleanup())
|
2022-02-17 17:46:55 +01:00
|
|
|
it('should render an component', () => {
|
|
|
|
|
const { container } = render(Smile);
|
|
|
|
|
expect(container).toMatchSnapshot();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should adjust the size, stroke color and stroke width', () => {
|
|
|
|
|
const { container } = render(Smile, {
|
|
|
|
|
props: {
|
|
|
|
|
size: 48,
|
|
|
|
|
color: 'red',
|
|
|
|
|
strokeWidth: 4
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(container).toMatchSnapshot();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should add a class to the element', () => {
|
|
|
|
|
render(Smile, {
|
|
|
|
|
props: {
|
|
|
|
|
class: "my-icon"
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const [icon] = document.getElementsByClassName('my-icon');
|
|
|
|
|
|
|
|
|
|
expect(icon).toBeInTheDocument();
|
|
|
|
|
expect(icon).toMatchSnapshot();
|
|
|
|
|
expect(icon.getAttribute("class")).toBe(['lucide-icon','lucide','lucide-smile', 'my-icon'].join(' '));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should add a style attribute to the element', () => {
|
|
|
|
|
render(Smile, {
|
|
|
|
|
props: {
|
|
|
|
|
style: "position: absolute;"
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
const [icon] = document.getElementsByClassName('lucide');
|
|
|
|
|
|
|
|
|
|
expect(icon.getAttribute('style')).toContain('position: absolute');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should render an icon slot', () => {
|
|
|
|
|
const { container, getByText } = render(TestSlots);
|
|
|
|
|
|
|
|
|
|
const textElement = getByText('Test');
|
|
|
|
|
expect(textElement).toBeInTheDocument();
|
|
|
|
|
expect(container).toMatchSnapshot();
|
|
|
|
|
});
|
2023-04-20 16:08:34 +02:00
|
|
|
|
|
|
|
|
it('should render the alias icon', () => {
|
|
|
|
|
const { container } = render(Pen);
|
|
|
|
|
|
|
|
|
|
const PenIconRenderedHTML = container.innerHTML
|
|
|
|
|
|
|
|
|
|
cleanup()
|
|
|
|
|
|
|
|
|
|
const { container: Edit2Container } = render(Edit2);
|
|
|
|
|
|
|
|
|
|
expect(PenIconRenderedHTML).toBe(Edit2Container.innerHTML)
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should not scale the strokeWidth when absoluteStrokeWidth is set', () => {
|
|
|
|
|
const testId = 'smile-icon';
|
|
|
|
|
const { container, getByTestId } = render(Smile, {
|
|
|
|
|
'data-testid':testId,
|
|
|
|
|
color: 'red',
|
|
|
|
|
size: 48,
|
|
|
|
|
absoluteStrokeWidth: true
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const { attributes } = getByTestId(testId) as unknown as{ attributes: Record<string, { value: string }>};
|
|
|
|
|
expect(attributes.stroke.value).toBe('red');
|
|
|
|
|
expect(attributes.width.value).toBe('48');
|
|
|
|
|
expect(attributes.height.value).toBe('48');
|
|
|
|
|
expect(attributes['stroke-width'].value).toBe('1');
|
|
|
|
|
|
|
|
|
|
expect( container.innerHTML ).toMatchSnapshot();
|
|
|
|
|
});
|
2022-02-17 17:46:55 +01:00
|
|
|
});
|