11import { expect , test } from '@playwright/test' ;
2+ import { authenticateTestUser , clearAuth } from '../utils/auth-helpers' ;
23import { generateTestData } from '../utils/helpers' ;
34
45test . describe ( 'Split Onboarding Flow' , ( ) => {
6+ test . beforeEach ( async ( { page } ) => {
7+ // Clear any existing auth state
8+ await clearAuth ( page ) ;
9+ } ) ;
10+
511 test ( 'new user completes split onboarding: 3 steps → payment → 9 steps → product access' , async ( {
612 page,
713 } ) => {
814 const testData = generateTestData ( ) ;
915 const website = `example${ Date . now ( ) } .com` ;
1016
11- // Start at setup
17+ // Authenticate user first
18+ await authenticateTestUser ( page , {
19+ email : testData . email ,
20+ name : testData . userName ,
21+ skipOrg : true , // Don't create org, user will go through setup
22+ } ) ;
23+
24+ // Navigate to setup
1225 await page . goto ( '/setup' ) ;
1326
27+ // Should redirect to /setup/[setupId]
28+ await page . waitForURL ( / \/ s e t u p \/ [ a - z A - Z 0 - 9 ] + / , { timeout : 10000 } ) ;
29+
30+ // Wait for content to load
31+ await page . waitForLoadState ( 'networkidle' , { timeout : 10000 } ) . catch ( ( ) => { } ) ;
32+
1433 // Step 1: Select framework
15- await expect ( page . getByText ( 'Which compliance frameworks do you need?' ) ) . toBeVisible ( ) ;
16- await page . getByRole ( 'checkbox' , { name : 'SOC 2' } ) . click ( ) ;
34+ await expect ( page . locator ( 'text=/compliance frameworks/i' ) . first ( ) ) . toBeVisible ( {
35+ timeout : 10000 ,
36+ } ) ;
37+
38+ // Check if framework is already selected, if not select one
39+ const checkedFrameworks = await page . locator ( 'input[type="checkbox"]:checked' ) . count ( ) ;
40+ if ( checkedFrameworks === 0 ) {
41+ await page . locator ( 'label:has-text("SOC 2")' ) . click ( ) ;
42+ }
1743 await page . getByRole ( 'button' , { name : 'Next' } ) . click ( ) ;
1844
1945 // Step 2: Organization name
20- await expect ( page . getByText ( "What's your organization's name?" ) ) . toBeVisible ( ) ;
21- await page . getByPlaceholder ( "Enter your organization's name" ) . fill ( testData . organizationName ) ;
46+ await page . waitForSelector ( 'input[name="organizationName"]' , { timeout : 10000 } ) ;
47+ await page . locator ( 'input[ name="organizationName"]' ) . fill ( testData . organizationName ) ;
2248 await page . getByRole ( 'button' , { name : 'Next' } ) . click ( ) ;
2349
2450 // Step 3: Website
25- await expect ( page . getByText ( "What's your organization's domain?" ) ) . toBeVisible ( ) ;
26- await page . getByPlaceholder ( 'example.com ') . fill ( website ) ;
51+ await page . waitForSelector ( 'input[name="website"]' , { timeout : 10000 } ) ;
52+ await page . locator ( 'input[name="website"] ') . fill ( website ) ;
2753 await page . getByRole ( 'button' , { name : 'Next' } ) . click ( ) ;
2854
2955 // Should redirect to upgrade page
@@ -92,13 +118,32 @@ test.describe('Split Onboarding Flow', () => {
92118 const testData = generateTestData ( ) ;
93119 const website = `example${ Date . now ( ) } .com` ;
94120
121+ // Authenticate user first
122+ await authenticateTestUser ( page , {
123+ email : testData . email ,
124+ name : testData . userName ,
125+ skipOrg : true ,
126+ } ) ;
127+
95128 // First create org through minimal flow
96129 await page . goto ( '/setup' ) ;
97- await page . getByRole ( 'checkbox' , { name : 'SOC 2' } ) . click ( ) ;
130+ await page . waitForURL ( / \/ s e t u p \/ [ a - z A - Z 0 - 9 ] + / , { timeout : 10000 } ) ;
131+
132+ // Select framework
133+ const checkedFrameworks = await page . locator ( 'input[type="checkbox"]:checked' ) . count ( ) ;
134+ if ( checkedFrameworks === 0 ) {
135+ await page . locator ( 'label:has-text("SOC 2")' ) . click ( ) ;
136+ }
98137 await page . getByRole ( 'button' , { name : 'Next' } ) . click ( ) ;
99- await page . getByPlaceholder ( "Enter your organization's name" ) . fill ( testData . organizationName ) ;
138+
139+ // Fill organization name
140+ await page . waitForSelector ( 'input[name="organizationName"]' , { timeout : 10000 } ) ;
141+ await page . locator ( 'input[name="organizationName"]' ) . fill ( testData . organizationName ) ;
100142 await page . getByRole ( 'button' , { name : 'Next' } ) . click ( ) ;
101- await page . getByPlaceholder ( 'example.com' ) . fill ( website ) ;
143+
144+ // Fill website
145+ await page . waitForSelector ( 'input[name="website"]' , { timeout : 10000 } ) ;
146+ await page . locator ( 'input[name="website"]' ) . fill ( website ) ;
102147 await page . getByRole ( 'button' , { name : 'Next' } ) . click ( ) ;
103148
104149 const orgIdMatch = page . url ( ) . match ( / o r g _ [ a - z A - Z 0 - 9 ] + / ) ;
@@ -129,12 +174,31 @@ test.describe('Split Onboarding Flow', () => {
129174 const firstOrg = generateTestData ( ) ;
130175 const firstWebsite = `example${ Date . now ( ) } .com` ;
131176
177+ // Authenticate user first
178+ await authenticateTestUser ( page , {
179+ email : firstOrg . email ,
180+ name : firstOrg . userName ,
181+ skipOrg : true ,
182+ } ) ;
183+
132184 await page . goto ( '/setup' ) ;
133- await page . getByRole ( 'checkbox' , { name : 'SOC 2' } ) . click ( ) ;
185+ await page . waitForURL ( / \/ s e t u p \/ [ a - z A - Z 0 - 9 ] + / , { timeout : 10000 } ) ;
186+
187+ // Select framework
188+ const checkedFrameworks = await page . locator ( 'input[type="checkbox"]:checked' ) . count ( ) ;
189+ if ( checkedFrameworks === 0 ) {
190+ await page . locator ( 'label:has-text("SOC 2")' ) . click ( ) ;
191+ }
134192 await page . getByRole ( 'button' , { name : 'Next' } ) . click ( ) ;
135- await page . getByPlaceholder ( "Enter your organization's name" ) . fill ( firstOrg . organizationName ) ;
193+
194+ // Fill organization name
195+ await page . waitForSelector ( 'input[name="organizationName"]' , { timeout : 10000 } ) ;
196+ await page . locator ( 'input[name="organizationName"]' ) . fill ( firstOrg . organizationName ) ;
136197 await page . getByRole ( 'button' , { name : 'Next' } ) . click ( ) ;
137- await page . getByPlaceholder ( 'example.com' ) . fill ( firstWebsite ) ;
198+
199+ // Fill website
200+ await page . waitForSelector ( 'input[name="website"]' , { timeout : 10000 } ) ;
201+ await page . locator ( 'input[name="website"]' ) . fill ( firstWebsite ) ;
138202 await page . getByRole ( 'button' , { name : 'Next' } ) . click ( ) ;
139203
140204 const firstOrgIdMatch = page . url ( ) . match ( / o r g _ [ a - z A - Z 0 - 9 ] + / ) ;
@@ -144,22 +208,28 @@ test.describe('Split Onboarding Flow', () => {
144208 // Now create additional org using dropdown
145209 await page . goto ( `/upgrade/${ firstOrgId } ` ) ;
146210
147- // Open org switcher
148- await page . getByRole ( 'button' , { name : firstOrg . organizationName } ) . click ( ) ;
149- await page . getByText ( 'Create Organization' ) . click ( ) ;
211+ // Try navigating directly to setup with intent
212+ await page . goto ( '/setup?intent=create-additional' ) ;
150213
151- // Should be at setup with intent
152- await expect ( page ) . toHaveURL ( '/ setup?intent=create-additional' ) ;
214+ // Should redirect to / setup/[setupId] with intent preserved
215+ await page . waitForURL ( / \/ s e t u p \/ [ a - z A - Z 0 - 9 ] + \ ?i n t e n t = c r e a t e - a d d i t i o n a l / , { timeout : 10000 } ) ;
153216
154217 // Complete setup for second org
155218 const secondOrg = generateTestData ( ) ;
156219 const secondWebsite = `example${ Date . now ( ) + 1 } .com` ;
157220
158- await page . getByRole ( 'checkbox' , { name : 'ISO 27001' } ) . click ( ) ;
221+ // Select a different framework
222+ await page . locator ( 'label:has-text("ISO 27001")' ) . click ( ) ;
159223 await page . getByRole ( 'button' , { name : 'Next' } ) . click ( ) ;
160- await page . getByPlaceholder ( "Enter your organization's name" ) . fill ( secondOrg . organizationName ) ;
224+
225+ // Fill organization name
226+ await page . waitForSelector ( 'input[name="organizationName"]' , { timeout : 10000 } ) ;
227+ await page . locator ( 'input[name="organizationName"]' ) . fill ( secondOrg . organizationName ) ;
161228 await page . getByRole ( 'button' , { name : 'Next' } ) . click ( ) ;
162- await page . getByPlaceholder ( 'example.com' ) . fill ( secondWebsite ) ;
229+
230+ // Fill website
231+ await page . waitForSelector ( 'input[name="website"]' , { timeout : 10000 } ) ;
232+ await page . locator ( 'input[name="website"]' ) . fill ( secondWebsite ) ;
163233 await page . getByRole ( 'button' , { name : 'Next' } ) . click ( ) ;
164234
165235 // Should redirect to upgrade for the new org
0 commit comments