Download automation/src/modules/exp/ui.ts from EnergyVenom/patchwise-agent-studio: direct link, hf CLI and curl.
- Browser
- Download file 2.71 kB
-
https://huggingface.co/spaces/EnergyVenom/patchwise-agent-studio/resolve/main/automation/src/modules/exp/ui.ts
- Command line
-
hf download hf://spaces/EnergyVenom/patchwise-agent-studio/automation/src/modules/exp/ui.ts
-
curl -L -o ui.ts https://huggingface.co/spaces/EnergyVenom/patchwise-agent-studio/resolve/main/automation/src/modules/exp/ui.ts
2.71 kB
| import { Page, expect } from '@playwright/test'; | |
| import { A2RUi } from '../a2r/ui'; | |
| import { NAV, FIELD, BUTTON, TABLE, TID } from './labels'; | |
| export type ExpenseItem = { type: string; amount: number; date: string; merchant: string }; | |
| /** Page actions for the MOCK EXP pack (same locator policy as the other packs). Every label comes from ./labels.ts. */ | |
| export class EXPUi extends A2RUi { | |
| constructor(page: Page) { super(page); } | |
| async expNav(key: keyof typeof NAV) { await this.go(NAV[key]); } | |
| tb(name: string) { return this.page.getByRole('textbox', { name, exact: true }); } | |
| /** Create Report -> Purpose -> Create Item, then each item (Expense Type, Amount, Date, Merchant, Attach Receipt, Save). Leaves the report saved, not submitted. */ | |
| async createReport(purpose: string, items: ExpenseItem[]) { | |
| await this.expNav('expenses'); | |
| await this.btn(BUTTON.createReport).click(); | |
| await this.tb(FIELD.purpose).fill(purpose); | |
| await this.btn(BUTTON.createItem).click(); | |
| for (const [i, it] of items.entries()) { | |
| if (i > 0) await this.btn(BUTTON.createItem).click(); | |
| await this.page.getByRole('combobox', { name: FIELD.expenseType, exact: true }).selectOption(it.type); | |
| await this.tb(FIELD.amount).fill(it.amount.toFixed(2)); | |
| await this.page.getByLabel(FIELD.date, { exact: true }).fill(it.date); | |
| await this.tb(FIELD.merchant).fill(it.merchant); | |
| await this.btn(BUTTON.attachReceipt).click(); | |
| await expect(this.page.getByRole('status', { name: 'Receipt' })).toContainText('Receipt attached'); | |
| await this.btn(BUTTON.save).click(); | |
| await this.expectOk(`Item ${it.amount.toFixed(2)} saved`); | |
| } | |
| } | |
| async reportNumber() { return (await this.value(TID.reportNumber).textContent())!.trim(); } | |
| /** Submit the open report; returns its number. */ | |
| async submitReport() { await this.btn(BUTTON.submit).click(); await this.expectOk('submitted'); return this.reportNumber(); } | |
| async approveFromNotifications(number: string) { | |
| await this.btn(BUTTON.notifications).click(); | |
| await this.table('Notifications').getByRole('link', { name: number, exact: true }).click(); | |
| await expect(this.value(TID.reportNumber)).toHaveText(number); | |
| await this.btn(BUTTON.approve).click(); | |
| await this.expectOk(`Expense report ${number} approved`); | |
| } | |
| /** Cell of the row containing rowText, in the column whose header is col (delegates to the shared guarded cellByHeader helper). */ | |
| cellAt(tableName: string, rowText: string | RegExp, col: string) { return this.cellByHeader(tableName, rowText, col); } | |
| reportTotal() { return this.cellByHeader(TABLE.totals, 'Report Total', 'Amount'); } | |
| } | |