Skip to content

Commit 3358d8a

Browse files
committed
fix: use testIDs to get rid of utils
1 parent 5c137da commit 3358d8a

File tree

8 files changed

+319
-130
lines changed

8 files changed

+319
-130
lines changed

package/src/components/MessageInput/__tests__/__snapshots__/AttachButton.test.js.snap

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,7 @@ exports[`AttachButton should call handleAttachButtonPress when the button is cli
816816
},
817817
]
818818
}
819+
testID="message-overlay-top"
819820
>
820821
<View
821822
name="top-item"
@@ -846,6 +847,7 @@ exports[`AttachButton should call handleAttachButtonPress when the button is cli
846847
},
847848
]
848849
}
850+
testID="message-overlay-message"
849851
>
850852
<View
851853
name="message-overlay"
@@ -878,6 +880,7 @@ exports[`AttachButton should call handleAttachButtonPress when the button is cli
878880
},
879881
]
880882
}
883+
testID="message-overlay-bottom"
881884
>
882885
<View
883886
name="bottom-item"
@@ -1713,6 +1716,7 @@ exports[`AttachButton should render a enabled AttachButton 1`] = `
17131716
},
17141717
]
17151718
}
1719+
testID="message-overlay-top"
17161720
>
17171721
<View
17181722
name="top-item"
@@ -1743,6 +1747,7 @@ exports[`AttachButton should render a enabled AttachButton 1`] = `
17431747
},
17441748
]
17451749
}
1750+
testID="message-overlay-message"
17461751
>
17471752
<View
17481753
name="message-overlay"
@@ -1775,6 +1780,7 @@ exports[`AttachButton should render a enabled AttachButton 1`] = `
17751780
},
17761781
]
17771782
}
1783+
testID="message-overlay-bottom"
17781784
>
17791785
<View
17801786
name="bottom-item"
@@ -2610,6 +2616,7 @@ exports[`AttachButton should render an disabled AttachButton 1`] = `
26102616
},
26112617
]
26122618
}
2619+
testID="message-overlay-top"
26132620
>
26142621
<View
26152622
name="top-item"
@@ -2640,6 +2647,7 @@ exports[`AttachButton should render an disabled AttachButton 1`] = `
26402647
},
26412648
]
26422649
}
2650+
testID="message-overlay-message"
26432651
>
26442652
<View
26452653
name="message-overlay"
@@ -2672,6 +2680,7 @@ exports[`AttachButton should render an disabled AttachButton 1`] = `
26722680
},
26732681
]
26742682
}
2683+
testID="message-overlay-bottom"
26752684
>
26762685
<View
26772686
name="bottom-item"

package/src/components/MessageInput/__tests__/__snapshots__/SendButton.test.js.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,7 @@ exports[`SendButton should render a SendButton 1`] = `
814814
},
815815
]
816816
}
817+
testID="message-overlay-top"
817818
>
818819
<View
819820
name="top-item"
@@ -844,6 +845,7 @@ exports[`SendButton should render a SendButton 1`] = `
844845
},
845846
]
846847
}
848+
testID="message-overlay-message"
847849
>
848850
<View
849851
name="message-overlay"
@@ -876,6 +878,7 @@ exports[`SendButton should render a SendButton 1`] = `
876878
},
877879
]
878880
}
881+
testID="message-overlay-bottom"
879882
>
880883
<View
881884
name="bottom-item"
@@ -1709,6 +1712,7 @@ exports[`SendButton should render a disabled SendButton 1`] = `
17091712
},
17101713
]
17111714
}
1715+
testID="message-overlay-top"
17121716
>
17131717
<View
17141718
name="top-item"
@@ -1739,6 +1743,7 @@ exports[`SendButton should render a disabled SendButton 1`] = `
17391743
},
17401744
]
17411745
}
1746+
testID="message-overlay-message"
17421747
>
17431748
<View
17441749
name="message-overlay"
@@ -1771,6 +1776,7 @@ exports[`SendButton should render a disabled SendButton 1`] = `
17711776
},
17721777
]
17731778
}
1779+
testID="message-overlay-bottom"
17741780
>
17751781
<View
17761782
name="bottom-item"

package/src/components/UIComponents/PortalWhileClosingView.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,13 @@ export const PortalWhileClosingView = ({
127127
{children}
128128
</View>
129129
</Portal>
130-
{shouldTeleport ? <Animated.View pointerEvents='none' style={placeholderStyle} /> : null}
130+
{shouldTeleport ? (
131+
<Animated.View
132+
pointerEvents='none'
133+
style={placeholderStyle}
134+
testID={`portal-while-closing-placeholder-${portalName}`}
135+
/>
136+
) : null}
131137
</>
132138
);
133139
};

package/src/components/UIComponents/__tests__/PortalWhileClosingView.test.tsx

Lines changed: 5 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -48,43 +48,6 @@ const BlacklistRegistrar = ({ hostNames }: { hostNames: string[] }) => {
4848
return null;
4949
};
5050

51-
const findPortalNode = (
52-
node: ReturnType<ReturnType<typeof render>['toJSON']>,
53-
portalName: string,
54-
): null | { props?: { hostName?: string; name?: string } } => {
55-
if (!node) {
56-
return null;
57-
}
58-
59-
if (Array.isArray(node)) {
60-
for (const child of node) {
61-
const found = findPortalNode(child, portalName);
62-
if (found) {
63-
return found;
64-
}
65-
}
66-
67-
return null;
68-
}
69-
70-
if (node.props?.name === portalName) {
71-
return node;
72-
}
73-
74-
for (const child of node.children ?? []) {
75-
if (typeof child === 'string') {
76-
continue;
77-
}
78-
79-
const found = findPortalNode(child, portalName);
80-
if (found) {
81-
return found;
82-
}
83-
}
84-
85-
return null;
86-
};
87-
8851
describe('PortalWhileClosingView', () => {
8952
beforeEach(() => {
9053
jest.useFakeTimers();
@@ -118,7 +81,7 @@ describe('PortalWhileClosingView', () => {
11881
});
11982

12083
it('uses the real store to teleport once the overlay is closing and this host is active', () => {
121-
const { toJSON } = render(
84+
render(
12285
<>
12386
<PortalWhileClosingView portalHostName='overlay-composer' portalName='composer-portal'>
12487
<Text>Composer</Text>
@@ -136,7 +99,7 @@ describe('PortalWhileClosingView', () => {
13699
});
137100

138101
expect(screen.getByTestId('teleport-state')).toHaveTextContent('false');
139-
expect(findPortalNode(toJSON(), 'composer-portal')?.props?.hostName).toBeUndefined();
102+
expect(screen.queryByTestId('portal-while-closing-placeholder-composer-portal')).toBeNull();
140103

141104
act(() => {
142105
stateStore.openOverlay('message-1');
@@ -145,11 +108,11 @@ describe('PortalWhileClosingView', () => {
145108
flushAnimationFrameQueue();
146109

147110
expect(screen.getByTestId('teleport-state')).toHaveTextContent('true');
148-
expect(findPortalNode(toJSON(), 'composer-portal')?.props?.hostName).toBe('overlay-composer');
111+
expect(screen.getByTestId('portal-while-closing-placeholder-composer-portal')).toBeTruthy();
149112
});
150113

151114
it('keeps the portal local when the host is blacklisted', () => {
152-
const { toJSON } = render(
115+
render(
153116
<>
154117
<BlacklistRegistrar hostNames={['overlay-composer']} />
155118
<PortalWhileClosingView portalHostName='overlay-composer' portalName='composer-portal'>
@@ -171,7 +134,7 @@ describe('PortalWhileClosingView', () => {
171134
flushAnimationFrameQueue();
172135

173136
expect(screen.getByTestId('teleport-state')).toHaveTextContent('false');
174-
expect(findPortalNode(toJSON(), 'composer-portal')?.props?.hostName).toBeUndefined();
137+
expect(screen.queryByTestId('portal-while-closing-placeholder-composer-portal')).toBeNull();
175138
});
176139

177140
it('clears its registration from the real store when it unmounts', () => {

package/src/contexts/overlayContext/ClosingPortalHostsLayer.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ const ClosingPortalHostSlot = ({
3131
});
3232

3333
return (
34-
<Animated.View pointerEvents='box-none' style={style}>
34+
<Animated.View
35+
pointerEvents='box-none'
36+
style={style}
37+
testID={`closing-portal-host-slot-${hostName}`}
38+
>
3539
<PortalHost name={hostName} style={StyleSheet.absoluteFillObject} />
3640
</Animated.View>
3741
);

package/src/contexts/overlayContext/MessageOverlayHostLayer.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,18 +264,29 @@ export const MessageOverlayHostLayer = ({ BackgroundComponent }: MessageOverlayH
264264

265265
<View pointerEvents='box-none' style={StyleSheet.absoluteFill}>
266266
{isActive ? (
267-
<Pressable onPress={closeOverlay} style={StyleSheet.absoluteFillObject} />
267+
<Pressable
268+
onPress={closeOverlay}
269+
style={StyleSheet.absoluteFillObject}
270+
testID='message-overlay-backdrop'
271+
/>
268272
) : null}
269273

270-
<Animated.View style={[topItemStyle, topItemTranslateStyle]}>
274+
<Animated.View style={[topItemStyle, topItemTranslateStyle]} testID='message-overlay-top'>
271275
<PortalHost name='top-item' style={StyleSheet.absoluteFillObject} />
272276
</Animated.View>
273277

274-
<Animated.View pointerEvents='box-none' style={[hostStyle, hostTranslateStyle]}>
278+
<Animated.View
279+
pointerEvents='box-none'
280+
style={[hostStyle, hostTranslateStyle]}
281+
testID='message-overlay-message'
282+
>
275283
<PortalHost name='message-overlay' style={StyleSheet.absoluteFillObject} />
276284
</Animated.View>
277285

278-
<Animated.View style={[bottomItemStyle, bottomItemTranslateStyle]}>
286+
<Animated.View
287+
style={[bottomItemStyle, bottomItemTranslateStyle]}
288+
testID='message-overlay-bottom'
289+
>
279290
<PortalHost name='bottom-item' style={StyleSheet.absoluteFillObject} />
280291
</Animated.View>
281292
</View>

0 commit comments

Comments
 (0)