|
3 | 3 | * Copyright 2025 Google LLC |
4 | 4 | * SPDX-License-Identifier: Apache-2.0 |
5 | 5 | */ |
6 | | -import {describe, it} from 'node:test'; |
| 6 | +import { describe, it } from 'node:test'; |
7 | 7 | import assert from 'assert'; |
8 | 8 |
|
9 | | -import {getMockRequest, html, withBrowser} from './utils.js'; |
| 9 | +import { getMockRequest, html, withBrowser } from './utils.js'; |
10 | 10 |
|
11 | 11 | describe('McpResponse', () => { |
12 | 12 | it('list pages', async () => { |
@@ -120,7 +120,7 @@ Navigation timeout set to 100000 ms`, |
120 | 120 | }); |
121 | 121 | it('adds image when image is attached', async () => { |
122 | 122 | await withBrowser(async (response, context) => { |
123 | | - response.attachImage({data: 'imageBase64', mimeType: 'image/png'}); |
| 123 | + response.attachImage({ data: 'imageBase64', mimeType: 'image/png' }); |
124 | 124 | const result = await response.handle('test', context); |
125 | 125 | assert.strictEqual(result[0].text, `# test response`); |
126 | 126 | assert.equal(result[1].type, 'image'); |
@@ -185,7 +185,7 @@ Call browser_handle_dialog to handle it before continuing.`, |
185 | 185 | result[0].text, |
186 | 186 | `# test response |
187 | 187 | ## Network requests |
188 | | -Showing 1-1 of 1. |
| 188 | +Showing 1-1 of 1 (Page 1 of 1). |
189 | 189 | http://example.com GET [pending]`, |
190 | 190 | ); |
191 | 191 | }); |
@@ -218,7 +218,7 @@ Status: [pending] |
218 | 218 | ### Request Headers |
219 | 219 | - content-size:10 |
220 | 220 | ## Network requests |
221 | | -Showing 1-1 of 1. |
| 221 | +Showing 1-1 of 1 (Page 1 of 1). |
222 | 222 | http://example.com GET [pending]`, |
223 | 223 | ); |
224 | 224 | }); |
@@ -267,66 +267,66 @@ Log>`), |
267 | 267 | describe('McpResponse network pagination', () => { |
268 | 268 | it('returns all requests when pagination is not provided', async () => { |
269 | 269 | await withBrowser(async (response, context) => { |
270 | | - const requests = Array.from({length: 5}, () => getMockRequest()); |
| 270 | + const requests = Array.from({ length: 5 }, () => getMockRequest()); |
271 | 271 | context.getNetworkRequests = () => requests; |
272 | 272 | response.setIncludeNetworkRequests(true); |
273 | 273 | const result = await response.handle('test', context); |
274 | 274 | const text = (result[0].text as string).toString(); |
275 | | - assert.ok(text.includes('Showing 1-5 of 5.')); |
276 | | - assert.ok(!text.includes('Next:')); |
277 | | - assert.ok(!text.includes('Prev:')); |
| 275 | + assert.ok(text.includes('Showing 1-5 of 5 (Page 1 of 1).')); |
| 276 | + assert.ok(!text.includes('Next page:')); |
| 277 | + assert.ok(!text.includes('Previous page:')); |
278 | 278 | }); |
279 | 279 | }); |
280 | 280 |
|
281 | 281 | it('returns first page by default', async () => { |
282 | 282 | await withBrowser(async (response, context) => { |
283 | | - const requests = Array.from({length: 30}, (_, idx) => |
284 | | - getMockRequest({method: `GET-${idx}`}), |
| 283 | + const requests = Array.from({ length: 30 }, (_, idx) => |
| 284 | + getMockRequest({ method: `GET-${idx}` }), |
285 | 285 | ); |
286 | 286 | context.getNetworkRequests = () => { |
287 | 287 | return requests; |
288 | 288 | }; |
289 | | - response.setIncludeNetworkRequests(true, {pageSize: 10}); |
| 289 | + response.setIncludeNetworkRequests(true, { pageSize: 10 }); |
290 | 290 | const result = await response.handle('test', context); |
291 | 291 | const text = (result[0].text as string).toString(); |
292 | | - assert.ok(text.includes('Showing 1-10 of 30.')); |
293 | | - assert.ok(text.includes('Next: 10')); |
294 | | - assert.ok(!text.includes('Prev:')); |
| 292 | + assert.ok(text.includes('Showing 1-10 of 30 (Page 1 of 3).')); |
| 293 | + assert.ok(text.includes('Next page: 1')); |
| 294 | + assert.ok(!text.includes('Previous page:')); |
295 | 295 | }); |
296 | 296 | }); |
297 | 297 |
|
298 | | - it('returns subsequent page when token provided', async () => { |
| 298 | + it('returns subsequent page when pageIdx provided', async () => { |
299 | 299 | await withBrowser(async (response, context) => { |
300 | | - const requests = Array.from({length: 25}, (_, idx) => |
301 | | - getMockRequest({method: `GET-${idx}`}), |
| 300 | + const requests = Array.from({ length: 25 }, (_, idx) => |
| 301 | + getMockRequest({ method: `GET-${idx}` }), |
302 | 302 | ); |
303 | 303 | context.getNetworkRequests = () => requests; |
304 | 304 | response.setIncludeNetworkRequests(true, { |
305 | 305 | pageSize: 10, |
306 | | - pageToken: '10', |
| 306 | + pageIdx: 1, |
307 | 307 | }); |
308 | 308 | const result = await response.handle('test', context); |
309 | 309 | const text = (result[0].text as string).toString(); |
310 | | - assert.ok(text.includes('Showing 11-20 of 25.')); |
311 | | - assert.ok(text.includes('Next: 20')); |
312 | | - assert.ok(text.includes('Prev: 0')); |
| 310 | + assert.ok(text.includes('Showing 11-20 of 25 (Page 2 of 3).')); |
| 311 | + assert.ok(text.includes('Next page: 2')); |
| 312 | + assert.ok(text.includes('Previous page: 0')); |
313 | 313 | }); |
314 | 314 | }); |
315 | 315 |
|
316 | | - it('handles invalid token by showing first page', async () => { |
| 316 | + it('handles invalid page number by showing first page', async () => { |
317 | 317 | await withBrowser(async (response, context) => { |
318 | | - const requests = Array.from({length: 5}, () => getMockRequest()); |
| 318 | + const requests = Array.from({ length: 5 }, () => getMockRequest()); |
319 | 319 | context.getNetworkRequests = () => requests; |
320 | 320 | response.setIncludeNetworkRequests(true, { |
321 | 321 | pageSize: 2, |
322 | | - pageToken: 'invalid', |
| 322 | + pageIdx: 10, // Invalid page number |
323 | 323 | }); |
324 | 324 | const result = await response.handle('test', context); |
325 | 325 | const text = (result[0].text as string).toString(); |
326 | 326 | assert.ok( |
327 | | - text.includes('Invalid page token provided. Showing first page.'), |
| 327 | + text.includes('Invalid page number provided. Showing first page.'), |
328 | 328 | ); |
329 | | - assert.ok(text.includes('Showing 1-2 of 5.')); |
| 329 | + assert.ok(text.includes('Showing 1-2 of 5 (Page 1 of 3).')); |
330 | 330 | }); |
331 | 331 | }); |
332 | 332 | }); |
0 commit comments