| 12 | } |
| 13 | |
| 14 | export class Result { |
| 15 | private nextCallIndex = 0; |
| 16 | public readonly calls: CapturedFunctionCall[]; |
| 17 | public readonly serverArgs: string[]; |
| 18 | |
| 19 | constructor(calls: CapturedFunctionCall[], serverArgs: string[]) { |
| 20 | this.calls = calls; |
| 21 | this.serverArgs = serverArgs; |
| 22 | } |
| 23 | |
| 24 | get hasPageIdRouting(): boolean { |
| 25 | return this.serverArgs.includes('--experimental-page-id-routing'); |
| 26 | } |
| 27 | |
| 28 | get remainingCalls(): CapturedFunctionCall[] { |
| 29 | return this.calls.slice(this.nextCallIndex); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Consumes initial page navigation/setup boilerplate. |
| 34 | * - Ignores/skips leading list_pages calls. |
| 35 | * - Asserts that new_page or navigate_page was called. |
| 36 | * - Determines the expected pageId. |
| 37 | * - Returns the active pageId. |
| 38 | */ |
| 39 | consumePageNavigation(): number | undefined { |
| 40 | if (this.calls[this.nextCallIndex]?.name === 'list_pages') { |
| 41 | this.nextCallIndex++; |
| 42 | } |
| 43 | |
| 44 | const navCall = this.calls[this.nextCallIndex]; |
| 45 | assert.ok( |
| 46 | navCall && |
| 47 | (navCall.name === 'new_page' || navCall.name === 'navigate_page'), |
| 48 | `Expected navigation call (new_page or navigate_page), but got: ${navCall?.name || 'none'}`, |
| 49 | ); |
| 50 | this.nextCallIndex++; |
| 51 | |
| 52 | const isNewPage = navCall.name === 'new_page'; |
| 53 | let pageId: number | undefined; |
| 54 | if (this.hasPageIdRouting) { |
| 55 | pageId = isNewPage ? 2 : 1; |
| 56 | } |
| 57 | |
| 58 | return pageId; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Asserts that the next call in sequence has the correct name and matches expected arguments. |
| 63 | * Increments the internal call index. |
| 64 | */ |
| 65 | assertNextCall( |
| 66 | name: string, |
| 67 | expectedArgs?: Record<string, unknown>, |
| 68 | ): CapturedFunctionCall { |
| 69 | const call = this.calls[this.nextCallIndex]; |
| 70 | assert.ok( |
| 71 | call, |
nothing calls this directly
no outgoing calls
no test coverage detected