/* eslint-disable no-console */
import { render, screen } from '@testing-library/react';
import { MemoryRouter } from 'react-router-dom';
import { NavPillItem, NavPills } from '../../shlink-frontend-kit/src/navigation/NavPills';
describe('', () => {
let originalError: typeof console.error;
beforeEach(() => {
originalError = console.error;
console.error = () => {}; // Suppress errors logged during this test
});
afterEach(() => {
console.error = originalError;
});
it.each([
['Foo'],
[Hi!],
[[, Hi!]],
])('throws error when any of the children is not a NavPillItem', (children) => {
expect.assertions(1);
expect(() => render({children})).toThrow(
'Only NavPillItem children are allowed inside NavPills.',
);
});
it.each([
[undefined],
[true],
[false],
])('renders provided items', (fill) => {
const { container } = render(
1
2
3
,
);
const links = screen.getAllByRole('link');
expect(links).toHaveLength(3);
links.forEach((link, index) => {
expect(link).toHaveTextContent(`${index + 1}`);
expect(link).toHaveAttribute('href', `/${index + 1}`);
});
if (fill) {
expect(container.querySelector('.nav')).toHaveClass('nav-fill');
} else {
expect(container.querySelector('.nav')).not.toHaveClass('nav-fill');
}
});
});