1- import { chromium , request , type FullConfig , type LaunchOptions } from '@playwright/test' ;
1+ import { request } from '@playwright/test' ;
22import { mkdirSync , writeFileSync } from 'node:fs' ;
33import { dirname } from 'node:path' ;
44
@@ -19,9 +19,8 @@ const API = process.env.SMOKE_API_URL || 'http://localhost:3000';
1919const EMAIL = process . env . SMOKE_EMAIL || 'admin@objectos.ai' ;
2020const PASSWORD = process . env . SMOKE_PASSWORD || 'admin123' ;
2121const STATE_PATH = 'e2e/.auth/state.json' ;
22- const APP = process . env . SHOWCASE_APP || 'com.example.showcase' ;
2322
24- export default async function globalSetup ( config : FullConfig ) {
23+ export default async function globalSetup ( ) {
2524 const ctx = await request . newContext ( ) ;
2625 const res = await ctx . post ( `${ API } /api/v1/auth/sign-in/email` , {
2726 data : { email : EMAIL , password : PASSWORD } ,
@@ -38,102 +37,5 @@ export default async function globalSetup(config: FullConfig) {
3837 } ;
3938 mkdirSync ( dirname ( STATE_PATH ) , { recursive : true } ) ;
4039 writeFileSync ( STATE_PATH , JSON . stringify ( state , null , 2 ) ) ;
41-
42- // The specs' own launch options (playwright.config.ts carries
43- // `OS_TEST_CHROMIUM_EXECUTABLE_PATH` there), so the prompt is answered in the
44- // browser the specs run in.
45- const promptRecord = await declineWorkspacePrompt ( token , config . projects [ 0 ] ?. use ?. launchOptions ) ;
46- if ( promptRecord . length > 0 ) {
47- state . origins [ 0 ] . localStorage . push ( ...promptRecord ) ;
48- writeFileSync ( STATE_PATH , JSON . stringify ( state , null , 2 ) ) ;
49- }
5040}
5141
52- /**
53- * Decline the console's one-time workspace prompt before any spec runs.
54- *
55- * The console asks an administrator, in ONE modal dialog on the first app page
56- * it renders, to set the workspace timezone while it is still the manifest
57- * default, and — since the prompt's currency arm (objectstack#28872, commit
58- * 2ac698baf1) — the default currency while `localization.currency` has no
59- * value. The showcase's dev seed derives the currency from the host's POSIX
60- * locale and leaves it unset on a host that sets none or names no country, and
61- * the seeded admin may write settings, so every spec would meet that dialog in
62- * front of the page it reads: the modal makes the page behind it
63- * `aria-hidden`, so role queries (`getByRole('checkbox')`, `getByRole('table')`,
64- * a section's disclosure button) find nothing and a click never lands.
65- *
66- * The run answers it ONCE, in a real browser, through the prompt's own decline
67- * button ("Not now" / "Keep the default"), the same way the console's own live
68- * suite does (ui/e2e/live/global-setup.ts). Declining writes nothing to the
69- * workspace — the showcase stays exactly as seeded, so no spec's reading of an
70- * amount moves — and the prompt keeps its per-device record of having asked in
71- * this origin's localStorage (`PROMPT_RECORD_PREFIX`:ORG:USER). That record,
72- * and nothing else the console stored while it was open, is what this returns
73- * for the storageState every spec reuses: the rest (the sidebar's wide-open
74- * flag, recent items, the active organization) would change the fresh-context
75- * layout the specs measure from — detail-shapes derives its 780 px window from
76- * a context with no stored sidebar state.
77- *
78- * Skipped when the backend says the prompt would not ask (the console's own
79- * condition per key, `workspaceTimezonePromptLogic.ts`). A prompt that was
80- * expected but never shown is reported, not failed: the specs then show whether
81- * anything stands in their way. A prompt that was declined but left no record
82- * throws: every spec would meet it again, and that is the run's one cause.
83- */
84- const PROMPT_RECORD_PREFIX = 'os:workspace-timezone-prompt:' ;
85-
86- async function declineWorkspacePrompt (
87- token : string ,
88- launchOptions : LaunchOptions | undefined ,
89- ) : Promise < { name : string ; value : string } [ ] > {
90- const api = await request . newContext ( { extraHTTPHeaders : { Authorization : `Bearer ${ token } ` } } ) ;
91- let wouldAsk = false ;
92- try {
93- const res = await api . get ( `${ API } /api/settings/localization` ) ;
94- if ( res . ok ( ) ) {
95- const body = await res . json ( ) ;
96- const values = ( body ?. data ?? body ) ?. values ;
97- const timezone = values ?. timezone ;
98- const currency = values ?. currency ;
99- const timezoneUnset = timezone ?. source === 'default' && ! timezone ?. locked ;
100- const currencyUnset =
101- currency ?. source === 'default' &&
102- ! currency ?. locked &&
103- ( currency ?. value === null || currency ?. value === undefined || currency ?. value === '' ) ;
104- wouldAsk = timezoneUnset || currencyUnset ;
105- }
106- } finally {
107- await api . dispose ( ) ;
108- }
109- if ( ! wouldAsk ) return [ ] ;
110-
111- const browser = await chromium . launch ( launchOptions ) ;
112- try {
113- const context = await browser . newContext ( { storageState : STATE_PATH , baseURL : API } ) ;
114- const page = await context . newPage ( ) ;
115- await page . goto ( `/_console/apps/${ APP } ` , { waitUntil : 'domcontentloaded' } ) ;
116- const prompt = page . getByTestId ( 'workspace-timezone-prompt' ) ;
117- try {
118- await prompt . waitFor ( { state : 'visible' , timeout : 60_000 } ) ;
119- } catch {
120- console . warn ( '[showcase-smoke] the workspace timezone or currency is unset, but the console showed no prompt' ) ;
121- return [ ] ;
122- }
123- await page . getByTestId ( 'workspace-timezone-prompt-decline' ) . click ( ) ;
124- await prompt . waitFor ( { state : 'hidden' } ) ;
125- const stored = await context . storageState ( ) ;
126- const record = ( stored . origins . find ( ( o ) => o . origin === new URL ( API ) . origin ) ?. localStorage ?? [ ] ) . filter ( ( e ) =>
127- e . name . startsWith ( PROMPT_RECORD_PREFIX ) ,
128- ) ;
129- if ( record . length === 0 ) {
130- throw new Error (
131- `the workspace prompt was declined but left no ${ PROMPT_RECORD_PREFIX } * record in localStorage, ` +
132- 'so every spec would meet it again' ,
133- ) ;
134- }
135- return record ;
136- } finally {
137- await browser . close ( ) ;
138- }
139- }
0 commit comments