mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-14 00:26:51 +08:00
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:
@@ -391,6 +391,7 @@ export class AIChatContent extends SignalWatcher(
|
||||
})
|
||||
.catch(console.error);
|
||||
}
|
||||
AIProvider.slots.requestOpenWithChat.next(null);
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
@@ -405,6 +405,7 @@ export class AIChatInput extends SignalWatcher(
|
||||
this.send(input).catch(console.error);
|
||||
}, 0);
|
||||
}
|
||||
AIProvider.slots.requestSendWithChat.next(null);
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
+7
-1
@@ -92,14 +92,20 @@ export class AIChatToolbar extends WithDisposable(ShadowlessElement) {
|
||||
const pinned = this.session?.pinned;
|
||||
return html`
|
||||
<div class="ai-chat-toolbar">
|
||||
<div class="chat-toolbar-icon" @click=${this.onPlusClick}>
|
||||
<div
|
||||
class="chat-toolbar-icon"
|
||||
@click=${this.onPlusClick}
|
||||
data-testid="ai-panel-new-chat"
|
||||
>
|
||||
${PlusIcon()}
|
||||
<affine-tooltip>New Chat</affine-tooltip>
|
||||
</div>
|
||||
<div
|
||||
class="chat-toolbar-icon"
|
||||
@click=${this.onPinClick}
|
||||
data-pinned=${!!pinned}
|
||||
data-disabled=${this.isGenerating}
|
||||
data-testid="ai-panel-pin-chat"
|
||||
>
|
||||
${pinned ? PinedIcon() : PinIcon()}
|
||||
<affine-tooltip>
|
||||
|
||||
@@ -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, []);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user