Files
planet/frontend/public/earth/js/earth-update-batch.test.js
linkong c1d651589a
ci / backend (push) Has been cancelled
ci / frontend (push) Has been cancelled
ci / delivery (push) Has been cancelled
release / images (push) Has been cancelled
release: bump version to 0.76.19
2026-11-09 15:12:50 +08:00

33 lines
1.2 KiB
JavaScript

import { expect, test } from "bun:test";
import { refreshEarthUpdateBatch } from "./earth-update-batch.js";
function batchFixture(layers) {
const calls = [];
return {
calls,
batch: () => refreshEarthUpdateBatch({
layers,
strategies: new Map(layers.map((layer) => [layer, "reload"])),
isDatabaseChange: true,
loadSummary: async () => { calls.push("summary"); },
refreshLayer: async (layer, options) => { calls.push({ layer, options }); },
}),
};
}
test("a news-only database update refreshes news without fetching Earth summary", async () => {
const fixture = batchFixture(["news"]);
expect(await fixture.batch()).toEqual([{ status: "fulfilled", value: undefined }]);
expect(fixture.calls).toEqual([{ layer: "news", options: { force: true, strategy: "reload" } }]);
});
test("a mixed news and vessel update refreshes summary before both layers", async () => {
const fixture = batchFixture(["news", "vessels"]);
expect(await fixture.batch()).toHaveLength(2);
expect(fixture.calls).toEqual([
"summary",
{ layer: "news", options: { force: true, strategy: "reload" } },
{ layer: "vessels", options: { force: true, strategy: "reload" } },
]);
});