Skip to content

Commit 3c08c78

Browse files
Add e2e tests for conditional payment button text
- Test 'Pay again' button for failed payments - Test 'Pay now' button for non-failed payable invoices - Test 'Payment initiated' success message - Update existing tests with defensive assertions Co-Authored-By: sahil.lavingia@gmail.com <sahil.lavingia@gmail.com>
1 parent d7cec4c commit 3c08c78

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

e2e/tests/company/invoices/complete-flow.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,12 @@ test.describe("Invoice submission, approval and rejection", () => {
106106
await expect(firstRow).toContainText("$23");
107107
await expect(firstRow).toContainText("Awaiting approval");
108108
await expect(firstRow.getByRole("button", { name: "Pay now" })).toBeVisible();
109+
await expect(firstRow.getByRole("button", { name: "Pay again" })).not.toBeVisible();
109110
await expect(secondRow).toContainText("Nov 20, 2024");
110111
await expect(secondRow).toContainText("$623");
111112
await expect(secondRow).toContainText("Awaiting approval");
112113
await expect(secondRow.getByRole("button", { name: "Pay now" })).toBeVisible();
114+
await expect(secondRow.getByRole("button", { name: "Pay again" })).not.toBeVisible();
113115
await expect(thirdRow).toContainText("Nov 1, 2024");
114116
await expect(thirdRow).toContainText("$870");
115117
await expect(thirdRow).toContainText("Awaiting approval");
@@ -166,6 +168,8 @@ test.describe("Invoice submission, approval and rejection", () => {
166168
await page.getByRole("cell", { name: workerUserB.legalName ?? "never" }).click();
167169
await page.getByRole("link", { name: "View invoice" }).click();
168170
await expect(page.getByRole("heading", { name: "Invoice" })).toBeVisible();
171+
await expect(page.locator("header").filter({ hasText: "Invoice" }).getByRole("button", { name: "Pay now" })).toBeVisible();
172+
await expect(page.locator("header").filter({ hasText: "Invoice" }).getByRole("button", { name: "Pay again" })).not.toBeVisible();
169173
await page.locator("header").filter({ hasText: "Invoice" }).getByRole("button", { name: "Pay now" }).click();
170174

171175
await expect(openInvoicesBadge).not.toBeVisible();

e2e/tests/company/invoices/one-off-payments.spec.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,11 +378,48 @@ test.describe("One-off payments", () => {
378378
await page.reload();
379379
await expect(page.getByRole("row", { name: "$123.45" })).toBeVisible();
380380

381+
await expect(page.getByRole("button", { name: "Pay now" })).toBeVisible();
382+
await expect(page.getByRole("button", { name: "Pay again" })).not.toBeVisible();
383+
381384
await page.getByRole("button", { name: "Pay now" }).click();
382385
await page.getByRole("button", { name: "Filter" }).click();
383386
await page.getByRole("menuitem", { name: "Clear all filters" }).click();
384387

385388
await expect(page.getByRole("row", { name: "$123.45 Payment scheduled" })).toBeVisible();
386389
});
390+
391+
test("shows 'Pay again' button for failed payments", async ({ page }) => {
392+
const { invoice } = await invoicesFactory.create({
393+
companyId: company.id,
394+
companyContractorId: companyContractor.id,
395+
status: "failed",
396+
totalAmountInUsdCents: BigInt(50000),
397+
});
398+
399+
await login(page, adminUser);
400+
await page.goto("/invoices");
401+
402+
const invoiceRow = page.locator("tbody tr").filter({ hasText: invoice.invoiceNumber });
403+
await expect(invoiceRow.getByRole("button", { name: "Pay again" })).toBeVisible();
404+
await expect(invoiceRow.getByRole("button", { name: "Pay now" })).not.toBeVisible();
405+
});
406+
407+
test("shows 'Payment initiated' success message when paying", async ({ page }) => {
408+
const { invoice } = await invoicesFactory.create({
409+
companyId: company.id,
410+
companyContractorId: companyContractor.id,
411+
status: "approved",
412+
totalAmountInUsdCents: BigInt(50000),
413+
});
414+
415+
await login(page, adminUser);
416+
await page.goto("/invoices");
417+
418+
const invoiceRow = page.locator("tbody tr").filter({ hasText: invoice.invoiceNumber });
419+
await invoiceRow.getByRole("button", { name: "Pay now" }).click();
420+
421+
await expect(page.getByText("Payment initiated")).toBeVisible();
422+
await expect(page.getByText("Payment sent!")).not.toBeVisible();
423+
});
387424
});
388425
});

0 commit comments

Comments
 (0)