Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

test(billing): make date assertions time-zone independent (#9178)

Austin Mooreb3011786bcc9
diff --git a/packages/views/settings/components/billing-tab.test.tsx b/packages/views/settings/components/billing-tab.test.tsx
index ca86ed859b..641b37ae72 100644
--- a/packages/views/settings/components/billing-tab.test.tsx
+++ b/packages/views/settings/components/billing-tab.test.tsx
@@ -176,6 +176,20 @@ vi.mock("../../platform", () => ({ openExternal: mocks.openExternal }));
import { BillingTab, formatStripeMinorAmount } from "./billing-tab";
+// The component formats dates in the viewer's own time zone, so a midnight-UTC
+// fixture reads as the previous calendar day anywhere behind UTC. Build the
+// expected text with the same formatter instead of hard-coding the calendar day.
+function formatExpectedDate(iso: string): string {
+ return new Intl.DateTimeFormat("en", { dateStyle: "medium" }).format(
+ new Date(iso),
+ );
+}
+
+const FEB_1_2030 = formatExpectedDate("2030-02-01T00:00:00Z");
+const FEB_15_2030 = formatExpectedDate("2030-02-15T00:00:00Z");
+const MAR_1_2030 = formatExpectedDate("2030-03-01T00:00:00Z");
+const APR_1_2030 = formatExpectedDate("2030-04-01T00:00:00Z");
+
function setSeatCapacity({
humanMembers = 4,
purchased = 5,
@@ -782,7 +796,9 @@ describe("BillingTab", () => {
expect(screen.getByText("4 seats")).toBeInTheDocument();
expect(screen.getByText("1 seat")).toBeInTheDocument();
expect(screen.getByText("0 seats")).toBeInTheDocument();
- expect(screen.getByText(/4 seats from Feb 1, 2030/)).toBeInTheDocument();
+ expect(
+ screen.getByText(new RegExp(`4 seats from ${FEB_1_2030}`)),
+ ).toBeInTheDocument();
expect(screen.getAllByText("4 members")).toHaveLength(1);
expect(screen.getByText("Available seats").closest("summary")).toBeNull();
const formula = "Purchased seats minus members and reserved invitations.";
@@ -1299,11 +1315,13 @@ describe("BillingTab", () => {
renderWithI18n(<BillingTab />);
expect(
- screen.getByText(/Update your payment method by Feb 15, 2030/),
+ screen.getByText(
+ new RegExp(`Update your payment method by ${FEB_15_2030}`),
+ ),
).toBeInTheDocument();
expect(screen.getByText("Cancellation is scheduled")).toBeInTheDocument();
expect(
- screen.getByText(/subscription will cancel on Mar 1, 2030/),
+ screen.getByText(new RegExp(`subscription will cancel on ${MAR_1_2030}`)),
).toBeInTheDocument();
});
@@ -1353,13 +1371,15 @@ describe("BillingTab", () => {
renderWithI18n(<BillingTab />);
expect(
- screen.getByText(/subscription will cancel on Apr 1, 2030/),
+ screen.getByText(new RegExp(`subscription will cancel on ${APR_1_2030}`)),
+ ).toBeInTheDocument();
+ expect(
+ screen.getByText(new RegExp(`4 seats from ${APR_1_2030}`)),
).toBeInTheDocument();
- expect(screen.getByText(/4 seats from Apr 1, 2030/)).toBeInTheDocument();
- expect(screen.getByText("Apr 1, 2030")).toBeInTheDocument();
- expect(screen.queryByText("Mar 1, 2030")).not.toBeInTheDocument();
+ expect(screen.getByText(APR_1_2030)).toBeInTheDocument();
+ expect(screen.queryByText(MAR_1_2030)).not.toBeInTheDocument();
expect(
- screen.queryByText(/subscription will cancel on Mar 1, 2030/),
+ screen.queryByText(new RegExp(`subscription will cancel on ${MAR_1_2030}`)),
).not.toBeInTheDocument();
expect(screen.queryByText(/Pro remains available/)).not.toBeInTheDocument();
});