Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
test(frontend): stubs that keep the thing the test is about
zchpeterab15febc42da
diff --git a/frontend/src/components/HumanizeTs.test.tsx b/frontend/src/components/HumanizeTs.test.tsxindex 4d30a75c7c..1dd0415bc4 100644--- a/frontend/src/components/HumanizeTs.test.tsx+++ b/frontend/src/components/HumanizeTs.test.tsx@@ -1,5 +1,6 @@import { act } from "react";import { createRoot } from "react-dom/client";+import { advanceSeconds } from "@/test-utils/clock";import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";// The real datetime module is loaded below for its domain check, and importing@@ -107,15 +108,6 @@ const openTooltip = async (el: Element | null) => {const overlayText = () =>document.getElementById("bb-react-layer-overlay")?.textContent ?? "";-// One act per second, as a browser commits between timer turns; a single long-// act would commit only once, at its end, and hide when the render happened.-const advanceSeconds = (seconds: number) => {- for (let second = 0; second < seconds; second++) {- act(() => {- vi.advanceTimersByTime(1_000);- });- }-};const secondsAgo = (seconds: number) => Date.now() - seconds * 1000;@@ -192,11 +184,15 @@ describe("HumanizeTs", () => {// on it; the row should lose its timestamp, not the page its subtree.const { container, root } = mount();act(() => root.render(<HumanizeTs tsMs={Number.NaN} />));- expect(container.textContent).toBe("");+ // Nothing at all, not an empty box: a box still occupies the row, and its+ // tooltip would ask the formatters for a time nobody gave them -- which+ // renders the current time, the plausible-looking lie this all exists to+ // avoid.+ expect(container.innerHTML).toBe("");// Finite, and one millisecond past the last instant there is.act(() => root.render(<HumanizeTs tsMs={8.64e15 + 1} />));- expect(container.textContent).toBe("");+ expect(container.innerHTML).toBe("");});test.each(["compact", "operational", "datetime"] as const)(diff --git a/frontend/src/components/issue-activity/IssueCommentActivity.test.tsx b/frontend/src/components/issue-activity/IssueCommentActivity.test.tsxindex c819aacc9e..7f0af30527 100644--- a/frontend/src/components/issue-activity/IssueCommentActivity.test.tsx+++ b/frontend/src/components/issue-activity/IssueCommentActivity.test.tsx@@ -63,8 +63,8 @@ vi.mock("@/stores/app", () => ({}),}));-vi.mock("@/components/HumanizeTs", () => ({- HumanizeTs: () => null,+vi.mock("@/components/HumanizeTs", async () => ({+ ...(await import("@/test-utils/humanizeTs")).humanizeTsStub(),}));vi.mock("@/components/monaco", () => ({diff --git a/frontend/src/modules/sql-editor/components/AccessGrantItem.test.tsx b/frontend/src/modules/sql-editor/components/AccessGrantItem.test.tsxindex 2cc9fc12a0..1a2390ad81 100644--- a/frontend/src/modules/sql-editor/components/AccessGrantItem.test.tsx+++ b/frontend/src/modules/sql-editor/components/AccessGrantItem.test.tsx@@ -2,6 +2,7 @@ import type { ReactElement } from "react";import { act } from "react";import { timestampFromMs } from "@bufbuild/protobuf/wkt";import { createRoot } from "react-dom/client";+import { advanceSeconds } from "@/test-utils/clock";import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";(@@ -64,8 +65,9 @@ vi.mock("@/components/ui/badge", () => ({}));vi.mock("@/components/ui/tooltip", () => ({- // The real Tooltip renders nothing for an absent body, so the stub carries- // the body it was given: a row that hides a reading has to offer it back.+ // The real Tooltip renders nothing for a body that is falsy -- not merely+ // absent -- so the stub answers the same question it does. A row that hides+ // a reading has to offer it back.Tooltip: ({children,content,@@ -73,7 +75,7 @@ vi.mock("@/components/ui/tooltip", () => ({children: React.ReactNode;content?: React.ReactNode;}) => (- <span data-testid="tooltip" data-has-content={content !== undefined}>+ <span data-testid="tooltip" data-has-content={Boolean(content)}>{children}</span>),@@ -367,13 +369,6 @@ describe("AccessGrantItem", () => {<AccessGrantItem grant={grant as never} onRun={vi.fn()} onRequest={vi.fn()} />);render();- const advanceSeconds = (seconds: number) => {- for (let second = 0; second < seconds; second++) {- act(() => {- vi.advanceTimersByTime(1_000);- });- }- };expect(container.textContent).toContain("sql-editor.expire-in:3m");// A countdown is the one form that hides the deadline, so the row has todiff --git a/frontend/src/modules/sql-editor/components/SchemaPane/SchemaPane.test.tsx b/frontend/src/modules/sql-editor/components/SchemaPane/SchemaPane.test.tsxindex 22e6cfffa1..ff2481a992 100644--- a/frontend/src/modules/sql-editor/components/SchemaPane/SchemaPane.test.tsx+++ b/frontend/src/modules/sql-editor/components/SchemaPane/SchemaPane.test.tsx@@ -183,8 +183,8 @@ vi.mock("@/components/monaco/sqlFormatter", () => ({formatSQL: async (sql: string) => ({ data: sql, error: null }),}));-vi.mock("@/components/HumanizeTs", () => ({- HumanizeTs: () => <span />,+vi.mock("@/components/HumanizeTs", async () => ({+ ...(await import("@/test-utils/humanizeTs")).humanizeTsStub(),}));vi.mock("@/components/ui/input", () => ({diff --git a/frontend/src/modules/sql-editor/components/SchemaPane/SyncSchemaButton.test.tsx b/frontend/src/modules/sql-editor/components/SchemaPane/SyncSchemaButton.test.tsxindex 5cd0cbcb72..18c2541ae1 100644--- a/frontend/src/modules/sql-editor/components/SchemaPane/SyncSchemaButton.test.tsx+++ b/frontend/src/modules/sql-editor/components/SchemaPane/SyncSchemaButton.test.tsx@@ -24,8 +24,8 @@ vi.mock("react-i18next", () => ({Trans: ({ i18nKey }: { i18nKey: string }) => <span>{i18nKey}</span>,}));-vi.mock("@/components/HumanizeTs", () => ({- HumanizeTs: () => <span data-testid="humanize" />,+vi.mock("@/components/HumanizeTs", async () => ({+ ...(await import("@/test-utils/humanizeTs")).humanizeTsStub(),}));vi.mock("@/components/ui/tooltip", () => ({diff --git a/frontend/src/routes/project/ProjectPlanDashboardPage.test.tsx b/frontend/src/routes/project/ProjectPlanDashboardPage.test.tsxindex 89004d2fa9..1b6e426ae8 100644--- a/frontend/src/routes/project/ProjectPlanDashboardPage.test.tsx+++ b/frontend/src/routes/project/ProjectPlanDashboardPage.test.tsx@@ -65,8 +65,8 @@ vi.mock("@/components/database", () => ({DatabaseTable: () => null,}));-vi.mock("@/components/HumanizeTs", () => ({- HumanizeTs: () => createElement("span"),+vi.mock("@/components/HumanizeTs", async () => ({+ ...(await import("@/test-utils/humanizeTs")).humanizeTsStub(),}));vi.mock("@/components/PermissionGuard", () => ({diff --git a/frontend/src/routes/project/database-detail/changelog/DatabaseChangelogTable.test.tsx b/frontend/src/routes/project/database-detail/changelog/DatabaseChangelogTable.test.tsxindex e9db222c5a..bc0f42427c 100644--- a/frontend/src/routes/project/database-detail/changelog/DatabaseChangelogTable.test.tsx+++ b/frontend/src/routes/project/database-detail/changelog/DatabaseChangelogTable.test.tsx@@ -1,4 +1,5 @@import { create } from "@bufbuild/protobuf";+import { timestampFromMs } from "@bufbuild/protobuf/wkt";import type { ReactElement } from "react";import { act } from "react";import { createRoot } from "react-dom/client";@@ -30,8 +31,8 @@ vi.mock("@/types", () => ({getTimeForPbTimestampProtoEs: () => new Date("2026-04-15T00:00:00Z").getTime(),}));-vi.mock("@/components/HumanizeTs", () => ({- HumanizeTs: () => null,+vi.mock("@/components/HumanizeTs", async () => ({+ ...(await import("@/test-utils/humanizeTs")).humanizeTsStub(),}));import { DatabaseChangelogTable } from "./DatabaseChangelogTable";@@ -65,6 +66,31 @@ beforeEach(() => {});describe("DatabaseChangelogTable", () => {+ test("dates each row in the embedded history form", () => {+ const { container, render, unmount } = renderIntoContainer(+ <DatabaseChangelogTable+ loading={false}+ changelogs={[+ create(ChangelogSchema, {+ name: "changelogs/1",+ createTime: timestampFromMs(Date.UTC(2026, 2, 2, 12)),+ }),+ ]}+ />+ );++ render();++ // A row in a list orients the reader; the changelog's own page testifies.+ expect(+ Array.from(+ container.querySelectorAll<HTMLElement>("[data-testid=humanize-ts]")+ ).map((node) => node.dataset.mode)+ ).toEqual(["compact"]);++ unmount();+ });+test("inherits default zebra striping from shared table primitives", () => {const { container, render, unmount } = renderIntoContainer(<DatabaseChangelogTablediff --git a/frontend/src/routes/project/issue-detail/components/IssueDetailAccessGrantDetails.test.tsx b/frontend/src/routes/project/issue-detail/components/IssueDetailAccessGrantDetails.test.tsxindex 2fc3425c91..ad441fa635 100644--- a/frontend/src/routes/project/issue-detail/components/IssueDetailAccessGrantDetails.test.tsx+++ b/frontend/src/routes/project/issue-detail/components/IssueDetailAccessGrantDetails.test.tsx@@ -3,6 +3,10 @@ import { beforeEach, describe, expect, test, vi } from "vitest";import { IssueDetailAccessGrantDetails } from "./IssueDetailAccessGrantDetails";const mocks = vi.hoisted(() => ({+ expiration: { type: "never" } as+ | { type: "never" }+ | { type: "duration"; value: string }+ | { type: "datetime"; expireTimeMs: number },accessGrant: undefined as| {name: string;@@ -69,8 +73,12 @@ vi.mock("@/utils", () => ({hasProjectPermissionV2: () => true,}));+vi.mock("@/components/HumanizeTs", async () => ({+ ...(await import("@/test-utils/humanizeTs")).humanizeTsStub(),+}));+vi.mock("@/utils/accessGrant", () => ({- getAccessGrantExpirationText: () => ({ type: "never" }),+ getAccessGrantExpirationText: () => mocks.expiration,}));vi.mock("../context/IssueDetailContext", () => ({@@ -90,9 +98,23 @@ beforeEach(() => {};mocks.fetchAccessGrant.mockImplementation(async () => mocks.accessGrant);mocks.searchMyAccessGrants.mockResolvedValue({ accessGrants: [] });+ mocks.expiration = { type: "never" };});describe("IssueDetailAccessGrantDetails", () => {+ test("names a fixed expiry in the operational form", async () => {+ // An expiry is acted on, not skimmed: it carries its date and its zone,+ // which is what tells a reader in another zone when access really ends.+ mocks.expiration = {+ type: "datetime",+ expireTimeMs: Date.UTC(2026, 8, 15, 1, 0),+ };+ render(<IssueDetailAccessGrantDetails />);++ const timestamp = await screen.findByTestId("humanize-ts");+ expect(timestamp.dataset.mode).toBe("operational");+ });+test("renders schema and CosmosDB container for approvers", async () => {render(<IssueDetailAccessGrantDetails />);diff --git a/frontend/src/routes/project/plan-detail/components/PlanDetailMeta.test.tsx b/frontend/src/routes/project/plan-detail/components/PlanDetailMeta.test.tsxindex f073bb0885..b385b6fb68 100644--- a/frontend/src/routes/project/plan-detail/components/PlanDetailMeta.test.tsx+++ b/frontend/src/routes/project/plan-detail/components/PlanDetailMeta.test.tsx@@ -31,7 +31,9 @@ vi.mock("@/api", () => ({issueServiceClientConnect: { updateIssue: mocks.updateIssue },}));-vi.mock("@/components/HumanizeTs", () => ({ HumanizeTs: () => null }));+vi.mock("@/components/HumanizeTs", async () => ({+ ...(await import("@/test-utils/humanizeTs")).humanizeTsStub(),+}));vi.mock("@/components/ui/checkbox", () => ({Checkbox: ({ checked }: { checked: boolean }) => (diff --git a/frontend/src/routes/project/plan-detail/components/deploy/DeployTaskRunHistorySheet.test.tsx b/frontend/src/routes/project/plan-detail/components/deploy/DeployTaskRunHistorySheet.test.tsxindex 841e9a8862..21c6e1c07a 100644--- a/frontend/src/routes/project/plan-detail/components/deploy/DeployTaskRunHistorySheet.test.tsx+++ b/frontend/src/routes/project/plan-detail/components/deploy/DeployTaskRunHistorySheet.test.tsx@@ -48,8 +48,8 @@ vi.mock("@/components/task-run-log", async () => {};});-vi.mock("@/components/HumanizeTs", () => ({- HumanizeTs: ({ ts }: { ts: number }) => <span>{ts}</span>,+vi.mock("@/components/HumanizeTs", async () => ({+ ...(await import("@/test-utils/humanizeTs")).humanizeTsStub(),}));const taskName = "projects/p1/rollouts/r1/stages/s1/tasks/t1";@@ -90,12 +90,25 @@ const renderSheet = (taskRuns: ReturnType<typeof makeTaskRuns>) => {};};+const timestampModes = (container: HTMLElement) =>+ Array.from(+ container.querySelectorAll<HTMLElement>("[data-testid=humanize-ts]")+ ).map((node) => node.dataset.mode);+const mountedLogNames = (container: HTMLElement) =>Array.from(container.querySelectorAll<HTMLElement>("[data-testid=log-viewer]")).map((node) => node.dataset.taskRunName);describe("DeployTaskRunHistorySheet", () => {+ test("dates each run in the embedded history form", () => {+ // A history row orients; the record itself testifies elsewhere. The form+ // is the decision this surface makes, so it is the thing asserted.+ const { container, cleanup } = renderSheet(makeTaskRuns(1));+ expect(timestampModes(container)).toEqual(["compact"]);+ cleanup();+ });+test("renders runs newest-first with descending run numbers", () => {const { container, cleanup } = renderSheet(makeTaskRuns(3));const labels = Array.from(container.querySelectorAll("button")).map(diff --git a/frontend/src/routes/project/plan-detail/components/review/PlanReviewSection.test.tsx b/frontend/src/routes/project/plan-detail/components/review/PlanReviewSection.test.tsxindex d67d660681..f1a881ad18 100644--- a/frontend/src/routes/project/plan-detail/components/review/PlanReviewSection.test.tsx+++ b/frontend/src/routes/project/plan-detail/components/review/PlanReviewSection.test.tsx@@ -152,10 +152,8 @@ vi.mock("@/components/MarkdownEditor", () => ({),}));-vi.mock("@/components/HumanizeTs", () => ({- HumanizeTs: ({ ts }: { ts: number }) => (- <span data-testid="humanize-ts">{ts}</span>- ),+vi.mock("@/components/HumanizeTs", async () => ({+ ...(await import("@/test-utils/humanizeTs")).humanizeTsStub(),}));vi.mock("@/components/UserAvatar", () => ({diff --git a/frontend/src/routes/project/plan-detail/components/review/ReviewActivityTimeline.test.tsx b/frontend/src/routes/project/plan-detail/components/review/ReviewActivityTimeline.test.tsxindex bf79d06dc6..b71634888d 100644--- a/frontend/src/routes/project/plan-detail/components/review/ReviewActivityTimeline.test.tsx+++ b/frontend/src/routes/project/plan-detail/components/review/ReviewActivityTimeline.test.tsx@@ -1,4 +1,5 @@import { create } from "@bufbuild/protobuf";+import { timestampFromMs } from "@bufbuild/protobuf/wkt";import { act, type ReactNode } from "react";import { createRoot } from "react-dom/client";import { describe, expect, test, vi } from "vitest";@@ -59,8 +60,8 @@ vi.mock("@/components/issue-activity/IssueCommentActivity", () => ({),}));-vi.mock("@/components/HumanizeTs", () => ({- HumanizeTs: () => null,+vi.mock("@/components/HumanizeTs", async () => ({+ ...(await import("@/test-utils/humanizeTs")).humanizeTsStub(),}));vi.mock("@/components/MarkdownEditor", () => ({@@ -187,6 +188,41 @@ const reviewSubmission = (name: string) =>});describe("ReviewActivityTimeline", () => {+ test("times an activity entry in the work-queue form", () => {+ // A feed is read for what just happened, so its entries age with the+ // clock rather than naming a date.+ const container = document.createElement("div");+ const root = createRoot(container);++ act(() => {+ root.render(+ <ReviewActivityTimeline+ comments={[+ create(IssueCommentSchema, {+ name: "comments/timed",+ creator: "users/[email protected]",+ createTime: timestampFromMs(Date.UTC(2026, 2, 2, 12)),+ event: {+ case: "reviewSubmission",+ value: create(IssueComment_ReviewSubmissionSchema),+ },+ }),+ ]}+ issue={create(IssueSchema, { name: "projects/p1/issues/1" })}+ plan={create(PlanSchema, { name: "projects/p1/plans/1" })}+ />+ );+ });++ expect(+ Array.from(+ container.querySelectorAll<HTMLElement>("[data-testid=humanize-ts]")+ ).map((node) => node.dataset.mode)+ ).toEqual(["queue"]);++ act(() => root.unmount());+ });+test("renders one persisted Review Submission instead of a fallback duplicate", () => {const issue = create(IssueSchema, {name: "projects/p1/issues/1",diff --git a/frontend/src/routes/project/plan-detail/components/threads/CommentThreadCard.test.tsx b/frontend/src/routes/project/plan-detail/components/threads/CommentThreadCard.test.tsxindex 913bb0b965..d87c98556b 100644--- a/frontend/src/routes/project/plan-detail/components/threads/CommentThreadCard.test.tsx+++ b/frontend/src/routes/project/plan-detail/components/threads/CommentThreadCard.test.tsx@@ -26,7 +26,9 @@ vi.mock("react-i18next", () => ({}),}));-vi.mock("@/components/HumanizeTs", () => ({ HumanizeTs: () => null }));+vi.mock("@/components/HumanizeTs", async () => ({+ ...(await import("@/test-utils/humanizeTs")).humanizeTsStub(),+}));// The activity module drags Monaco into the test; only the edit rule matters.vi.mock("@/components/issue-activity/IssueCommentActivity", () => ({diff --git a/frontend/src/routes/project/plan-detail/components/threads/ThreadStack.test.tsx b/frontend/src/routes/project/plan-detail/components/threads/ThreadStack.test.tsxindex 3a270b268c..7b39ca88f0 100644--- a/frontend/src/routes/project/plan-detail/components/threads/ThreadStack.test.tsx+++ b/frontend/src/routes/project/plan-detail/components/threads/ThreadStack.test.tsx@@ -11,7 +11,9 @@ vi.mock("react-i18next", () => ({initReactI18next: { type: "3rdParty", init: () => {} },useTranslation: () => ({ t: (key: string) => key }),}));-vi.mock("@/components/HumanizeTs", () => ({ HumanizeTs: () => <span>17h</span> }));+vi.mock("@/components/HumanizeTs", async () => ({+ ...(await import("@/test-utils/humanizeTs")).humanizeTsStub(),+}));vi.mock("@/stores/app", () => ({useAppStore: (selector: (state: unknown) => unknown) =>selector({ getUserByIdentifier: () => ({ email: "[email protected]", title: "Aurora" }) }),diff --git a/frontend/src/test-utils/clock.ts b/frontend/src/test-utils/clock.tsnew file mode 100644index 0000000000..1148165c09--- /dev/null+++ b/frontend/src/test-utils/clock.ts@@ -0,0 +1,15 @@+import { act } from "react";+import { vi } from "vitest";++/**+ * Advance fake timers a second at a time, committing between turns as a+ * browser does. A single long advance would commit once, at its end, and hide+ * whether a display re-rendered when it should have or only at the finish.+ */+export const advanceSeconds = (seconds: number) => {+ for (let second = 0; second < seconds; second++) {+ act(() => {+ vi.advanceTimersByTime(1_000);+ });+ }+};diff --git a/frontend/src/test-utils/humanizeTs.tsx b/frontend/src/test-utils/humanizeTs.tsxnew file mode 100644index 0000000000..9cc7b6e3b3--- /dev/null+++ b/frontend/src/test-utils/humanizeTs.tsx@@ -0,0 +1,19 @@+/**+ * A stand-in for `HumanizeTs` that keeps what a test might be about: the+ * instant, and the form the surface asked for. A stub that renders only its+ * children, or nothing, cannot see a surface given the wrong form — which is+ * the decision docs/design/timestamp-display.md exists to make.+ */+export const humanizeTsStub = () => ({+ HumanizeTs: ({+ tsMs,+ mode = "queue",+ }: {+ tsMs: number | undefined;+ mode?: string;+ }) => (+ <span data-testid="humanize-ts" data-mode={mode}>+ {tsMs ?? ""}+ </span>+ ),+});