fix: reference parameters and add test cases (#8740)

Upstreams: https://github.com/toeverything/blocksuite/pull/8689
Closes: AF-1650
This commit is contained in:
fundon
2024-11-12 09:23:57 +00:00
parent 68573aa35e
commit a5bcfb0b14
8 changed files with 376 additions and 44 deletions

View File

@@ -63,3 +63,26 @@ export async function pasteByKeyboard(page: Page) {
await page.keyboard.press('v', { delay: 50 });
await keyUpCtrlOrMeta(page);
}
export async function writeTextToClipboard(page: Page, text: string) {
// paste the url
await page.evaluate(
async ([text]) => {
const clipData = {
'text/plain': text,
};
const e = new ClipboardEvent('paste', {
clipboardData: new DataTransfer(),
});
Object.defineProperty(e, 'target', {
writable: false,
value: document,
});
Object.entries(clipData).forEach(([key, value]) => {
e.clipboardData?.setData(key, value);
});
document.dispatchEvent(e);
},
[text]
);
}