Track HiveGrid Cloud planning reference

This commit is contained in:
david committed 2026-06-26 20:48:01 +02:00
1 parent b3d5ea6764
commit e341c5938a
5784 files changed
+1104929 -3

No files matched your search

@@ -0,0 +1,27 @@
import React from "react";
import "@testing-library/jest-dom/vitest";
import { render } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import { PortalTimestamp } from "./PortalTimestamp";
vi.mock("react-i18next", () => ({
useTranslation: () => ({ i18n: { language: "de" } }),
}));
describe("PortalTimestamp", () => {
it("renders locale-aware relative text with machine-readable time metadata", () => {
const value = new Date("2026-05-26T10:20:30.000Z");
const { container } = render(<PortalTimestamp value={value} className="text-xs" />);
const timestamp = container.querySelector("time");
if (!timestamp) {
throw new Error("expected PortalTimestamp to render a time element");
}
expect(timestamp.tagName).toBe("TIME");
expect(timestamp).toHaveAttribute("dateTime", value.toISOString());
expect(timestamp).toHaveAttribute("title");
expect(timestamp).toHaveClass("text-xs");
expect(timestamp?.textContent).toBeTruthy();
});
});
@@ -0,0 +1,17 @@
import { useLocaleFormatters } from "~/locale/format";
type PortalTimestampProps = {
value: Date | string | number;
className?: string;
};
export function PortalTimestamp({ value, className }: PortalTimestampProps) {
const formatters = useLocaleFormatters();
const date = value instanceof Date ? value : new Date(value);
return (
<time dateTime={date.toISOString()} title={formatters.dateTime(date, { timeStyle: "medium" })} className={className}>
{formatters.relativeDate(date)}
</time>
);
}