Improve terminal chart loading states

This commit is contained in:
2569718930@qq.com
2026-05-30 22:37:08 +08:00
parent a48a7bcca5
commit 6222f60573
4 changed files with 93 additions and 3 deletions
@@ -1,4 +1,5 @@
import { __buildTemperatureStatsLabelsForTest } from "@/components/dashboard/scan-terminal/TemperatureStatsBars";
import { temp } from "@/components/dashboard/scan-terminal/utils";
function assert(condition: unknown, message: string) {
if (!condition) throw new Error(message);
@@ -46,4 +47,8 @@ export function runTests() {
assert(zh.primary === "天文台实测 (10分钟)", "Chinese primary label should remain unchanged");
assert(zh.compactSecondary === "当日最高", "Chinese Shenzhen compact secondary label should remain 当日最高");
assert(temp(null, "°C") === "--", "empty temperature values should not render as 0.0°C while city detail is loading");
assert(temp(undefined, "°C") === "--", "undefined temperature values should not render as 0.0°C while city detail is loading");
assert(temp("", "°C") === "--", "blank temperature values should not render as 0.0°C while city detail is loading");
}
@@ -121,6 +121,19 @@ export function runTests() {
);
assert(
__shouldKeepTemperatureChartLoadingForTest({
row: { city: "Moscow" } as any,
isHourlyLoading: true,
activeSeries: [],
probabilityOverlay: null,
zoomedData: [
{ label: "00:00", ts: 1 },
{ label: "05:00", ts: 2 },
],
}),
"temperature chart should show the loading skeleton while the first detail fetch is in flight and no drawable data exists",
);
assert(
!__shouldKeepTemperatureChartLoadingForTest({
row: { city: "Moscow" } as any,
isHourlyLoading: false,
activeSeries: [],
@@ -130,7 +143,7 @@ export function runTests() {
{ label: "05:00", ts: 2 },
],
}),
"temperature chart must keep loading instead of rendering an empty axis grid when no drawable series is available",
"temperature chart must stop showing an indefinite loading overlay after the detail fetch finishes without drawable data",
);
assert(
!__shouldKeepTemperatureChartLoadingForTest({
@@ -153,4 +166,25 @@ export function runTests() {
}),
"temperature chart should render once a visible series has drawable values",
);
assert(
!__shouldKeepTemperatureChartLoadingForTest({
row: { city: "Moscow" } as any,
isHourlyLoading: true,
activeSeries: [
{
key: "current",
label: "Current reference",
source: "Live",
color: "#009688",
values: [13, 13],
},
] as any,
probabilityOverlay: null,
zoomedData: [
{ label: "00:00", ts: 1, current: 13 },
{ label: "05:00", ts: 2, current: 13 },
],
}),
"temperature chart must render seeded or cached data immediately while full detail continues loading in the background",
);
}