Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions src/components/breadcrumbs/__test__/Breadcrumbs.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,29 @@ describe('Breadcrumbs Component', () => {
expect(separators).toHaveLength(3);
});

it('opens the dropdown menu when clicked', async () => {
const { getByRole, getByText } = renderBreadcrumbs();
it('renders a dropdown menu with functionally hidden items for lists larger than 3 components', async () => {
const fiveItemsProps = {
...mockProps,
items: [
...mockProps.items,
{ uuid: '5', label: 'Details', icon: null, active: true },
],
};

const { getByRole, getByText } = render(
<DndProvider backend={HTML5Backend}>
<Breadcrumbs {...fiveItemsProps} />
</DndProvider>
);

const dropdownButton = getByRole('button');
await act(async () => {
userEvent.click(dropdownButton);
});
const hiddenItem = getByText('Subcategory');
expect(hiddenItem).toBeInTheDocument();

const hiddenItemCategory = getByText('Category');
const hiddenItemSubcategory = getByText('Subcategory');
expect(hiddenItemCategory).toBeInTheDocument();
expect(hiddenItemSubcategory).toBeInTheDocument();
});
});
12 changes: 12 additions & 0 deletions src/components/breadcrumbs/__test__/BreadcrumbsItem.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,16 @@ describe('BreadcrumbsItem Component', () => {
const { getByTestId } = renderBreadcrumbsItem({ itemComponent: ItemComponentMock });
expect(getByTestId('custom-icon')).toBeInTheDocument();
});

it('applies first path styling when isFirstPath is true', () => {
const firstPathItem = { ...breadcrumbItem, isFirstPath: true };
const { getByText } = renderBreadcrumbsItem({ item: firstPathItem, totalBreadcrumbsLength: 1 });
expect(getByText('Item 1').parentElement).toHaveClass('shrink-0 pr-1');
});

it('renders gracefully when label is not provided', () => {
const noLabelItem = { ...breadcrumbItem, label: '' };
const { container } = renderBreadcrumbsItem({ item: noLabelItem });
expect(container).toBeInTheDocument();
});
});
34 changes: 34 additions & 0 deletions src/components/button/__test__/Button.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ describe('Button component', () => {
expect(keydown).toHaveBeenCalledOnce();
});

it('Button should handle default onClick and onKeyDown without crashing', () => {
const { getByRole } = render(<Button />);
const button = getByRole('button');
fireEvent.click(button);
fireEvent.keyDown(button, { key: 'Enter', code: 'Enter' });
});

it('Primary button should render correctly', () => {
const button = render(<Button variant="primary">Primary</Button>);
expect(button).toMatchSnapshot();
Expand Down Expand Up @@ -94,4 +101,31 @@ describe('Button component', () => {
const button = render(<Button variant="tertiary" size="medium" />);
expect(button).toMatchSnapshot();
});

it('Destructive loading button should render correctly', () => {
const button = render(<Button variant="destructive" loading />);
expect(button).toMatchSnapshot();
});

it('Button with id, dataTest, autofocus, buttonDataCy and buttonChildrenDataCy renders correctly', () => {
const button = render(
<Button
variant="primary"
id="btn-id"
dataTest="btn-test"
autofocus
buttonDataCy="btn-cy"
buttonChildrenDataCy="btn-children-cy"
>
With Props
</Button>,
);
expect(button).toMatchSnapshot();
});

it('Button with unknown variant should render default styles', () => {
// @ts-expect-error testing invalid variant
const button = render(<Button variant="unknown">Unknown</Button>);
expect(button).toMatchSnapshot();
});
});
Loading
Loading