buster/web/playwright-tests/question-helpers/ask-question.ts

31 lines
1.3 KiB
TypeScript
Raw Normal View History

2025-05-30 04:35:02 +08:00
import type { Page } from '@playwright/test';
2025-05-03 01:41:55 +08:00
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();
2025-05-03 04:00:14 +08:00
await page.getByRole('textbox', { name: 'Ask Buster a question...' }).fill(question);
2025-05-03 01:41:55 +08:00
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();
2025-05-03 04:00:14 +08:00
await page.getByRole('textbox', { name: 'Ask Buster a question...' }).fill(question);
2025-05-03 01:41:55 +08:00
// Submit the question
await page.getByRole('main').getByRole('button').click();
};
export const checkThatPageWasRedirected = async (
page: Page,
2025-05-03 04:00:14 +08:00
redirectPath: ('metrics' | 'reasoning' | 'dashboard' | 'chart')[]
2025-05-03 01:41:55 +08:00
) => {
for (const path of redirectPath) {
await page.waitForURL((url) => url.toString().includes(path), {
timeout: 180000
});
expect(page.url()).toContain(path);
}
};