|
1 | 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
2 | 2 | // SPDX-License-Identifier: Apache-2.0 |
3 | 3 | import React from 'react'; |
4 | | -import { act, fireEvent, screen, waitFor, within } from '@testing-library/react'; |
| 4 | +import { act, fireEvent, screen, waitFor } from '@testing-library/react'; |
5 | 5 |
|
6 | 6 | import AppLayout, { AppLayoutProps } from '../../../lib/components/app-layout'; |
7 | 7 | import customCssProps from '../../../lib/components/internal/generated/custom-css-properties'; |
8 | 8 | import { KeyCode } from '../../internal/keycode'; |
9 | | -import { |
10 | | - describeEachAppLayout, |
11 | | - getActiveDrawerWidth, |
12 | | - manyDrawers, |
13 | | - renderComponent, |
14 | | - testDrawer, |
15 | | - testDrawerWithoutLabels, |
16 | | -} from './utils'; |
17 | | - |
18 | | -import drawerStyles from '../../../lib/components/app-layout/drawer/styles.css.js'; |
| 9 | +import { describeEachAppLayout, getActiveDrawerWidth, manyDrawers, renderComponent, testDrawer } from './utils'; |
| 10 | + |
19 | 11 | import notificationStyles from '../../../lib/components/app-layout/notifications/styles.css.js'; |
20 | 12 | import styles from '../../../lib/components/app-layout/styles.css.js'; |
21 | 13 | import visualRefreshStyles from '../../../lib/components/app-layout/visual-refresh/styles.css.js'; |
22 | 14 | import visualRefreshToolbarNotificationStyles from '../../../lib/components/app-layout/visual-refresh-toolbar/notifications/styles.css.js'; |
23 | | -import toolbarStyles from '../../../lib/components/app-layout/visual-refresh-toolbar/toolbar/styles.css.js'; |
24 | 15 |
|
25 | 16 | jest.mock('@cloudscape-design/component-toolkit', () => ({ |
26 | 17 | ...jest.requireActual('@cloudscape-design/component-toolkit'), |
@@ -152,14 +143,6 @@ describeEachAppLayout({ sizes: ['desktop'] }, ({ theme }) => { |
152 | 143 | }); |
153 | 144 | }); |
154 | 145 |
|
155 | | - test('should render an active drawer', () => { |
156 | | - const { wrapper } = renderComponent( |
157 | | - <AppLayout activeDrawerId={testDrawer.id} drawers={[testDrawer]} onDrawerChange={() => {}} /> |
158 | | - ); |
159 | | - |
160 | | - expect(wrapper.findActiveDrawer()).toBeTruthy(); |
161 | | - }); |
162 | | - |
163 | 146 | test(`should toggle drawer on click`, () => { |
164 | 147 | const { wrapper } = renderComponent(<AppLayout toolsHide={true} drawers={[testDrawer]} />); |
165 | 148 | wrapper.findDrawersTriggers()![0].click(); |
@@ -225,13 +208,6 @@ describeEachAppLayout({ sizes: ['desktop'] }, ({ theme }) => { |
225 | 208 | expect(wrapper.findDrawersTriggers()!.length).toBeLessThan(100); |
226 | 209 | }); |
227 | 210 |
|
228 | | - test('Renders aria-controls on toggle only when active', () => { |
229 | | - const { wrapper } = renderComponent(<AppLayout drawers={[testDrawer]} />); |
230 | | - expect(wrapper.findDrawerTriggerById('security')!.getElement()).not.toHaveAttribute('aria-controls'); |
231 | | - wrapper.findDrawerTriggerById('security')!.click(); |
232 | | - expect(wrapper.findDrawerTriggerById('security')!.getElement()).toHaveAttribute('aria-controls', 'security'); |
233 | | - }); |
234 | | - |
235 | 211 | test('should render badge when defined', () => { |
236 | 212 | const { wrapper } = renderComponent(<AppLayout drawers={manyDrawers} />); |
237 | 213 |
|
@@ -272,62 +248,4 @@ describeEachAppLayout({ themes: ['classic'], sizes: ['desktop'] }, () => { |
272 | 248 | fireEvent.click(screen.getByLabelText('Drawers', { selector: '[role=region]' })); |
273 | 249 | expect(wrapper.findActiveDrawer()).toBeFalsy(); |
274 | 250 | }); |
275 | | - |
276 | | - test('renders roles only when aria labels are not provided (classic)', () => { |
277 | | - const { wrapper } = renderComponent(<AppLayout navigationHide={true} drawers={[testDrawerWithoutLabels]} />); |
278 | | - const drawersAside = within(wrapper.findByClassName(drawerStyles['drawer-closed'])!.getElement()).getByRole( |
279 | | - 'region' |
280 | | - ); |
281 | | - |
282 | | - expect(wrapper.findDrawerTriggerById(testDrawer.id)!.getElement()).not.toHaveAttribute('aria-label'); |
283 | | - expect(drawersAside).not.toHaveAttribute('aria-label'); |
284 | | - expect(wrapper.findByClassName(drawerStyles['drawer-triggers-wrapper'])!.getElement()).toHaveAttribute( |
285 | | - 'role', |
286 | | - 'toolbar' |
287 | | - ); |
288 | | - }); |
289 | | - |
290 | | - test('renders roles and aria labels when provided (classic)', () => { |
291 | | - const { wrapper } = renderComponent(<AppLayout drawers={[testDrawer]} ariaLabels={{ drawers: 'Drawers' }} />); |
292 | | - const drawersAside = within(wrapper.findByClassName(drawerStyles['drawer-closed'])!.getElement()).getByRole( |
293 | | - 'region' |
294 | | - ); |
295 | | - |
296 | | - expect(wrapper.findDrawerTriggerById('security')!.getElement()).toHaveAttribute( |
297 | | - 'aria-label', |
298 | | - 'Security trigger button' |
299 | | - ); |
300 | | - expect(drawersAside).toHaveAttribute('aria-label', 'Drawers'); |
301 | | - expect(wrapper.findByClassName(drawerStyles['drawer-triggers-wrapper'])!.getElement()).toHaveAttribute( |
302 | | - 'role', |
303 | | - 'toolbar' |
304 | | - ); |
305 | | - }); |
306 | | -}); |
307 | | - |
308 | | -describeEachAppLayout({ themes: ['refresh', 'refresh-toolbar'], sizes: ['desktop'] }, ({ theme }) => { |
309 | | - const styles = theme === 'refresh' ? visualRefreshStyles : toolbarStyles; |
310 | | - test(`${theme} - renders roles only when aria labels are not provided`, () => { |
311 | | - const { wrapper } = renderComponent(<AppLayout navigationHide={true} drawers={[testDrawerWithoutLabels]} />); |
312 | | - |
313 | | - expect(wrapper.findDrawerTriggerById(testDrawer.id)!.getElement()).not.toHaveAttribute('aria-label'); |
314 | | - expect(wrapper.findByClassName(styles['drawers-desktop-triggers-container'])!.getElement()).not.toHaveAttribute( |
315 | | - 'aria-label' |
316 | | - ); |
317 | | - expect(wrapper.findByClassName(styles['drawers-trigger-content'])!.getElement()).toHaveAttribute('role', 'toolbar'); |
318 | | - }); |
319 | | - |
320 | | - test(`${theme} - renders roles and aria labels when provided`, () => { |
321 | | - const { wrapper } = renderComponent(<AppLayout drawers={[testDrawer]} ariaLabels={{ drawers: 'Drawers' }} />); |
322 | | - |
323 | | - expect(wrapper.findDrawerTriggerById('security')!.getElement()).toHaveAttribute( |
324 | | - 'aria-label', |
325 | | - 'Security trigger button' |
326 | | - ); |
327 | | - expect(wrapper.findByClassName(styles['drawers-desktop-triggers-container'])!.getElement()).toHaveAttribute( |
328 | | - 'aria-label', |
329 | | - 'Drawers' |
330 | | - ); |
331 | | - expect(wrapper.findByClassName(styles['drawers-trigger-content'])!.getElement()).toHaveAttribute('role', 'toolbar'); |
332 | | - }); |
333 | 251 | }); |
0 commit comments