@amsterdam/design-system-react
Version:
All React components from the Amsterdam Design System. Use it to compose pages in your website or application.
67 lines (66 loc) • 3.23 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { render, screen } from '@testing-library/react';
import { createRef } from 'react';
import { describe, expect, it } from 'vitest';
import { TabNavigationLink } from './TabNavigationLink';
const TestIcon = () => _jsx("svg", { "data-testid": "test-icon" });
describe('TabNavigationLink', () => {
it('renders', () => {
render(_jsx(TabNavigationLink, { href: "/" }));
const component = screen.getByRole('listitem');
expect(component).toBeInTheDocument();
expect(component).toBeVisible();
});
it('renders a design system BEM class name', () => {
render(_jsx(TabNavigationLink, { href: "/" }));
const item = screen.getByRole('listitem');
expect(item).toHaveClass('ams-tab-navigation__item');
const link = screen.getByRole('link');
expect(link).toHaveClass('ams-tab-navigation__link');
});
it('renders an extra class name', () => {
render(_jsx(TabNavigationLink, { className: "extra", href: "/" }));
const component = screen.getByRole('link');
expect(component).toHaveClass('ams-tab-navigation__link extra');
});
it('renders the href attribute', () => {
render(_jsx(TabNavigationLink, { href: "/test" }));
const component = screen.getByRole('link');
expect(component).toHaveAttribute('href', '/test');
});
it('supports aria-current attribute', () => {
render(_jsx(TabNavigationLink, { "aria-current": "page", href: "/" }));
const component = screen.getByRole('link');
expect(component).toHaveAttribute('aria-current', 'page');
});
it('renders a custom link component', () => {
const CustomLink = ({ children, ...props }) => (_jsx("a", { ...props, "data-custom": "true", children: children }));
render(_jsx(TabNavigationLink, { href: "/test", linkComponent: CustomLink }));
const component = screen.getByRole('link');
expect(component).toHaveAttribute('data-custom', 'true');
expect(component).toHaveAttribute('href', '/test');
});
it('renders an icon', () => {
render(_jsx(TabNavigationLink, { href: "/", icon: TestIcon }));
const icon = screen.getByTestId('test-icon');
expect(icon).toBeInTheDocument();
});
it('does not render an icon by default', () => {
const { container } = render(_jsx(TabNavigationLink, { href: "/" }));
const icon = container.querySelector('.ams-icon');
expect(icon).not.toBeInTheDocument();
});
it('supports ForwardRef in React', () => {
const ref = createRef();
render(_jsx(TabNavigationLink, { href: "/", ref: ref }));
const component = screen.getByRole('link');
expect(ref.current).toBe(component);
});
it('passes additional props', () => {
render(_jsx(TabNavigationLink, { "aria-hidden": false, "data-test": "data-test", href: "/", id: "id" }));
const component = screen.getByRole('link');
expect(component).toHaveAttribute('aria-hidden', 'false');
expect(component).toHaveAttribute('id', 'id');
expect(component).toHaveAttribute('data-test', 'data-test');
});
});