Skip to content

Commit d0ea796

Browse files
committed
fix async widget mock
1 parent 03eb8db commit d0ea796

File tree

3 files changed

+161
-13
lines changed

3 files changed

+161
-13
lines changed

src/app-layout/__tests__/__snapshots__/widget-contract.test.tsx.snap

Lines changed: 146 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,24 @@ Map {
3434
"appLayoutState": {
3535
"isIntersecting": true,
3636
},
37-
"toolbarProps": null,
37+
"toolbarProps": {
38+
"ariaLabels": {
39+
"drawers": undefined,
40+
"drawersOverflow": undefined,
41+
"drawersOverflowWithBadge": undefined,
42+
"navigation": undefined,
43+
"navigationClose": undefined,
44+
"navigationToggle": undefined,
45+
"notifications": undefined,
46+
"tools": undefined,
47+
"toolsClose": undefined,
48+
"toolsToggle": undefined,
49+
},
50+
"hasNavigation": true,
51+
"navigationFocusRef": undefined,
52+
"navigationOpen": true,
53+
"onNavigationToggle": undefined,
54+
},
3855
},
3956
[Function] => {
4057
"appLayoutProps": {
@@ -68,7 +85,24 @@ Map {
6885
"appLayoutState": {
6986
"isIntersecting": true,
7087
},
71-
"toolbarProps": null,
88+
"toolbarProps": {
89+
"ariaLabels": {
90+
"drawers": undefined,
91+
"drawersOverflow": undefined,
92+
"drawersOverflowWithBadge": undefined,
93+
"navigation": undefined,
94+
"navigationClose": undefined,
95+
"navigationToggle": undefined,
96+
"notifications": undefined,
97+
"tools": undefined,
98+
"toolsClose": undefined,
99+
"toolsToggle": undefined,
100+
},
101+
"hasNavigation": true,
102+
"navigationFocusRef": undefined,
103+
"navigationOpen": true,
104+
"onNavigationToggle": undefined,
105+
},
72106
},
73107
[Function] => {
74108
"appLayoutProps": {
@@ -102,7 +136,24 @@ Map {
102136
"appLayoutState": {
103137
"isIntersecting": true,
104138
},
105-
"toolbarProps": null,
139+
"toolbarProps": {
140+
"ariaLabels": {
141+
"drawers": undefined,
142+
"drawersOverflow": undefined,
143+
"drawersOverflowWithBadge": undefined,
144+
"navigation": undefined,
145+
"navigationClose": undefined,
146+
"navigationToggle": undefined,
147+
"notifications": undefined,
148+
"tools": undefined,
149+
"toolsClose": undefined,
150+
"toolsToggle": undefined,
151+
},
152+
"hasNavigation": true,
153+
"navigationFocusRef": undefined,
154+
"navigationOpen": true,
155+
"onNavigationToggle": undefined,
156+
},
106157
},
107158
[Function] => {
108159
"appLayoutProps": {
@@ -136,7 +187,24 @@ Map {
136187
"appLayoutState": {
137188
"isIntersecting": true,
138189
},
139-
"toolbarProps": null,
190+
"toolbarProps": {
191+
"ariaLabels": {
192+
"drawers": undefined,
193+
"drawersOverflow": undefined,
194+
"drawersOverflowWithBadge": undefined,
195+
"navigation": undefined,
196+
"navigationClose": undefined,
197+
"navigationToggle": undefined,
198+
"notifications": undefined,
199+
"tools": undefined,
200+
"toolsClose": undefined,
201+
"toolsToggle": undefined,
202+
},
203+
"hasNavigation": true,
204+
"navigationFocusRef": undefined,
205+
"navigationOpen": true,
206+
"onNavigationToggle": undefined,
207+
},
140208
},
141209
[Function] => {
142210
"appLayoutProps": {
@@ -170,7 +238,7 @@ Map {
170238
"forwardRef": null,
171239
"stateManager": {
172240
"current": {
173-
"hasToolbar": false,
241+
"hasToolbar": true,
174242
"setState": [Function],
175243
"setToolbar": undefined,
176244
},
@@ -573,7 +641,24 @@ Map {
573641
"appLayoutState": {
574642
"isIntersecting": true,
575643
},
576-
"toolbarProps": null,
644+
"toolbarProps": {
645+
"ariaLabels": {
646+
"drawers": undefined,
647+
"drawersOverflow": undefined,
648+
"drawersOverflowWithBadge": undefined,
649+
"navigation": undefined,
650+
"navigationClose": undefined,
651+
"navigationToggle": undefined,
652+
"notifications": undefined,
653+
"tools": undefined,
654+
"toolsClose": undefined,
655+
"toolsToggle": undefined,
656+
},
657+
"hasNavigation": true,
658+
"navigationFocusRef": undefined,
659+
"navigationOpen": true,
660+
"onNavigationToggle": undefined,
661+
},
577662
},
578663
[Function] => {
579664
"appLayoutProps": {
@@ -626,7 +711,24 @@ Map {
626711
"appLayoutState": {
627712
"isIntersecting": true,
628713
},
629-
"toolbarProps": null,
714+
"toolbarProps": {
715+
"ariaLabels": {
716+
"drawers": undefined,
717+
"drawersOverflow": undefined,
718+
"drawersOverflowWithBadge": undefined,
719+
"navigation": undefined,
720+
"navigationClose": undefined,
721+
"navigationToggle": undefined,
722+
"notifications": undefined,
723+
"tools": undefined,
724+
"toolsClose": undefined,
725+
"toolsToggle": undefined,
726+
},
727+
"hasNavigation": true,
728+
"navigationFocusRef": undefined,
729+
"navigationOpen": true,
730+
"onNavigationToggle": undefined,
731+
},
630732
},
631733
[Function] => {
632734
"appLayoutProps": {
@@ -679,7 +781,24 @@ Map {
679781
"appLayoutState": {
680782
"isIntersecting": true,
681783
},
682-
"toolbarProps": null,
784+
"toolbarProps": {
785+
"ariaLabels": {
786+
"drawers": undefined,
787+
"drawersOverflow": undefined,
788+
"drawersOverflowWithBadge": undefined,
789+
"navigation": undefined,
790+
"navigationClose": undefined,
791+
"navigationToggle": undefined,
792+
"notifications": undefined,
793+
"tools": undefined,
794+
"toolsClose": undefined,
795+
"toolsToggle": undefined,
796+
},
797+
"hasNavigation": true,
798+
"navigationFocusRef": undefined,
799+
"navigationOpen": true,
800+
"onNavigationToggle": undefined,
801+
},
683802
},
684803
[Function] => {
685804
"appLayoutProps": {
@@ -732,7 +851,24 @@ Map {
732851
"appLayoutState": {
733852
"isIntersecting": true,
734853
},
735-
"toolbarProps": null,
854+
"toolbarProps": {
855+
"ariaLabels": {
856+
"drawers": undefined,
857+
"drawersOverflow": undefined,
858+
"drawersOverflowWithBadge": undefined,
859+
"navigation": undefined,
860+
"navigationClose": undefined,
861+
"navigationToggle": undefined,
862+
"notifications": undefined,
863+
"tools": undefined,
864+
"toolsClose": undefined,
865+
"toolsToggle": undefined,
866+
},
867+
"hasNavigation": true,
868+
"navigationFocusRef": undefined,
869+
"navigationOpen": true,
870+
"onNavigationToggle": undefined,
871+
},
736872
},
737873
[Function] => {
738874
"appLayoutProps": {
@@ -785,7 +921,7 @@ Map {
785921
"forwardRef": null,
786922
"stateManager": {
787923
"current": {
788-
"hasToolbar": false,
924+
"hasToolbar": true,
789925
"setState": [Function],
790926
"setToolbar": undefined,
791927
},

src/app-layout/visual-refresh-toolbar/state/props-merger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export const getPropsToMerge = (props: AppLayoutInternalProps, appLayoutState: A
7070
return {
7171
breadcrumbs: props.breadcrumbs,
7272
ariaLabels: state ? state.ariaLabels : props.ariaLabels,
73-
navigation: !props.navigationTriggerHide && (state ? state.navigation : props.navigation),
73+
navigation: !props.navigationTriggerHide && !props.navigationHide,
7474
navigationOpen: state ? state.navigationOpen : props.navigationOpen,
7575
onNavigationToggle: state?.onNavigationToggle,
7676
navigationFocusRef: state?.navigationFocusControl.refs.toggle,

src/internal/widgets/loader-mock.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ const isAppLayoutDelayedWidget = () => {
1616

1717
const enableDelayedComponents = isAppLayoutDelayedWidget();
1818

19+
let loadPromise: Promise<void>;
20+
1921
export function createLoadableComponent<ComponentType extends FunctionComponent<any>>(
2022
Component: ComponentType
2123
): ComponentType | undefined {
@@ -26,8 +28,18 @@ export function createLoadableComponent<ComponentType extends FunctionComponent<
2628
const [mounted, setMounted] = useState(false);
2729

2830
useEffect(() => {
29-
const timeoutId = setTimeout(() => setMounted(true), 1000);
30-
return () => clearTimeout(timeoutId);
31+
if (!loadPromise) {
32+
loadPromise = new Promise(resolve => setTimeout(() => resolve(), 1000));
33+
}
34+
let mounted = true;
35+
loadPromise.then(() => {
36+
if (mounted) {
37+
setMounted(true);
38+
}
39+
});
40+
return () => {
41+
mounted = false;
42+
};
3143
}, []);
3244

3345
if (mounted) {

0 commit comments

Comments
 (0)