Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

devtools-tools.spec.ts

80 lines2.8 KB

1import { test, expect } from './fixtures'
2import {
3 devtoolsUrl,
4 openDevtools,
5 selectDevtoolsTab,
6 selectHook,
7} from './devtools-helpers'
8​
9test.beforeEach(async ({ page }) => {
10 // Reset persisted devtools state on the FIRST page load of each test
11 // only, so in-test page.reload() flows can verify localStorage
12 // persistence (e.g. saved tool fixtures surviving a refresh).
13 await page.addInitScript(() => {
14 if (!sessionStorage.getItem('tanstack-ai-e2e:initialized')) {
15 localStorage.clear()
16 sessionStorage.setItem('tanstack-ai-e2e:initialized', '1')
17 }
18 })
19})
20​
21test('tool tab fires, saves, replays, orders, persists, and deletes fixtures', async ({
22 page,
23 testId,
24 aimockPort,
25}) => {
26 await page.goto(devtoolsUrl('/devtools-tools', testId, aimockPort))
27 await openDevtools(page)
28 await selectHook(page, 'Tool Runner')
29 await selectDevtoolsTab(page, 'Tools')
30​
31 const toolRow = page.getByTestId('ai-devtools-tool-row')
32 await expect(toolRow).toHaveAttribute('data-tool-name', 'InventoryLookup')
33 await expect(toolRow).toContainText('InventoryLookup')
34​
35 await page.getByLabel('sku').fill('STRAT-001')
36 await page.getByLabel('includeAvailability').selectOption('true')
37 await page
38 .getByLabel('Output JSON')
39 .fill('{"sku":"STRAT-001","name":"Fender Stratocaster","available":true}')
40 await page.getByTestId('ai-devtools-tool-fire').click()
41 await expect(page.getByTestId('tool-call-InventoryLookup')).toBeVisible()
42 await expect(page.getByTestId('tool-call-InventoryLookup')).toContainText(
43 'STRAT-001',
44 )
45​
46 await page.getByTestId('ai-devtools-tool-save').click()
47 await page.getByTestId('ai-devtools-fixture-name-input').fill('first lookup')
48 await page.getByTestId('ai-devtools-fixture-save-confirm').click()
49 await expect(
50 page
51 .getByTestId('ai-devtools-fixture-row')
52 .filter({ hasText: 'first lookup' }),
53 ).toBeVisible()
54​
55 await page.getByTestId('ai-devtools-tool-save').click()
56 await page.getByTestId('ai-devtools-fixture-name-input').fill('second lookup')
57 await page.getByTestId('ai-devtools-fixture-save-confirm').click()
58 await expect(
59 page.getByTestId('ai-devtools-fixture-row').first(),
60 ).toHaveAttribute('data-fixture-name', 'second lookup')
61​
62 await page.reload()
63 await openDevtools(page)
64 await selectHook(page, 'Tool Runner')
65 await selectDevtoolsTab(page, 'Tools')
66 await expect(
67 page
68 .getByTestId('ai-devtools-fixture-row')
69 .filter({ hasText: 'second lookup' }),
70 ).toBeVisible()
71​
72 await page.getByTestId('ai-devtools-fixture-replay').first().click()
73 await expect(page.getByTestId('tool-call-InventoryLookup')).toBeVisible()
74 await page.getByTestId('ai-devtools-fixture-delete').first().click()
75 await expect(
76 page
77 .getByTestId('ai-devtools-fixture-row')
78 .filter({ hasText: 'second lookup' }),
79 ).toHaveCount(0)
80})