feat: render hourly investment states
This commit is contained in:
@@ -5,20 +5,23 @@ import { resource } from "@/test/resource";
|
||||
import { section } from "./section";
|
||||
|
||||
describe("instrument source and transport presentation", () => {
|
||||
it.each(["missing", "partial", "complete"] as const)(
|
||||
it.each([
|
||||
["initial-loading", "incomplete"],
|
||||
["available", "complete"],
|
||||
] as const)(
|
||||
"keeps %s separate from successful transport",
|
||||
(availability) => {
|
||||
const data = availability === "missing" ? undefined : { rows: [] };
|
||||
(availability, completeness) => {
|
||||
const data = availability === "initial-loading" ? undefined : { rows: [] };
|
||||
|
||||
const state = section({
|
||||
data,
|
||||
isError: false,
|
||||
meta: resource(data, { availability }).meta,
|
||||
meta: resource(data, { availability, completeness }).meta,
|
||||
});
|
||||
|
||||
expect(state.loading).toBe(availability === "missing");
|
||||
expect(state.partial).toBe(availability === "partial");
|
||||
expect(state.hasData).toBe(availability !== "missing");
|
||||
expect(state.loading).toBe(availability === "initial-loading");
|
||||
expect(state.partial).toBe(completeness === "incomplete");
|
||||
expect(state.hasData).toBe(availability !== "initial-loading");
|
||||
},
|
||||
);
|
||||
it("preserves empty successful data instead of treating it as missing", () => {
|
||||
@@ -37,7 +40,12 @@ describe("instrument source and transport presentation", () => {
|
||||
|
||||
it("preserves a full source when force fails", () => {
|
||||
const meta = resource([], {
|
||||
sync: { errorCode: "TBANK_UNAVAILABLE", id: "work", state: "failed" },
|
||||
lastAttempt: {
|
||||
finishedAt: "2026-08-14T00:01:00Z",
|
||||
problems: [],
|
||||
startedAt: "2026-08-14T00:00:00Z",
|
||||
state: "failed",
|
||||
},
|
||||
}).meta;
|
||||
|
||||
const state = section({ data: [], isError: false, meta });
|
||||
@@ -53,7 +61,12 @@ describe("instrument source and transport presentation", () => {
|
||||
data: undefined,
|
||||
isError: false,
|
||||
meta: resource(null, {
|
||||
sync: { errorCode: "TBANK_UNAVAILABLE", id: "work", state: "failed" },
|
||||
lastAttempt: {
|
||||
finishedAt: "2026-08-14T00:01:00Z",
|
||||
problems: [],
|
||||
startedAt: "2026-08-14T00:00:00Z",
|
||||
state: "failed",
|
||||
},
|
||||
}).meta,
|
||||
});
|
||||
|
||||
|
||||
@@ -16,14 +16,14 @@ function section(query: {
|
||||
isError: boolean;
|
||||
meta?: InvestmentResourceMeta;
|
||||
}): SectionState {
|
||||
const isError = query.isError || query.meta?.sync.state === "failed";
|
||||
const isError = query.isError || query.meta?.lastAttempt.state === "failed";
|
||||
const hasData = hasSectionData(query.data);
|
||||
|
||||
return {
|
||||
error: isError,
|
||||
hasData,
|
||||
loading: !hasData && !isError,
|
||||
partial: query.meta?.availability === "partial",
|
||||
partial: query.meta?.completeness === "incomplete",
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user