AFFiNE/tests/libs/keyboard.ts
DarkSky 6c2c7dcd48
milestone: publish alpha version (#637)
- document folder
- full-text search
- blob storage
- basic edgeless support

Co-authored-by: tzhangchi <terry.zhangchi@outlook.com>
Co-authored-by: QiShaoXuan <qishaoxuan777@gmail.com>
Co-authored-by: DiamondThree <diamond.shx@gmail.com>
Co-authored-by: MingLiang Wang <mingliangwang0o0@gmail.com>
Co-authored-by: JimmFly <yangjinfei001@gmail.com>
Co-authored-by: Yifeng Wang <doodlewind@toeverything.info>
Co-authored-by: Himself65 <himself65@outlook.com>
Co-authored-by: lawvs <18554747+lawvs@users.noreply.github.com>
Co-authored-by: Qi <474021214@qq.com>
2022-12-30 21:40:15 +08:00

66 lines
1.7 KiB
TypeScript

import type { Page } from '@playwright/test';
const IS_MAC = process.platform === 'darwin';
async function keyDownCtrlOrMeta(page: Page) {
if (IS_MAC) {
await page.keyboard.down('Meta');
} else {
await page.keyboard.down('Control');
}
}
async function keyUpCtrlOrMeta(page: Page) {
if (IS_MAC) {
await page.keyboard.up('Meta');
} else {
await page.keyboard.up('Control');
}
}
// It's not good enough, but better than calling keyDownCtrlOrMeta and keyUpCtrlOrMeta separately
export const withCtrlOrMeta = async (page: Page, fn: () => Promise<void>) => {
await keyDownCtrlOrMeta(page);
await fn();
await keyUpCtrlOrMeta(page);
};
export async function pressEnter(page: Page) {
// avoid flaky test by simulate real user input
await page.keyboard.press('Enter', { delay: 50 });
}
export async function pressTab(page: Page) {
await page.keyboard.press('Tab', { delay: 50 });
}
export async function pressShiftTab(page: Page) {
await page.keyboard.down('Shift');
await page.keyboard.press('Tab', { delay: 50 });
await page.keyboard.up('Shift');
}
export async function pressShiftEnter(page: Page) {
await page.keyboard.down('Shift');
await page.keyboard.press('Enter', { delay: 50 });
await page.keyboard.up('Shift');
}
export async function copyByKeyboard(page: Page) {
await keyDownCtrlOrMeta(page);
await page.keyboard.press('c', { delay: 50 });
await keyUpCtrlOrMeta(page);
}
export async function cutByKeyboard(page: Page) {
await keyDownCtrlOrMeta(page);
await page.keyboard.press('x', { delay: 50 });
await keyUpCtrlOrMeta(page);
}
export async function pasteByKeyboard(page: Page) {
await keyDownCtrlOrMeta(page);
await page.keyboard.press('v', { delay: 50 });
await keyUpCtrlOrMeta(page);
}