Skip to content

Commit

Permalink
Add a unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
ThorntonMatthewD authored and oliviasculley committed Oct 29, 2023
1 parent 60f9bcd commit 3631dce
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/tests/stores/map.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,59 @@ describe("mapStore", () => {
mapStore.removeMapLayer(fakeMapSlug);
expect(mapStore.loadedMaps).toStrictEqual({});
});

describe("clearLayerData", () => {
it("clears feature collection and retains options from previous copy of layer", async () => {
const featureCollection: GeoJSON.FeatureCollection<any> = {
type: "FeatureCollection",
features: [
{
type: "Feature",
geometry: {
type: "Point",
coordinates: [0, 0],
},
properties: {},
},
],
};

const mapStore = useMapStore();
const layerData: LayerData = {
layer: L.geoJSON(featureCollection, {
style: () => ({
fillColor: "test",
color: "test",
}),
}),
loaded: false,
visible: false,
};

mapStore.addMapLayer(fakeMapSlug, layerData, sampleMaintainerData);

const beforeKeyCount = Object.keys(
mapStore.loadedMaps[fakeMapSlug].layer,
).length;

await mapStore.clearLayerData();

const afterKeyCount = Object.keys(
mapStore.loadedMaps[fakeMapSlug].layer,
).length;

expect(beforeKeyCount).toBeGreaterThan(afterKeyCount);

expect(typeof layerData.layer.options.style).toEqual("function");

if (typeof layerData.layer.options.style == "function") {
expect(JSON.stringify(layerData.layer.options.style())).toEqual(
JSON.stringify({
fillColor: "test",
color: "test",
}),
);
}
});
});
});

0 comments on commit 3631dce

Please sign in to comment.