From c80cf4f63d1a0c7ab255c354bed83a7f816d8203 Mon Sep 17 00:00:00 2001 From: "Daniel W. Steinbrook" Date: Sun, 24 Nov 2024 20:57:10 -0500 Subject: [PATCH] Unit tests for cache --- src/state/cache.test.ts | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/state/cache.test.ts diff --git a/src/state/cache.test.ts b/src/state/cache.test.ts new file mode 100644 index 0000000..c926064 --- /dev/null +++ b/src/state/cache.test.ts @@ -0,0 +1,38 @@ +import { cache } from "./cache"; +import { expect } from "chai"; + +describe("cache", () => { + it('should be empty for unloaded tiles', () => { + cache.getFeatures("16/18109/23965").then((result) => { + expect(result.length).to.equal(0); + }); + }); + + it('should store and retrieve features', () => { + // Real feature extracted from tile + cache.addFeature({ + "feature_type": "amenity", + "feature_value": "cafe", + "geometry": { + "coordinates": [-80.52166, 43.463198], + "type": "Point" + }, + "osm_ids": [503048818], + "properties": { + "amenity": "cafe", + "cuisine": "bubble_tea", + "name": "The Bingsu" + }, + "type": "Feature" + }, + "16/18109/23965"); + + cache.getFeatures("16/18109/23965").then((result) => { + expect(result.length).to.equal(1); + expect(result[0]).to.include({ + "feature_type": "amenity", + "feature_value": "cafe", + }); + }); + }); +}); \ No newline at end of file