mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-07 01:09:54 +08:00
test(core): common setup for ai tests (#11644)
### TL:DR By sharing initialization logic, accelerate test case execution. ### What Changed * Global setup for copilot e2e * Login * Create Workspace * Enable fully parallel for ci ### Optimization Comparison Comparing with PR [fix(core): ask AI input box in the whiteboard is blocked by the menu …](https://github.com/toeverything/AFFiNE/pull/11634): | | Shard 1 |2|3|4|5|6|7|8| | ------|----|----|----|----|----|---|---|--| |Before|15min|14min|14min|14min|14min|13min|15min|10min| |After|8min|11min|8min|8min|8min|8min|8min|7min| ### Trade-Off Since all copilot use cases currently share a single user and workspace, some test cases need to focus on **isolation** and **independence**. For example, when testing Embedding-related workflows: * Different document contents should be used to avoid interference. * After each test case execution, **cleanup** operations are also required. * Some tests should be configured to **serial** mode. ```ts 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, }) => { // Create two collections await utils.editor.createCollectionAndDoc( page, 'Collection 1', 'CollectionAAaa is a cute dog' ); await utils.chatPanel.chatWithCollections(page, ['Collection 1']); await utils.chatPanel.makeChat(page, 'What is CollectionAAaa(Use English)'); // ... }); test('should support chat with multiple collections', async ({ loggedInPage: page, utils, }) => { // Create two collections await utils.editor.createCollectionAndDoc( page, 'Collection 2', 'CollectionEEee is a cute cat' ); await utils.editor.createCollectionAndDoc( page, 'Collection 3', 'CollectionFFff is a cute dog' ); await utils.chatPanel.chatWithCollections(page, [ 'Collection 2', 'Collection 3', ]); await utils.chatPanel.makeChat( page, 'What is CollectionEEee? What is CollectionFFff?(Use English)' ); // ... }); }); ``` > CLOSE AI-51
This commit is contained in:
@@ -1,18 +1,18 @@
|
||||
import { loginUser } from '@affine-test/kit/utils/cloud';
|
||||
import { expect } from '@playwright/test';
|
||||
|
||||
import { test } from '../base/base-test';
|
||||
|
||||
test.describe('AIChatWith/Attachments', () => {
|
||||
test.beforeEach(async ({ page, utils }) => {
|
||||
const user = await utils.testUtils.getUser();
|
||||
await loginUser(page, user);
|
||||
test.beforeEach(async ({ loggedInPage: page, utils }) => {
|
||||
await utils.testUtils.setupTestEnvironment(page);
|
||||
await utils.chatPanel.openChatPanel(page);
|
||||
});
|
||||
|
||||
test('support chat with attachment', async ({ page, utils }) => {
|
||||
const textContent = 'EEee is a cute cat';
|
||||
test('support chat with attachment', async ({
|
||||
loggedInPage: page,
|
||||
utils,
|
||||
}) => {
|
||||
const textContent = 'AttachmentEEee is a cute cat';
|
||||
const buffer = Buffer.from(textContent);
|
||||
|
||||
await utils.chatPanel.chatWithAttachments(
|
||||
@@ -24,13 +24,13 @@ test.describe('AIChatWith/Attachments', () => {
|
||||
buffer: buffer,
|
||||
},
|
||||
],
|
||||
'What is EEee?'
|
||||
'What is AttachmentEEee?'
|
||||
);
|
||||
|
||||
await utils.chatPanel.waitForHistory(page, [
|
||||
{
|
||||
role: 'user',
|
||||
content: 'What is EEee?',
|
||||
content: 'What is AttachmentEEee?',
|
||||
},
|
||||
{
|
||||
role: 'assistant',
|
||||
@@ -44,9 +44,12 @@ test.describe('AIChatWith/Attachments', () => {
|
||||
}).toPass({ timeout: 10000 });
|
||||
});
|
||||
|
||||
test('support chat with multiple attachments', async ({ page, utils }) => {
|
||||
const textContent1 = 'EEee is a cute cat';
|
||||
const textContent2 = 'FFff is a cute dog';
|
||||
test('support chat with multiple attachments', async ({
|
||||
loggedInPage: page,
|
||||
utils,
|
||||
}) => {
|
||||
const textContent1 = 'AttachmentEEee is a cute cat';
|
||||
const textContent2 = 'AttachmentFFff is a cute dog';
|
||||
const buffer1 = Buffer.from(textContent1);
|
||||
const buffer2 = Buffer.from(textContent2);
|
||||
|
||||
@@ -64,13 +67,13 @@ test.describe('AIChatWith/Attachments', () => {
|
||||
buffer: buffer2,
|
||||
},
|
||||
],
|
||||
'What is EEee? What is FFff?'
|
||||
'What is AttachmentEEee? What is AttachmentFFff?'
|
||||
);
|
||||
|
||||
await utils.chatPanel.waitForHistory(page, [
|
||||
{
|
||||
role: 'user',
|
||||
content: 'What is EEee? What is FFff?',
|
||||
content: 'What is AttachmentEEee? What is AttachmentFFff?',
|
||||
},
|
||||
{
|
||||
role: 'assistant',
|
||||
@@ -81,8 +84,8 @@ test.describe('AIChatWith/Attachments', () => {
|
||||
await expect(async () => {
|
||||
const { content, message } =
|
||||
await utils.chatPanel.getLatestAssistantMessage(page);
|
||||
expect(content).toMatch(/EEee/);
|
||||
expect(content).toMatch(/FFff/);
|
||||
expect(content).toMatch(/AttachmentEEee/);
|
||||
expect(content).toMatch(/AttachmentFFff/);
|
||||
expect(await message.locator('affine-footnote-node').count()).toBe(2);
|
||||
}).toPass({ timeout: 20000 });
|
||||
});
|
||||
|
||||
@@ -1,35 +1,40 @@
|
||||
import { loginUser } from '@affine-test/kit/utils/cloud';
|
||||
import { expect } from '@playwright/test';
|
||||
|
||||
import { test } from '../base/base-test';
|
||||
|
||||
test.describe.configure({ mode: 'serial' });
|
||||
|
||||
test.describe('AIChatWith/Collections', () => {
|
||||
test.beforeEach(async ({ page, utils }) => {
|
||||
const user = await utils.testUtils.getUser();
|
||||
await loginUser(page, user);
|
||||
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,
|
||||
}) => {
|
||||
// Create two collections
|
||||
await utils.editor.createCollectionAndDoc(
|
||||
page,
|
||||
'Collection 1',
|
||||
'EEee is a cute cat'
|
||||
'CollectionAAaa is a cute dog'
|
||||
);
|
||||
await utils.editor.createCollectionAndDoc(
|
||||
page,
|
||||
'Collection 2',
|
||||
'FFff is a cute dog'
|
||||
);
|
||||
});
|
||||
|
||||
test('should support chat with collection', async ({ page, utils }) => {
|
||||
await utils.chatPanel.chatWithCollections(page, ['Collection 1']);
|
||||
await utils.chatPanel.makeChat(page, 'What is EEee(Use English)');
|
||||
await utils.chatPanel.makeChat(page, 'What is CollectionAAaa(Use English)');
|
||||
await utils.chatPanel.waitForHistory(page, [
|
||||
{
|
||||
role: 'user',
|
||||
content: 'What is EEee(Use English)',
|
||||
content: 'What is CollectionAAaa(Use English)',
|
||||
},
|
||||
{
|
||||
role: 'assistant',
|
||||
@@ -40,27 +45,40 @@ test.describe('AIChatWith/Collections', () => {
|
||||
await expect(async () => {
|
||||
const { content, message } =
|
||||
await utils.chatPanel.getLatestAssistantMessage(page);
|
||||
expect(content).toMatch(/EEee.*cat/);
|
||||
expect(content).toMatch(/CollectionAAaa.*dog/);
|
||||
expect(await message.locator('affine-footnote-node').count()).toBe(1);
|
||||
}).toPass();
|
||||
});
|
||||
|
||||
test('should support chat with multiple collections', async ({
|
||||
page,
|
||||
loggedInPage: page,
|
||||
utils,
|
||||
}) => {
|
||||
await utils.chatPanel.chatWithCollections(page, [
|
||||
'Collection 1',
|
||||
// Create two collections
|
||||
await utils.editor.createCollectionAndDoc(
|
||||
page,
|
||||
'Collection 2',
|
||||
'CollectionEEee is a cute cat'
|
||||
);
|
||||
|
||||
await utils.editor.createCollectionAndDoc(
|
||||
page,
|
||||
'Collection 3',
|
||||
'CollectionFFff is a cute dog'
|
||||
);
|
||||
|
||||
await utils.chatPanel.chatWithCollections(page, [
|
||||
'Collection 2',
|
||||
'Collection 3',
|
||||
]);
|
||||
await utils.chatPanel.makeChat(
|
||||
page,
|
||||
'What is EEee? What is FFff?(Use English)'
|
||||
'What is CollectionEEee? What is CollectionFFff?(Use English)'
|
||||
);
|
||||
await utils.chatPanel.waitForHistory(page, [
|
||||
{
|
||||
role: 'user',
|
||||
content: 'What is EEee? What is FFff?(Use English)',
|
||||
content: 'What is CollectionEEee? What is CollectionFFff?(Use English)',
|
||||
},
|
||||
{
|
||||
role: 'assistant',
|
||||
@@ -71,8 +89,8 @@ test.describe('AIChatWith/Collections', () => {
|
||||
await expect(async () => {
|
||||
const { content, message } =
|
||||
await utils.chatPanel.getLatestAssistantMessage(page);
|
||||
expect(content).toMatch(/EEee.*cat/);
|
||||
expect(content).toMatch(/FFff.*dog/);
|
||||
expect(content).toMatch(/CollectionEEee.*cat/);
|
||||
expect(content).toMatch(/CollectionFFff.*dog/);
|
||||
expect(await message.locator('affine-footnote-node').count()).toBe(2);
|
||||
}).toPass();
|
||||
});
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { loginUser } from '@affine-test/kit/utils/cloud';
|
||||
import { focusDocTitle } from '@affine-test/kit/utils/editor';
|
||||
import {
|
||||
clickNewPageButton,
|
||||
@@ -9,27 +8,28 @@ import { expect } from '@playwright/test';
|
||||
import { test } from '../base/base-test';
|
||||
|
||||
test.describe('AIChatWith/Doc', () => {
|
||||
test.beforeEach(async ({ page, utils }) => {
|
||||
const user = await utils.testUtils.getUser();
|
||||
await loginUser(page, user);
|
||||
test.beforeEach(async ({ loggedInPage: page, utils }) => {
|
||||
await utils.testUtils.setupTestEnvironment(page);
|
||||
await utils.chatPanel.openChatPanel(page);
|
||||
});
|
||||
|
||||
test('support chat with specified doc', async ({ page, utils }) => {
|
||||
test('support chat with specified doc', async ({
|
||||
loggedInPage: page,
|
||||
utils,
|
||||
}) => {
|
||||
// Initialize the doc
|
||||
await focusDocTitle(page);
|
||||
await page.keyboard.insertText('Test Doc');
|
||||
await page.keyboard.press('Enter');
|
||||
await page.keyboard.insertText('EEee is a cute cat');
|
||||
await page.keyboard.insertText('DocEEee is a cute cat');
|
||||
|
||||
await utils.chatPanel.chatWithDoc(page, 'Test Doc');
|
||||
|
||||
await utils.chatPanel.makeChat(page, 'What is EEee?');
|
||||
await utils.chatPanel.makeChat(page, 'What is DocEEee?');
|
||||
await utils.chatPanel.waitForHistory(page, [
|
||||
{
|
||||
role: 'user',
|
||||
content: 'What is EEee?',
|
||||
content: 'What is DocEEee?',
|
||||
},
|
||||
{
|
||||
role: 'assistant',
|
||||
@@ -39,16 +39,19 @@ test.describe('AIChatWith/Doc', () => {
|
||||
|
||||
await expect(async () => {
|
||||
const { content } = await utils.chatPanel.getLatestAssistantMessage(page);
|
||||
expect(content).toMatch(/EEee/);
|
||||
expect(content).toMatch(/DocEEee/);
|
||||
}).toPass({ timeout: 10000 });
|
||||
});
|
||||
|
||||
test('support chat with specified docs', async ({ page, utils }) => {
|
||||
test('support chat with specified docs', async ({
|
||||
loggedInPage: page,
|
||||
utils,
|
||||
}) => {
|
||||
// Initialize the doc 1
|
||||
await focusDocTitle(page);
|
||||
await page.keyboard.insertText('Test Doc1');
|
||||
await page.keyboard.press('Enter');
|
||||
await page.keyboard.insertText('EEee is a cute cat');
|
||||
await page.keyboard.insertText('DocEEee is a cute cat');
|
||||
|
||||
// Initialize the doc 2
|
||||
await clickNewPageButton(page);
|
||||
@@ -56,16 +59,16 @@ test.describe('AIChatWith/Doc', () => {
|
||||
await focusDocTitle(page);
|
||||
await page.keyboard.insertText('Test Doc2');
|
||||
await page.keyboard.press('Enter');
|
||||
await page.keyboard.insertText('FFff is a cute dog');
|
||||
await page.keyboard.insertText('DocFFff is a cute dog');
|
||||
|
||||
await utils.chatPanel.chatWithDoc(page, 'Test Doc1');
|
||||
await utils.chatPanel.chatWithDoc(page, 'Test Doc2');
|
||||
|
||||
await utils.chatPanel.makeChat(page, 'What is EEee? What is FFff?');
|
||||
await utils.chatPanel.makeChat(page, 'What is DocEEee? What is DocFFff?');
|
||||
await utils.chatPanel.waitForHistory(page, [
|
||||
{
|
||||
role: 'user',
|
||||
content: 'What is EEee? What is FFff?',
|
||||
content: 'What is DocEEee? What is DocFFff?',
|
||||
},
|
||||
{
|
||||
role: 'assistant',
|
||||
@@ -75,8 +78,8 @@ test.describe('AIChatWith/Doc', () => {
|
||||
|
||||
await expect(async () => {
|
||||
const { content } = await utils.chatPanel.getLatestAssistantMessage(page);
|
||||
expect(content).toMatch(/EEee/);
|
||||
expect(content).toMatch(/FFff/);
|
||||
expect(content).toMatch(/DocEEee/);
|
||||
expect(content).toMatch(/DocFFff/);
|
||||
}).toPass({ timeout: 10000 });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { loginUser } from '@affine-test/kit/utils/cloud';
|
||||
import type { EdgelessRootBlockComponent } from '@blocksuite/affine/blocks/root';
|
||||
import type { GfxModel } from '@blocksuite/std/gfx';
|
||||
import { expect } from '@playwright/test';
|
||||
@@ -6,15 +5,13 @@ import { expect } from '@playwright/test';
|
||||
import { test } from '../base/base-test';
|
||||
|
||||
test.describe('AIChatWith/EdgelessMindMap', () => {
|
||||
test.beforeEach(async ({ page, utils }) => {
|
||||
const user = await utils.testUtils.getUser();
|
||||
await loginUser(page, user);
|
||||
test.beforeEach(async ({ loggedInPage: page, utils }) => {
|
||||
await utils.testUtils.setupTestEnvironment(page);
|
||||
await utils.chatPanel.openChatPanel(page);
|
||||
});
|
||||
|
||||
test('should support replace mindmap with the regenerated one', async ({
|
||||
page,
|
||||
loggedInPage: page,
|
||||
utils,
|
||||
}) => {
|
||||
let id: string;
|
||||
|
||||
@@ -1,18 +1,15 @@
|
||||
import { loginUser } from '@affine-test/kit/utils/cloud';
|
||||
import { expect } from '@playwright/test';
|
||||
|
||||
import { test } from '../base/base-test';
|
||||
|
||||
test.describe('AIChatWith/EdgelessNoteBlock', () => {
|
||||
test.beforeEach(async ({ page, utils }) => {
|
||||
const user = await utils.testUtils.getUser();
|
||||
await loginUser(page, user);
|
||||
test.beforeEach(async ({ loggedInPage: page, utils }) => {
|
||||
await utils.testUtils.setupTestEnvironment(page);
|
||||
await utils.chatPanel.openChatPanel(page);
|
||||
});
|
||||
|
||||
test('should support insert a new note block below the current', async ({
|
||||
page,
|
||||
loggedInPage: page,
|
||||
utils,
|
||||
}) => {
|
||||
const { translate } = await utils.editor.askAIWithEdgeless(
|
||||
|
||||
@@ -1,18 +1,15 @@
|
||||
import { loginUser } from '@affine-test/kit/utils/cloud';
|
||||
import { expect } from '@playwright/test';
|
||||
|
||||
import { test } from '../base/base-test';
|
||||
|
||||
test.describe('AIChatWith/EdgelessTextBlock', () => {
|
||||
test.beforeEach(async ({ page, utils }) => {
|
||||
const user = await utils.testUtils.getUser();
|
||||
await loginUser(page, user);
|
||||
test.beforeEach(async ({ loggedInPage: page, utils }) => {
|
||||
await utils.testUtils.setupTestEnvironment(page);
|
||||
await utils.chatPanel.openChatPanel(page);
|
||||
});
|
||||
|
||||
test('should support insert answer below the current text', async ({
|
||||
page,
|
||||
loggedInPage: page,
|
||||
utils,
|
||||
}) => {
|
||||
const { translate } = await utils.editor.askAIWithEdgeless(
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { loginUser } from '@affine-test/kit/utils/cloud';
|
||||
import { expect } from '@playwright/test';
|
||||
|
||||
import { test } from '../base/base-test';
|
||||
@@ -13,14 +12,15 @@ const image = {
|
||||
};
|
||||
|
||||
test.describe('AIChatWith/Image', () => {
|
||||
test.beforeEach(async ({ page, utils }) => {
|
||||
const user = await utils.testUtils.getUser();
|
||||
await loginUser(page, user);
|
||||
test.beforeEach(async ({ loggedInPage: page, utils }) => {
|
||||
await utils.testUtils.setupTestEnvironment(page);
|
||||
await utils.chatPanel.openChatPanel(page);
|
||||
});
|
||||
|
||||
test('should support use the generated caption', async ({ page, utils }) => {
|
||||
test('should support use the generated caption', async ({
|
||||
loggedInPage: page,
|
||||
utils,
|
||||
}) => {
|
||||
const { generateCaption } = await utils.editor.askAIWithImage(page, image);
|
||||
const { answer } = await generateCaption();
|
||||
await expect(answer).toHaveText(/cat|kitten/i);
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,18 +1,15 @@
|
||||
import { loginUser } from '@affine-test/kit/utils/cloud';
|
||||
import { expect } from '@playwright/test';
|
||||
|
||||
import { test } from '../base/base-test';
|
||||
|
||||
test.describe('AIChatWith/Network', () => {
|
||||
test.beforeEach(async ({ page, utils }) => {
|
||||
const user = await utils.testUtils.getUser();
|
||||
await loginUser(page, user);
|
||||
test.beforeEach(async ({ loggedInPage: page, utils }) => {
|
||||
await utils.testUtils.setupTestEnvironment(page);
|
||||
await utils.chatPanel.openChatPanel(page);
|
||||
});
|
||||
|
||||
test('should support chat with network if network search enabled', async ({
|
||||
page,
|
||||
loggedInPage: page,
|
||||
utils,
|
||||
}) => {
|
||||
await utils.chatPanel.enableNetworkSearch(page);
|
||||
@@ -40,7 +37,7 @@ test.describe('AIChatWith/Network', () => {
|
||||
});
|
||||
|
||||
test('should disable chat with image if network search enabled', async ({
|
||||
page,
|
||||
loggedInPage: page,
|
||||
utils,
|
||||
}) => {
|
||||
await utils.chatPanel.enableNetworkSearch(page);
|
||||
@@ -49,7 +46,10 @@ test.describe('AIChatWith/Network', () => {
|
||||
expect(isImageUploadEnabled).toBe(false);
|
||||
});
|
||||
|
||||
test('should prevent network search if disabled', async ({ page, utils }) => {
|
||||
test('should prevent network search if disabled', async ({
|
||||
loggedInPage: page,
|
||||
utils,
|
||||
}) => {
|
||||
await utils.chatPanel.disableNetworkSearch(page);
|
||||
await utils.chatPanel.makeChat(
|
||||
page,
|
||||
@@ -74,7 +74,7 @@ test.describe('AIChatWith/Network', () => {
|
||||
});
|
||||
|
||||
test('should disable network search when chating with image', async ({
|
||||
page,
|
||||
loggedInPage: page,
|
||||
utils,
|
||||
}) => {
|
||||
const image =
|
||||
|
||||
@@ -1,25 +1,32 @@
|
||||
import { loginUser } from '@affine-test/kit/utils/cloud';
|
||||
import { expect } from '@playwright/test';
|
||||
|
||||
import { test } from '../base/base-test';
|
||||
|
||||
test.describe.configure({ mode: 'serial' });
|
||||
|
||||
test.describe('AIChatWith/tags', () => {
|
||||
test.beforeEach(async ({ page, utils }) => {
|
||||
const user = await utils.testUtils.getUser();
|
||||
await loginUser(page, user);
|
||||
test.beforeEach(async ({ loggedInPage: page, utils }) => {
|
||||
await utils.testUtils.setupTestEnvironment(page);
|
||||
await utils.chatPanel.openChatPanel(page);
|
||||
await utils.editor.createTagAndDoc(page, 'Tag 1', 'EEee is a cute cat');
|
||||
await utils.editor.createTagAndDoc(page, 'Tag 2', 'FFff is a cute dog');
|
||||
await utils.editor.clearAllTags(page);
|
||||
await utils.testUtils.createNewPage(page);
|
||||
});
|
||||
|
||||
test('should support chat with tag', async ({ page, utils }) => {
|
||||
test.afterEach(async ({ loggedInPage: page, utils }) => {
|
||||
await utils.editor.clearAllTags(page);
|
||||
});
|
||||
|
||||
test('should support chat with tag', async ({
|
||||
loggedInPage: page,
|
||||
utils,
|
||||
}) => {
|
||||
await utils.editor.createTagAndDoc(page, 'Tag 1', 'TagAAaa is a cute cat');
|
||||
await utils.chatPanel.chatWithTags(page, ['Tag 1']);
|
||||
await utils.chatPanel.makeChat(page, 'What is EEee(Use English)');
|
||||
await utils.chatPanel.makeChat(page, 'What is TagAAaa(Use English)');
|
||||
await utils.chatPanel.waitForHistory(page, [
|
||||
{
|
||||
role: 'user',
|
||||
content: 'What is EEee(Use English)',
|
||||
content: 'What is TagAAaa(Use English)',
|
||||
},
|
||||
{
|
||||
role: 'assistant',
|
||||
@@ -29,21 +36,26 @@ test.describe('AIChatWith/tags', () => {
|
||||
await expect(async () => {
|
||||
const { content, message } =
|
||||
await utils.chatPanel.getLatestAssistantMessage(page);
|
||||
expect(content).toMatch(/EEee.*cat/);
|
||||
expect(content).toMatch(/TagAAaa.*cat/);
|
||||
expect(await message.locator('affine-footnote-node').count()).toBe(1);
|
||||
}).toPass();
|
||||
});
|
||||
|
||||
test('should support chat with multiple tags', async ({ page, utils }) => {
|
||||
await utils.chatPanel.chatWithTags(page, ['Tag 1', 'Tag 2']);
|
||||
test('should support chat with multiple tags', async ({
|
||||
loggedInPage: page,
|
||||
utils,
|
||||
}) => {
|
||||
await utils.editor.createTagAndDoc(page, 'Tag 2', 'TagEEee is a cute cat');
|
||||
await utils.editor.createTagAndDoc(page, 'Tag 3', 'TagFFff is a cute dog');
|
||||
await utils.chatPanel.chatWithTags(page, ['Tag 2', 'Tag 3']);
|
||||
await utils.chatPanel.makeChat(
|
||||
page,
|
||||
'What is EEee? What is FFff?(Use English)'
|
||||
'What is TagEEee? What is TagFFff?(Use English)'
|
||||
);
|
||||
await utils.chatPanel.waitForHistory(page, [
|
||||
{
|
||||
role: 'user',
|
||||
content: 'What is EEee? What is FFff?(Use English)',
|
||||
content: 'What is TagEEee? What is TagFFff?(Use English)',
|
||||
},
|
||||
{
|
||||
role: 'assistant',
|
||||
@@ -53,8 +65,8 @@ test.describe('AIChatWith/tags', () => {
|
||||
await expect(async () => {
|
||||
const { content, message } =
|
||||
await utils.chatPanel.getLatestAssistantMessage(page);
|
||||
expect(content).toMatch(/EEee.*cat/);
|
||||
expect(content).toMatch(/FFff.*dog/);
|
||||
expect(content).toMatch(/TagEEee.*cat/);
|
||||
expect(content).toMatch(/TagFFff.*dog/);
|
||||
expect(await message.locator('affine-footnote-node').count()).toBe(2);
|
||||
}).toPass();
|
||||
});
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import { loginUser } from '@affine-test/kit/utils/cloud';
|
||||
import { expect } from '@playwright/test';
|
||||
|
||||
import { test } from '../base/base-test';
|
||||
|
||||
test.describe('AIChatWith/Text', () => {
|
||||
test.beforeEach(async ({ page, utils }) => {
|
||||
const user = await utils.testUtils.getUser();
|
||||
await loginUser(page, user);
|
||||
test.beforeEach(async ({ loggedInPage: page, utils }) => {
|
||||
await utils.testUtils.setupTestEnvironment(page);
|
||||
await utils.chatPanel.openChatPanel(page);
|
||||
});
|
||||
|
||||
test('should support stop generating', async ({ page, utils }) => {
|
||||
test('should support stop generating', async ({
|
||||
loggedInPage: page,
|
||||
utils,
|
||||
}) => {
|
||||
await utils.editor.askAIWithText(page, 'Appel');
|
||||
await page.getByTestId('action-fix-grammar').click();
|
||||
await expect(page.getByTestId('ai-generating')).toBeVisible();
|
||||
@@ -20,7 +20,7 @@ test.describe('AIChatWith/Text', () => {
|
||||
await expect(page.getByTestId('ai-generating')).not.toBeVisible();
|
||||
});
|
||||
|
||||
test('should support copy answer', async ({ page, utils }) => {
|
||||
test('should support copy answer', async ({ loggedInPage: page, utils }) => {
|
||||
const { translate } = await utils.editor.askAIWithText(page, 'Apple');
|
||||
const { answer } = await translate('German');
|
||||
await expect(answer).toHaveText(/Apfel/, { timeout: 10000 });
|
||||
@@ -33,7 +33,7 @@ test.describe('AIChatWith/Text', () => {
|
||||
expect(clipboardText).toBe('Apfel');
|
||||
});
|
||||
|
||||
test('should support insert below', async ({ page, utils }) => {
|
||||
test('should support insert below', async ({ loggedInPage: page, utils }) => {
|
||||
const { translate } = await utils.editor.askAIWithText(page, 'Apple');
|
||||
const { answer } = await translate('German');
|
||||
await expect(answer).toHaveText(/Apfel/, { timeout: 10000 });
|
||||
@@ -43,7 +43,7 @@ test.describe('AIChatWith/Text', () => {
|
||||
expect(content).toBe('Apple\nApfel');
|
||||
});
|
||||
|
||||
test('should support insert above', async ({ page, utils }) => {
|
||||
test('should support insert above', async ({ loggedInPage: page, utils }) => {
|
||||
const { generateHeadings } = await utils.editor.askAIWithText(
|
||||
page,
|
||||
'AFFiNE'
|
||||
@@ -58,7 +58,10 @@ test.describe('AIChatWith/Text', () => {
|
||||
expect(content).toBe('AFFiNE\nAFFiNE');
|
||||
});
|
||||
|
||||
test('should support replace selection', async ({ page, utils }) => {
|
||||
test('should support replace selection', async ({
|
||||
loggedInPage: page,
|
||||
utils,
|
||||
}) => {
|
||||
const { translate } = await utils.editor.askAIWithText(page, 'Apple');
|
||||
const { answer } = await translate('German');
|
||||
await expect(answer).toHaveText(/Apfel/, { timeout: 10000 });
|
||||
@@ -68,7 +71,10 @@ test.describe('AIChatWith/Text', () => {
|
||||
expect(content).toBe('Apfel');
|
||||
});
|
||||
|
||||
test('should support continue in chat', async ({ page, utils }) => {
|
||||
test('should support continue in chat', async ({
|
||||
loggedInPage: page,
|
||||
utils,
|
||||
}) => {
|
||||
const { translate } = await utils.editor.askAIWithText(page, 'Apple');
|
||||
const { answer } = await translate('German');
|
||||
await expect(answer).toHaveText(/Apfel/, { timeout: 10000 });
|
||||
@@ -79,7 +85,7 @@ test.describe('AIChatWith/Text', () => {
|
||||
await expect(quote).toHaveText(/Apple/, { timeout: 10000 });
|
||||
});
|
||||
|
||||
test('should support regenerate', async ({ page, utils }) => {
|
||||
test('should support regenerate', async ({ loggedInPage: page, utils }) => {
|
||||
const { translate } = await utils.editor.askAIWithText(page, 'Apple');
|
||||
const { answer } = await translate('German');
|
||||
const regenerate = answer.getByTestId('answer-regenerate');
|
||||
@@ -88,14 +94,20 @@ test.describe('AIChatWith/Text', () => {
|
||||
expect(content).toBe('Apple');
|
||||
});
|
||||
|
||||
test('should show error when request failed', async ({ page, utils }) => {
|
||||
test('should show error when request failed', async ({
|
||||
loggedInPage: page,
|
||||
utils,
|
||||
}) => {
|
||||
await page.route('**/graphql', route => route.abort('failed'));
|
||||
await utils.editor.askAIWithText(page, 'Appel');
|
||||
await page.getByTestId('action-fix-spelling').click();
|
||||
await expect(page.getByTestId('ai-error')).toBeVisible();
|
||||
});
|
||||
|
||||
test('should support retry when error', async ({ page, utils }) => {
|
||||
test('should support retry when error', async ({
|
||||
loggedInPage: page,
|
||||
utils,
|
||||
}) => {
|
||||
await page.route('**/graphql', route => route.abort('failed'));
|
||||
await utils.editor.askAIWithText(page, 'Appel');
|
||||
await page.getByTestId('action-fix-spelling').click();
|
||||
@@ -107,7 +119,7 @@ test.describe('AIChatWith/Text', () => {
|
||||
await expect(answer).toHaveText(/Apple/, { timeout: 10000 });
|
||||
});
|
||||
|
||||
test('should support discard', async ({ page, utils }) => {
|
||||
test('should support discard', async ({ loggedInPage: page, utils }) => {
|
||||
const { translate } = await utils.editor.askAIWithText(page, 'Apple');
|
||||
const { answer } = await translate('German');
|
||||
const discard = answer.getByTestId('answer-discard');
|
||||
@@ -117,7 +129,10 @@ test.describe('AIChatWith/Text', () => {
|
||||
expect(content).toBe('Apple');
|
||||
});
|
||||
|
||||
test('should support discard when click outside', async ({ page, utils }) => {
|
||||
test('should support discard when click outside', async ({
|
||||
loggedInPage: page,
|
||||
utils,
|
||||
}) => {
|
||||
const { translate } = await utils.editor.askAIWithText(page, 'Apple');
|
||||
const { answer } = await translate('German');
|
||||
await page.mouse.click(0, 0);
|
||||
@@ -128,7 +143,7 @@ test.describe('AIChatWith/Text', () => {
|
||||
expect(content).toBe('Apple');
|
||||
});
|
||||
|
||||
test('should focus on textarea', async ({ page, utils }) => {
|
||||
test('should focus on textarea', async ({ loggedInPage: page, utils }) => {
|
||||
await utils.editor.askAIWithText(page, 'Apple');
|
||||
|
||||
const textarea = await utils.editor.whatAreYourThoughts(page, 'Coffee');
|
||||
|
||||
Reference in New Issue
Block a user