Skip to content

Commit add1bdd

Browse files
authored
chore: Fixes some integ tests for React 18 (#3897)
1 parent b878843 commit add1bdd

File tree

7 files changed

+67
-49
lines changed

7 files changed

+67
-49
lines changed

src/anchor-navigation/__integ__/anchor-navigation.test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ describe('AnchorNavigation', () => {
2020
return useBrowser(async browser => {
2121
const page = new AnchorNavigationPage(browser);
2222
await browser.url('#/light/anchor-navigation/basic');
23+
await page.waitForVisible(wrapper.toSelector());
2324
await testFn(page);
2425
});
2526
}
@@ -65,11 +66,6 @@ describe('AnchorNavigation', () => {
6566
test(
6667
'scrolling to the end of the page makes the last anchor item active',
6768
setupTest(async page => {
68-
// TODO: fix test for React 18
69-
if ((await page.getReactVersion()) === '18') {
70-
return;
71-
}
72-
7369
const lastAnchorLink = wrapper.findAnchorLinkByHref('#section-1-2-1-1');
7470
await page.windowScrollTo({ top: 99999 }); // Very high value to ensure we are scrolled to the end
7571
return expect(await page.getElementAttribute(lastAnchorLink.toSelector(), 'aria-current')).toBe('true');

src/app-layout/__integ__/app-layout-focus-delegation.test.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@ describe.each(['classic', 'refresh', 'refresh-toolbar'] as const)('%s', theme =>
4848
'should not focus panels on page load',
4949
setupTest(
5050
async page => {
51-
// TODO: fix test for React 18
52-
if ((await page.getReactVersion()) === '18') {
53-
return;
54-
}
5551
await expect(page.isFocused('body')).resolves.toBe(true);
5652
},
5753
{ pageName: 'with-split-panel', theme, mobile }

src/app-layout/classic.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ const ClassicAppLayout = React.forwardRef(
137137
loseFocus: loseDrawersFocus,
138138
} = useFocusControl(!!activeDrawerId, true, activeDrawerId);
139139

140-
const onNavigationToggle = useStableCallback((open: boolean) => {
141-
focusNavButtons();
142-
fireNonCancelableEvent(onNavigationChange, { open });
140+
const onNavigationToggle = useStableCallback(({ isOpen, autoFocus }: { isOpen: boolean; autoFocus: boolean }) => {
141+
focusNavButtons({ force: false, autoFocus });
142+
fireNonCancelableEvent(onNavigationChange, { open: isOpen });
143143
});
144144

145145
const onNavigationClick = (event: React.MouseEvent) => {
@@ -148,14 +148,14 @@ const ClassicAppLayout = React.forwardRef(
148148
node => node.tagName === 'A' && !!(node as HTMLAnchorElement).href
149149
);
150150
if (hasLink) {
151-
onNavigationToggle(false);
151+
onNavigationToggle({ isOpen: false, autoFocus: true });
152152
}
153153
};
154154

155155
useEffect(() => {
156156
// Close navigation drawer on mobile so that the main content is visible
157157
if (isMobile) {
158-
onNavigationToggle(false);
158+
onNavigationToggle({ isOpen: false, autoFocus: false });
159159
}
160160
}, [isMobile, onNavigationToggle]);
161161

@@ -367,17 +367,17 @@ const ClassicAppLayout = React.forwardRef(
367367
openTools: () => onToolsToggle(true),
368368
closeNavigationIfNecessary: () => {
369369
if (isMobile) {
370-
onNavigationToggle(false);
370+
onNavigationToggle({ isOpen: false, autoFocus: true });
371371
}
372372
},
373373
focusToolsClose: () => {
374374
if (hasDrawers) {
375-
focusDrawersButtons(true);
375+
focusDrawersButtons({ force: true });
376376
} else {
377-
focusToolsButtons(true);
377+
focusToolsButtons({ force: true });
378378
}
379379
},
380-
focusActiveDrawer: () => focusDrawersButtons(true),
380+
focusActiveDrawer: () => focusDrawersButtons({ force: true }),
381381
focusSplitPanel: () => splitPanelRefs.slider.current?.focus(),
382382
}));
383383

@@ -404,7 +404,7 @@ const ClassicAppLayout = React.forwardRef(
404404
ariaLabels={ariaLabels}
405405
navigationHide={navigationHide}
406406
toolsHide={toolsHide}
407-
onNavigationOpen={() => onNavigationToggle(true)}
407+
onNavigationOpen={() => onNavigationToggle({ isOpen: true, autoFocus: true })}
408408
onToolsOpen={() => onToolsToggle(true)}
409409
unfocusable={anyPanelOpen}
410410
mobileBarRef={mobileBarRef}
@@ -433,7 +433,7 @@ const ClassicAppLayout = React.forwardRef(
433433
isMobile={isMobile}
434434
isOpen={navigationOpen}
435435
onClick={isMobile ? onNavigationClick : undefined}
436-
onToggle={onNavigationToggle}
436+
onToggle={isOpen => onNavigationToggle({ isOpen, autoFocus: true })}
437437
toggleRefs={navigationRefs}
438438
type="navigation"
439439
width={navigationWidth}

src/app-layout/utils/use-focus-control.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export interface FocusControlRefs {
1414

1515
export interface FocusControlState {
1616
refs: FocusControlRefs;
17-
setFocus: (force?: boolean) => void;
17+
setFocus: (options?: { force: boolean; autoFocus?: boolean }) => void;
1818
loseFocus: () => void;
1919
}
2020

@@ -132,10 +132,12 @@ export function useFocusControl(
132132
shouldFocus.current = false;
133133
};
134134

135-
const setFocus = (force?: boolean) => {
136-
shouldFocus.current = true;
135+
const setFocus = ({ force, autoFocus = true }: { force: boolean; autoFocus?: boolean } = { force: false }) => {
137136
if (force && isOpen) {
137+
shouldFocus.current = true;
138138
doFocus();
139+
} else if (autoFocus) {
140+
shouldFocus.current = true;
139141
}
140142
};
141143

@@ -185,10 +187,10 @@ export function useAsyncFocusControl(
185187
}
186188
};
187189

188-
const setFocus = (force?: boolean) => {
190+
const setFocus = ({ force, autoFocus = true }: { force: boolean; autoFocus?: boolean } = { force: false }) => {
189191
if (force && isOpen) {
190192
doFocus();
191-
} else {
193+
} else if (autoFocus) {
192194
shouldFocus.current = true;
193195
}
194196
};

src/app-layout/visual-refresh-toolbar/state/use-app-layout.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -227,19 +227,19 @@ export const useAppLayout = (
227227
const navigationFocusControl = useAsyncFocusControl(navigationOpen, navigationTriggerHide);
228228
const splitPanelFocusControl = useSplitPanelFocusControl([splitPanelPreferences, splitPanelOpen]);
229229

230-
const onNavigationToggle = useStableCallback((open: boolean) => {
230+
const onNavigationToggle = useStableCallback(({ isOpen, autoFocus }: { isOpen: boolean; autoFocus: boolean }) => {
231231
setNavigationAnimationDisabled(false);
232-
navigationFocusControl.setFocus();
233-
fireNonCancelableEvent(onNavigationChange, { open });
232+
navigationFocusControl.setFocus({ force: false, autoFocus });
233+
fireNonCancelableEvent(onNavigationChange, { open: isOpen });
234234
});
235235

236236
useImperativeHandle(forwardRef, () => ({
237-
closeNavigationIfNecessary: () => isMobile && onNavigationToggle(false),
237+
closeNavigationIfNecessary: () => isMobile && onNavigationToggle({ isOpen: false, autoFocus: true }),
238238
openTools: () => onToolsToggle(true),
239-
focusToolsClose: () => drawersFocusControl.setFocus(true),
240-
focusActiveDrawer: () => drawersFocusControl.setFocus(true),
239+
focusToolsClose: () => drawersFocusControl.setFocus({ force: true }),
240+
focusActiveDrawer: () => drawersFocusControl.setFocus({ force: true }),
241241
focusSplitPanel: () => splitPanelFocusControl.setLastInteraction({ type: 'open' }),
242-
focusNavigation: () => navigationFocusControl.setFocus(true),
242+
focusNavigation: () => navigationFocusControl.setFocus({ force: true }),
243243
}));
244244

245245
const resolvedStickyNotifications = !!stickyNotifications && !isMobile;
@@ -322,7 +322,7 @@ export const useAppLayout = (
322322
setToolbarHeight,
323323
setNotificationsHeight,
324324
onSplitPanelToggle: onSplitPanelToggleHandler,
325-
onNavigationToggle,
325+
onNavigationToggle: isOpen => onNavigationToggle({ isOpen, autoFocus: true }),
326326
onActiveDrawerChange: onActiveDrawerChangeHandler,
327327
onActiveDrawerResize,
328328
splitPanelAnimationDisabled,
@@ -377,7 +377,7 @@ export const useAppLayout = (
377377
useEffect(() => {
378378
// Close navigation drawer on mobile so that the main content is visible
379379
if (isMobile) {
380-
onNavigationToggle(false);
380+
onNavigationToggle({ isOpen: false, autoFocus: false });
381381
}
382382
// eslint-disable-next-line react-hooks/exhaustive-deps
383383
}, [isMobile]);
@@ -414,7 +414,7 @@ export const useAppLayout = (
414414
const hasHorizontalScroll = scrollWidth > placement.inlineSize;
415415
if (hasHorizontalScroll) {
416416
if (!navigationHide && navigationOpen) {
417-
onNavigationToggle(false);
417+
onNavigationToggle({ isOpen: false, autoFocus: false });
418418
return;
419419
}
420420

src/app-layout/visual-refresh/context.tsx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,17 @@ export const AppLayoutInternalsProvider = React.forwardRef(
139139

140140
const { refs: navigationRefs, setFocus: focusNavButtons } = useFocusControl(navigationOpen);
141141

142-
const handleNavigationClick = useStableCallback(function handleNavigationChange(isOpen: boolean) {
143-
focusNavButtons();
144-
fireNonCancelableEvent(props.onNavigationChange, { open: isOpen });
145-
});
142+
const handleNavigationClick = useStableCallback(
143+
({ isOpen, autoFocus }: { isOpen: boolean; autoFocus: boolean }) => {
144+
focusNavButtons({ force: false, autoFocus });
145+
fireNonCancelableEvent(props.onNavigationChange, { open: isOpen });
146+
}
147+
);
146148

147149
useEffect(() => {
148150
// Close navigation drawer on mobile so that the main content is visible
149151
if (isMobile) {
150-
handleNavigationClick(false);
152+
handleNavigationClick({ isOpen: false, autoFocus: false });
151153
}
152154
}, [isMobile, handleNavigationClick]);
153155

@@ -168,7 +170,7 @@ export const AppLayoutInternalsProvider = React.forwardRef(
168170
function handleToolsChange(isOpen: boolean, skipFocusControl?: boolean) {
169171
setIsToolsOpen(isOpen);
170172
if (!skipFocusControl) {
171-
focusToolsButtons();
173+
focusToolsButtons({ force: false });
172174
}
173175
fireNonCancelableEvent(props.onToolsChange, { open: isOpen });
174176
},
@@ -476,23 +478,23 @@ export const AppLayoutInternalsProvider = React.forwardRef(
476478
return {
477479
closeNavigationIfNecessary: function () {
478480
if (isMobile) {
479-
handleNavigationClick(false);
481+
handleNavigationClick({ isOpen: false, autoFocus: true });
480482
}
481483
},
482484
openTools: function () {
483485
handleToolsClick(true, hasDrawers);
484486
if (hasDrawers) {
485-
focusDrawersButtons(true);
487+
focusDrawersButtons({ force: true });
486488
}
487489
},
488490
focusToolsClose: () => {
489491
if (hasDrawers) {
490-
focusDrawersButtons(true);
492+
focusDrawersButtons({ force: true });
491493
} else {
492-
focusToolsButtons(true);
494+
focusToolsButtons({ force: true });
493495
}
494496
},
495-
focusActiveDrawer: () => focusDrawersButtons(true),
497+
focusActiveDrawer: () => focusDrawersButtons({ force: true }),
496498
focusSplitPanel: () => splitPanelRefs.slider.current?.focus(),
497499
};
498500
},
@@ -528,7 +530,7 @@ export const AppLayoutInternalsProvider = React.forwardRef(
528530
footerHeight: placement.insetBlockEnd,
529531
hasDrawerViewportOverlay,
530532
handleDrawersClick,
531-
handleNavigationClick,
533+
handleNavigationClick: isOpen => handleNavigationClick({ isOpen, autoFocus: true }),
532534
handleSplitPanelClick,
533535
handleSplitPanelPreferencesChange,
534536
handleSplitPanelResize,

src/property-filter/__integ__/async-loading.test.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ const testCases: TestCase[] = [
128128
],
129129
],
130130
[
131-
'request for property specific suggestions from the search input',
131+
'request for property specific suggestions from the search input React=16',
132132
false,
133133
'property',
134134
[
@@ -146,6 +146,22 @@ const testCases: TestCase[] = [
146146
},
147147
],
148148
],
149+
[
150+
'request for property specific suggestions from the search input React=18',
151+
false,
152+
'property',
153+
[
154+
{ command: 'open-filtering-input', result: [] },
155+
{
156+
command: 'type-in-filtering-input',
157+
param: 'label=',
158+
result: [
159+
{ filteringText: 'l', firstPage: false, samePage: false },
160+
{ filteringProperty, filteringOperator: '=', filteringText: '', firstPage: true, samePage: false },
161+
],
162+
},
163+
],
164+
],
149165
[
150166
'request for properties from the property selector in the edit popover',
151167
true,
@@ -187,8 +203,14 @@ const testCases: TestCase[] = [
187203
],
188204
];
189205

190-
test.each<TestCase>(testCases)('%p', (_, asyncProperties, token, scenario) =>
206+
test.each<TestCase>(testCases)('%p', (scenarioName, asyncProperties, token, scenario) =>
191207
setupTest(asyncProperties, token, async page => {
208+
if (scenarioName.includes('React=16') && (await page.getReactVersion()) !== '16') {
209+
return;
210+
}
211+
if (scenarioName.includes('React=18') && (await page.getReactVersion()) !== '18') {
212+
return;
213+
}
192214
for (let i = 0; i < scenario.length; i++) {
193215
const { command, result, param = '' } = scenario[i];
194216
switch (command) {

0 commit comments

Comments
 (0)