Skip to content

Commit 49ebc43

Browse files
committed
test(healthcheck): trim duplicate drawer coverage
Reuse the Healthcheck fixture and keep focus restoration checks alongside the browser interaction matrix. Check reload once per opening order and make the external-close test detect focus stealing.
1 parent 59a9fca commit 49ebc43

4 files changed

Lines changed: 18 additions & 89 deletions

File tree

‎src/components/Drawer/__test__/DrawerAccessibility.test.tsx‎

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jest.mock('../../../utils/hooks/useSetting', () => ({
1010
useSetting: () => [undefined, jest.fn()],
1111
}));
1212

13-
function Fixture({disableModal = true}: {disableModal?: boolean}) {
13+
function Fixture() {
1414
const [healthcheck, setHealthcheck] = React.useState(false);
1515
const [assistant, setAssistant] = React.useState(false);
1616
return (
@@ -21,7 +21,7 @@ function Fixture({disableModal = true}: {disableModal?: boolean}) {
2121
isDrawerVisible={healthcheck}
2222
onCloseDrawer={() => setHealthcheck(false)}
2323
drawerControls={[{type: 'close'}]}
24-
disableModal={disableModal}
24+
disableModal
2525
renderDrawerContent={() => <input aria-label="Healthcheck filter" />}
2626
>
2727
<button onClick={() => setHealthcheck(true)}>Open Healthcheck</button>
@@ -65,46 +65,6 @@ afterEach(() => {
6565
jest.restoreAllMocks();
6666
});
6767

68-
for (const first of ['Healthcheck', 'assistant']) {
69-
test(`keeps both panels and the page accessible with ${first} opened first`, async () => {
70-
render(<Fixture />);
71-
fireEvent.click(screen.getByRole('button', {name: `Open ${first}`}));
72-
const second = first === 'Healthcheck' ? 'assistant' : 'Healthcheck';
73-
fireEvent.click(await screen.findByRole('button', {name: `Open ${second}`}));
74-
expect(await screen.findByRole('dialog', {name: 'Healthcheck'})).toBeInTheDocument();
75-
expect(screen.getByRole('dialog', {name: 'Assistant'})).toBeInTheDocument();
76-
expect(screen.getByRole('button', {name: 'Open assistant'})).toBeInTheDocument();
77-
fireEvent.click(
78-
within(screen.getByRole('dialog', {name: 'Healthcheck'})).getByRole('button', {
79-
name: 'Close',
80-
}),
81-
);
82-
await waitFor(() =>
83-
expect(screen.queryByRole('dialog', {name: 'Healthcheck'})).not.toBeInTheDocument(),
84-
);
85-
expect(screen.getByRole('dialog', {name: 'Assistant'})).toBeInTheDocument();
86-
});
87-
}
88-
89-
test('Escape outside a non-modal drawer leaves it open, Escape inside closes it', async () => {
90-
render(<Fixture />);
91-
fireEvent.click(screen.getByRole('button', {name: 'Open Healthcheck'}));
92-
const panel = await screen.findByRole('dialog', {name: 'Healthcheck'});
93-
fireEvent.keyDown(screen.getByRole('button', {name: 'Open assistant'}), {key: 'Escape'});
94-
expect(panel).toBeInTheDocument();
95-
fireEvent.keyDown(panel, {key: 'Escape'});
96-
await waitFor(() =>
97-
expect(screen.queryByRole('dialog', {name: 'Healthcheck'})).not.toBeInTheDocument(),
98-
);
99-
});
100-
101-
test('preserves modal behavior for callers that opt out of the new mode', async () => {
102-
render(<Fixture disableModal={false} />);
103-
fireEvent.click(screen.getByRole('button', {name: 'Open Healthcheck'}));
104-
expect(await screen.findByRole('dialog', {name: 'Healthcheck'})).toBeInTheDocument();
105-
expect(screen.queryByRole('button', {name: 'Open assistant'})).not.toBeInTheDocument();
106-
});
107-
10868
test('returns focus to its opener after visiting the adjacent panel', async () => {
10969
render(<Fixture />);
11070
const opener = screen.getByRole('button', {name: 'Open Healthcheck'});
@@ -123,7 +83,9 @@ test('returns focus to its opener after visiting the adjacent panel', async () =
12383

12484
test('does not steal focus from an adjacent panel when closed externally', async () => {
12585
render(<Fixture />);
126-
fireEvent.click(screen.getByRole('button', {name: 'Open Healthcheck'}));
86+
const opener = screen.getByRole('button', {name: 'Open Healthcheck'});
87+
opener.focus();
88+
fireEvent.click(opener);
12789
const healthcheck = await screen.findByRole('dialog', {name: 'Healthcheck'});
12890
fireEvent.click(screen.getByRole('button', {name: 'Open assistant'}));
12991
const assistantClose = await screen.findByRole('button', {name: 'Close assistant'});

‎src/containers/Tenant/Healthcheck/components/__test__/HealthcheckDrawerExtension.test.tsx‎

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22

33
import {ThemeProvider} from '@gravity-ui/uikit';
4-
import {fireEvent, render, screen, waitFor, within} from '@testing-library/react';
4+
import {isInaccessible, render, screen, waitFor} from '@testing-library/react';
55

66
import {
77
DrawerContextProvider,
@@ -70,6 +70,7 @@ function DrawerFixture({
7070
downloadTooltip="Download"
7171
>
7272
<InsetProbe />
73+
<button>Page action</button>
7374
</HealthcheckDrawer>
7475
</DrawerContextProvider>
7576
</ThemeProvider>
@@ -153,45 +154,11 @@ describe('Healthcheck drawer extension', () => {
153154
async (disableModal) => {
154155
configureUIFactory({healthcheck: {disableModal}});
155156

156-
function ConfiguredDrawer() {
157-
const [open, setOpen] = React.useState(false);
158-
const close = React.useCallback(() => setOpen(false), []);
159-
160-
return (
161-
<ThemeProvider theme="light">
162-
<DrawerContextProvider>
163-
<HealthcheckDrawer
164-
isDrawerVisible={open}
165-
onCloseDrawer={close}
166-
drawerId="configured-healthcheck"
167-
storageKey="configured-healthcheck"
168-
title="Configured Healthcheck"
169-
healthcheckData={undefined}
170-
downloadFilePrefix="healthcheck"
171-
downloadTooltip="Download"
172-
renderDrawerContent={() => <input aria-label="Filter" />}
173-
>
174-
<button onClick={() => setOpen(true)}>Open Healthcheck</button>
175-
<button>Adjacent panel</button>
176-
</HealthcheckDrawer>
177-
</DrawerContextProvider>
178-
</ThemeProvider>
179-
);
180-
}
181-
182-
render(<ConfiguredDrawer />);
183-
fireEvent.click(screen.getByRole('button', {name: 'Open Healthcheck'}));
184-
const drawer = await screen.findByRole('dialog', {name: 'Configured Healthcheck'});
185-
if (disableModal) {
186-
expect(screen.getByRole('button', {name: 'Adjacent panel'})).toBeInTheDocument();
187-
} else {
188-
expect(
189-
screen.queryByRole('button', {name: 'Adjacent panel'}),
190-
).not.toBeInTheDocument();
191-
}
192-
fireEvent.click(within(drawer).getByRole('button', {name: 'Close'}));
193-
await waitFor(() => expect(drawer).not.toBeInTheDocument());
194-
expect(screen.getByRole('button', {name: 'Adjacent panel'})).toBeInTheDocument();
157+
render(<DrawerFixture />);
158+
await screen.findByRole('dialog', {name: 'Healthcheck'});
159+
await waitFor(() => {
160+
expect(isInaccessible(screen.getByText('Page action'))).toBe(!disableModal);
161+
});
195162
},
196163
);
197164

‎tests/fixtures/healthcheckDrawer.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {Provider} from 'react-redux';
77
import {DrawerContextProvider} from '../../src/components/Drawer/DrawerContext';
88
import {HealthcheckDrawer} from '../../src/containers/Tenant/Healthcheck/components/HealthcheckDrawer';
99
import {store} from '../../src/store/defaultStore';
10-
import {configureUIFactory, uiFactory} from '../../src/uiFactory/uiFactory';
10+
import {configureUIFactory} from '../../src/uiFactory/uiFactory';
1111

1212
const COMPANION_WIDTH = 320;
1313

@@ -109,7 +109,7 @@ export function renderHealthcheckDrawerFixture(
109109
mode: NonNullable<Window['e2eHealthcheckDrawerMode']>,
110110
) {
111111
const overrides = mode === 'default' ? {} : {disableModal: mode === 'non-modal'};
112-
configureUIFactory({healthcheck: {...uiFactory.healthcheck, ...overrides}});
112+
configureUIFactory({healthcheck: overrides});
113113

114114
const container = document.getElementById('root');
115115
if (!container) {

‎tests/suites/sidebar/healthcheckAccessibility.test.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,14 @@ test.describe('Non-modal Healthcheck accessibility', () => {
9191
await expect(panel(page, 'companion')).toBeVisible();
9292
await openPanel(page, 'Healthcheck');
9393
await expect(page.getByRole('dialog')).toHaveCount(2);
94+
await page.reload();
95+
await expect(page.getByTestId('healthcheck-drawer-fixture')).toBeVisible();
96+
await openBoth(page, first);
9497
});
9598

9699
for (const closing of ['Healthcheck', 'companion'] as const) {
97100
for (const method of ['Close', 'Escape'] as const) {
98-
test(`${first} first: ${method} ${closing}, reopen and reload`, async ({page}) => {
101+
test(`${first} first: ${method} ${closing} and reopen`, async ({page}) => {
99102
await openFixture(page);
100103
await openBoth(page, first);
101104
const closingPanel = panel(page, closing);
@@ -118,9 +121,6 @@ test.describe('Non-modal Healthcheck accessibility', () => {
118121
).toBeFocused();
119122
await openPanel(page, closing);
120123
await expect(page.getByRole('dialog')).toHaveCount(2);
121-
await page.reload();
122-
await expect(page.getByTestId('healthcheck-drawer-fixture')).toBeVisible();
123-
await openBoth(page, first);
124124
});
125125
}
126126
}

0 commit comments

Comments
 (0)