| import { Page, Locator } from '@playwright/test'; |
| import { clickElement, fillInput } from '../core/interactions'; |
| import { waitForElement, waitForElementHidden } from '../core/waiting'; |
| import { getByTestId } from '../core/elements'; |
| import { expect } from '@playwright/test'; |
|
|
| |
| |
| |
| export async function getContextFileList(page: Page): Promise<Locator> { |
| return page.locator('[data-testid="context-file-list"]'); |
| } |
|
|
| |
| |
| |
| export async function clickContextFile(page: Page, fileName: string): Promise<void> { |
| const fileButton = page.locator(`[data-testid="context-file-${fileName}"]`); |
| await fileButton.click(); |
| } |
|
|
| |
| |
| |
| export async function getContextEditor(page: Page): Promise<Locator> { |
| return page.locator('[data-testid="context-editor"]'); |
| } |
|
|
| |
| |
| |
| export async function getContextEditorContent(page: Page): Promise<string> { |
| const editor = await getByTestId(page, 'context-editor'); |
| return await editor.inputValue(); |
| } |
|
|
| |
| |
| |
| export async function setContextEditorContent(page: Page, content: string): Promise<void> { |
| const editor = await getByTestId(page, 'context-editor'); |
| await editor.fill(content); |
| } |
|
|
| |
| |
| |
| export async function openAddContextFileDialog(page: Page): Promise<void> { |
| await clickElement(page, 'add-context-file'); |
| await waitForElement(page, 'add-context-dialog'); |
| } |
|
|
| |
| |
| |
| export async function createContextFile( |
| page: Page, |
| filename: string, |
| content: string |
| ): Promise<void> { |
| await openAddContextFileDialog(page); |
| await clickElement(page, 'add-text-type'); |
| await fillInput(page, 'new-file-name', filename); |
| await fillInput(page, 'new-file-content', content); |
| await clickElement(page, 'confirm-add-file'); |
| await waitForElementHidden(page, 'add-context-dialog'); |
| } |
|
|
| |
| |
| |
| export async function createContextImage( |
| page: Page, |
| filename: string, |
| imagePath: string |
| ): Promise<void> { |
| await openAddContextFileDialog(page); |
| await clickElement(page, 'add-image-type'); |
| await fillInput(page, 'new-file-name', filename); |
| await page.setInputFiles('[data-testid="image-upload-input"]', imagePath); |
| await clickElement(page, 'confirm-add-file'); |
| await waitForElementHidden(page, 'add-context-dialog'); |
| } |
|
|
| |
| |
| |
| export async function deleteSelectedContextFile(page: Page): Promise<void> { |
| await clickElement(page, 'delete-context-file'); |
| await waitForElement(page, 'delete-context-dialog'); |
| |
| const dialog = page.locator('[data-testid="delete-context-dialog"]'); |
| await dialog.locator('[data-testid="confirm-delete-file"]').click(); |
| |
| await waitForElementHidden(page, 'delete-context-dialog', { timeout: 15000 }); |
| } |
|
|
| |
| |
| |
| export async function saveContextFile(page: Page): Promise<void> { |
| await clickElement(page, 'save-context-file'); |
| |
| |
| |
| await page.waitForFunction( |
| () => { |
| const btn = document.querySelector('[data-testid="save-context-file"]'); |
| if (!btn) return false; |
| const stateText = [ |
| btn.textContent ?? '', |
| btn.getAttribute('aria-label') ?? '', |
| btn.getAttribute('title') ?? '', |
| ] |
| .join(' ') |
| .toLowerCase(); |
| return stateText.includes('saved'); |
| }, |
| { timeout: 5000 } |
| ); |
| } |
|
|
| |
| |
| |
| export async function toggleContextPreviewMode(page: Page): Promise<void> { |
| await clickElement(page, 'toggle-preview-mode'); |
| } |
|
|
| |
| |
| |
| |
| |
| export async function waitForContextFile( |
| page: Page, |
| filename: string, |
| timeout: number = 20000 |
| ): Promise<void> { |
| |
| const fileList = page.locator('[data-testid="context-file-list"]'); |
| await fileList.scrollIntoViewIfNeeded().catch(() => {}); |
|
|
| const locator = page.locator(`[data-testid="context-file-${filename}"]`); |
| |
| await expect(locator).toBeVisible({ timeout }); |
| } |
|
|
| |
| |
| |
| |
| export async function selectContextFile( |
| page: Page, |
| filename: string, |
| timeout: number = 15000 |
| ): Promise<void> { |
| const fileButton = await getByTestId(page, `context-file-${filename}`); |
|
|
| |
| |
| await expect(async () => { |
| |
| await fileButton.evaluate((el) => (el as HTMLButtonElement).click()); |
| |
| const contentLocator = page.locator( |
| '[data-testid="context-editor"], [data-testid="markdown-preview"], [data-testid="image-preview"]' |
| ); |
| await expect(contentLocator).toBeVisible(); |
| }).toPass({ timeout, intervals: [200, 500, 1000] }); |
| } |
|
|
| |
| |
| |
| |
| export async function waitForFileContentToLoad(page: Page, timeout: number = 15000): Promise<void> { |
| await expect(async () => { |
| const contentLocator = page.locator( |
| '[data-testid="context-editor"], [data-testid="markdown-preview"], [data-testid="image-preview"]' |
| ); |
| await expect(contentLocator).toBeVisible(); |
| }).toPass({ timeout, intervals: [200, 500, 1000] }); |
| } |
|
|
| |
| |
| |
| |
| export async function switchToEditMode(page: Page): Promise<void> { |
| |
| await waitForFileContentToLoad(page); |
|
|
| const markdownPreview = await getByTestId(page, 'markdown-preview'); |
| const isPreview = await markdownPreview.isVisible().catch(() => false); |
|
|
| if (isPreview) { |
| await clickElement(page, 'toggle-preview-mode'); |
| await page.waitForSelector('[data-testid="context-editor"]', { |
| timeout: 5000, |
| }); |
| } |
| } |
|
|