Skip to content

Commit 11a9cd0

Browse files
committed
test(ol-feature, ol-map, ol-overlay): provide unit tests
re-use code from #252 big thanks to @chrstnbwnkl relates to #222
1 parent fb6a63a commit 11a9cd0

File tree

3 files changed

+123
-0
lines changed

3 files changed

+123
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { VueWrapper, mount } from "@vue/test-utils";
2+
import OlFeature from "../OlFeature.vue";
3+
import { beforeAll, describe, expect, it } from "vitest";
4+
import VectorSource from "ol/source/Vector";
5+
import { computed, ref } from "vue";
6+
7+
describe("OlMap.vue", () => {
8+
let featureComponent: VueWrapper;
9+
const props = ref({ attributions: "test" });
10+
const vectorSource = computed(() => {
11+
return new VectorSource(props.value);
12+
});
13+
14+
beforeAll(() => {
15+
featureComponent = mount(OlFeature, {
16+
props: {
17+
properties: {
18+
foo: "bar",
19+
},
20+
},
21+
global: {
22+
provide: {
23+
"ol-options": { debug: true },
24+
vectorSource,
25+
},
26+
},
27+
});
28+
});
29+
it("passes props to the feature constructor", () => {
30+
// @ts-ignore
31+
expect(featureComponent.vm.feature.getProperties().foo).toBe("bar");
32+
});
33+
it("updates feature properties on change", async () => {
34+
await featureComponent.setProps({ properties: { foo: "baz" } });
35+
// @ts-ignore
36+
expect(featureComponent.vm.feature.getProperties().foo).toBe("baz");
37+
});
38+
});
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { VueWrapper, mount } from "@vue/test-utils";
2+
import OlMap from "../OlMap.vue";
3+
import { beforeAll, describe, expect, it } from "vitest";
4+
import { FullScreen, Zoom } from "ol/control";
5+
6+
describe("OlMap.vue", () => {
7+
let mapComponent: VueWrapper;
8+
beforeAll(() => {
9+
mapComponent = mount(OlMap, {
10+
props: {
11+
controls: [new FullScreen({}), new Zoom({})],
12+
},
13+
global: {
14+
provide: {
15+
"ol-options": { debug: true },
16+
},
17+
},
18+
});
19+
});
20+
it("passes props to the map constructor", () => {
21+
const olViewportWrapepr = mapComponent.find(".ol-viewport");
22+
expect(olViewportWrapepr.exists());
23+
});
24+
it("renders viewport DOM element", () => {
25+
mapComponent.find(".ol-viewport").exists();
26+
});
27+
});
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { VueWrapper, mount } from "@vue/test-utils";
2+
import OlOverlay from "../OlOverlay.vue";
3+
import { beforeAll, describe, expect, it } from "vitest";
4+
import { Map } from "ol";
5+
6+
const map = new Map({});
7+
8+
describe("OlOverlay.vue", () => {
9+
let overlayComponent: VueWrapper;
10+
beforeAll(() => {
11+
overlayComponent = mount(OlOverlay, {
12+
props: {
13+
position: [974749, 6749373],
14+
positioning: "center-left",
15+
},
16+
global: {
17+
provide: {
18+
"ol-options": { debug: true },
19+
map,
20+
},
21+
},
22+
slots: {
23+
default: "this is not just any overlay",
24+
},
25+
});
26+
});
27+
it("sets the position on the overlay instance", () => {
28+
// @ts-ignore
29+
expect(overlayComponent.vm.overlay.getPosition()).toStrictEqual([
30+
974749, 6749373,
31+
]);
32+
});
33+
it("sets the positioning on the overlay instance", () => {
34+
// @ts-ignore
35+
expect(overlayComponent.vm.overlay.getPositioning()).toBe("center-left");
36+
});
37+
it("emits position:changed when position is updated via instance method", () => {
38+
// @ts-ignore
39+
overlayComponent.vm.setPosition([12, 13]);
40+
expect(overlayComponent.emitted()).toHaveProperty("change:position");
41+
expect(
42+
// @ts-ignore
43+
overlayComponent.emitted("change:position")[0][0].target.get("position"),
44+
).toStrictEqual([12, 13]);
45+
});
46+
it("emits position:changed when position property is updated", async () => {
47+
// @ts-ignore
48+
await overlayComponent.setProps({
49+
position: [12, 13],
50+
});
51+
52+
expect(overlayComponent.emitted()).toHaveProperty("change:position");
53+
expect(
54+
// @ts-ignore
55+
overlayComponent.emitted("change:position")[0][0].target.get("position"),
56+
).toStrictEqual([12, 13]);
57+
});
58+
});

0 commit comments

Comments
 (0)