Skip to content

Commit e8c45d9

Browse files
committed
test(integration): fix session_exists tests to use multiple tabs
- Update tests to open sign-in in multiple tabs before signing in - This properly tests the session_exists error scenario where the sign-in component is already mounted - Sign in on one tab, then attempt to sign in on the other tab - Prevents component from redirecting on mount before API call is made
1 parent a57c28d commit e8c45d9

File tree

2 files changed

+46
-32
lines changed

2 files changed

+46
-32
lines changed

integration/tests/oauth-flows.test.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,16 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withLegalConsent] })(
264264
}) => {
265265
const u = createTestUtils({ app, page, context, browser });
266266

267-
// Sign in on the first tab via OAuth
267+
// Open sign-in page in both tabs before signing in
268268
await u.po.signIn.goTo();
269+
270+
let secondTabUtils: any;
271+
await u.tabs.runInNewTab(async u2 => {
272+
secondTabUtils = u2;
273+
await u2.po.signIn.goTo();
274+
});
275+
276+
// Sign in via OAuth on the first tab
269277
await u.page.getByRole('button', { name: 'E2E OAuth Provider' }).click();
270278
await u.page.getByText('Sign in to oauth-provider').waitFor();
271279
await u.po.signIn.setIdentifier(fakeUser.email);
@@ -274,18 +282,11 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withLegalConsent] })(
274282
await u.page.getByText('SignedIn').waitFor();
275283
await u.po.expect.toBeSignedIn();
276284

277-
// Open a new tab and attempt to sign in again via OAuth with the same user
278-
await u.tabs.runInNewTab(async u2 => {
279-
await u2.po.signIn.goTo();
280-
await u2.page.getByRole('button', { name: 'E2E OAuth Provider' }).click();
281-
await u2.page.getByText('Sign in to oauth-provider').waitFor();
282-
await u2.po.signIn.setIdentifier(fakeUser.email);
283-
await u2.po.signIn.continue();
284-
await u2.po.signIn.enterTestOtpCode();
285-
286-
// Should redirect and remain signed in instead of showing an error
287-
await u2.po.expect.toBeSignedIn();
288-
});
285+
// Attempt to sign in via OAuth on the second tab (which already has sign-in mounted)
286+
await secondTabUtils.page.getByRole('button', { name: 'E2E OAuth Provider' }).click();
287+
288+
// Should redirect and be signed in without error
289+
await secondTabUtils.po.expect.toBeSignedIn();
289290
});
290291
},
291292
);

integration/tests/sign-in-flow.test.ts

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -158,46 +158,59 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withEmailCodes] })('sign in f
158158
}) => {
159159
const u = createTestUtils({ app, page, context, browser });
160160

161-
// Sign in on the first tab
161+
// Open sign-in page in both tabs before signing in
162162
await u.po.signIn.goTo();
163+
164+
let secondTabUtils: any;
165+
await u.tabs.runInNewTab(async u2 => {
166+
secondTabUtils = u2;
167+
await u2.po.signIn.goTo();
168+
});
169+
170+
// Sign in on the first tab
163171
await u.po.signIn.setIdentifier(fakeUser.email);
164172
await u.po.signIn.continue();
165173
await u.po.signIn.setPassword(fakeUser.password);
166174
await u.po.signIn.continue();
167175
await u.po.expect.toBeSignedIn();
168176

169-
// Open a new tab and attempt to sign in again with the same user
170-
await u.tabs.runInNewTab(async u2 => {
171-
await u2.po.signIn.goTo();
172-
await u2.po.signIn.setIdentifier(fakeUser.email);
173-
await u2.po.signIn.continue();
174-
await u2.po.signIn.setPassword(fakeUser.password);
175-
await u2.po.signIn.continue();
177+
// Attempt to sign in on the second tab (which already has sign-in mounted)
178+
await secondTabUtils.po.signIn.setIdentifier(fakeUser.email);
179+
await secondTabUtils.po.signIn.continue();
180+
await secondTabUtils.po.signIn.setPassword(fakeUser.password);
181+
await secondTabUtils.po.signIn.continue();
176182

177-
// Should redirect and be signed in without error
178-
await u2.po.expect.toBeSignedIn();
179-
});
183+
// Should redirect and be signed in without error
184+
await secondTabUtils.po.expect.toBeSignedIn();
180185
});
181186

182-
test('redirects when attempting to sign in again with instant password in another tab', async ({
187+
test('redirects when attempting to sign in with instant password and existing session in another tab', async ({
183188
page,
184189
context,
185190
browser,
186191
}) => {
187192
const u = createTestUtils({ app, page, context, browser });
188193

189-
// Sign in on the first tab
194+
// Open sign-in page in both tabs before signing in
190195
await u.po.signIn.goTo();
191-
await u.po.signIn.signInWithEmailAndInstantPassword({ email: fakeUser.email, password: fakeUser.password });
192-
await u.po.expect.toBeSignedIn();
193196

194-
// Open a new tab and attempt to sign in again with instant password
197+
let secondTabUtils: any;
195198
await u.tabs.runInNewTab(async u2 => {
199+
secondTabUtils = u2;
196200
await u2.po.signIn.goTo();
197-
await u2.po.signIn.signInWithEmailAndInstantPassword({ email: fakeUser.email, password: fakeUser.password });
201+
});
198202

199-
// Should redirect and remain signed in without error
200-
await u2.po.expect.toBeSignedIn();
203+
// Sign in with instant password on the first tab
204+
await u.po.signIn.signInWithEmailAndInstantPassword({ email: fakeUser.email, password: fakeUser.password });
205+
await u.po.expect.toBeSignedIn();
206+
207+
// Attempt to sign in with instant password on the second tab
208+
await secondTabUtils.po.signIn.signInWithEmailAndInstantPassword({
209+
email: fakeUser.email,
210+
password: fakeUser.password,
201211
});
212+
213+
// Should redirect and be signed in without error
214+
await secondTabUtils.po.expect.toBeSignedIn();
202215
});
203216
});

0 commit comments

Comments
 (0)