mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 05:14:54 +00:00
Close [AI-260](https://linear.app/affine-design/issue/AI-260) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added theme support to AI chat and message components, enabling dynamic theming based on the current app theme. * Introduced a reactive theme signal to the theme service for improved theme handling. * Integrated notification and theme services across various AI chat, playground, and message components for consistent user experience. * **Refactor** * Simplified component APIs by removing dependencies on editor host and related properties across AI chat, message, and tool components. * Centralized and streamlined clipboard and markdown conversion utilities, reducing external dependencies. * Standardized the interface for context file addition and improved type usage for better consistency. * Reworked notification service to a class-based implementation for improved encapsulation. * Updated AI chat components to use injected notification and theme services instead of host-based retrieval. * **Bug Fixes** * Improved reliability of copy and notification actions by decoupling them from editor host dependencies. * **Chores** * Updated and cleaned up internal imports and removed unused properties to enhance maintainability. * Added test IDs for sidebar close button to improve test reliability. * Updated test prompts in end-to-end tests for consistency. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
76 lines
2.2 KiB
TypeScript
76 lines
2.2 KiB
TypeScript
import { expect } from '@playwright/test';
|
|
|
|
import { test } from '../base/base-test';
|
|
|
|
test.describe('AIInsertion/SaveAsDoc', () => {
|
|
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 ({
|
|
loggedInPage: page,
|
|
utils,
|
|
}) => {
|
|
await utils.chatPanel.openChatPanel(page);
|
|
await utils.chatPanel.makeChat(page, 'Hello. Answer in 50 words.');
|
|
|
|
await utils.chatPanel.waitForHistory(page, [
|
|
{
|
|
role: 'user',
|
|
content: 'Hello. Answer in 50 words.',
|
|
},
|
|
{
|
|
role: 'assistant',
|
|
status: 'success',
|
|
},
|
|
]);
|
|
|
|
// Wait for the assistant answer to be completely rendered
|
|
await page.waitForTimeout(1000);
|
|
const { actions, content } =
|
|
await utils.chatPanel.getLatestAssistantMessage(page);
|
|
await actions.saveAsDoc();
|
|
await page.getByText('New doc created').waitFor({ state: 'visible' });
|
|
|
|
// Verify the ai block is created
|
|
const editorContent = await utils.editor.getEditorContent(page);
|
|
expect(editorContent).toBe(content);
|
|
});
|
|
|
|
test('should save content as a doc in edgeless mode', async ({
|
|
loggedInPage: page,
|
|
utils,
|
|
}) => {
|
|
await utils.editor.switchToEdgelessMode(page);
|
|
|
|
await utils.chatPanel.openChatPanel(page);
|
|
await utils.chatPanel.makeChat(page, 'Hello. Answer in 50 words.');
|
|
|
|
await utils.chatPanel.waitForHistory(page, [
|
|
{
|
|
role: 'user',
|
|
content: 'Hello. Answer in 50 words.',
|
|
},
|
|
{
|
|
role: 'assistant',
|
|
status: 'success',
|
|
},
|
|
]);
|
|
|
|
// Wait for the assistant answer to be completely rendered
|
|
await page.waitForTimeout(1000);
|
|
const { actions, content } =
|
|
await utils.chatPanel.getLatestAssistantMessage(page);
|
|
await actions.saveAsDoc();
|
|
await page.getByText('New doc created').waitFor({ state: 'visible' });
|
|
|
|
// Switch to page mode
|
|
await utils.editor.isPageMode(page);
|
|
|
|
// Verify the ai block is created
|
|
const editorContent = await utils.editor.getEditorContent(page);
|
|
expect(editorContent).toBe(content);
|
|
});
|
|
});
|