Skip to content

Commit ab9cd35

Browse files
mikepitreclaude
andcommitted
test(expo): open the fixture on its home for every verify launch
A verify launch could name a screen, and the fixture opened on it. A user never lands on those screens, and each recording started somewhere else. The fixture now always opens on the home. The home lists a link to each screen the device tests need: full-screen sign-in with and without a close button, sign-in with a logo, the custom sign-in and sign-up forms, the native modules, the embedded profile, and the token cache. Signed-out links show when signed out, the embedded profile when signed in, and the token cache always. The fixture reads the token cache when it starts, before Clerk loads, and the token cache screen shows that answer when the home opens it. The verifyScreen launch input and its unknown-screen error are gone. A launch with no verify inputs still shows the older fixture. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 44146bc commit ab9cd35

6 files changed

Lines changed: 120 additions & 83 deletions

File tree

‎integration/templates/expo-native/screens/AuthLogo.tsx‎

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
1-
import { type AuthViewMode } from '@clerk/expo/native';
21
import { type ReactElement } from 'react';
32
import { StyleSheet, Text, View } from 'react-native';
43

5-
import { Home } from './Home';
6-
7-
export function AuthLogo({ authMode }: { authMode: AuthViewMode }): ReactElement {
4+
export function AuthLogo(): ReactElement {
85
return (
9-
<Home
10-
authMode={authMode}
11-
authLogo={
12-
<View
13-
testID='verify.authLogo.logo'
14-
style={styles.logo}
15-
>
16-
<Text style={styles.logoText}>E2E Custom Logo</Text>
17-
</View>
18-
}
19-
/>
6+
<View
7+
testID='verify.authLogo.logo'
8+
style={styles.logo}
9+
>
10+
<Text style={styles.logoText}>E2E Custom Logo</Text>
11+
</View>
2012
);
2113
}
2214

‎integration/templates/expo-native/screens/Home.tsx‎

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
import { useAuth, useSession, useUser } from '@clerk/expo';
22
import { AuthView, type AuthViewMode, UserButton } from '@clerk/expo/native';
3-
import { type ComponentProps, type ReactElement, useState } from 'react';
3+
import { type ReactElement, useState } from 'react';
44
import { Button, Modal, StyleSheet, Text, View } from 'react-native';
55

6-
type HomeProps = { authMode: AuthViewMode; authLogo?: ComponentProps<typeof AuthView>['logo'] };
6+
import { AuthLogo } from './AuthLogo';
7+
import { type Destination, homeLinksFor } from './destinations';
78

8-
export function Home({ authMode, authLogo }: HomeProps): ReactElement {
9+
type HomeProps = { authMode: AuthViewMode; onOpen: (destination: Destination) => void };
10+
11+
export function Home({ authMode, onOpen }: HomeProps): ReactElement {
912
const { isSignedIn, signOut } = useAuth();
1013
const { user } = useUser();
1114
const { session } = useSession();
12-
const [isAuthOpen, setIsAuthOpen] = useState(false);
13-
const closeAuth = (): void => setIsAuthOpen(false);
15+
const [authSheet, setAuthSheet] = useState<'closed' | 'plain' | 'withLogo'>('closed');
16+
const closeAuth = (): void => setAuthSheet('closed');
1417

1518
const pending = session?.status === 'pending';
1619
const account = pending ? null : user;
@@ -71,20 +74,37 @@ export function Home({ authMode, authLogo }: HomeProps): ReactElement {
7174
<Button
7275
testID='e2e.auth.signIn'
7376
title='Sign in'
74-
onPress={() => setIsAuthOpen(true)}
77+
onPress={() => setAuthSheet('plain')}
7578
/>
7679
</>
7780
)}
81+
<View style={styles.links}>
82+
{!isSignedIn && (
83+
<Button
84+
testID='e2e.home.authLogo'
85+
title='Sign in with a logo'
86+
onPress={() => setAuthSheet('withLogo')}
87+
/>
88+
)}
89+
{homeLinksFor(Boolean(isSignedIn)).map(link => (
90+
<Button
91+
key={link.opens}
92+
testID={link.testID}
93+
title={link.label}
94+
onPress={() => onOpen(link.opens)}
95+
/>
96+
))}
97+
</View>
7898

7999
<Modal
80100
animationType='slide'
81-
visible={isAuthOpen}
101+
visible={authSheet !== 'closed'}
82102
presentationStyle='pageSheet'
83103
onRequestClose={closeAuth}
84104
>
85105
<AuthView
86106
mode={authMode}
87-
logo={authLogo}
107+
logo={authSheet === 'withLogo' ? <AuthLogo /> : undefined}
88108
onDismiss={closeAuth}
89109
/>
90110
</Modal>
@@ -112,6 +132,10 @@ const styles = StyleSheet.create({
112132
justifyContent: 'center',
113133
padding: 24,
114134
},
135+
links: {
136+
alignItems: 'center',
137+
gap: 4,
138+
},
115139
summary: {
116140
alignItems: 'center',
117141
gap: 4,

‎integration/templates/expo-native/screens/TokenCache.tsx‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,23 @@ import { styles } from './styles';
77

88
const clientTokenKey = '__clerk_client_jwt';
99

10-
export function TokenCache(): ReactElement {
10+
export async function readClientTokenKept(): Promise<boolean> {
11+
return Boolean(await tokenCache?.getToken(clientTokenKey));
12+
}
13+
14+
export function TokenCache({ keptAtLaunch }: { keptAtLaunch: Promise<boolean> }): ReactElement {
1115
const { isLoaded, user } = useUser();
12-
const [keptAtLaunch, setKeptAtLaunch] = useState<boolean | null>(null);
16+
const [kept, setKept] = useState<boolean | null>(null);
1317

1418
useEffect(() => {
15-
void tokenCache?.getToken(clientTokenKey).then(token => setKeptAtLaunch(Boolean(token)));
16-
}, []);
19+
void keptAtLaunch.then(setKept);
20+
}, [keptAtLaunch]);
1721

1822
return (
1923
<View style={styles.form}>
2024
<Text style={styles.title}>Token cache</Text>
2125
<Text testID='verify.tokenCache.clientToken'>
22-
{`client token kept from the last launch: ${keptAtLaunch === null ? 'checking' : keptAtLaunch ? 'yes' : 'no'}`}
26+
{`client token kept from the last launch: ${kept === null ? 'checking' : kept ? 'yes' : 'no'}`}
2327
</Text>
2428
<Text testID='verify.tokenCache.user'>{`user: ${isLoaded ? (user?.id ?? 'none') : 'loading'}`}</Text>
2529
</View>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
export type Destination =
2+
| 'auth'
3+
| 'nativeAuth'
4+
| 'customSignIn'
5+
| 'customSignUp'
6+
| 'nativeModules'
7+
| 'embeddedProfile'
8+
| 'tokenCache';
9+
10+
type HomeLink = {
11+
opens: Destination;
12+
label: string;
13+
testID: string;
14+
shownWhen: 'signedOut' | 'signedIn' | 'always';
15+
};
16+
17+
const homeLinks: readonly HomeLink[] = [
18+
{ opens: 'auth', label: 'Sign in full screen', testID: 'e2e.auth.signInFullScreen', shownWhen: 'signedOut' },
19+
{
20+
opens: 'nativeAuth',
21+
label: 'Sign in full screen with a close button',
22+
testID: 'e2e.home.nativeAuth',
23+
shownWhen: 'signedOut',
24+
},
25+
{ opens: 'customSignIn', label: 'Custom sign-in', testID: 'e2e.home.customSignIn', shownWhen: 'signedOut' },
26+
{ opens: 'customSignUp', label: 'Custom sign-up', testID: 'e2e.home.customSignUp', shownWhen: 'signedOut' },
27+
{ opens: 'nativeModules', label: 'Native modules', testID: 'e2e.home.nativeModules', shownWhen: 'signedOut' },
28+
{ opens: 'embeddedProfile', label: 'Embedded profile', testID: 'e2e.home.embeddedProfile', shownWhen: 'signedIn' },
29+
{ opens: 'tokenCache', label: 'Token cache', testID: 'e2e.home.tokenCache', shownWhen: 'always' },
30+
];
31+
32+
export function homeLinksFor(isSignedIn: boolean): readonly HomeLink[] {
33+
const state = isSignedIn ? 'signedIn' : 'signedOut';
34+
return homeLinks.filter(link => link.shownWhen === 'always' || link.shownWhen === state);
35+
}

‎integration/templates/expo-native/verify/VerifyHost.tsx‎

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,22 @@ import { tokenCache } from '@clerk/expo/token-cache';
1313
import { type ReactElement, useCallback, useEffect, useRef, useState, useSyncExternalStore } from 'react';
1414
import { ActivityIndicator, StyleSheet, Text, View } from 'react-native';
1515

16-
import { AuthLogo } from '../screens/AuthLogo';
1716
import { CustomSignIn } from '../screens/CustomSignIn';
1817
import { CustomSignUp } from '../screens/CustomSignUp';
18+
import { type Destination, homeLinksFor } from '../screens/destinations';
1919
import { EmbeddedProfile } from '../screens/EmbeddedProfile';
2020
import { Home } from '../screens/Home';
2121
import { NativeModules } from '../screens/NativeModules';
22-
import { TokenCache } from '../screens/TokenCache';
23-
import { publishableKeyFailure, type VerifyFailure, type VerifyLaunch, type VerifyScreen } from './launch';
22+
import { readClientTokenKept, TokenCache } from '../screens/TokenCache';
23+
import { publishableKeyFailure, type VerifyFailure, type VerifyLaunch } from './launch';
2424
import { type VerifyState, verifyStateJson, type VerifyTicket } from './state';
2525

2626
type HostProps = { launch: VerifyLaunch };
27+
type RoutedHostProps = HostProps & { clientTokenKeptAtLaunch: Promise<boolean> };
2728

2829
export function VerifyHost({ launch }: HostProps): ReactElement {
29-
const failure = publishableKeyFailure(launch.publishableKey) ?? launch.screenFailure;
30+
const [clientTokenKeptAtLaunch] = useState(readClientTokenKept);
31+
const failure = publishableKeyFailure(launch.publishableKey);
3032
if (failure) {
3133
return (
3234
<ConfigurationFailure
@@ -41,7 +43,10 @@ export function VerifyHost({ launch }: HostProps): ReactElement {
4143
publishableKey={launch.publishableKey}
4244
tokenCache={tokenCache}
4345
>
44-
<RoutedHost launch={launch} />
46+
<RoutedHost
47+
launch={launch}
48+
clientTokenKeptAtLaunch={clientTokenKeptAtLaunch}
49+
/>
4550
</ClerkProvider>
4651
);
4752
}
@@ -91,15 +96,16 @@ function useVerifyLog(state: VerifyState): void {
9196
}, [json]);
9297
}
9398

94-
function RoutedHost({ launch }: HostProps): ReactElement {
99+
function RoutedHost({ launch, clientTokenKeptAtLaunch }: RoutedHostProps): ReactElement {
95100
const status = useClerkStatus();
96101
const { isLoaded, isSignedIn, orgId } = useAuth();
97102
const { user } = useUser();
98103
const { session } = useSession();
99104
const { signIn } = useSignIn();
100105
const { signUp } = useSignUp();
101106
const authView = useAuthViewState();
102-
const [screenClosed, setScreenClosed] = useState(false);
107+
const [opened, setOpened] = useState<Destination | null>(null);
108+
const goHome = useCallback(() => setOpened(null), []);
103109
const [ticket, setTicket] = useState<VerifyTicket>(launch.signInTicket ? 'pending' : 'none');
104110
const [failure, setFailure] = useState<VerifyFailure | null>(null);
105111
const ticketStarted = useRef(false);
@@ -139,30 +145,26 @@ function RoutedHost({ launch }: HostProps): ReactElement {
139145
);
140146
}, [isLoaded, launch.signInTicket, signIn]);
141147

142-
const screen = ((): VerifyScreen | 'loading' => {
143-
if (launch.screen === 'tokenCache') {
144-
return launch.screen;
148+
const showsAuthView = opened === 'auth' || opened === 'nativeAuth';
149+
const finished = showsAuthView
150+
? authView.isAuthFlowComplete
151+
: !homeLinksFor(Boolean(isSignedIn)).some(link => link.opens === opened);
152+
const left = opened !== null && finished;
153+
154+
useEffect(() => {
155+
if (left) {
156+
goHome();
145157
}
158+
}, [goHome, left]);
159+
160+
const screen = ((): Destination | 'home' | 'loading' => {
146161
if (!isLoaded || ticket === 'pending') {
147162
return 'loading';
148163
}
149-
switch (launch.screen) {
150-
case 'auth':
151-
case 'nativeAuth':
152-
if (authView.isAuthFlowComplete || screenClosed) {
153-
return 'home';
154-
}
155-
return authView.isLoaded ? launch.screen : 'loading';
156-
case 'customSignIn':
157-
case 'customSignUp':
158-
return isSignedIn ? 'home' : launch.screen;
159-
case 'embeddedProfile':
160-
return isSignedIn && !screenClosed ? launch.screen : 'home';
161-
case 'home':
162-
case 'authLogo':
163-
case 'nativeModules':
164-
return launch.screen;
164+
if (opened === null || left) {
165+
return 'home';
165166
}
167+
return showsAuthView && !authView.isLoaded ? 'loading' : opened;
166168
})();
167169

168170
useVerifyLog({
@@ -192,7 +194,12 @@ function RoutedHost({ launch }: HostProps): ReactElement {
192194
case 'loading':
193195
return <ActivityIndicator style={styles.fill} />;
194196
case 'home':
195-
return <Home authMode={launch.authMode} />;
197+
return (
198+
<Home
199+
authMode={launch.authMode}
200+
onOpen={setOpened}
201+
/>
202+
);
196203
case 'auth':
197204
return (
198205
<AuthView
@@ -204,19 +211,17 @@ function RoutedHost({ launch }: HostProps): ReactElement {
204211
return (
205212
<AuthView
206213
mode={launch.authMode}
207-
onDismiss={() => setScreenClosed(true)}
214+
onDismiss={goHome}
208215
/>
209216
);
210217
case 'customSignIn':
211218
return <CustomSignIn />;
212219
case 'customSignUp':
213220
return <CustomSignUp />;
214221
case 'tokenCache':
215-
return <TokenCache />;
216-
case 'authLogo':
217-
return <AuthLogo authMode={launch.authMode} />;
222+
return <TokenCache keptAtLaunch={clientTokenKeptAtLaunch} />;
218223
case 'embeddedProfile':
219-
return <EmbeddedProfile onHostBack={() => setScreenClosed(true)} />;
224+
return <EmbeddedProfile onHostBack={goHome} />;
220225
case 'nativeModules':
221226
return <NativeModules />;
222227
}

‎integration/templates/expo-native/verify/launch.ts‎

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,14 @@
11
import { VerifyLaunchConfig } from '../modules/verify-launch-config';
22

3-
const verifyScreens = [
4-
'home',
5-
'auth',
6-
'nativeAuth',
7-
'authLogo',
8-
'customSignIn',
9-
'customSignUp',
10-
'tokenCache',
11-
'embeddedProfile',
12-
'nativeModules',
13-
] as const;
14-
153
const authModes = ['signIn', 'signUp', 'signInOrUp'] as const;
164

17-
export type VerifyScreen = (typeof verifyScreens)[number];
185
type AuthMode = (typeof authModes)[number];
196
export type VerifyFailure = { code: string; message: string };
207

218
export type VerifyLaunch = {
229
publishableKey: string;
2310
runId: string | null;
2411
launchId: string | null;
25-
screen: VerifyScreen;
26-
screenFailure: VerifyFailure | null;
2712
authMode: AuthMode;
2813
signInTicket: string | null;
2914
debugLogging: boolean;
@@ -41,18 +26,10 @@ function parseVerifyLaunch(
4126
return null;
4227
}
4328

44-
const requestedScreen = inputs.verifyScreen;
45-
const knownScreen = isOneOf(verifyScreens, requestedScreen);
46-
4729
return {
4830
publishableKey: inputs.verifyPublishableKey ?? fallbackPublishableKey ?? '',
4931
runId: inputs.verifyRunId ?? null,
5032
launchId: inputs.verifyLaunchId ?? null,
51-
screen: knownScreen ? requestedScreen : 'home',
52-
screenFailure:
53-
requestedScreen === undefined || knownScreen
54-
? null
55-
: { code: 'unknown-screen', message: `The fixture has no screen named ${requestedScreen}.` },
5633
authMode: isOneOf(authModes, inputs.verifyAuthMode) ? inputs.verifyAuthMode : 'signInOrUp',
5734
signInTicket: inputs.verifySignInTicket ?? null,
5835
debugLogging: inputs.verifyLogLevel === 'debug',

0 commit comments

Comments
 (0)