fix(web): derive mock action labels from invoice status

This commit is contained in:
Adam Moussa 2026-09-25 17:13:37 -04:00
parent 070730e4ee
commit f076b91aff
No known key found for this signature in database
2 changed files with 31 additions and 12 deletions

View file

@ -84,6 +84,26 @@ describe("mocks module", () => {
expect(pending.every((invoice) => invoice.actionLabel === "Approve invoice")).toBe(true);
const nonPending = invoices.filter((invoice) => invoice.status !== "pending_approval");
expect(nonPending.every((invoice) => invoice.actionLabel !== "Approve invoice")).toBe(true);
expect(
invoices
.filter((invoice) => invoice.status === "approved")
.every((invoice) => invoice.actionLabel === "Approved"),
).toBe(true);
expect(
invoices
.filter((invoice) => invoice.status === "paid")
.every((invoice) => invoice.actionLabel === "Paid"),
).toBe(true);
expect(
invoices
.filter((invoice) => invoice.status === "scheduled")
.every((invoice) => invoice.actionLabel === "Scheduled"),
).toBe(true);
expect(
invoices
.filter((invoice) => invoice.status === "rejected")
.every((invoice) => invoice.actionLabel === "Rejected"),
).toBe(true);
});
it("seeds at least two invoices per dashboard tab", () => {

View file

@ -1,4 +1,3 @@
import { INVOICE_ACTION_OPTIONS } from "@/dashboard/column-catalog";
import { syncMockApprovalsForInvoice } from "@/mocks/approvals";
import { areMocksEnabled } from "@/mocks/env";
@ -104,16 +103,16 @@ type MockInvoiceCore = Omit<
| "rowCount"
>;
/** Non-pending rows never show the pending-only "Approve invoice" action. */
const NON_PENDING_ACTION_OPTIONS = INVOICE_ACTION_OPTIONS.filter(
(option) => option !== "Approve invoice",
);
const ACTION_LABEL_BY_STATUS: Record<MockInvoiceStatus, string> = {
pending_approval: "Approve invoice",
approved: "Approved",
scheduled: "Scheduled",
paid: "Paid",
rejected: "Rejected",
};
function actionLabelForStatus(status: MockInvoiceStatus, index: number): string {
if (status === "pending_approval") {
return "Approve invoice";
}
return NON_PENDING_ACTION_OPTIONS[index % NON_PENDING_ACTION_OPTIONS.length];
function actionLabelForStatus(status: MockInvoiceStatus): string {
return ACTION_LABEL_BY_STATUS[status];
}
function derivedActivityFields(invoice: Pick<MockInvoice, "activity" | "comments" | "dueDate">) {
@ -160,7 +159,7 @@ function invoiceDateBeforeDue(dueDate: string, index: number): string {
function withRefreshedCatalogFields(invoice: MockInvoice, index: number): MockInvoice {
return {
...invoice,
actionLabel: actionLabelForStatus(invoice.status, index),
actionLabel: actionLabelForStatus(invoice.status),
...derivedActivityFields(invoice),
description: invoice.memo,
paymentAccount: paymentAccountFor(invoice.paymentMethod),
@ -175,7 +174,7 @@ function enrichInvoice(core: MockInvoiceCore, index: number): MockInvoice {
hasBolt: index % 3 === 0,
hasBell: index % 2 === 0,
hasEye: true,
actionLabel: actionLabelForStatus(core.status, index),
actionLabel: actionLabelForStatus(core.status),
lastUpdate: "",
lastUpdateMessage: "",
lastUpdateActorName: "",