Also: copy public/ into the runtime image, exclude /images from the login redirect, and fix 768px horizontal overflow. Co-Authored-By: Claude Opus 5.5 <[email protected]>
57 lines
2.5 KiB
TypeScript
57 lines
2.5 KiB
TypeScript
import { expect, type Page } from "@playwright/test";
|
|
|
|
// 申請表單的共用操作(applications.spec、review.spec)。
|
|
|
|
export const PDF = {
|
|
name: "invoice_chatgpt.pdf",
|
|
mimeType: "application/pdf",
|
|
buffer: Buffer.from("%PDF-1.7\nhello"),
|
|
};
|
|
export const CARD = {
|
|
name: "card_statement.pdf",
|
|
mimeType: "application/pdf",
|
|
buffer: Buffer.from("%PDF-1.7\ncard"),
|
|
};
|
|
|
|
/** 今日(台北)`YYYY-MM-DD`:送出要在期限內,刷卡日期用今天。 */
|
|
export const today = () =>
|
|
new Intl.DateTimeFormat("en-CA", { timeZone: "Asia/Taipei" }).format(new Date());
|
|
|
|
/** 平台以圖示卡片(radio)選擇;點選卡片文字所在的 label。 */
|
|
export async function choosePlatform(page: Page, name: string) {
|
|
await page
|
|
.getByRole("radiogroup", { name: /選擇 AI 平台/ })
|
|
.locator("label")
|
|
.filter({ hasText: new RegExp(`^${name}$`) })
|
|
.click();
|
|
await expect(page.getByRole("radio", { name, exact: true })).toBeChecked();
|
|
}
|
|
|
|
// 金額用偶數(898):settings.spec 會把全站取整方式改為四捨五入,平行執行時奇數金額的試算會不穩定。
|
|
export async function fillComplete(page: Page) {
|
|
await choosePlatform(page, "ChatGPT");
|
|
await page.getByLabel("訂閱方案/項目").fill("ChatGPT Plus");
|
|
await page.getByLabel("實際台幣支付金額").fill("898");
|
|
await page.getByLabel("刷卡日期").fill(today());
|
|
await page.getByLabel("工作用途說明").fill("整理客戶訪談逐字稿並產出會議摘要,每週節省約三小時");
|
|
await page.getByLabel("成果產出").fill("完成本月 12 場訪談摘要");
|
|
await page.getByLabel("我確認以上資料真實,且訂閱用途符合工作需求。").check();
|
|
}
|
|
|
|
export async function uploadBoth(page: Page) {
|
|
await page.getByTestId("uploader-invoice").locator("input[type=file]").setInputFiles(PDF);
|
|
await expect(page.getByTestId("uploaded-invoice")).toContainText("invoice_chatgpt.pdf");
|
|
await page.getByTestId("uploader-card_statement").locator("input[type=file]").setInputFiles(CARD);
|
|
await expect(page.getByTestId("uploaded-card_statement")).toContainText("card_statement.pdf");
|
|
}
|
|
|
|
/** 建立並送出一筆完整申請,回傳申請 id。 */
|
|
export async function submitNew(page: Page): Promise<number> {
|
|
await page.goto("/applications/new");
|
|
await fillComplete(page);
|
|
await uploadBoth(page);
|
|
await page.getByRole("button", { name: "送出申請" }).click();
|
|
await expect(page).toHaveURL(/\/applications\/\d+\?submitted=1$/);
|
|
return Number(page.url().match(/applications\/(\d+)/)![1]);
|
|
}
|