Skip to content

Commit 4425a4e

Browse files
committed
test(raster): pin that a repeated sync keeps a local raster's path
Answers review feedback on #1472 suggesting localFilePath be added to GEOLIBRE_OWNED_METADATA_KEYS. It does not need to be: unlike the keys on that list, localFilePath is re-derived from the path registry by createRasterStoreLayer on every sync. This locks that in.
1 parent 0027fb2 commit 4425a4e

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

tests/raster-layer-sync.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,33 @@ describe("syncRasterLayersToStore", () => {
305305
assert.deepEqual(layer.metadata.nativeLayerIds, []);
306306
});
307307

308+
// localFilePath is derived from the path registry on every sync rather than
309+
// carried in GEOLIBRE_OWNED_METADATA_KEYS, so a repeated sync (any control
310+
// event: an opacity drag, a header load) must not drop it. The registry
311+
// outlives a control teardown -- LayerManager.destroy() clears its layers
312+
// without emitting rasterremove -- so the only thing that forgets a path is
313+
// an actual raster removal, which drops the store layer too.
314+
it("keeps a local raster's path across repeated syncs", () => {
315+
const fileInfo = rasterInfo({
316+
source: { kind: "file", fileName: "local.tif", objectUrl: "blob:x" },
317+
});
318+
rememberLocalRasterPath("raster-1", "/data/local.tif");
319+
try {
320+
syncRasterLayersToStore(fakeControl([fileInfo]).control);
321+
assert.equal(useAppStore.getState().layers[0].metadata.localFilePath, "/data/local.tif");
322+
323+
// A later control event rebuilds the metadata wholesale.
324+
syncRasterLayersToStore(
325+
fakeControl([{ ...fileInfo, state: rasterState({ opacity: 0.4 }) }]).control,
326+
);
327+
const layer = useAppStore.getState().layers[0];
328+
assert.equal(layer.opacity, 0.4);
329+
assert.equal(layer.metadata.localFilePath, "/data/local.tif");
330+
} finally {
331+
rememberLocalRasterPath("raster-1", undefined);
332+
}
333+
});
334+
308335
it("removes store layers whose rasters are gone", () => {
309336
const { control } = fakeControl([rasterInfo()]);
310337
syncRasterLayersToStore(control);

0 commit comments

Comments
 (0)