Files
AFFiNE-Mirror/tests/affine-cloud-copilot/e2e/chat-with/collections.spec.ts
darkskygit 6f9361caee feat(server): trigger workspace embedding (#12328)
fix AI-127

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **New Features**
  - Added automated event handling for workspace updates and document embedding, streamlining document embedding workflows.
  - Introduced detection and queuing of documents needing embedding, excluding ignored documents.
- **Improvements**
  - Enhanced performance of embedding-related searches by filtering results at the database level.
  - Increased concurrency for embedding job processing to improve throughput.
- **Bug Fixes**
  - Improved error handling and fallback for missing document titles during embedding.
  - Added safeguards to skip invalid embedding jobs based on document identifiers.
- **Tests**
  - Expanded test coverage for document embedding and ignored document filtering.
  - Updated end-to-end tests to use dynamic content for improved reliability.
  - Added synchronization waits in document creation utilities to improve test stability.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-05-20 05:16:45 +00:00

104 lines
3.0 KiB
TypeScript

import { expect } from '@playwright/test';
import { test } from '../base/base-test';
test.describe.configure({ mode: 'serial' });
test.describe('AIChatWith/Collections', () => {
test.beforeEach(async ({ loggedInPage: page, utils }) => {
await utils.testUtils.setupTestEnvironment(page);
await utils.chatPanel.openChatPanel(page);
await utils.editor.clearAllCollections(page);
await utils.testUtils.createNewPage(page);
});
test.afterEach(async ({ loggedInPage: page, utils }) => {
// clear all collections
await utils.editor.clearAllCollections(page);
});
test('should support chat with collection', async ({
loggedInPage: page,
utils,
}) => {
const randomStr = Math.random().toString(36).substring(2, 6);
// Create two collections
await utils.editor.createCollectionAndDoc(
page,
'Collection 1',
`Collection${randomStr} is a cute dog`
);
await utils.chatPanel.chatWithCollections(page, ['Collection 1']);
await utils.chatPanel.makeChat(
page,
`What is Collection${randomStr}(Use English)`
);
await utils.chatPanel.waitForHistory(page, [
{
role: 'user',
content: `What is Collection${randomStr}(Use English)`,
},
{
role: 'assistant',
status: 'success',
},
]);
await expect(async () => {
const { content, message } =
await utils.chatPanel.getLatestAssistantMessage(page);
expect(content).toMatch(new RegExp(`Collection${randomStr}.*dog`));
expect(await message.locator('affine-footnote-node').count()).toBe(1);
}).toPass();
});
test('should support chat with multiple collections', async ({
loggedInPage: page,
utils,
}) => {
const randomStr1 = Math.random().toString(36).substring(2, 6);
const randomStr2 = Math.random().toString(36).substring(2, 6);
// Create two collections
await utils.editor.createCollectionAndDoc(
page,
'Collection 2',
`Collection${randomStr1} is a cute cat`
);
await utils.editor.createCollectionAndDoc(
page,
'Collection 3',
`Collection${randomStr2} is a cute dog`
);
await utils.chatPanel.chatWithCollections(page, [
'Collection 2',
'Collection 3',
]);
await utils.chatPanel.makeChat(
page,
`What is Collection${randomStr1}? What is Collection${randomStr2}?(Use English)`
);
await utils.chatPanel.waitForHistory(page, [
{
role: 'user',
content: `What is Collection${randomStr1}? What is Collection${randomStr2}?(Use English)`,
},
{
role: 'assistant',
status: 'success',
},
]);
await expect(async () => {
const { content, message } =
await utils.chatPanel.getLatestAssistantMessage(page);
expect(content).toMatch(new RegExp(`Collection${randomStr1}.*cat`));
expect(content).toMatch(new RegExp(`Collection${randomStr2}.*dog`));
expect(await message.locator('affine-footnote-node').count()).toBe(2);
}).toPass();
});
});