mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
### TL:DR fix: cannot input space at the beginning of a blank paragraph > CLOSE BS-3427 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Improved space key handling in the editor: pressing space on an empty AI input now hides the AI panel and inserts a space character back into the editor. - **Bug Fixes** - Prevented the AI panel from processing empty input when space is pressed, ensuring smoother user experience. - **Tests** - Added an end-to-end test verifying that pressing space on an empty AI input hides the AI panel and inserts a space. - **Refactor** - Streamlined event handling logic for space key detection in the editor. - **Chores** - Enhanced editor content retrieval to optionally preserve whitespace while removing invisible characters. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
55 lines
1.7 KiB
TypeScript
55 lines
1.7 KiB
TypeScript
import { expect } from '@playwright/test';
|
|
|
|
import { test } from '../base/base-test';
|
|
|
|
test.describe('AIBasic/Guidance', () => {
|
|
test.beforeEach(async ({ page, utils }) => {
|
|
await utils.testUtils.setupTestEnvironment(page);
|
|
});
|
|
|
|
test('should show AI panel when space is pressed on empty paragraph', async ({
|
|
page,
|
|
utils,
|
|
}) => {
|
|
await utils.editor.focusToEditor(page);
|
|
await page.keyboard.press('Space');
|
|
await expect(page.locator('affine-ai-panel-widget')).toBeVisible();
|
|
});
|
|
|
|
test('should not show AI panel when space is pressed on non-empty paragraph', async ({
|
|
page,
|
|
utils,
|
|
}) => {
|
|
await utils.editor.focusToEditor(page);
|
|
await page.keyboard.insertText('HelloWorld');
|
|
await page.keyboard.press('Space');
|
|
await expect(page.locator('affine-ai-panel-widget')).not.toBeVisible();
|
|
});
|
|
|
|
test('should not show AI panel when space is pressed on non-paragraph block', async ({
|
|
page,
|
|
utils,
|
|
}) => {
|
|
await utils.editor.focusToEditor(page);
|
|
await page.keyboard.insertText('```js');
|
|
await page.keyboard.press('Enter');
|
|
await expect(page.locator('affine-ai-panel-widget')).not.toBeVisible();
|
|
});
|
|
|
|
test('should hide AI panel and insert space back to editor when space is pressed on empty input', async ({
|
|
page,
|
|
utils,
|
|
}) => {
|
|
await utils.editor.focusToEditor(page);
|
|
await page.keyboard.press('Space');
|
|
await expect(page.locator('affine-ai-panel-widget')).toBeVisible();
|
|
|
|
await page.keyboard.press('Space');
|
|
await expect(page.locator('affine-ai-panel-widget')).not.toBeVisible();
|
|
await expect(async () => {
|
|
const content = await utils.editor.getEditorContent(page, false);
|
|
expect(content).toBe(' ');
|
|
}).toPass({ timeout: 5000 });
|
|
});
|
|
});
|