mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00:00
refactor(core): workspace mutation effect (#12488)
### TL;DR * refactor: workspace embedding mutation effect * tests: error display for workspace embedding
This commit is contained in:
@@ -43,6 +43,23 @@ test.describe('AISettings/Embedding', () => {
|
||||
await utils.settings.waitForWorkspaceEmbeddingSwitchToBe(page, true);
|
||||
});
|
||||
|
||||
test('should show error message if enable workspace embedding failed', async ({
|
||||
loggedInPage: page,
|
||||
utils,
|
||||
}) => {
|
||||
await utils.settings.enableWorkspaceEmbedding(page);
|
||||
await utils.settings.disableWorkspaceEmbedding(page);
|
||||
await utils.settings.waitForWorkspaceEmbeddingSwitchToBe(page, false);
|
||||
|
||||
await page.context().setOffline(true);
|
||||
await utils.settings.enableWorkspaceEmbedding(page, false);
|
||||
|
||||
await expect(
|
||||
page.getByText(/Failed to update workspace doc embedding enabled/i)
|
||||
).toBeVisible();
|
||||
await page.context().setOffline(false);
|
||||
});
|
||||
|
||||
test('should show embedding progress', async ({
|
||||
loggedInPage: page,
|
||||
utils,
|
||||
@@ -297,6 +314,36 @@ test.describe('AISettings/Embedding', () => {
|
||||
await utils.settings.removeAttachment(page, 'document1.txt');
|
||||
});
|
||||
|
||||
test('should show error message if remove attachment failed', async ({
|
||||
loggedInPage: page,
|
||||
utils,
|
||||
}) => {
|
||||
await utils.settings.enableWorkspaceEmbedding(page);
|
||||
const textContent = 'WorkspaceEBEEE is a cute cat';
|
||||
const attachments = [
|
||||
{
|
||||
name: 'document1.txt',
|
||||
mimeType: 'text/plain',
|
||||
buffer: Buffer.from(textContent),
|
||||
},
|
||||
];
|
||||
await utils.settings.uploadWorkspaceEmbedding(page, attachments);
|
||||
|
||||
const attachmentList = await page.getByTestId(
|
||||
'workspace-embedding-setting-attachment-list'
|
||||
);
|
||||
await expect(
|
||||
attachmentList.getByTestId('workspace-embedding-setting-attachment-item')
|
||||
).toHaveCount(1);
|
||||
|
||||
await page.context().setOffline(true);
|
||||
await utils.settings.clickRemoveAttachment(page, 'document1.txt');
|
||||
await expect(
|
||||
page.getByText(/Failed to remove attachment from embedding/i)
|
||||
).toBeVisible();
|
||||
await page.context().setOffline(false);
|
||||
});
|
||||
|
||||
test('should support remove error attachment directly', async ({
|
||||
loggedInPage: page,
|
||||
utils,
|
||||
@@ -393,4 +440,23 @@ test.describe('AISettings/Embedding', () => {
|
||||
expect(content).toMatch(/I dont know/i);
|
||||
}).toPass({ timeout: 20000 });
|
||||
});
|
||||
|
||||
test('should show error message if update ignored docs failed', async ({
|
||||
loggedInPage: page,
|
||||
utils,
|
||||
}) => {
|
||||
await utils.settings.enableWorkspaceEmbedding(page);
|
||||
await utils.settings.closeSettingsPanel(page);
|
||||
|
||||
await utils.editor.createDoc(page, 'Test Doc', 'HelloWorld');
|
||||
|
||||
// Ignore docs
|
||||
await utils.settings.openSettingsPanel(page);
|
||||
await page.context().setOffline(true);
|
||||
await utils.settings.ignoreDocForEmbedding(page, 'Test Doc', false);
|
||||
await expect(
|
||||
page.getByText(/Failed to update ignored docs/i)
|
||||
).toBeVisible();
|
||||
await page.context().setOffline(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -46,20 +46,30 @@ export class SettingsPanelUtils {
|
||||
await input.click();
|
||||
}
|
||||
|
||||
public static async enableWorkspaceEmbedding(page: Page) {
|
||||
public static async enableWorkspaceEmbedding(
|
||||
page: Page,
|
||||
waitForEnabled = true
|
||||
) {
|
||||
const enabled = await this.isWorkspaceEmbeddingEnabled(page);
|
||||
if (!enabled) {
|
||||
await this.toggleWorkspaceEmbedding(page);
|
||||
}
|
||||
await this.waitForWorkspaceEmbeddingSwitchToBe(page, true);
|
||||
if (waitForEnabled) {
|
||||
await this.waitForWorkspaceEmbeddingSwitchToBe(page, true);
|
||||
}
|
||||
}
|
||||
|
||||
public static async disableWorkspaceEmbedding(page: Page) {
|
||||
public static async disableWorkspaceEmbedding(
|
||||
page: Page,
|
||||
waitForDisabled = true
|
||||
) {
|
||||
const enabled = await this.isWorkspaceEmbeddingEnabled(page);
|
||||
if (enabled) {
|
||||
await this.toggleWorkspaceEmbedding(page);
|
||||
}
|
||||
await this.waitForWorkspaceEmbeddingSwitchToBe(page, false);
|
||||
if (waitForDisabled) {
|
||||
await this.waitForWorkspaceEmbeddingSwitchToBe(page, false);
|
||||
}
|
||||
}
|
||||
|
||||
public static async uploadWorkspaceEmbedding(
|
||||
@@ -102,7 +112,7 @@ export class SettingsPanelUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static async removeAttachment(
|
||||
public static async clickRemoveAttachment(
|
||||
page: Page,
|
||||
attachment: string,
|
||||
shouldConfirm = true
|
||||
@@ -116,6 +126,14 @@ export class SettingsPanelUtils {
|
||||
if (shouldConfirm) {
|
||||
await page.getByTestId('confirm-modal-confirm').click();
|
||||
}
|
||||
}
|
||||
|
||||
public static async removeAttachment(
|
||||
page: Page,
|
||||
attachment: string,
|
||||
shouldConfirm = true
|
||||
) {
|
||||
await this.clickRemoveAttachment(page, attachment, shouldConfirm);
|
||||
await page
|
||||
.getByTestId('workspace-embedding-setting-attachment-item')
|
||||
.filter({ hasText: attachment })
|
||||
@@ -124,7 +142,11 @@ export class SettingsPanelUtils {
|
||||
});
|
||||
}
|
||||
|
||||
public static async ignoreDocForEmbedding(page: Page, doc: string) {
|
||||
public static async ignoreDocForEmbedding(
|
||||
page: Page,
|
||||
doc: string,
|
||||
shouldWaitForRefresh = true
|
||||
) {
|
||||
// Open Dos Searcher
|
||||
const ignoreDocsButton = await page.getByTestId(
|
||||
'workspace-embedding-setting-ignore-docs-button'
|
||||
@@ -137,25 +159,24 @@ export class SettingsPanelUtils {
|
||||
await searchInput.focus();
|
||||
await page.keyboard.insertText(doc);
|
||||
|
||||
const pageListItem = searcher.getByTestId('page-list-item');
|
||||
const pageListItem = searcher.getByTestId('doc-list-item');
|
||||
await expect(pageListItem).toHaveCount(1);
|
||||
const pageListItemTitle = pageListItem.getByTestId(
|
||||
'page-list-item-title-text'
|
||||
);
|
||||
const pageListItemTitle = pageListItem.getByTestId('doc-list-item-title');
|
||||
await expect(pageListItemTitle).toHaveText(doc);
|
||||
|
||||
await pageListItem.getByTestId('affine-checkbox').check();
|
||||
await pageListItem.click();
|
||||
|
||||
await searcher.getByTestId('doc-selector-confirm-button').click();
|
||||
|
||||
const ignoredDocs = await page.getByTestId(
|
||||
'workspace-embedding-setting-ignore-docs-list'
|
||||
);
|
||||
await expect(
|
||||
ignoredDocs
|
||||
.getByTestId('workspace-embedding-setting-ignore-docs-list-item')
|
||||
.filter({ hasText: doc })
|
||||
).toBeVisible();
|
||||
if (shouldWaitForRefresh) {
|
||||
const ignoredDocs = await page.getByTestId(
|
||||
'workspace-embedding-setting-ignore-docs-list'
|
||||
);
|
||||
await expect(
|
||||
ignoredDocs
|
||||
.getByTestId('workspace-embedding-setting-ignore-docs-list-item')
|
||||
.filter({ hasText: doc })
|
||||
).toBeVisible();
|
||||
}
|
||||
}
|
||||
|
||||
public static async clearAllIgnoredDocs(page: Page) {
|
||||
|
||||
Reference in New Issue
Block a user