Skip to content

Commit c4f6133

Browse files
authored
chore: Add a test on split panel programmatic focus (#3733)
1 parent 2c99e1a commit c4f6133

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

pages/app-layout/dashboard-content-type.page.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
3-
import React, { useState } from 'react';
3+
import React, { useEffect, useRef, useState } from 'react';
44

5-
import AppLayout from '~components/app-layout';
5+
import AppLayout, { AppLayoutProps } from '~components/app-layout';
66
import Button from '~components/button';
77
import Header from '~components/header';
88
import SpaceBetween from '~components/space-between';
@@ -16,9 +16,18 @@ import * as toolsContent from './utils/tools-content';
1616

1717
export default function () {
1818
const [splitPanelOpen, setSplitPanelOpen] = useState(false);
19+
const appLayoutRef = useRef<AppLayoutProps.Ref>(null);
20+
21+
useEffect(() => {
22+
if (splitPanelOpen) {
23+
appLayoutRef.current!.focusSplitPanel();
24+
}
25+
}, [splitPanelOpen]);
26+
1927
return (
2028
<ScreenshotArea gutters={false}>
2129
<AppLayout
30+
ref={appLayoutRef}
2231
contentType="dashboard"
2332
ariaLabels={labels}
2433
breadcrumbs={<Breadcrumbs />}
@@ -33,6 +42,7 @@ export default function () {
3342
</SpaceBetween>
3443
}
3544
splitPanelPreferences={{ position: 'side' }}
45+
onSplitPanelPreferencesChange={() => {}}
3646
splitPanelOpen={splitPanelOpen}
3747
splitPanel={
3848
<SplitPanel

src/app-layout/__integ__/app-layout-split-panel.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ describe.each(['classic', 'refresh', 'refresh-toolbar'] as const)('%s', theme =>
6565
})
6666
);
6767

68+
test(
69+
'can focus split panel programmatically after opening',
70+
setupTest(async page => {
71+
await page.click('button=Add widget');
72+
await expect(page.isFocused(wrapper.findSplitPanel().findSlider().toSelector())).resolves.toBe(true);
73+
}, '#/light/app-layout/dashboard-content-type')
74+
);
75+
6876
(theme === 'classic' ? test : test.skip).each([
6977
{ position: 'side', repeatKey: 'ArrowLeft', expectedValue: 0 },
7078
{ position: 'side', repeatKey: 'ArrowRight', expectedValue: 100 },

0 commit comments

Comments
 (0)