fix(mobile): keep live activity layout self-contained
Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
4aebaca9d0
commit
03e5e416d3
4 files changed
+60
-31
No files matched your search
@@ -1,16 +0,0 @@
|
||||
import { describe, expect, it } from "@effect/vitest";
|
||||
|
||||
import { formatAgentActivityUpdatedAtLabel } from "./updatedAtLabel";
|
||||
|
||||
describe("formatAgentActivityUpdatedAtLabel", () => {
|
||||
it("formats ISO timestamps without using ambient time APIs", () => {
|
||||
expect(formatAgentActivityUpdatedAtLabel("2026-05-25T00:03:00.000Z")).toBe("12:03");
|
||||
expect(formatAgentActivityUpdatedAtLabel("2026-05-25T09:45:00.000Z")).toBe("9:45");
|
||||
expect(formatAgentActivityUpdatedAtLabel("2026-05-25T13:07:00.000Z")).toBe("1:07");
|
||||
});
|
||||
|
||||
it("uses now for malformed timestamps", () => {
|
||||
expect(formatAgentActivityUpdatedAtLabel("not-a-date")).toBe("now");
|
||||
expect(formatAgentActivityUpdatedAtLabel("2026-05-25T24:00:00.000Z")).toBe("now");
|
||||
});
|
||||
});
|
||||
@@ -1,12 +0,0 @@
|
||||
const ISO_TIME_PATTERN = /^\d{4}-\d{2}-\d{2}T(?<hours>\d{2}):(?<minutes>\d{2}):/;
|
||||
|
||||
export function formatAgentActivityUpdatedAtLabel(updatedAt: string): string {
|
||||
const match = ISO_TIME_PATTERN.exec(updatedAt);
|
||||
const hours24 = Number(match?.groups?.hours);
|
||||
const minutes = match?.groups?.minutes;
|
||||
if (!Number.isInteger(hours24) || hours24 < 0 || hours24 > 23 || !minutes) {
|
||||
return "now";
|
||||
}
|
||||
|
||||
return `${hours24 % 12 || 12}:${minutes}`;
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
vi.mock("@expo/ui/swift-ui", () => ({
|
||||
HStack: "HStack",
|
||||
Spacer: "Spacer",
|
||||
Text: "Text",
|
||||
VStack: "VStack",
|
||||
}));
|
||||
|
||||
vi.mock("@expo/ui/swift-ui/modifiers", () => ({
|
||||
font: (value: unknown) => value,
|
||||
foregroundStyle: (value: unknown) => value,
|
||||
lineLimit: (value: unknown) => value,
|
||||
padding: (value: unknown) => value,
|
||||
}));
|
||||
|
||||
vi.mock("expo-widgets", () => ({
|
||||
createLiveActivity: vi.fn((name: string, layout: unknown) => ({ layout, name })),
|
||||
}));
|
||||
|
||||
import { AgentActivity, type AgentActivityProps } from "./AgentActivity";
|
||||
|
||||
const props = {
|
||||
title: "T3 Code",
|
||||
subtitle: "Agent work in progress",
|
||||
activeCount: 1,
|
||||
updatedAt: "2026-05-25T13:07:00.000Z",
|
||||
activities: [],
|
||||
} satisfies AgentActivityProps;
|
||||
|
||||
const environment = {
|
||||
colorScheme: "dark",
|
||||
isLuminanceReduced: false,
|
||||
} as const;
|
||||
|
||||
describe("AgentActivity widget layout", () => {
|
||||
it("formats its updated-at label without app-runtime helper references", () => {
|
||||
expect(JSON.stringify(AgentActivity(props, environment as never))).toContain(
|
||||
'"children":["Updated ","1:07"]',
|
||||
);
|
||||
expect(AgentActivity.toString()).not.toContain("formatAgentActivityUpdatedAtLabel");
|
||||
});
|
||||
|
||||
it("uses now when the updated-at timestamp is malformed", () => {
|
||||
expect(
|
||||
JSON.stringify(AgentActivity({ ...props, updatedAt: "not-a-date" }, environment as never)),
|
||||
).toContain('"children":["Updated ","now"]');
|
||||
});
|
||||
});
|
||||
@@ -5,7 +5,6 @@ import {
|
||||
type LiveActivityComponent,
|
||||
type LiveActivityLayout,
|
||||
} from "expo-widgets";
|
||||
import { formatAgentActivityUpdatedAtLabel } from "../features/agent-awareness/updatedAtLabel";
|
||||
|
||||
type LiveActivityEnvironment = Parameters<LiveActivityComponent<AgentActivityProps>>[1];
|
||||
|
||||
@@ -38,7 +37,7 @@ export interface AgentActivityProps {
|
||||
readonly activities: ReadonlyArray<AgentActivityRowProps>;
|
||||
}
|
||||
|
||||
function AgentActivity(
|
||||
export function AgentActivity(
|
||||
props: AgentActivityProps,
|
||||
environment: LiveActivityEnvironment,
|
||||
): LiveActivityLayout {
|
||||
@@ -47,7 +46,16 @@ function AgentActivity(
|
||||
const row0 = props.activities[0];
|
||||
const row1 = props.activities[1];
|
||||
const row2 = props.activities[2];
|
||||
const updatedAt = formatAgentActivityUpdatedAtLabel(props.updatedAt);
|
||||
const updatedAtMatch = /^\d{4}-\d{2}-\d{2}T(\d{2}):(\d{2}):/.exec(props.updatedAt);
|
||||
const updatedAtHours24 = Number(updatedAtMatch?.[1]);
|
||||
const updatedAtMinutes = updatedAtMatch?.[2];
|
||||
const updatedAt =
|
||||
Number.isInteger(updatedAtHours24) &&
|
||||
updatedAtHours24 >= 0 &&
|
||||
updatedAtHours24 <= 23 &&
|
||||
updatedAtMinutes
|
||||
? `${updatedAtHours24 % 12 || 12}:${updatedAtMinutes}`
|
||||
: "now";
|
||||
const activeLabel = `${props.activeCount} active`;
|
||||
const isLight = environment.colorScheme === "light";
|
||||
const primaryForeground = isLight ? "#0f172a" : "#ffffff";
|
||||
|
||||
Reference in new issue
Block a user