Files
payload/test/helpers.ts
rpfaeffle 942cfec286 feat: add support for hotkeys (#1821)
Co-authored-by: Jacob Fletcher <jacobsfletch@gmail.com>
Co-authored-by: Alessio Gravili <70709113+AlessioGr@users.noreply.github.com>
Co-authored-by: Alessio Gravili <alessio@gravili.de>
Co-authored-by: Jessica Boezwinkle <jessica@trbl.design>
2023-08-14 15:36:49 -04:00

56 lines
1.7 KiB
TypeScript

import type { Page } from '@playwright/test';
import { expect } from '@playwright/test';
import wait from '../src/utilities/wait';
import { devUser } from './credentials';
type FirstRegisterArgs = {
page: Page;
serverURL: string;
};
type LoginArgs = {
page: Page;
serverURL: string;
};
export async function firstRegister(args: FirstRegisterArgs): Promise<void> {
const { page, serverURL } = args;
await page.goto(`${serverURL}/admin`);
await page.fill('#field-email', devUser.email);
await page.fill('#field-password', devUser.password);
await page.fill('#field-confirm-password', devUser.password);
await wait(500);
await page.click('[type=submit]');
await page.waitForURL(`${serverURL}/admin`);
}
export async function login(args: LoginArgs): Promise<void> {
const { page, serverURL } = args;
await page.goto(`${serverURL}/admin`);
await page.fill('#field-email', devUser.email);
await page.fill('#field-password', devUser.password);
await wait(500);
await page.click('[type=submit]');
await page.waitForURL(`${serverURL}/admin`);
}
export async function saveDocHotkeyAndAssert(page: Page): Promise<void> {
const ua = page.evaluate(() => navigator.userAgent);
const isMac = (await ua).includes('Mac OS X');
if (isMac) {
await page.keyboard.down('Meta');
} else {
await page.keyboard.down('Control');
}
await page.keyboard.down('s');
await expect(page.locator('.Toastify')).toContainText('successfully');
}
export async function saveDocAndAssert(page: Page, selector = '#action-save'): Promise<void> {
await page.click(selector, { delay: 100 });
await expect(page.locator('.Toastify')).toContainText('successfully');
expect(page.url()).not.toContain('create');
}