mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-04 08:38:34 +00:00
@@ -36,6 +36,8 @@ test.describe('AIAction/ImageProcessing', () => {
|
||||
await expect(answer.getByTestId('ai-answer-image')).toBeVisible();
|
||||
const insert = answer.getByTestId('answer-insert-below');
|
||||
await insert.click();
|
||||
await page.reload();
|
||||
|
||||
await utils.chatPanel.waitForHistory(page, [
|
||||
{
|
||||
role: 'action',
|
||||
|
||||
@@ -45,28 +45,30 @@ test.describe('AIBasic/Chat', () => {
|
||||
// Type and send a message
|
||||
await utils.chatPanel.makeChat(
|
||||
page,
|
||||
'Introduce AFFiNE to me. Answer in 50 words.'
|
||||
'Introduce AFFiNE to me. Answer in 500 words.'
|
||||
);
|
||||
|
||||
// AI is loading
|
||||
await utils.chatPanel.waitForHistory(page, [
|
||||
{
|
||||
role: 'user',
|
||||
content: 'Introduce AFFiNE to me. Answer in 50 words.',
|
||||
},
|
||||
{
|
||||
role: 'assistant',
|
||||
status: 'loading',
|
||||
},
|
||||
]);
|
||||
if (!(await page.getByTestId('ai-loading').isVisible())) {
|
||||
// AI is loading
|
||||
await utils.chatPanel.waitForHistory(page, [
|
||||
{
|
||||
role: 'user',
|
||||
content: 'Introduce AFFiNE to me. Answer in 500 words.',
|
||||
},
|
||||
{
|
||||
role: 'assistant',
|
||||
status: 'loading',
|
||||
},
|
||||
]);
|
||||
|
||||
await expect(page.getByTestId('ai-loading')).toBeVisible();
|
||||
await expect(page.getByTestId('ai-loading')).toBeVisible();
|
||||
}
|
||||
|
||||
// AI Generating
|
||||
await utils.chatPanel.waitForHistory(page, [
|
||||
{
|
||||
role: 'user',
|
||||
content: 'Introduce AFFiNE to me. Answer in 50 words.',
|
||||
content: 'Introduce AFFiNE to me. Answer in 500 words.',
|
||||
},
|
||||
{
|
||||
role: 'assistant',
|
||||
@@ -79,7 +81,7 @@ test.describe('AIBasic/Chat', () => {
|
||||
await utils.chatPanel.waitForHistory(page, [
|
||||
{
|
||||
role: 'user',
|
||||
content: 'Introduce AFFiNE to me. Answer in 50 words.',
|
||||
content: 'Introduce AFFiNE to me. Answer in 500 words.',
|
||||
},
|
||||
{
|
||||
role: 'assistant',
|
||||
@@ -94,14 +96,14 @@ test.describe('AIBasic/Chat', () => {
|
||||
}) => {
|
||||
await utils.chatPanel.makeChat(
|
||||
page,
|
||||
'Introduce AFFiNE to me. Answer in 50 words.'
|
||||
'Introduce AFFiNE to me. Answer in 5000 words.'
|
||||
);
|
||||
|
||||
// AI Generating
|
||||
await utils.chatPanel.waitForHistory(page, [
|
||||
{
|
||||
role: 'user',
|
||||
content: 'Introduce AFFiNE to me. Answer in 50 words.',
|
||||
content: 'Introduce AFFiNE to me. Answer in 5000 words.',
|
||||
},
|
||||
{
|
||||
role: 'assistant',
|
||||
@@ -113,7 +115,7 @@ test.describe('AIBasic/Chat', () => {
|
||||
await utils.chatPanel.waitForHistory(page, [
|
||||
{
|
||||
role: 'user',
|
||||
content: 'Introduce AFFiNE to me. Answer in 50 words.',
|
||||
content: 'Introduce AFFiNE to me. Answer in 5000 words.',
|
||||
},
|
||||
{
|
||||
role: 'assistant',
|
||||
@@ -183,13 +185,14 @@ test.describe('AIBasic/Chat', () => {
|
||||
// Type and send a message
|
||||
await utils.chatPanel.makeChat(
|
||||
page,
|
||||
'Hello, write a poem about the moon. Answer in 50 words.'
|
||||
'Hello, give a introduction about the moon. Answer in 500 words.'
|
||||
);
|
||||
|
||||
await utils.chatPanel.waitForHistory(page, [
|
||||
{
|
||||
role: 'user',
|
||||
content: 'Hello, write a poem about the moon. Answer in 50 words.',
|
||||
content:
|
||||
'Hello, give a introduction about the moon. Answer in 500 words.',
|
||||
},
|
||||
{
|
||||
role: 'assistant',
|
||||
|
||||
@@ -2,9 +2,14 @@ import { expect } from '@playwright/test';
|
||||
|
||||
import { test } from '../base/base-test';
|
||||
|
||||
test.describe.configure({ mode: 'serial' });
|
||||
|
||||
test.describe('AIChatWith/Attachments', () => {
|
||||
test.beforeEach(async ({ loggedInPage: page, utils }) => {
|
||||
await utils.testUtils.setupTestEnvironment(page);
|
||||
await utils.testUtils.setupTestEnvironment(
|
||||
page,
|
||||
'claude-sonnet-4@20250514'
|
||||
);
|
||||
await utils.chatPanel.openChatPanel(page);
|
||||
});
|
||||
|
||||
@@ -48,8 +53,10 @@ test.describe('AIChatWith/Attachments', () => {
|
||||
loggedInPage: page,
|
||||
utils,
|
||||
}) => {
|
||||
const textContent1 = 'AttachmentEEee is a cute cat';
|
||||
const textContent2 = 'AttachmentFFff is a cute dog';
|
||||
const randomStr1 = Math.random().toString(36).substring(2, 6);
|
||||
const randomStr2 = Math.random().toString(36).substring(2, 6);
|
||||
const textContent1 = `Attachment${randomStr1} is a cute cat`;
|
||||
const textContent2 = `Attachment${randomStr2} is a cute dog`;
|
||||
const buffer1 = Buffer.from(textContent1);
|
||||
const buffer2 = Buffer.from(textContent2);
|
||||
|
||||
@@ -67,13 +74,13 @@ test.describe('AIChatWith/Attachments', () => {
|
||||
buffer: buffer2,
|
||||
},
|
||||
],
|
||||
'What is AttachmentEEee? What is AttachmentFFff?'
|
||||
`What is Attachment${randomStr1}? What is Attachment${randomStr2}?`
|
||||
);
|
||||
|
||||
await utils.chatPanel.waitForHistory(page, [
|
||||
{
|
||||
role: 'user',
|
||||
content: 'What is AttachmentEEee? What is AttachmentFFff?',
|
||||
content: `What is Attachment${randomStr1}? What is Attachment${randomStr2}?`,
|
||||
},
|
||||
{
|
||||
role: 'assistant',
|
||||
@@ -84,8 +91,8 @@ test.describe('AIChatWith/Attachments', () => {
|
||||
await expect(async () => {
|
||||
const { content, message } =
|
||||
await utils.chatPanel.getLatestAssistantMessage(page);
|
||||
expect(content).toMatch(/AttachmentEEee/);
|
||||
expect(content).toMatch(/AttachmentFFff/);
|
||||
expect(content).toMatch(new RegExp(`Attachment${randomStr1}`));
|
||||
expect(content).toMatch(new RegExp(`Attachment${randomStr2}`));
|
||||
expect(await message.locator('affine-footnote-node').count()).toBe(2);
|
||||
}).toPass({ timeout: 20000 });
|
||||
});
|
||||
|
||||
@@ -6,7 +6,10 @@ test.describe.configure({ mode: 'serial' });
|
||||
|
||||
test.describe('AIChatWith/Collections', () => {
|
||||
test.beforeEach(async ({ loggedInPage: page, utils }) => {
|
||||
await utils.testUtils.setupTestEnvironment(page);
|
||||
await utils.testUtils.setupTestEnvironment(
|
||||
page,
|
||||
'claude-sonnet-4@20250514'
|
||||
);
|
||||
await utils.chatPanel.openChatPanel(page);
|
||||
await utils.editor.clearAllCollections(page);
|
||||
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
import { createLocalWorkspace } from '@affine-test/kit/utils/workspace';
|
||||
import { faker } from '@faker-js/faker';
|
||||
import { expect } from '@playwright/test';
|
||||
|
||||
import { test } from '../base/base-test';
|
||||
|
||||
test.describe.configure({ mode: 'serial' });
|
||||
|
||||
test.describe('AISettings/Embedding', () => {
|
||||
test.beforeEach(async ({ loggedInPage: page, utils }) => {
|
||||
await utils.testUtils.setupTestEnvironment(page);
|
||||
await utils.testUtils.setupTestEnvironment(
|
||||
page,
|
||||
'claude-sonnet-4@20250514'
|
||||
);
|
||||
await utils.chatPanel.openChatPanel(page);
|
||||
});
|
||||
|
||||
@@ -246,7 +250,7 @@ test.describe('AISettings/Embedding', () => {
|
||||
await createLocalWorkspace({ name: 'test' }, page, false, 'affine-cloud');
|
||||
await utils.settings.openSettingsPanel(page);
|
||||
await utils.settings.enableWorkspaceEmbedding(page);
|
||||
const person = faker.person.fullName();
|
||||
const person = 'test123';
|
||||
|
||||
const hobby1 = Buffer.from(`${person} love climbing`);
|
||||
const hobby2 = Buffer.from(`${person} love skating`);
|
||||
|
||||
@@ -201,7 +201,7 @@ export class ChatPanelUtils {
|
||||
public static async chatWithDoc(page: Page, docName: string) {
|
||||
const withButton = page.getByTestId('chat-panel-with-button');
|
||||
await withButton.hover();
|
||||
await withButton.click();
|
||||
await withButton.click({ delay: 200 });
|
||||
const withMenu = page.getByTestId('ai-add-popover');
|
||||
await withMenu.waitFor({ state: 'visible' });
|
||||
await withMenu.getByText(docName).click();
|
||||
@@ -221,7 +221,7 @@ export class ChatPanelUtils {
|
||||
const fileChooserPromise = page.waitForEvent('filechooser');
|
||||
const withButton = page.getByTestId('chat-panel-with-button');
|
||||
await withButton.hover();
|
||||
await withButton.click();
|
||||
await withButton.click({ delay: 200 });
|
||||
const withMenu = page.getByTestId('ai-add-popover');
|
||||
await withMenu.waitFor({ state: 'visible' });
|
||||
await withMenu.getByTestId('ai-chat-with-files').click();
|
||||
@@ -282,7 +282,7 @@ export class ChatPanelUtils {
|
||||
for (const tag of tags) {
|
||||
const withButton = page.getByTestId('chat-panel-with-button');
|
||||
await withButton.hover();
|
||||
await withButton.click();
|
||||
await withButton.click({ delay: 200 });
|
||||
const withMenu = page.getByTestId('ai-add-popover');
|
||||
await withMenu.waitFor({ state: 'visible' });
|
||||
await withMenu.getByTestId('ai-chat-with-tags').click();
|
||||
@@ -299,7 +299,7 @@ export class ChatPanelUtils {
|
||||
for (const collection of collections) {
|
||||
const withButton = page.getByTestId('chat-panel-with-button');
|
||||
await withButton.hover();
|
||||
await withButton.click();
|
||||
await withButton.click({ delay: 200 });
|
||||
const withMenu = page.getByTestId('ai-add-popover');
|
||||
await withMenu.waitFor({ state: 'visible' });
|
||||
await withMenu.getByTestId('ai-chat-with-collections').click();
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { skipOnboarding } from '@affine-test/kit/playwright';
|
||||
import { createRandomAIUser } from '@affine-test/kit/utils/cloud';
|
||||
import {
|
||||
createRandomAIUser,
|
||||
switchDefaultChatModel,
|
||||
} from '@affine-test/kit/utils/cloud';
|
||||
import { openHomePage, setCoreUrl } from '@affine-test/kit/utils/load-page';
|
||||
import {
|
||||
clickNewPageButton,
|
||||
@@ -58,7 +61,12 @@ export class TestUtils {
|
||||
await waitForEditorLoad(page);
|
||||
}
|
||||
|
||||
public async setupTestEnvironment(page: Page) {
|
||||
public async setupTestEnvironment(
|
||||
page: Page,
|
||||
defaultModel = 'gemini-2.5-flash'
|
||||
) {
|
||||
await switchDefaultChatModel(defaultModel);
|
||||
|
||||
await skipOnboarding(page.context());
|
||||
await openHomePage(page);
|
||||
await this.createNewPage(page);
|
||||
|
||||
@@ -152,6 +152,22 @@ export async function createRandomUser(): Promise<{
|
||||
} as any;
|
||||
}
|
||||
|
||||
export async function switchDefaultChatModel(model: string) {
|
||||
await runPrisma(async client => {
|
||||
const promptId = await client.aiPrompt
|
||||
.findFirst({
|
||||
where: { name: 'Chat With AFFiNE AI' },
|
||||
select: { id: true },
|
||||
})
|
||||
.then(f => f!.id);
|
||||
|
||||
await client.aiPrompt.update({
|
||||
where: { id: promptId },
|
||||
data: { model },
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export async function createRandomAIUser(): Promise<{
|
||||
name: string;
|
||||
email: string;
|
||||
|
||||
Reference in New Issue
Block a user