From 15fbca325120d3ae9ba2f2a2fa2f1092112444d7 Mon Sep 17 00:00:00 2001 From: Nate Kelley Date: Fri, 2 May 2025 11:41:55 -0600 Subject: [PATCH] Ask a question --- web/playwright-tests/0_Question_1.test.ts | 58 +++++++++++++++++++ .../question-helpers/ask-question.ts | 35 +++++++++++ 2 files changed, 93 insertions(+) create mode 100644 web/playwright-tests/0_Question_1.test.ts create mode 100644 web/playwright-tests/question-helpers/ask-question.ts diff --git a/web/playwright-tests/0_Question_1.test.ts b/web/playwright-tests/0_Question_1.test.ts new file mode 100644 index 000000000..d4a92c496 --- /dev/null +++ b/web/playwright-tests/0_Question_1.test.ts @@ -0,0 +1,58 @@ +import { test, expect } from '@playwright/test'; +import { askQuestion, checkThatPageWasRedirected } from './question-helpers/ask-question'; + +test('Question: Who is my top customer?', async ({ page }) => { + await askQuestion(page, 'Who is my top customer?'); + + await checkThatPageWasRedirected(page, ['reasoning', 'metrics']); + + // Optional: Check specific metrics route format without checking IDs + expect(page.url()).toMatch(/\/app\/chats\/[^/]+\/metrics\/[^/]+\/chart/); + + // Check that the input field is empty + await expect(page.getByRole('textbox', { name: 'Ask Buster a question...' })).toHaveValue(''); + + await page.getByRole('tab', { name: 'Results' }).click(); + await page.waitForURL((url) => url.toString().includes('results')); + expect(page.url()).toContain('results'); + + await page.getByRole('tab', { name: 'File' }).click(); + await page.waitForURL((url) => url.toString().includes('file')); + expect(page.url()).toContain('file'); + + await page.getByRole('tab', { name: 'Chart' }).click(); + await page.waitForURL((url) => url.toString().includes('chart')); + expect(page.url()).toContain('chart'); + + await page.locator('a[aria-label="Reasoning link"]').click(); + await page.waitForURL((url) => url.toString().includes('reasoning')); + expect(page.url()).toContain('reasoning'); + + await page.click('[aria-label="Collapse file button"]'); + // Wait for and check redirection to chat page after collapsing file + await page.waitForURL((url) => { + // URL should be in format /app/chats/{id} without any additional segments + return url.pathname.match(/^\/app\/chats\/[^/]+$/) !== null; + }); + + // Verify we're on the main chat page without any file/reasoning/metrics segments + expect(page.url()).toMatch(/\/app\/chats\/[^/]+$/); + expect(page.url()).not.toContain('reasoning'); + expect(page.url()).not.toContain('metrics'); + expect(page.url()).not.toContain('file'); + expect(page.url()).not.toContain('chart'); + + // Verify at least one chat response message file element exists + const fileElements = page.locator('[data-testid="chat-response-message-file"]'); + await expect(fileElements.first()).toBeVisible(); + + // Click the last matching element + const count = await fileElements.count(); + expect(count).toBeGreaterThan(0); + await fileElements.nth(count - 1).click(); + + await page.waitForURL((url) => url.toString().includes('chart')); + expect(page.url()).toContain('chart'); + + await expect(page.getByTestId('metric-view-chart-content')).toBeVisible(); +}); diff --git a/web/playwright-tests/question-helpers/ask-question.ts b/web/playwright-tests/question-helpers/ask-question.ts new file mode 100644 index 000000000..47943f689 --- /dev/null +++ b/web/playwright-tests/question-helpers/ask-question.ts @@ -0,0 +1,35 @@ +import { Page } from '@playwright/test'; +import { expect } from '@playwright/test'; + +export const askQuestion = async (page: Page, question: string) => { + await page.goto('http://localhost:3000/app/home'); + await page.getByRole('textbox', { name: 'Ask Buster a question...' }).click(); + await page + .getByRole('textbox', { name: 'Ask Buster a question...' }) + .fill('Who is my top customer?'); + + await expect(page.getByRole('main').getByRole('button')).toBeVisible(); + await page.getByRole('textbox', { name: 'Ask Buster a question...' }).dblclick(); + await page.getByRole('textbox', { name: 'Ask Buster a question...' }).press('ControlOrMeta+a'); + await page.getByRole('textbox', { name: 'Ask Buster a question...' }).fill(''); + await expect(page.getByRole('main').getByRole('button')).toBeDisabled(); + await page.getByRole('textbox', { name: 'Ask Buster a question...' }).click(); + await page + .getByRole('textbox', { name: 'Ask Buster a question...' }) + .fill('Who is my top customer?'); + + // Submit the question + await page.getByRole('main').getByRole('button').click(); +}; + +export const checkThatPageWasRedirected = async ( + page: Page, + redirectPath: ('metrics' | 'reasoning' | 'dashboard')[] +) => { + for (const path of redirectPath) { + await page.waitForURL((url) => url.toString().includes(path), { + timeout: 180000 + }); + expect(page.url()).toContain(path); + } +};