import { test, expect } from "@playwright/test"; test("Save button enqueues analyze and upserts stock", async ({ page }) => { await page.goto("/stocks"); await page.waitForSelector("table tbody tr"); const firstRow = page.locator("tbody tr").first(); const symbol = (await firstRow.locator("td a").textContent()) || ""; // Click the Save button in the first row and wait for analyze enqueue response const [resp] = await Promise.all([ page.waitForResponse((r) => r.url().endsWith('/api/analyze') && (r.status() === 202 || r.status() === 200)), firstRow.locator("button:has-text('Save')").click(), ]); expect([200, 202]).toContain(resp.status()); // Poll the /api/stocks until the ticker appears (give it a few seconds for background job) const base = new URL(page.url()).origin; let found = false; for (let i = 0; i < 20; i++) { const r = await page.request.get(`${base}/api/stocks`); const list = await r.json(); if (list.some((s: any) => s.ticker === symbol.trim())) { found = true; break; } await page.waitForTimeout(300); } expect(found).toBeTruthy(); });