mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-16 05:47:09 +08:00
@@ -199,9 +199,11 @@ export class ChatPanelUtils {
|
||||
}
|
||||
|
||||
public static async chatWithDoc(page: Page, docName: string) {
|
||||
const withButton = await page.getByTestId('chat-panel-with-button');
|
||||
const withButton = page.getByTestId('chat-panel-with-button');
|
||||
await withButton.hover();
|
||||
await withButton.click();
|
||||
const withMenu = await page.getByTestId('ai-add-popover');
|
||||
const withMenu = page.getByTestId('ai-add-popover');
|
||||
await withMenu.waitFor({ state: 'visible' });
|
||||
await withMenu.getByText(docName).click();
|
||||
await page.getByTestId('chat-panel-chips').getByText(docName);
|
||||
}
|
||||
@@ -221,9 +223,20 @@ export class ChatPanelUtils {
|
||||
await withButton.hover();
|
||||
await withButton.click();
|
||||
const withMenu = page.getByTestId('ai-add-popover');
|
||||
await withMenu.waitFor({ state: 'visible' });
|
||||
await withMenu.getByTestId('ai-chat-with-files').click();
|
||||
const fileChooser = await fileChooserPromise;
|
||||
await fileChooser.setFiles(attachment);
|
||||
|
||||
await expect(async () => {
|
||||
const states = await page
|
||||
.getByTestId('chat-panel-chip')
|
||||
.evaluateAll(elements =>
|
||||
elements.map(el => el.getAttribute('data-state'))
|
||||
);
|
||||
|
||||
expect(states.every(state => state === 'finished')).toBe(true);
|
||||
}).toPass({ timeout: 20000 });
|
||||
}
|
||||
await expect(async () => {
|
||||
const states = await page
|
||||
@@ -267,9 +280,11 @@ export class ChatPanelUtils {
|
||||
|
||||
public static async chatWithTags(page: Page, tags: string[]) {
|
||||
for (const tag of tags) {
|
||||
const withButton = await page.getByTestId('chat-panel-with-button');
|
||||
const withButton = page.getByTestId('chat-panel-with-button');
|
||||
await withButton.hover();
|
||||
await withButton.click();
|
||||
const withMenu = await page.getByTestId('ai-add-popover');
|
||||
const withMenu = page.getByTestId('ai-add-popover');
|
||||
await withMenu.waitFor({ state: 'visible' });
|
||||
await withMenu.getByTestId('ai-chat-with-tags').click();
|
||||
await withMenu.getByText(tag).click();
|
||||
await page.getByTestId('chat-panel-chips').getByText(tag);
|
||||
@@ -282,9 +297,11 @@ export class ChatPanelUtils {
|
||||
|
||||
public static async chatWithCollections(page: Page, collections: string[]) {
|
||||
for (const collection of collections) {
|
||||
const withButton = await page.getByTestId('chat-panel-with-button');
|
||||
const withButton = page.getByTestId('chat-panel-with-button');
|
||||
await withButton.hover();
|
||||
await withButton.click();
|
||||
const withMenu = await page.getByTestId('ai-add-popover');
|
||||
const withMenu = page.getByTestId('ai-add-popover');
|
||||
await withMenu.waitFor({ state: 'visible' });
|
||||
await withMenu.getByTestId('ai-chat-with-collections').click();
|
||||
await withMenu.getByText(collection).click();
|
||||
await page.getByTestId('chat-panel-chips').getByText(collection);
|
||||
|
||||
@@ -207,4 +207,53 @@ export class SettingsPanelUtils {
|
||||
await searcher.getByTestId('doc-selector-confirm-button').click();
|
||||
}
|
||||
}
|
||||
|
||||
private static async waitForEmbeddingStatus(
|
||||
page: Page,
|
||||
timeout: number,
|
||||
status = 'synced'
|
||||
) {
|
||||
await expect(async () => {
|
||||
await this.openSettingsPanel(page);
|
||||
const title = page.getByTestId('embedding-progress-title');
|
||||
// oxlint-disable-next-line prefer-dom-node-dataset
|
||||
const progressAttr = await title.getAttribute('data-progress');
|
||||
expect(progressAttr).not.toBe('loading');
|
||||
|
||||
expect(progressAttr).toBe(status);
|
||||
}).toPass({ timeout });
|
||||
}
|
||||
|
||||
public static async waitForEmbeddingComplete(page: Page, timeout = 30000) {
|
||||
await this.waitForEmbeddingStatus(page, timeout);
|
||||
|
||||
// check embedding progress count
|
||||
await expect(async () => {
|
||||
const count = page.getByTestId('embedding-progress-count');
|
||||
const countText = await count.textContent();
|
||||
if (countText) {
|
||||
const [embedded, total] = countText.split('/').map(Number);
|
||||
expect(embedded).toBe(total);
|
||||
expect(embedded).toBeGreaterThan(0);
|
||||
}
|
||||
}).toPass({ timeout });
|
||||
}
|
||||
|
||||
public static async waitForFileEmbeddingReadiness(
|
||||
page: Page,
|
||||
expectedFileCount: number,
|
||||
timeout = 30000
|
||||
) {
|
||||
await expect(async () => {
|
||||
const attachmentList = page.getByTestId(
|
||||
'workspace-embedding-setting-attachment-list'
|
||||
);
|
||||
const attachmentItems = attachmentList.getByTestId(
|
||||
'workspace-embedding-setting-attachment-item'
|
||||
);
|
||||
await expect(attachmentItems).toHaveCount(expectedFileCount);
|
||||
}).toPass({ timeout });
|
||||
|
||||
await this.waitForEmbeddingComplete(page, timeout);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user