mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-06 17:43:51 +00:00
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added a toggle in the code block toolbar to show or hide line numbers for individual code blocks. - The display of line numbers now respects both global and per-block settings, allowing more flexible control. - **Style** - Updated styles to hide line numbers when disabled via the new toggle option. - **Tests** - Added end-to-end tests to verify toggling line numbers visibility and undo/redo behavior. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
68 lines
1.8 KiB
TypeScript
68 lines
1.8 KiB
TypeScript
import type { Page } from '@playwright/test';
|
|
|
|
/**
|
|
* @example
|
|
* ```ts
|
|
* const codeBlockController = getCodeBlock(page);
|
|
* const codeBlock = codeBlockController.codeBlock;
|
|
* ```
|
|
*/
|
|
export function getCodeBlock(page: Page) {
|
|
const codeBlock = page.locator('affine-code');
|
|
const languageButton = page.getByTestId('lang-button');
|
|
|
|
const clickLanguageButton = async () => {
|
|
await codeBlock.hover();
|
|
await languageButton.click({ delay: 50 });
|
|
};
|
|
|
|
const langList = page.locator('affine-filterable-list');
|
|
const langFilterInput = langList.locator('#filter-input');
|
|
|
|
const codeToolbar = page.locator('affine-code-toolbar');
|
|
|
|
const copyButton = codeToolbar.getByRole('button', { name: 'Copy code' });
|
|
const captionButton = codeToolbar.getByRole('button', { name: 'Caption' });
|
|
const moreButton = codeToolbar.getByRole('button', { name: 'More' });
|
|
|
|
const menu = page.locator('.more-popup-menu');
|
|
|
|
const openMore = async () => {
|
|
await moreButton.click();
|
|
|
|
const wrapButton = menu.getByRole('button', { name: 'Wrap' });
|
|
const cancelWrapButton = menu.getByRole('button', { name: 'Cancel wrap' });
|
|
const duplicateButton = menu.getByRole('button', { name: 'Duplicate' });
|
|
const deleteButton = menu.getByRole('button', { name: 'Delete' });
|
|
const lineNumberButton = menu.getByRole('button', { name: 'Line number' });
|
|
const cancelLineNumberButton = menu.getByRole('button', {
|
|
name: 'Cancel line number',
|
|
});
|
|
|
|
return {
|
|
menu,
|
|
wrapButton,
|
|
cancelWrapButton,
|
|
duplicateButton,
|
|
deleteButton,
|
|
lineNumberButton,
|
|
cancelLineNumberButton,
|
|
};
|
|
};
|
|
|
|
return {
|
|
codeBlock,
|
|
codeToolbar,
|
|
captionButton,
|
|
languageButton,
|
|
langList,
|
|
copyButton,
|
|
moreButton,
|
|
langFilterInput,
|
|
moreMenu: menu,
|
|
|
|
openMore,
|
|
clickLanguageButton,
|
|
};
|
|
}
|