mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-16 05:47:09 +08:00
fix(core): can not clear chat-panel history (#10634)
Close [BS-2754](https://linear.app/affine-design/issue/BS-2754). ### What Changed? Use the latest session id and display the corresponding historical messages.
This commit is contained in:
@@ -103,6 +103,19 @@ const clearChat = async (page: Page) => {
|
||||
await page.waitForTimeout(500);
|
||||
};
|
||||
|
||||
const collectHistory = async (page: Page) => {
|
||||
const chatPanel = await page.waitForSelector('.chat-panel-messages');
|
||||
return Promise.all(
|
||||
Array.from(await chatPanel.$$('.message')).map(async m => ({
|
||||
name: await m.$('.user-info').then(i => i?.innerText()),
|
||||
content: await m
|
||||
.$('chat-text')
|
||||
.then(t => t?.$('editor-host'))
|
||||
.then(e => e?.innerText()),
|
||||
}))
|
||||
);
|
||||
};
|
||||
|
||||
const collectChat = async (page: Page) => {
|
||||
await page.waitForTimeout(ONE_SECOND);
|
||||
const chatPanel = await page.waitForSelector('.chat-panel-messages');
|
||||
@@ -117,15 +130,7 @@ const collectChat = async (page: Page) => {
|
||||
const lastMessage = await chatPanel.$$('.message').then(m => m[m.length - 1]);
|
||||
await lastMessage.waitForSelector('chat-copy-more');
|
||||
await page.waitForTimeout(200);
|
||||
return Promise.all(
|
||||
Array.from(await chatPanel.$$('.message')).map(async m => ({
|
||||
name: await m.$('.user-info').then(i => i?.innerText()),
|
||||
content: await m
|
||||
.$('chat-text')
|
||||
.then(t => t?.$('editor-host'))
|
||||
.then(e => e?.innerText()),
|
||||
}))
|
||||
);
|
||||
return collectHistory(page);
|
||||
};
|
||||
|
||||
const focusToEditor = async (page: Page) => {
|
||||
@@ -372,6 +377,18 @@ test.describe('chat panel', () => {
|
||||
).toStrictEqual(contents);
|
||||
});
|
||||
|
||||
test('can save chat to block and clear history', async ({ page }) => {
|
||||
await collectChat(page);
|
||||
expect(await getPageMode(page)).toBe('page');
|
||||
await page.getByTestId('action-save-chat-to-block').click();
|
||||
await page.waitForSelector('affine-edgeless-ai-chat');
|
||||
|
||||
await page.reload();
|
||||
await page.waitForTimeout(200);
|
||||
await clearChat(page);
|
||||
expect((await collectChat(page)).length).toBe(0);
|
||||
});
|
||||
|
||||
test('chat in center peek', async ({ page }) => {
|
||||
const contents = (await collectChat(page)).map(m => m.content);
|
||||
await page.getByTestId('action-save-chat-to-block').click();
|
||||
@@ -678,6 +695,7 @@ test.describe('chat with block', () => {
|
||||
await createLocalWorkspace({ name: 'test' }, page);
|
||||
await clickNewPageButton(page);
|
||||
await pasteTextToPageEditor(page, 'Mac Mini');
|
||||
await openChat(page);
|
||||
});
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
@@ -750,6 +768,19 @@ test.describe('chat with block', () => {
|
||||
} else {
|
||||
expect(await collectTextAnswer(page)).toBeTruthy();
|
||||
}
|
||||
// TODO some actions do not have history yet
|
||||
if (
|
||||
option !== 'Generate presentation' &&
|
||||
option !== 'Brainstorm ideas with mind map'
|
||||
) {
|
||||
const history = await collectHistory(page);
|
||||
expect(history.length).toBe(1);
|
||||
expect(history[0].name).toBe('AFFiNE AI');
|
||||
const discard = await page.waitForSelector('.ai-item-discard');
|
||||
await discard.click();
|
||||
await clearChat(page);
|
||||
expect((await collectHistory(page)).length).toBe(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -887,6 +918,43 @@ test.describe('chat with block', () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test('clear history', async ({ page }) => {
|
||||
await page.reload();
|
||||
await clickSideBarAllPageButton(page);
|
||||
await page.waitForTimeout(200);
|
||||
await createLocalWorkspace({ name: 'test' }, page);
|
||||
await clickNewPageButton(page);
|
||||
await focusToEditor(page);
|
||||
await page.keyboard.type('Mac Mini');
|
||||
await openChat(page);
|
||||
|
||||
await makeChat(page, 'hello');
|
||||
await collectHistory(page);
|
||||
|
||||
await page.waitForSelector('affine-paragraph').then(i => i.click());
|
||||
await page.keyboard.press('ControlOrMeta+A');
|
||||
await page
|
||||
.waitForSelector('page-editor editor-toolbar ask-ai-icon', {
|
||||
state: 'attached',
|
||||
timeout: 10000,
|
||||
})
|
||||
.then(b => b.click());
|
||||
await disableEditorBlank(page);
|
||||
await page
|
||||
.waitForSelector(
|
||||
`.ai-item-${`Fix spelling`.replaceAll(' ', '-').toLowerCase()}`
|
||||
)
|
||||
.then(i => i.click());
|
||||
await collectTextAnswer(page);
|
||||
|
||||
await page.reload();
|
||||
await page.waitForTimeout(1000);
|
||||
const history = await collectHistory(page);
|
||||
expect(history.length).toBe(3);
|
||||
await clearChat(page);
|
||||
expect((await collectHistory(page)).length).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
test.describe('chat with doc', () => {
|
||||
|
||||
Reference in New Issue
Block a user