fix(core): ai message resending (#13359)

Close [AI-395](https://linear.app/affine-design/issue/AI-395)

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

* **Bug Fixes**
* Improved chat stability by resetting chat action signals after
processing to prevent repeated triggers.

* **New Features**
* Added end-to-end tests for new chat session creation and chat pinning
functionality to enhance reliability.

* **Enhancements**
* Enhanced chat toolbar with test identifiers and pinned state
attributes for better accessibility and testing.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Co-authored-by: fengmk2 <fengmk2@gmail.com>
This commit is contained in:
Wu Yue
2025-07-30 14:44:44 +08:00
committed by GitHub
parent b61807d005
commit 603f2a1e5a
4 changed files with 94 additions and 1 deletions

View File

@@ -450,4 +450,89 @@ test.describe('AIBasic/Chat', () => {
},
]);
});
test('should support create a new chat after ask ai', async ({
loggedInPage: page,
utils,
}) => {
await utils.chatPanel.closeChatPanel(page);
await utils.editor.askAIWithText(
page,
'AFFiNE is an open source all in one workspace.'
);
await page.keyboard.type('Translate to chinese.');
const sendButton = await page.getByTestId('ai-panel-input-send');
await expect(sendButton).toHaveAttribute('data-active', 'true');
await sendButton.click();
await expect(page.getByTestId('sidebar-tab-content-chat')).toBeVisible();
await utils.chatPanel.waitForHistory(page, [
{
role: 'user',
content:
'AFFiNE is an open source all in one workspace.\nTranslate to chinese.',
},
{
role: 'assistant',
status: 'success',
},
]);
await page.getByTestId('ai-panel-new-chat').click();
await page.waitForTimeout(1000);
await utils.chatPanel.expectToHaveHistory(page, []);
});
test('should support pin chat', async ({ loggedInPage: page, utils }) => {
await utils.chatPanel.openChatPanel(page);
await utils.chatPanel.makeChat(
page,
'Hello, how can you help me? Answer in 50 words.'
);
await utils.chatPanel.waitForHistory(page, [
{
role: 'user',
content: 'Hello, how can you help me? Answer in 50 words.',
},
{
role: 'assistant',
status: 'success',
},
]);
// pinned
await expect(page.getByTestId('ai-panel-pin-chat')).toHaveAttribute(
'data-pinned',
'false'
);
await page.getByTestId('ai-panel-pin-chat').click();
await expect(page.getByTestId('ai-panel-pin-chat')).toHaveAttribute(
'data-pinned',
'true'
);
// create new doc
await utils.editor.createDoc(page, 'Doc 1', 'doc1');
await utils.chatPanel.expectToHaveHistory(page, [
{
role: 'user',
content: 'Hello, how can you help me? Answer in 50 words.',
},
{
role: 'assistant',
status: 'idle',
},
]);
await page.getByTestId('ai-panel-pin-chat').click();
// unpinned
await expect(page.getByTestId('ai-panel-pin-chat')).toHaveAttribute(
'data-pinned',
'false'
);
await utils.editor.createDoc(page, 'Doc 2', 'doc2');
await utils.chatPanel.expectToHaveHistory(page, []);
});
});