Skip to content

Commit

Permalink
fix(@clayui/vertical-nav): Update tests and snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
ilzamcmed committed Jan 16, 2024
1 parent 7e2a35b commit 714281d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ exports[`VerticalNav basic rendering render dynamic content 1`] = `
role="none"
>
<button
aria-controls="clay-id-6"
aria-expanded="false"
aria-haspopup="true"
class="nav-link collapse-icon collapsed btn btn-unstyled"
role="button"
role="menuitem"
type="button"
>
Home
Expand Down
5 changes: 3 additions & 2 deletions packages/clay-nav/src/__tests__/__snapshots__/index.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ exports[`ClayVerticalNav renders 1`] = `
role="none"
>
<button
aria-controls="clay-id-2"
aria-expanded="true"
aria-haspopup="true"
class="nav-link collapse-icon btn btn-unstyled"
role="button"
role="menuitem"
type="button"
>
Home
Expand Down Expand Up @@ -73,6 +73,7 @@ exports[`ClayVerticalNav renders 1`] = `
</button>
<ul
class="nav nav-stacked"
id="clay-id-2"
role="menu"
>
<li
Expand Down
33 changes: 11 additions & 22 deletions packages/clay-nav/src/__tests__/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@
*/

import {ClayVerticalNav} from '..';
import {
cleanup,
fireEvent,
getAllByRole as docGetAllByRole,
render,
} from '@testing-library/react';
import {cleanup, fireEvent, render} from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import React from 'react';

Expand Down Expand Up @@ -92,11 +87,11 @@ describe('ClayVerticalNav', () => {
});

it('expand items by pressing the right arrow key', () => {
const {getAllByRole} = render(
const {getByText} = render(
<ClayVerticalNav items={ITEMS} spritemap="/path/to" />
);

const [, , projects] = getAllByRole('button');
const projects = getByText('Projects');

userEvent.tab();
userEvent.tab();
Expand All @@ -109,11 +104,11 @@ describe('ClayVerticalNav', () => {
});

it('collapse items by pressing the left arrow key', () => {
const {getAllByRole} = render(
const {getByText} = render(
<ClayVerticalNav items={ITEMS} spritemap="/path/to" />
);

const [, , projects] = getAllByRole('button');
const projects = getByText('Projects');

userEvent.tab();
userEvent.tab();
Expand All @@ -130,11 +125,11 @@ describe('ClayVerticalNav', () => {
});

it('moves focus to first item if item is expanded', () => {
const {getAllByRole} = render(
const {getByText} = render(
<ClayVerticalNav items={ITEMS} spritemap="/path/to" />
);

const [, , projects] = getAllByRole('button');
const projects = getByText('Projects');

userEvent.tab();
userEvent.tab();
Expand All @@ -147,20 +142,17 @@ describe('ClayVerticalNav', () => {

userEvent.keyboard('[ArrowRight]');

const [first] = docGetAllByRole(
projects!.parentNode as HTMLElement,
'menuitem'
);
const first = getByText('Five');

expect(first).toEqual(document.activeElement);
});

it('move focus to parent if focus is on child when pressing left arrow key', () => {
const {getAllByRole} = render(
const {getByText} = render(
<ClayVerticalNav items={ITEMS} spritemap="/path/to" />
);

const [, , projects] = getAllByRole('button');
const projects = getByText('Projects');

userEvent.tab();
userEvent.tab();
Expand All @@ -173,10 +165,7 @@ describe('ClayVerticalNav', () => {

userEvent.keyboard('[ArrowRight]');

const [first] = docGetAllByRole(
projects!.parentNode as HTMLElement,
'menuitem'
);
const first = getByText('Five');

expect(first).toEqual(document.activeElement);

Expand Down

0 comments on commit 714281d

Please sign in to comment.