Skip to content

Commit 07fb693

Browse files
author
Fabian Stoehr
committed
tests: fix tests
1 parent a3e62ce commit 07fb693

4 files changed

Lines changed: 31 additions & 23 deletions

File tree

__tests__/src/components/WindowTopMenu.test.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,21 @@ describe('WindowTopMenu', () => {
3333

3434
const menuSections = within(screen.getByRole('menu')).getAllByRole('presentation');
3535
expect(menuSections).toHaveLength(2);
36+
3637
expect(menuSections[0]).toHaveTextContent('View');
37-
expect(menuSections[1]).toHaveTextContent('Thumbnails');
38+
const menus = within(screen.getByRole('menu')).getAllByRole('menubar');
3839

39-
const menuItems = screen.getAllByRole('menuitem');
40-
expect(menuItems).toHaveLength(5);
41-
expect(menuItems[0]).toHaveTextContent('Single');
42-
expect(menuItems[1]).toHaveTextContent('Gallery');
43-
expect(menuItems[2]).toHaveTextContent('Off');
44-
expect(menuItems[3]).toHaveTextContent('Bottom');
45-
expect(menuItems[4]).toHaveTextContent('Right');
40+
const viewItems = within(menus[0]).getAllByRole('menuitemradio');
41+
expect(viewItems).toHaveLength(2);
42+
expect(viewItems[0]).toHaveTextContent('Single');
43+
expect(viewItems[1]).toHaveTextContent('Gallery');
44+
45+
expect(menuSections[1]).toHaveTextContent('Thumbnails');
46+
const thumbnailItems = within(menus[1]).getAllByRole('menuitemradio');
47+
expect(thumbnailItems).toHaveLength(3);
48+
expect(thumbnailItems[0]).toHaveTextContent('Off');
49+
expect(thumbnailItems[1]).toHaveTextContent('Bottom');
50+
expect(thumbnailItems[2]).toHaveTextContent('Right');
4651
});
4752

4853
it('does not display unless open', () => {
@@ -66,7 +71,7 @@ describe('WindowTopMenu', () => {
6671
/>);
6772

6873
// click a menu item should close the menu
69-
const menuItems = screen.getAllByRole('menuitem');
74+
const menuItems = screen.getAllByRole('menuitemradio');
7075
await user.click(menuItems[0]);
7176
expect(handleClose).toHaveBeenCalledTimes(1);
7277
expect(toggleDraggingEnabled).toHaveBeenCalledTimes(1);

__tests__/src/components/WindowViewSettings.test.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('WindowViewSettings', () => {
2020
it('renders all elements correctly', () => {
2121
createWrapper();
2222
expect(screen.getByRole('presentation', { selector: 'li' })).toBeInTheDocument();
23-
const menuItems = screen.queryAllByRole('menuitem');
23+
const menuItems = screen.queryAllByRole('menuitemradio');
2424
expect(menuItems.length).toBe(4);
2525
expect(menuItems[0]).toHaveTextContent(/Single/i);
2626
expect(menuItems[1]).toHaveTextContent(/Book/i);
@@ -29,29 +29,29 @@ describe('WindowViewSettings', () => {
2929
});
3030
it('single should set the correct label active (by setting the secondary color)', () => {
3131
createWrapper({ windowViewType: 'single' });
32-
expect(screen.getByRole('menuitem', { name: /Single/ }).querySelector('svg')).toHaveClass('MuiSvgIcon-colorSecondary'); // eslint-disable-line testing-library/no-node-access
33-
expect(screen.getByRole('menuitem', { name: /Book/ }).querySelector('svg')).not.toHaveClass('MuiSvgIcon-colorSecondary'); // eslint-disable-line testing-library/no-node-access
32+
expect(screen.getByRole('menuitemradio', { name: /Single/ }).querySelector('svg')).toHaveClass('MuiSvgIcon-colorSecondary'); // eslint-disable-line testing-library/no-node-access
33+
expect(screen.getByRole('menuitemradio', { name: /Book/ }).querySelector('svg')).not.toHaveClass('MuiSvgIcon-colorSecondary'); // eslint-disable-line testing-library/no-node-access
3434
});
3535
it('book should set the correct label active (by setting the secondary color)', () => {
3636
createWrapper({ windowViewType: 'book' });
37-
expect(screen.getByRole('menuitem', { name: /Book/ }).querySelector('svg')).toHaveClass('MuiSvgIcon-colorSecondary'); // eslint-disable-line testing-library/no-node-access
38-
expect(screen.getByRole('menuitem', { name: /Single/ }).querySelector('svg')).not.toHaveClass('MuiSvgIcon-colorSecondary'); // eslint-disable-line testing-library/no-node-access
37+
expect(screen.getByRole('menuitemradio', { name: /Book/ }).querySelector('svg')).toHaveClass('MuiSvgIcon-colorSecondary'); // eslint-disable-line testing-library/no-node-access
38+
expect(screen.getByRole('menuitemradio', { name: /Single/ }).querySelector('svg')).not.toHaveClass('MuiSvgIcon-colorSecondary'); // eslint-disable-line testing-library/no-node-access
3939
});
4040
it('scroll should set the correct label active (by setting the secondary color)', () => {
4141
createWrapper({ windowViewType: 'scroll' });
42-
expect(screen.getByRole('menuitem', { name: /Scroll/ }).querySelector('svg')).toHaveClass('MuiSvgIcon-colorSecondary'); // eslint-disable-line testing-library/no-node-access
43-
expect(screen.getByRole('menuitem', { name: /Single/ }).querySelector('svg')).not.toHaveClass('MuiSvgIcon-colorSecondary'); // eslint-disable-line testing-library/no-node-access
42+
expect(screen.getByRole('menuitemradio', { name: /Scroll/ }).querySelector('svg')).toHaveClass('MuiSvgIcon-colorSecondary'); // eslint-disable-line testing-library/no-node-access
43+
expect(screen.getByRole('menuitemradio', { name: /Single/ }).querySelector('svg')).not.toHaveClass('MuiSvgIcon-colorSecondary'); // eslint-disable-line testing-library/no-node-access
4444
});
4545
it('gallery should set the correct label active (by setting the secondary color)', () => {
4646
createWrapper({ windowViewType: 'gallery' });
47-
expect(screen.getByRole('menuitem', { name: /Gallery/ }).querySelector('svg')).toHaveClass('MuiSvgIcon-colorSecondary'); // eslint-disable-line testing-library/no-node-access
48-
expect(screen.getByRole('menuitem', { name: /Single/ }).querySelector('svg')).not.toHaveClass('MuiSvgIcon-colorSecondary'); // eslint-disable-line testing-library/no-node-access
47+
expect(screen.getByRole('menuitemradio', { name: /Gallery/ }).querySelector('svg')).toHaveClass('MuiSvgIcon-colorSecondary'); // eslint-disable-line testing-library/no-node-access
48+
expect(screen.getByRole('menuitemradio', { name: /Single/ }).querySelector('svg')).not.toHaveClass('MuiSvgIcon-colorSecondary'); // eslint-disable-line testing-library/no-node-access
4949
});
5050
it('updates state when the view config selection changes', async () => {
5151
const setWindowViewType = vi.fn();
5252
createWrapper({ setWindowViewType });
5353
const user = userEvent.setup();
54-
const menuItems = screen.queryAllByRole('menuitem');
54+
const menuItems = screen.queryAllByRole('menuitemradio');
5555
expect(menuItems.length).toBe(4);
5656
await user.click(menuItems[0]);
5757
expect(setWindowViewType).toHaveBeenCalledWith('xyz', 'single');

src/components/WindowThumbnailSettings.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@ export function WindowThumbnailSettings({
4747
<ListSubheader role="presentation" disableSticky>{t('thumbnails')}</ListSubheader>
4848
<StyledMenuList role="menubar">
4949
<ThumbnailOption
50-
aria-selected={thumbnailNavigationPosition === 'off'}
50+
aria-checked={thumbnailNavigationPosition === 'off'}
5151
autoFocus={thumbnailNavigationPosition === 'off'}
5252
key="off"
5353
onClick={() => { handleChange('off'); }}
54+
role="menuitemradio"
5455
selected={thumbnailNavigationPosition === 'off'}
5556
>
5657
<FormControlLabel
@@ -63,10 +64,11 @@ export function WindowThumbnailSettings({
6364
/>
6465
</ThumbnailOption>
6566
<ThumbnailOption
66-
aria-selected={thumbnailNavigationPosition === 'far-bottom'}
67+
aria-checked={thumbnailNavigationPosition === 'far-bottom'}
6768
autoFocus={thumbnailNavigationPosition === 'far-bottom'}
6869
key="far-bottom"
6970
onClick={() => { handleChange('far-bottom'); }}
71+
role="menuitemradio"
7072
selected={thumbnailNavigationPosition === 'far-bottom'}
7173
>
7274
<FormControlLabel
@@ -79,10 +81,11 @@ export function WindowThumbnailSettings({
7981
/>
8082
</ThumbnailOption>
8183
<ThumbnailOption
82-
aria-selected={thumbnailNavigationPosition === 'far-right'}
84+
aria-checked={thumbnailNavigationPosition === 'far-right'}
8385
autoFocus={thumbnailNavigationPosition === 'far-right'}
8486
key="far-right"
8587
onClick={() => { handleChange('far-right'); }}
88+
role="menuitemradio"
8689
selected={thumbnailNavigationPosition === 'far-right'}
8790
>
8891
<FormControlLabel

src/components/WindowViewSettings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ export function WindowViewSettings({
6161
autoFocus={windowViewType === value}
6262
key={value}
6363
onClick={() => { handleChange(value); handleClose(); }}
64-
selected={windowViewType === value}
6564
role="menuitemradio"
65+
selected={windowViewType === value}
6666
>
6767
<FormControlLabel
6868
value={value}

0 commit comments

Comments
 (0)