48 lines
1.8 KiB
TypeScript
48 lines
1.8 KiB
TypeScript
import { Page, expect } from "@playwright/test";
|
|
|
|
/** Registers a fresh account and lands on the lists page. */
|
|
export async function registerAndLogin(page: Page, email: string) {
|
|
await page.goto("/register");
|
|
await page.fill("#display-name", "Test User");
|
|
await page.fill("#email", email);
|
|
await page.fill("#password", "a-strong-password");
|
|
await page.click('button[type="submit"]');
|
|
await expect(page).toHaveURL(/\/lists/);
|
|
}
|
|
|
|
/** Creates a meal with the given name and markdown description. */
|
|
export async function createMeal(page: Page, name: string, description: string) {
|
|
await page.goto("/meals/new");
|
|
await page.fill("#meal-name", name);
|
|
await page.fill("#meal-description", description);
|
|
await page.click('button:has-text("Save meal")');
|
|
await expect(page).toHaveURL(/\/meals\/\d+/);
|
|
}
|
|
|
|
/** Creates a list and lands on its page. */
|
|
export async function createList(page: Page, name: string) {
|
|
await page.fill("#list-name", name);
|
|
await page.click('button:has-text("Create list")');
|
|
await expect(page).toHaveURL(/\/lists\/\d+/);
|
|
}
|
|
|
|
/** Adds an item to the current list page. */
|
|
export async function addItem(page: Page, name: string, quantity = "") {
|
|
await page.fill("#item-name", name);
|
|
if (quantity) {
|
|
await page.fill("#item-quantity", quantity);
|
|
}
|
|
await page.click("#add-item-button");
|
|
await expect(page.locator(".item-row").filter({ hasText: name })).toBeVisible();
|
|
}
|
|
|
|
/** Adds an ingredient to the current meal page. */
|
|
export async function addIngredient(page: Page, name: string, quantity = "") {
|
|
await page.fill("#ingredient-name", name);
|
|
if (quantity) {
|
|
await page.fill("#ingredient-quantity", quantity);
|
|
}
|
|
await page.click("#add-ingredient-button");
|
|
await expect(page.locator(".ingredient-list").filter({ hasText: name })).toBeVisible();
|
|
}
|