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:
yoyoyohamapi 2025-04-14 02:42:06 +00:00
parent 11d1b2fae5
commit d494394c8d
58 changed files with 564 additions and 410 deletions

3
.gitignore vendored
View File

@ -85,3 +85,6 @@ packages/frontend/core/public/static/templates
af
af.cmd
*.resolved
# playwright
storageState.json

View File

@ -193,6 +193,7 @@ export const useExplorerCollectionNodeOperations = (
<MenuItem
type={'danger'}
prefixIcon={<DeleteIcon />}
data-testid="collection-delete-button"
onClick={handleDeleteCollection}
>
{t['Delete']()}

View File

@ -145,6 +145,7 @@ export const useExplorerTagNodeOperations = (
type={'danger'}
prefixIcon={<DeleteIcon />}
onClick={handleMoveToTrash}
data-testid="tag-delete-button"
>
{t['Delete']()}
</MenuItem>

View File

@ -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('AIAction/BrainstormIdeasWithMindMap', () => {
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 generate a mind map for the selected content', async ({
page,
loggedInPage: page,
utils,
}) => {
const { brainstormMindMap } = await utils.editor.askAIWithText(
@ -25,7 +22,7 @@ test.describe('AIAction/BrainstormIdeasWithMindMap', () => {
});
test('should generate a mind map for the selected text block in edgeless', async ({
page,
loggedInPage: page,
utils,
}) => {
const { brainstormMindMap } = await utils.editor.askAIWithEdgeless(
@ -40,7 +37,7 @@ test.describe('AIAction/BrainstormIdeasWithMindMap', () => {
});
test('should generate a mind map for the selected note block in edgeless', async ({
page,
loggedInPage: page,
utils,
}) => {
const { brainstormMindMap } = await utils.editor.askAIWithEdgeless(

View File

@ -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('AIAction/ChangeTone', () => {
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 changing the tone of the selected content', async ({
page,
loggedInPage: page,
utils,
}) => {
const { changeTone } = await utils.editor.askAIWithText(
@ -25,7 +22,7 @@ test.describe('AIAction/ChangeTone', () => {
});
test('should support changing the tone of the selected text block in edgeless', async ({
page,
loggedInPage: page,
utils,
}) => {
const { changeTone } = await utils.editor.askAIWithEdgeless(
@ -44,7 +41,7 @@ test.describe('AIAction/ChangeTone', () => {
});
test('should support changing the tone of the selected note block in edgeless', async ({
page,
loggedInPage: page,
utils,
}) => {
const { changeTone } = await utils.editor.askAIWithEdgeless(
@ -62,7 +59,10 @@ test.describe('AIAction/ChangeTone', () => {
expect(responses).toEqual(new Set(['insert-below']));
});
test('should show chat history in chat panel', async ({ page, utils }) => {
test('should show chat history in chat panel', async ({
loggedInPage: page,
utils,
}) => {
const { changeTone } = await utils.editor.askAIWithText(
page,
'AFFiNE is a great note-taking app'

View File

@ -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('AIAction/CheckCodeError', () => {
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 check code error', async ({ page, utils }) => {
test('should support check code error', async ({
loggedInPage: page,
utils,
}) => {
const { checkCodeError } = await utils.editor.askAIWithCode(
page,
'consloe.log("Hello,World!");',
@ -24,7 +24,10 @@ test.describe('AIAction/CheckCodeError', () => {
);
});
test('should show chat history in chat panel', async ({ page, utils }) => {
test('should show chat history in chat panel', async ({
loggedInPage: page,
utils,
}) => {
const { checkCodeError } = await utils.editor.askAIWithCode(
page,
'consloe.log("Hello,World!");',

View File

@ -1,16 +1,16 @@
import { loginUser } from '@affine-test/kit/utils/cloud';
import { expect } from '@playwright/test';
import { test } from '../base/base-test';
test.describe('AIAction/ContinueWithAI', () => {
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);
});
test('should support continue in chat panel', async ({ page, utils }) => {
test('should support continue in chat panel', async ({
loggedInPage: page,
utils,
}) => {
const { continueWithAi } = await utils.editor.askAIWithText(page, 'Apple');
await continueWithAi();
const chatPanelInput = await page.getByTestId('chat-panel-input-container');

View File

@ -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('AIAction/ContinueWriting', () => {
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 continue writing the selected content', async ({
page,
loggedInPage: page,
utils,
}) => {
await page.setViewportSize({ width: 1280, height: 2000 });
@ -26,7 +23,7 @@ test.describe('AIAction/ContinueWriting', () => {
});
test('should support continue writing the selected text block in edgeless', async ({
page,
loggedInPage: page,
utils,
}) => {
const { continueWriting } = await utils.editor.askAIWithEdgeless(
@ -45,7 +42,7 @@ test.describe('AIAction/ContinueWriting', () => {
});
test('should support continue writing the selected note block in edgeless', async ({
page,
loggedInPage: page,
utils,
}) => {
const { continueWriting } = await utils.editor.askAIWithEdgeless(
@ -63,7 +60,10 @@ test.describe('AIAction/ContinueWriting', () => {
expect(responses).toEqual(new Set(['insert-below']));
});
test('should show chat history in chat panel', async ({ page, utils }) => {
test('should show chat history in chat panel', async ({
loggedInPage: page,
utils,
}) => {
const { continueWriting } = await utils.editor.askAIWithText(
page,
'AFFiNE is a workspace with fully merged docs'

View File

@ -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('expand mindmap node', () => {
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 expand the mindmap node', async ({ page, utils }) => {
test('should expand the mindmap node', async ({
loggedInPage: page,
utils,
}) => {
let id: string;
const { expandMindMapNode } = await utils.editor.askAIWithEdgeless(
page,

View File

@ -1,17 +1,14 @@
import { loginUser } from '@affine-test/kit/utils/cloud';
import { expect } from '@playwright/test';
import { test } from '../base/base-test';
test.describe('AIAction/ExplainCode', () => {
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 explain code', async ({ page, utils }) => {
test('should support explain code', async ({ loggedInPage: page, utils }) => {
const { explainCode } = await utils.editor.askAIWithCode(
page,
'console.log("Hello, World!");',
@ -21,7 +18,10 @@ test.describe('AIAction/ExplainCode', () => {
await expect(answer).toHaveText(/console.log/);
});
test('should show chat history in chat panel', async ({ page, utils }) => {
test('should show chat history in chat panel', async ({
loggedInPage: page,
utils,
}) => {
const { explainCode } = await utils.editor.askAIWithCode(
page,
'console.log("Hello, World!");',

View File

@ -1,4 +1,3 @@
import { loginUser } from '@affine-test/kit/utils/cloud';
import { expect } from '@playwright/test';
import { test } from '../base/base-test';
@ -13,15 +12,13 @@ const image = {
};
test.describe('AIAction/ExplainImage', () => {
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 explaining the selected image', async ({
page,
loggedInPage: page,
utils,
}) => {
const { explainImage } = await utils.editor.askAIWithImage(page, image);
@ -30,7 +27,10 @@ test.describe('AIAction/ExplainImage', () => {
expect(responses).toEqual(new Set(['insert-below', 'replace-selection']));
});
test('should show chat history in chat panel', async ({ page, utils }) => {
test('should show chat history in chat panel', async ({
loggedInPage: page,
utils,
}) => {
const { explainImage } = await utils.editor.askAIWithImage(page, image);
const { answer } = await explainImage();
const insertBelow = answer.getByTestId('answer-insert-below');

View File

@ -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('AIAction/ExplainSelection', () => {
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 explaining the selected content', async ({
page,
loggedInPage: page,
utils,
}) => {
const { explainSelection } = await utils.editor.askAIWithText(
@ -25,7 +22,7 @@ test.describe('AIAction/ExplainSelection', () => {
});
test('should support explaining the selected text block in edgeless', async ({
page,
loggedInPage: page,
utils,
}) => {
const { explainSelection } = await utils.editor.askAIWithEdgeless(
@ -41,7 +38,7 @@ test.describe('AIAction/ExplainSelection', () => {
});
test('should support explaining the selected note block in edgeless', async ({
page,
loggedInPage: page,
utils,
}) => {
const { explainSelection } = await utils.editor.askAIWithEdgeless(
@ -56,7 +53,10 @@ test.describe('AIAction/ExplainSelection', () => {
expect(responses).toEqual(new Set(['insert-below']));
});
test('should show chat history in chat panel', async ({ page, utils }) => {
test('should show chat history in chat panel', async ({
loggedInPage: page,
utils,
}) => {
const { explainSelection } = await utils.editor.askAIWithText(page, 'LLM');
const { answer } = await explainSelection();
const replace = answer.getByTestId('answer-replace');

View File

@ -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('AIAction/FindActions', () => {
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 find actions for selected content', async ({ page, utils }) => {
test('should find actions for selected content', async ({
loggedInPage: page,
utils,
}) => {
const { findActions } = await utils.editor.askAIWithText(
page,
`Choose a Booking Platform
@ -39,7 +39,7 @@ Compare and Select Flights`
});
test('should find actions for selected text block in edgeless', async ({
page,
loggedInPage: page,
utils,
}) => {
const { findActions } = await utils.editor.askAIWithEdgeless(
@ -71,7 +71,7 @@ Compare and Select Flights`
});
test('should find actions for selected note block in edgeless', async ({
page,
loggedInPage: page,
utils,
}) => {
const { findActions } = await utils.editor.askAIWithEdgeless(
@ -102,7 +102,10 @@ Compare and Select Flights`
expect(responses).toEqual(new Set(['insert-below']));
});
test('should show chat history in chat panel', async ({ page, utils }) => {
test('should show chat history in chat panel', async ({
loggedInPage: page,
utils,
}) => {
const { findActions } = await utils.editor.askAIWithText(
page,
`Choose a Booking Platform

View File

@ -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('AIAction/FixGrammar', () => {
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 fixing grammatical errors in the selected content', async ({
page,
loggedInPage: page,
utils,
}) => {
const { fixGrammar } = await utils.editor.askAIWithText(
@ -25,7 +22,7 @@ test.describe('AIAction/FixGrammar', () => {
});
test('should support fixing grammatical errors in the selected text block in edgeless', async ({
page,
loggedInPage: page,
utils,
}) => {
const { fixGrammar } = await utils.editor.askAIWithEdgeless(
@ -41,7 +38,7 @@ test.describe('AIAction/FixGrammar', () => {
});
test('should support fixing grammatical errors in the selected note block in edgeless', async ({
page,
loggedInPage: page,
utils,
}) => {
const { fixGrammar } = await utils.editor.askAIWithEdgeless(
@ -56,7 +53,10 @@ test.describe('AIAction/FixGrammar', () => {
expect(responses).toEqual(new Set(['insert-below']));
});
test('should show chat history in chat panel', async ({ page, utils }) => {
test('should show chat history in chat panel', async ({
loggedInPage: page,
utils,
}) => {
const { fixGrammar } = await utils.editor.askAIWithText(
page,
'I is a student'

View File

@ -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('AIAction/FixSpelling', () => {
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 fixing spelling errors in the selected content', async ({
page,
loggedInPage: page,
utils,
}) => {
const { fixSpelling } = await utils.editor.askAIWithText(page, 'Appel');
@ -22,7 +19,7 @@ test.describe('AIAction/FixSpelling', () => {
});
test('should support fixing spelling errors in the selected text block in edgeless', async ({
page,
loggedInPage: page,
utils,
}) => {
const { fixSpelling } = await utils.editor.askAIWithEdgeless(
@ -38,7 +35,7 @@ test.describe('AIAction/FixSpelling', () => {
});
test('should support fixing spelling errors in the selected note block in edgeless', async ({
page,
loggedInPage: page,
utils,
}) => {
const { fixSpelling } = await utils.editor.askAIWithEdgeless(
@ -53,7 +50,10 @@ test.describe('AIAction/FixSpelling', () => {
expect(responses).toEqual(new Set(['insert-below']));
});
test('should show chat history in chat panel', async ({ page, utils }) => {
test('should show chat history in chat panel', async ({
loggedInPage: page,
utils,
}) => {
const { fixSpelling } = await utils.editor.askAIWithText(page, 'Appel');
const { answer } = await fixSpelling();
await expect(answer).toHaveText(/Apple/, { timeout: 10000 });

View File

@ -1,4 +1,3 @@
import { loginUser } from '@affine-test/kit/utils/cloud';
import { expect } from '@playwright/test';
import { test } from '../base/base-test';
@ -13,15 +12,13 @@ const image = {
};
test.describe('AIAction/GenerateAnImageWithImage', () => {
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 generate an image for the selected image', async ({
page,
loggedInPage: page,
utils,
}) => {
const { generateImage } = await utils.editor.askAIWithImage(page, image);
@ -30,7 +27,10 @@ test.describe('AIAction/GenerateAnImageWithImage', () => {
expect(responses).toEqual(new Set(['insert-below']));
});
test('should show chat history in chat panel', async ({ page, utils }) => {
test('should show chat history in chat panel', async ({
loggedInPage: page,
utils,
}) => {
const { generateImage } = await utils.editor.askAIWithImage(page, image);
const { answer } = await generateImage();
await expect(answer.getByTestId('ai-answer-image')).toBeVisible();

View File

@ -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('AIAction/GenerateAnImageWithText', () => {
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 generate an image for the selected content', async ({
page,
loggedInPage: page,
utils,
}) => {
const { generateImage } = await utils.editor.askAIWithText(page, 'Panda');
@ -22,7 +19,7 @@ test.describe('AIAction/GenerateAnImageWithText', () => {
});
test('should generate an image for the selected text block in edgeless', async ({
page,
loggedInPage: page,
utils,
}) => {
const { generateImage } = await utils.editor.askAIWithEdgeless(
@ -37,7 +34,7 @@ test.describe('AIAction/GenerateAnImageWithText', () => {
});
test('should generate an image for the selected note block in edgeless', async ({
page,
loggedInPage: page,
utils,
}) => {
const { generateImage } = await utils.editor.askAIWithEdgeless(
@ -52,7 +49,7 @@ test.describe('AIAction/GenerateAnImageWithText', () => {
});
test('should generate an image for the selected shape in edgeless', async ({
page,
loggedInPage: page,
utils,
}) => {
const { generateImage } = await utils.editor.askAIWithEdgeless(
@ -66,7 +63,10 @@ test.describe('AIAction/GenerateAnImageWithText', () => {
expect(responses).toEqual(new Set(['insert-below']));
});
test('should show chat history in chat panel', async ({ page, utils }) => {
test('should show chat history in chat panel', async ({
loggedInPage: page,
utils,
}) => {
const { generateImage } = await utils.editor.askAIWithText(page, 'Panda');
const { answer } = await generateImage();
const insert = answer.getByTestId('answer-insert-below');

View File

@ -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('AIAction/GenerateHeadings', () => {
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 generate headings for selected content', async ({
page,
loggedInPage: page,
utils,
}) => {
const { generateHeadings } = await utils.editor.askAIWithText(
@ -30,7 +27,7 @@ test.describe('AIAction/GenerateHeadings', () => {
});
test('should generate headings for selected text block in edgeless', async ({
page,
loggedInPage: page,
utils,
}) => {
const { generateHeadings } = await utils.editor.askAIWithEdgeless(
@ -54,7 +51,7 @@ test.describe('AIAction/GenerateHeadings', () => {
});
test('should generate headings for selected note block in edgeless', async ({
page,
loggedInPage: page,
utils,
}) => {
const { generateHeadings } = await utils.editor.askAIWithEdgeless(
@ -77,7 +74,10 @@ test.describe('AIAction/GenerateHeadings', () => {
expect(responses).toEqual(new Set(['insert-below']));
});
test('should show chat history in chat panel', async ({ page, utils }) => {
test('should show chat history in chat panel', async ({
loggedInPage: page,
utils,
}) => {
const { generateHeadings } = await utils.editor.askAIWithText(
page,
'AFFiNE is a workspace with fully merged docs'

View File

@ -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('AIAction/GenerateImageCaption', () => {
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 generate image caption', async ({ page, utils }) => {
test('should generate image caption', async ({
loggedInPage: page,
utils,
}) => {
const { generateCaption } = await utils.editor.askAIWithImage(page, image);
const { answer, responses } = await generateCaption();
await expect(answer).toHaveText(/cat|kitten/i);
@ -29,7 +29,10 @@ test.describe('AIAction/GenerateImageCaption', () => {
);
});
test('should show chat history in chat panel', async ({ page, utils }) => {
test('should show chat history in chat panel', async ({
loggedInPage: page,
utils,
}) => {
const { generateCaption } = await utils.editor.askAIWithImage(page, image);
const { answer } = await generateCaption();
await expect(answer).toHaveText(/cat|kitten/i);

View File

@ -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('AIAction/GenerateOutline', () => {
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 generate outline for selected content', async ({
page,
loggedInPage: page,
utils,
}) => {
const { generateOutline } = await utils.editor.askAIWithText(
@ -25,7 +22,7 @@ test.describe('AIAction/GenerateOutline', () => {
});
test('should generate outline for selected text block in edgeless', async ({
page,
loggedInPage: page,
utils,
}) => {
const { generateOutline } = await utils.editor.askAIWithEdgeless(
@ -43,7 +40,7 @@ test.describe('AIAction/GenerateOutline', () => {
});
test('should generate outline for selected note block in edgeless', async ({
page,
loggedInPage: page,
utils,
}) => {
const { generateOutline } = await utils.editor.askAIWithEdgeless(
@ -60,7 +57,10 @@ test.describe('AIAction/GenerateOutline', () => {
expect(responses).toEqual(new Set(['insert-below']));
});
test('should show chat history in chat panel', async ({ page, utils }) => {
test('should show chat history in chat panel', async ({
loggedInPage: page,
utils,
}) => {
const { generateOutline } = await utils.editor.askAIWithText(
page,
'AFFiNE is a workspace with fully merged docs'

View File

@ -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('AIAction/GeneratePresentation', () => {
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 generate a presentation for the selected content', async ({
page,
loggedInPage: page,
utils,
}) => {
const { generatePresentation } = await utils.editor.askAIWithText(
@ -25,7 +22,7 @@ test.describe('AIAction/GeneratePresentation', () => {
});
test('should generate a presentation for the selected text block in edgeless', async ({
page,
loggedInPage: page,
utils,
}) => {
const { generatePresentation } = await utils.editor.askAIWithEdgeless(
@ -43,7 +40,7 @@ test.describe('AIAction/GeneratePresentation', () => {
});
test('should generate a presentation for the selected note block in edgeless', async ({
page,
loggedInPage: page,
utils,
}) => {
const { generatePresentation } = await utils.editor.askAIWithEdgeless(

View File

@ -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,12 @@ const image = {
};
test.describe('AIAction/ImageFilter', () => {
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 image filter', async ({ page, utils }) => {
test('should support image filter', async ({ loggedInPage: page, utils }) => {
const { imageFilter } = await utils.editor.askAIWithImage(page, image);
const { answer, responses } = await imageFilter('pixel-style');
await expect(answer.getByTestId('ai-answer-image')).toBeVisible();

View File

@ -1,4 +1,3 @@
import { loginUser } from '@affine-test/kit/utils/cloud';
import { expect } from '@playwright/test';
import { test } from '../base/base-test';
@ -13,21 +12,25 @@ const image = {
};
test.describe('AIAction/ImageProcessing', () => {
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 image processing', async ({ page, utils }) => {
test('should support image processing', async ({
loggedInPage: page,
utils,
}) => {
const { imageProcessing } = await utils.editor.askAIWithImage(page, image);
const { answer, responses } = await imageProcessing('remove-background');
await expect(answer.getByTestId('ai-answer-image')).toBeVisible();
await expect(responses).toEqual(new Set(['insert-below']));
});
test('should show chat history in chat panel', async ({ page, utils }) => {
test('should show chat history in chat panel', async ({
loggedInPage: page,
utils,
}) => {
const { imageProcessing } = await utils.editor.askAIWithImage(page, image);
const { answer } = await imageProcessing('remove-background');
await expect(answer.getByTestId('ai-answer-image')).toBeVisible();

View File

@ -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('AIAction/ImproveWriting', () => {
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 improving the writing of the selected content', async ({
page,
loggedInPage: page,
utils,
}) => {
const { improveWriting } = await utils.editor.askAIWithText(
@ -25,7 +22,7 @@ test.describe('AIAction/ImproveWriting', () => {
});
test('should support improving the writing of the selected text block in edgeless', async ({
page,
loggedInPage: page,
utils,
}) => {
const { improveWriting } = await utils.editor.askAIWithEdgeless(
@ -40,7 +37,7 @@ test.describe('AIAction/ImproveWriting', () => {
});
test('should support improving the writing of the selected note block in edgeless', async ({
page,
loggedInPage: page,
utils,
}) => {
const { improveWriting } = await utils.editor.askAIWithEdgeless(
@ -54,7 +51,10 @@ test.describe('AIAction/ImproveWriting', () => {
expect(responses).toEqual(new Set(['insert-below']));
});
test('should show chat history in chat panel', async ({ page, utils }) => {
test('should show chat history in chat panel', async ({
loggedInPage: page,
utils,
}) => {
const { improveWriting } = await utils.editor.askAIWithText(
page,
'AFFiNE is so smart'

View File

@ -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('AIAction/MakeItLonger', () => {
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 making the selected content longer', async ({
page,
loggedInPage: page,
utils,
}) => {
const { makeItLonger } = await utils.editor.askAIWithText(
@ -25,7 +22,7 @@ test.describe('AIAction/MakeItLonger', () => {
});
test('should support making the selected text block longer in edgeless', async ({
page,
loggedInPage: page,
utils,
}) => {
const { makeItLonger } = await utils.editor.askAIWithEdgeless(
@ -43,7 +40,7 @@ test.describe('AIAction/MakeItLonger', () => {
});
test('should support making the selected note block longer in edgeless', async ({
page,
loggedInPage: page,
utils,
}) => {
const { makeItLonger } = await utils.editor.askAIWithEdgeless(
@ -60,7 +57,10 @@ test.describe('AIAction/MakeItLonger', () => {
expect(responses).toEqual(new Set(['insert-below']));
});
test('should show chat history in chat panel', async ({ page, utils }) => {
test('should show chat history in chat panel', async ({
loggedInPage: page,
utils,
}) => {
const { makeItLonger } = await utils.editor.askAIWithText(
page,
'AFFiNE is a workspace with fully merged docs'

View File

@ -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('AIAction/MakeItReal', () => {
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 making the selected content to real', async ({
page,
loggedInPage: page,
utils,
}) => {
const { makeItReal } = await utils.editor.askAIWithText(
@ -25,7 +22,7 @@ test.describe('AIAction/MakeItReal', () => {
});
test('should support making the selected text block to real in edgeless', async ({
page,
loggedInPage: page,
utils,
}) => {
const { makeItReal } = await utils.editor.askAIWithEdgeless(
@ -43,7 +40,7 @@ test.describe('AIAction/MakeItReal', () => {
});
test('should support making the selected note block to real in edgeless', async ({
page,
loggedInPage: page,
utils,
}) => {
const { makeItReal } = await utils.editor.askAIWithEdgeless(
@ -61,7 +58,7 @@ test.describe('AIAction/MakeItReal', () => {
});
test('should support making the selected element to real in edgeless', async ({
page,
loggedInPage: page,
utils,
}) => {
const { makeItReal } = await utils.editor.askAIWithEdgeless(
@ -76,7 +73,10 @@ test.describe('AIAction/MakeItReal', () => {
expect(responses).toEqual(new Set(['insert-below']));
});
test('should show chat history in chat panel', async ({ page, utils }) => {
test('should show chat history in chat panel', async ({
loggedInPage: page,
utils,
}) => {
const { makeItReal } = await utils.editor.askAIWithText(
page,
'AFFiNE is a workspace with fully merged docs'

View File

@ -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('AIAction/MakeItShorter', () => {
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 making the selected content shorter', async ({
page,
loggedInPage: page,
utils,
}) => {
const { makeItShorter } = await utils.editor.askAIWithText(
@ -25,7 +22,7 @@ test.describe('AIAction/MakeItShorter', () => {
});
test('should support making the selected text block shorter in edgeless', async ({
page,
loggedInPage: page,
utils,
}) => {
const { makeItShorter } = await utils.editor.askAIWithEdgeless(
@ -43,7 +40,7 @@ test.describe('AIAction/MakeItShorter', () => {
});
test('should support making the selected note block shorter in edgeless', async ({
page,
loggedInPage: page,
utils,
}) => {
const { makeItShorter } = await utils.editor.askAIWithEdgeless(
@ -60,7 +57,10 @@ test.describe('AIAction/MakeItShorter', () => {
expect(responses).toEqual(new Set(['insert-below']));
});
test('should show chat history in chat panel', async ({ page, utils }) => {
test('should show chat history in chat panel', async ({
loggedInPage: page,
utils,
}) => {
const { makeItShorter } = await utils.editor.askAIWithText(
page,
'AFFiNE is a workspace with fully merged docs'

View File

@ -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('AIAction/RegenerateMindMap', () => {
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 regenerate the mind map for mindmap root', async ({
page,
loggedInPage: page,
utils,
}) => {
let id: string;

View File

@ -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('AIAction/Summarize', () => {
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 summarizing the selected content', async ({
page,
loggedInPage: page,
utils,
}) => {
const { summarize } = await utils.editor.askAIWithText(
@ -25,7 +22,7 @@ test.describe('AIAction/Summarize', () => {
});
test('should support summarizing the selected text block in edgeless', async ({
page,
loggedInPage: page,
utils,
}) => {
const { summarize } = await utils.editor.askAIWithEdgeless(
@ -43,7 +40,7 @@ test.describe('AIAction/Summarize', () => {
});
test('should support summarizing the selected note block in edgeless', async ({
page,
loggedInPage: page,
utils,
}) => {
const { summarize } = await utils.editor.askAIWithEdgeless(
@ -60,7 +57,10 @@ test.describe('AIAction/Summarize', () => {
expect(responses).toEqual(new Set(['insert-below']));
});
test('should show chat history in chat panel', async ({ page, utils }) => {
test('should show chat history in chat panel', async ({
loggedInPage: page,
utils,
}) => {
const { summarize } = await utils.editor.askAIWithText(
page,
'AFFiNE is a workspace with fully merged docs'

View File

@ -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('AIAction/Translate', () => {
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 translating the selected content', async ({
page,
loggedInPage: page,
utils,
}) => {
const { translate } = await utils.editor.askAIWithText(page, 'Apple');
@ -22,7 +19,7 @@ test.describe('AIAction/Translate', () => {
});
test('should support translating the selected text block in edgeless', async ({
page,
loggedInPage: page,
utils,
}) => {
const { translate } = await utils.editor.askAIWithEdgeless(
@ -37,7 +34,7 @@ test.describe('AIAction/Translate', () => {
});
test('should support translating the selected note block in edgeless', async ({
page,
loggedInPage: page,
utils,
}) => {
const { translate } = await utils.editor.askAIWithEdgeless(
@ -51,7 +48,10 @@ test.describe('AIAction/Translate', () => {
expect(responses).toEqual(new Set(['insert-below']));
});
test('support show chat history in chat panel', async ({ page, utils }) => {
test('support show chat history in chat panel', async ({
loggedInPage: page,
utils,
}) => {
const { translate } = await utils.editor.askAIWithText(page, 'Apple');
const { answer } = await translate('German');
await expect(answer).toHaveText(/Apfel/, { timeout: 10000 });

View File

@ -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('AIAction/WriteAnArticleAboutThis', () => {
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 generate an article for the selected content', async ({
page,
loggedInPage: page,
utils,
}) => {
const { writeArticle } = await utils.editor.askAIWithText(
@ -25,7 +22,7 @@ test.describe('AIAction/WriteAnArticleAboutThis', () => {
});
test('should support writing an article for the selected text block in edgeless', async ({
page,
loggedInPage: page,
utils,
}) => {
const { writeArticle } = await utils.editor.askAIWithEdgeless(
@ -43,7 +40,7 @@ test.describe('AIAction/WriteAnArticleAboutThis', () => {
});
test('should support writing an article for the selected note block in edgeless', async ({
page,
loggedInPage: page,
utils,
}) => {
const { writeArticle } = await utils.editor.askAIWithEdgeless(
@ -60,7 +57,10 @@ test.describe('AIAction/WriteAnArticleAboutThis', () => {
expect(responses).toEqual(new Set(['insert-below']));
});
test('should show chat history in chat panel', async ({ page, utils }) => {
test('should show chat history in chat panel', async ({
loggedInPage: page,
utils,
}) => {
const { writeArticle } = await utils.editor.askAIWithText(
page,
'AFFiNE is a workspace with fully merged docs'

View File

@ -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('AIAction/WriteAnBlogPostAboutThis', () => {
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 generate an blog post for the selected content', async ({
page,
loggedInPage: page,
utils,
}) => {
const { writeBlogPost } = await utils.editor.askAIWithText(
@ -25,7 +22,7 @@ test.describe('AIAction/WriteAnBlogPostAboutThis', () => {
});
test('should support writing an blog post for the selected text block in edgeless', async ({
page,
loggedInPage: page,
utils,
}) => {
const { writeBlogPost } = await utils.editor.askAIWithEdgeless(
@ -43,7 +40,7 @@ test.describe('AIAction/WriteAnBlogPostAboutThis', () => {
});
test('should support writing an blog post for the selected note block in edgeless', async ({
page,
loggedInPage: page,
utils,
}) => {
const { writeBlogPost } = await utils.editor.askAIWithEdgeless(
@ -60,7 +57,10 @@ test.describe('AIAction/WriteAnBlogPostAboutThis', () => {
expect(responses).toEqual(new Set(['insert-below']));
});
test('should show chat history in chat panel', async ({ page, utils }) => {
test('should show chat history in chat panel', async ({
loggedInPage: page,
utils,
}) => {
const { writeBlogPost } = await utils.editor.askAIWithText(
page,
'AFFiNE is a workspace with fully merged docs'

View File

@ -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('AIAction/WriteAnPoemAboutThis', () => {
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 generate an poem for the selected content', async ({
page,
loggedInPage: page,
utils,
}) => {
const { writePoem } = await utils.editor.askAIWithText(
@ -25,7 +22,7 @@ test.describe('AIAction/WriteAnPoemAboutThis', () => {
});
test('should generate an poem for the selected text block in edgeless', async ({
page,
loggedInPage: page,
utils,
}) => {
const { writePoem } = await utils.editor.askAIWithEdgeless(
@ -43,7 +40,7 @@ test.describe('AIAction/WriteAnPoemAboutThis', () => {
});
test('should generate an poem for the selected note block in edgeless', async ({
page,
loggedInPage: page,
utils,
}) => {
const { writePoem } = await utils.editor.askAIWithEdgeless(
@ -60,7 +57,10 @@ test.describe('AIAction/WriteAnPoemAboutThis', () => {
expect(responses).toEqual(new Set(['insert-below']));
});
test('should show chat history in chat panel', async ({ page, utils }) => {
test('should show chat history in chat panel', async ({
loggedInPage: page,
utils,
}) => {
const { writePoem } = await utils.editor.askAIWithText(
page,
'AFFiNE is a workspace with fully merged docs'

View File

@ -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('AIAction/WriteAnTweetAboutThis', () => {
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 generate an tweet for the selected content', async ({
page,
loggedInPage: page,
utils,
}) => {
const { writeTwitterPost } = await utils.editor.askAIWithText(
@ -25,7 +22,7 @@ test.describe('AIAction/WriteAnTweetAboutThis', () => {
});
test('should generate an tweet for the selected text block in edgeless', async ({
page,
loggedInPage: page,
utils,
}) => {
const { writeTwitterPost } = await utils.editor.askAIWithEdgeless(
@ -43,7 +40,7 @@ test.describe('AIAction/WriteAnTweetAboutThis', () => {
});
test('should generate an tweet for the selected note block in edgeless', async ({
page,
loggedInPage: page,
utils,
}) => {
const { writeTwitterPost } = await utils.editor.askAIWithEdgeless(
@ -60,7 +57,10 @@ test.describe('AIAction/WriteAnTweetAboutThis', () => {
expect(responses).toEqual(new Set(['insert-below']));
});
test('should show chat history in chat panel', async ({ page, utils }) => {
test('should show chat history in chat panel', async ({
loggedInPage: page,
utils,
}) => {
const { writeTwitterPost } = await utils.editor.askAIWithText(
page,
'AFFiNE is a workspace with fully merged docs'

View File

@ -1,5 +1,6 @@
// eslint-disable no-empty-pattern
import { test as base } from '@affine-test/kit/playwright';
import type { Page } from '@playwright/test';
import { ChatPanelUtils } from '../utils/chat-panel-utils';
import { EditorUtils } from '../utils/editor-utils';
@ -11,6 +12,7 @@ interface TestUtilsFixtures {
chatPanel: typeof ChatPanelUtils;
editor: typeof EditorUtils;
};
loggedInPage: Page;
}
export const test = base.extend<TestUtilsFixtures>({
@ -22,6 +24,14 @@ export const test = base.extend<TestUtilsFixtures>({
editor: EditorUtils,
});
},
loggedInPage: async ({ browser }, use) => {
const context = await browser.newContext({
storageState: 'storageState.json',
});
const page = await context.newPage();
await use(page);
await context.close();
},
});
export type TestFixtures = typeof test;

View File

@ -4,7 +4,8 @@ import { test } from '../base/base-test';
test.describe('AIBasic/Authority', () => {
test.beforeEach(async ({ page, utils }) => {
await utils.testUtils.setupTestEnvironment(page, false);
// Sign out
await utils.testUtils.setupTestEnvironment(page);
await utils.chatPanel.openChatPanel(page);
});

View File

@ -1,17 +1,16 @@
import { loginUser } from '@affine-test/kit/utils/cloud';
import { expect } from '@playwright/test';
import { test } from '../base/base-test';
test.describe('AIBasic/Chat', () => {
test.beforeEach(async ({ page, utils }) => {
const user = await utils.testUtils.getUser();
await loginUser(page, user);
test.beforeEach(async ({ utils, loggedInPage: page }) => {
await utils.testUtils.setupTestEnvironment(page);
await utils.chatPanel.openChatPanel(page);
});
test('should display empty state when no messages', async ({ page }) => {
test('should display empty state when no messages', async ({
loggedInPage: page,
}) => {
// Verify empty state UI
await expect(page.getByTestId('chat-panel-empty-state')).toBeVisible();
await expect(page.getByTestId('ai-onboarding')).toBeVisible();
@ -22,7 +21,7 @@ test.describe('AIBasic/Chat', () => {
- AI is loading
- AI generating
- AI success
`, async ({ page, utils }) => {
`, async ({ loggedInPage: page, utils }) => {
// Type and send a message
await utils.chatPanel.makeChat(page, 'Introduce AFFiNE to me');
@ -66,7 +65,10 @@ test.describe('AIBasic/Chat', () => {
]);
});
test('should support stop generating', async ({ page, utils }) => {
test('should support stop generating', async ({
loggedInPage: page,
utils,
}) => {
await utils.chatPanel.makeChat(page, 'Introduce AFFiNE to me');
// AI Generating
@ -95,7 +97,7 @@ test.describe('AIBasic/Chat', () => {
});
test('should render ai actions inline if the answer is the last one in the list, otherwise, nest them under the "More" menu', async ({
page,
loggedInPage: page,
utils,
}) => {
await utils.chatPanel.makeChat(page, 'Hello, how can you help me?');
@ -140,7 +142,7 @@ test.describe('AIBasic/Chat', () => {
});
test('should show scroll indicator when there are many messages', async ({
page,
loggedInPage: page,
utils,
}) => {
// Set window height to 100px to ensure scroll indicator appears
@ -188,7 +190,10 @@ test.describe('AIBasic/Chat', () => {
await expect(scrollDownIndicator).not.toBeVisible();
});
test('should show error when request failed', async ({ page, utils }) => {
test('should show error when request failed', async ({
loggedInPage: page,
utils,
}) => {
// Simulate network error by disconnecting
await page.route('**/graphql', route => route.abort('failed'));
@ -199,7 +204,10 @@ test.describe('AIBasic/Chat', () => {
await expect(page.getByTestId('action-retry-button')).toBeVisible();
});
test('should support retrying failed messages', async ({ page, utils }) => {
test('should support retrying failed messages', async ({
loggedInPage: page,
utils,
}) => {
// Simulate network error by disconnecting
await page.route('**/graphql', route => route.abort('failed'));
@ -238,7 +246,10 @@ test.describe('AIBasic/Chat', () => {
]);
});
test('should support retrying question', async ({ page, utils }) => {
test('should support retrying question', async ({
loggedInPage: page,
utils,
}) => {
await utils.chatPanel.makeChat(
page,
'Introduce Large Language Model in under 500 words'
@ -282,7 +293,7 @@ test.describe('AIBasic/Chat', () => {
});
test('should support sending message with button', async ({
page,
loggedInPage: page,
utils,
}) => {
await utils.chatPanel.openChatPanel(page);
@ -300,7 +311,10 @@ test.describe('AIBasic/Chat', () => {
]);
});
test('should support clearing chat', async ({ page, utils }) => {
test('should support clearing chat', async ({
loggedInPage: page,
utils,
}) => {
await utils.chatPanel.openChatPanel(page);
await utils.chatPanel.makeChat(page, 'Hello');
await utils.chatPanel.waitForHistory(page, [
@ -317,7 +331,10 @@ test.describe('AIBasic/Chat', () => {
await utils.chatPanel.waitForHistory(page, []);
});
test('should support copying answer', async ({ page, utils }) => {
test('should support copying answer', async ({
loggedInPage: page,
utils,
}) => {
await utils.chatPanel.openChatPanel(page);
await utils.chatPanel.makeChat(page, 'Hello');
await utils.chatPanel.waitForHistory(page, [

View File

@ -1,4 +1,3 @@
import { loginUser } from '@affine-test/kit/utils/cloud';
import { expect } from '@playwright/test';
import { test } from '../base/base-test';
@ -6,14 +5,12 @@ import { test } from '../base/base-test';
test.describe.configure({ mode: 'parallel' });
test.describe('AIBasic/Onboarding', () => {
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 show AI onboarding', async ({ page }) => {
test('should show AI onboarding', async ({ loggedInPage: page }) => {
await expect(page.getByTestId('ai-onboarding')).toBeVisible();
// Show options
@ -30,7 +27,10 @@ test.describe('AIBasic/Onboarding', () => {
await expect(page.getByTestId('freely-communicate-with-ai')).toBeVisible();
});
test('read a foreign language article with AI', async ({ page, utils }) => {
test('read a foreign language article with AI', async ({
loggedInPage: page,
utils,
}) => {
await page.getByTestId('read-foreign-language-article-with-ai').click();
await utils.editor.isEdgelessMode(page);
@ -38,7 +38,10 @@ test.describe('AIBasic/Onboarding', () => {
await expect(docTitle).toContain('Read a foreign language');
});
test('tidy an article with AI MindMap Action', async ({ page, utils }) => {
test('tidy an article with AI MindMap Action', async ({
loggedInPage: page,
utils,
}) => {
await page.getByTestId('tidy-an-article-with-ai-mindmap-action').click();
await utils.editor.isEdgelessMode(page);
@ -46,7 +49,10 @@ test.describe('AIBasic/Onboarding', () => {
await expect(docTitle).toContain('Tidy');
});
test('add illustrations to the article', async ({ page, utils }) => {
test('add illustrations to the article', async ({
loggedInPage: page,
utils,
}) => {
await page.getByTestId('add-illustrations-to-the-article').click();
await utils.editor.isEdgelessMode(page);
@ -54,7 +60,7 @@ test.describe('AIBasic/Onboarding', () => {
await expect(docTitle).toContain('Add illustrations');
});
test('complete writing with AI', async ({ page, utils }) => {
test('complete writing with AI', async ({ loggedInPage: page, utils }) => {
await page.getByTestId('complete-writing-with-ai').click();
await utils.editor.isEdgelessMode(page);
@ -62,7 +68,7 @@ test.describe('AIBasic/Onboarding', () => {
await expect(docTitle).toContain('Complete writing');
});
test('freely communicate with AI', async ({ page, utils }) => {
test('freely communicate with AI', async ({ loggedInPage: page, utils }) => {
await page.getByTestId('freely-communicate-with-ai').click();
await utils.editor.isEdgelessMode(page);

View File

@ -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 });
});

View File

@ -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();
});

View File

@ -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 });
});
});

View File

@ -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;

View File

@ -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(

View File

@ -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(

View File

@ -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

View File

@ -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 =

View File

@ -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();
});

View File

@ -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');

View File

@ -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('AIInsertion/AddToEdgelessAsNote', () => {
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 only show option in edgeless mode', async ({ page, utils }) => {
test('should only show option in edgeless mode', async ({
loggedInPage: page,
utils,
}) => {
await utils.editor.focusToEditor(page);
await utils.chatPanel.makeChat(page, 'Hello');
@ -37,7 +37,7 @@ test.describe('AIInsertion/AddToEdgelessAsNote', () => {
});
test('should add to edgeless as note in edgeless mode', async ({
page,
loggedInPage: page,
utils,
}) => {
await utils.editor.switchToEdgelessMode(page);

View File

@ -1,19 +1,16 @@
import { loginUser } from '@affine-test/kit/utils/cloud';
import { focusDocTitle } from '@affine-test/kit/utils/editor';
import { expect } from '@playwright/test';
import { test } from '../base/base-test';
test.describe('AIInsertion/Insert', () => {
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 insert content below selected block in page mode', async ({
page,
loggedInPage: page,
utils,
}) => {
// Create tow blocks
@ -53,7 +50,7 @@ test.describe('AIInsertion/Insert', () => {
});
test('should insert content below selected block in edgeless mode', async ({
page,
loggedInPage: page,
utils,
}) => {
await utils.editor.switchToEdgelessMode(page);
@ -92,7 +89,7 @@ test.describe('AIInsertion/Insert', () => {
});
test('should insert content at the end of the page when no block is selected', async ({
page,
loggedInPage: page,
utils,
}) => {
// Create tow blocks
@ -132,7 +129,7 @@ test.describe('AIInsertion/Insert', () => {
});
test('should insert content at the end of the note when no block is selected in edgeless mode', async ({
page,
loggedInPage: page,
utils,
}) => {
await utils.editor.switchToEdgelessMode(page);
@ -166,7 +163,7 @@ test.describe('AIInsertion/Insert', () => {
});
test('should create a new note when no block or note is selected in edgeless mode', async ({
page,
loggedInPage: page,
utils,
}) => {
await utils.editor.switchToEdgelessMode(page);

View File

@ -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('AIInsertion/SaveAsBlock', () => {
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 save content as a chat block in page mode', async ({
page,
loggedInPage: page,
utils,
}) => {
await utils.chatPanel.openChatPanel(page);
@ -42,7 +39,7 @@ test.describe('AIInsertion/SaveAsBlock', () => {
});
test('should save content as a chat block in edgeless mode', async ({
page,
loggedInPage: page,
utils,
}) => {
await utils.editor.switchToEdgelessMode(page);

View File

@ -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('AIInsertion/SaveAsDoc', () => {
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 save content as a doc in page mode', async ({ page, utils }) => {
test('should save content as a doc in page mode', async ({
loggedInPage: page,
utils,
}) => {
await utils.chatPanel.openChatPanel(page);
await utils.chatPanel.makeChat(page, 'Hello');
@ -39,7 +39,7 @@ test.describe('AIInsertion/SaveAsDoc', () => {
});
test('should save content as a doc in edgeless mode', async ({
page,
loggedInPage: page,
utils,
}) => {
await utils.editor.switchToEdgelessMode(page);

View File

@ -238,6 +238,50 @@ export class EditorUtils {
);
}
public static async clearAllCollections(page: Page) {
while (true) {
const collection = await page
.getByTestId('explorer-collections')
.locator('[data-testid^="explorer-collection-"]')
.first();
if (!(await collection.isVisible())) {
break;
}
const collectionContent = await collection.locator('div').first();
await collectionContent.hover();
const more = await collectionContent.getByTestId(
'explorer-tree-node-operation-button'
);
await more.click();
await page.getByTestId('collection-delete-button').click();
}
await page.waitForTimeout(100);
}
public static async clearAllTags(page: Page) {
while (true) {
const tag = await page
.getByTestId('explorer-tags')
.locator('[data-testid^="explorer-tag-"]')
.first();
if (!(await tag.isVisible())) {
break;
}
const tagContent = await tag.locator('div').first();
await tagContent.hover();
const more = await tagContent.getByTestId(
'explorer-tree-node-operation-button'
);
await more.click();
await page.getByTestId('tag-delete-button').click();
}
await page.waitForTimeout(100);
}
public static async createCollectionAndDoc(
page: Page,
collectionName: string,

View File

@ -1,7 +1,4 @@
import {
createRandomAIUser,
enableCloudWorkspace,
} from '@affine-test/kit/utils/cloud';
import { createRandomAIUser } from '@affine-test/kit/utils/cloud';
import { openHomePage, setCoreUrl } from '@affine-test/kit/utils/load-page';
import {
clickNewPageButton,
@ -55,13 +52,14 @@ export class TestUtils {
};
}
public async setupTestEnvironment(page: Page, enableCloud: boolean = true) {
await openHomePage(page);
public async createNewPage(page: Page) {
await clickNewPageButton(page);
await waitForEditorLoad(page);
if (enableCloud) {
await enableCloudWorkspace(page);
}
public async setupTestEnvironment(page: Page) {
await openHomePage(page);
await this.createNewPage(page);
}
public async createTestWorkspace(page: Page, name: string = 'test') {

View File

@ -0,0 +1,35 @@
import fs from 'node:fs';
import {
createRandomAIUser,
enableCloudWorkspace,
loginUserDirectly,
} from '@affine-test/kit/utils/cloud';
import { openHomePage } from '@affine-test/kit/utils/load-page';
import type { Page } from '@playwright/test';
import { chromium } from '@playwright/test';
function getUser() {
return createRandomAIUser();
}
async function setupTestEnvironment(page: Page) {
await openHomePage(page);
await enableCloudWorkspace(page);
}
export default async function globalSetup() {
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto('http://localhost:8080/', { timeout: 240 * 1000 });
const user = await getUser();
await page.getByTestId('sidebar-user-avatar').click({
delay: 200,
timeout: 20 * 1000,
});
await loginUserDirectly(page, user);
await setupTestEnvironment(page);
const state = await page.context().storageState();
fs.writeFileSync('storageState.json', JSON.stringify(state));
await browser.close();
}

View File

@ -6,9 +6,10 @@ import type {
const config: PlaywrightTestConfig = {
testDir: './e2e',
fullyParallel: !process.env.CI,
fullyParallel: true,
timeout: 120_000,
outputDir: testResultDir,
globalSetup: './global-setup.ts',
use: {
baseURL: 'http://localhost:8080/',
browserName:
@ -29,6 +30,8 @@ const config: PlaywrightTestConfig = {
{
command: 'yarn run -T affine dev -p @affine/web',
port: 8080,
stdout: 'ignore',
stderr: 'ignore',
timeout: 120 * 1000,
reuseExistingServer: !process.env.CI,
env: {
@ -40,8 +43,8 @@ const config: PlaywrightTestConfig = {
port: 3010,
timeout: 120 * 1000,
reuseExistingServer: !process.env.CI,
stdout: 'pipe',
stderr: 'pipe',
stdout: 'ignore',
stderr: 'ignore',
env: {
DATABASE_URL:
process.env.DATABASE_URL ??

View File

@ -39,7 +39,7 @@ export async function waitForAllPagesLoad(page: Page) {
export async function clickNewPageButton(page: Page, title?: string) {
await page.getByTestId('sidebar-new-page-button').click({
// default timeout is 5000ms, but it's not enough for the CI first page load
timeout: 8000,
timeout: 20000,
});
await waitForEmptyEditor(page);
if (title) {