mirror of
https://github.com/lucide-icons/lucide.git
synced 2026-12-03 16:59:42 +00:00
* Adjust accessibility behaviour for title elements * Adjust angular package as well * Fix types * fix(packages/angular): use fixture.whenStable instead of triggering change detection manually detectChanges() explicitly forces a check, so it can mask missing automatic change detection * test(packages/angular): add test for non-signal bound aria attribute * fix(angular): preserve explicit aria-hidden and support input bindings --------- Co-authored-by: Karsa <contact@karsa.org>
198 lines
5.1 KiB
TypeScript
198 lines
5.1 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { render } from '@solidjs/testing-library';
|
|
import { createSignal, flush } from 'solid-js';
|
|
|
|
import { airVent } from './testIconNodes';
|
|
import { Icon } from '../src/lucide-solid';
|
|
|
|
describe('Using Icon Component', () => {
|
|
const airVentIcon = { name: 'air-vent', node: airVent };
|
|
|
|
it('should render icon based on a iconNode', async () => {
|
|
const { container } = render(() => (
|
|
<Icon
|
|
iconNode={airVent}
|
|
size={48}
|
|
stroke="red"
|
|
absoluteStrokeWidth
|
|
/>
|
|
));
|
|
|
|
expect(container.firstChild).toBeDefined();
|
|
});
|
|
|
|
it('should render icon and match snapshot', async () => {
|
|
const { container } = render(() => (
|
|
<Icon
|
|
iconNode={airVent}
|
|
size={48}
|
|
stroke="red"
|
|
absoluteStrokeWidth
|
|
/>
|
|
));
|
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
|
});
|
|
|
|
it('should render icon based on icon data', async () => {
|
|
const { container } = render(() => (
|
|
<Icon
|
|
icon={airVentIcon}
|
|
size={48}
|
|
stroke="red"
|
|
/>
|
|
));
|
|
|
|
expect(container.firstChild).toBeDefined();
|
|
});
|
|
|
|
it('should support nonScalingStroke', async () => {
|
|
const { container } = render(() => (
|
|
<Icon
|
|
icon={airVentIcon}
|
|
size={48}
|
|
stroke="red"
|
|
strokeWidth={2}
|
|
nonScalingStroke
|
|
/>
|
|
));
|
|
|
|
expect(container.firstChild?.firstChild).toHaveAttribute('vector-effect', 'non-scaling-stroke');
|
|
});
|
|
|
|
it('should update when reactive props change', async () => {
|
|
const [size, setSize] = createSignal(24);
|
|
const { container } = render(() => (
|
|
<Icon
|
|
icon={airVentIcon}
|
|
size={size()}
|
|
/>
|
|
));
|
|
|
|
expect(container.firstChild).toHaveAttribute('width', '24');
|
|
expect(container.firstChild).toHaveAttribute('height', '24');
|
|
|
|
setSize(48);
|
|
flush();
|
|
|
|
expect(container.firstChild).toHaveAttribute('width', '48');
|
|
expect(container.firstChild).toHaveAttribute('height', '48');
|
|
});
|
|
});
|
|
|
|
describe('Icon Component Accessibility', () => {
|
|
it('should have aria-hidden prop when no aria prop is present', async () => {
|
|
const { container } = render(() => (
|
|
<Icon
|
|
iconNode={airVent}
|
|
size={48}
|
|
stroke="red"
|
|
absoluteStrokeWidth
|
|
/>
|
|
));
|
|
|
|
expect(container.firstChild).toHaveAttribute('aria-hidden', 'true');
|
|
});
|
|
|
|
it('should not have aria-hidden prop when aria prop is present', async () => {
|
|
const { container } = render(() => (
|
|
<Icon
|
|
iconNode={airVent}
|
|
size={48}
|
|
stroke="red"
|
|
absoluteStrokeWidth
|
|
aria-label="Air conditioning"
|
|
/>
|
|
));
|
|
|
|
expect(container.firstChild).not.toHaveAttribute('aria-hidden');
|
|
});
|
|
|
|
it('should not have aria-hidden prop when title prop is present', async () => {
|
|
const { container } = render(() => (
|
|
<Icon
|
|
iconNode={airVent}
|
|
size={48}
|
|
stroke="red"
|
|
absoluteStrokeWidth
|
|
// @ts-expect-error
|
|
title="Air conditioning"
|
|
/>
|
|
));
|
|
|
|
expect(container.firstChild).not.toHaveAttribute('aria-hidden');
|
|
});
|
|
|
|
it('should render a labelled title child and not have aria-hidden prop', async () => {
|
|
const { container } = render(() => (
|
|
<Icon
|
|
iconNode={airVent}
|
|
size={48}
|
|
stroke="red"
|
|
absoluteStrokeWidth
|
|
role="img"
|
|
aria-labelledby="warn-title"
|
|
>
|
|
<title id="warn-title">Warning: Action cannot be undone</title>
|
|
</Icon>
|
|
));
|
|
|
|
expect(container.firstChild).not.toHaveAttribute('aria-hidden');
|
|
expect(container.firstChild).toHaveAttribute('role', 'img');
|
|
expect(container.firstChild).toHaveAttribute('aria-labelledby', 'warn-title');
|
|
expect(container.querySelector('title#warn-title')).toHaveTextContent(
|
|
'Warning: Action cannot be undone',
|
|
);
|
|
});
|
|
|
|
it('should keep aria-hidden prop when there are only children', async () => {
|
|
const { container } = render(() => (
|
|
<Icon
|
|
iconNode={airVent}
|
|
size={48}
|
|
stroke="red"
|
|
absoluteStrokeWidth
|
|
>
|
|
<title>Some title</title>
|
|
</Icon>
|
|
));
|
|
|
|
expect(container.firstChild).toHaveAttribute('aria-hidden', 'true');
|
|
expect(container.querySelector('title')).toHaveTextContent('Some title');
|
|
});
|
|
|
|
it('should update reactive children', async () => {
|
|
const [showTitle, setShowTitle] = createSignal(false);
|
|
const { container } = render(() => (
|
|
<Icon
|
|
iconNode={airVent}
|
|
role="img"
|
|
aria-labelledby="dynamic-title"
|
|
>
|
|
{showTitle() && <title id="dynamic-title">Dynamic title</title>}
|
|
</Icon>
|
|
));
|
|
|
|
expect(container.querySelector('title')).toBeNull();
|
|
|
|
setShowTitle(true);
|
|
flush();
|
|
|
|
expect(container.querySelector('title#dynamic-title')).toHaveTextContent('Dynamic title');
|
|
});
|
|
|
|
it('should never override aria-hidden prop', async () => {
|
|
const { container } = render(() => (
|
|
<Icon
|
|
iconNode={airVent}
|
|
size={48}
|
|
stroke="red"
|
|
absoluteStrokeWidth
|
|
aria-hidden="false"
|
|
/>
|
|
));
|
|
|
|
expect(container.firstChild).toHaveAttribute('aria-hidden', 'false');
|
|
});
|
|
});
|