-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcesiumIonDetection.test.ts
More file actions
221 lines (193 loc) · 6.58 KB
/
Copy pathcesiumIonDetection.test.ts
File metadata and controls
221 lines (193 loc) · 6.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
import { describe, expect, test } from "vitest";
import { computeHasCesiumIonAsset } from "./cesiumIonDetection";
const makeSimple = (data?: object) => ({
id: "layer1",
type: "simple" as const,
...(data ? { data } : {}),
});
const makeGroup = (children: object[]) => ({
id: "group1",
type: "group" as const,
children,
});
describe("computeHasCesiumIonAsset", () => {
describe("tiles", () => {
test("returns false when no tiles", () => {
expect(computeHasCesiumIonAsset({ tiles: [] })).toBe(false);
});
test("returns true for cesium_ion tile type", () => {
expect(computeHasCesiumIonAsset({ tiles: [{ type: "cesium_ion" }] })).toBe(true);
});
test("returns true for cesium_ion_default tile type", () => {
expect(computeHasCesiumIonAsset({ tiles: [{ type: "cesium_ion_default" }] })).toBe(true);
});
test("returns true for legacy tile types", () => {
for (const type of ["default", "default_road", "default_label", "black_marble"]) {
expect(computeHasCesiumIonAsset({ tiles: [{ type }] })).toBe(true);
}
});
test("returns false for non-ion tile type", () => {
expect(computeHasCesiumIonAsset({ tiles: [{ type: "open_street_map" }] })).toBe(false);
});
});
describe("terrain", () => {
test("returns true for cesium terrain type when enabled", () => {
expect(
computeHasCesiumIonAsset({
terrain: { enabled: true, type: "cesium" },
}),
).toBe(true);
});
test("returns true for cesiumion terrain type when enabled", () => {
expect(
computeHasCesiumIonAsset({
terrain: { enabled: true, type: "cesiumion" },
}),
).toBe(true);
});
test("returns false for cesium terrain when disabled", () => {
expect(
computeHasCesiumIonAsset({
terrain: { enabled: false, type: "cesium" },
}),
).toBe(false);
});
test("returns true for ion terrain URL", () => {
expect(
computeHasCesiumIonAsset({
terrain: { enabled: true, type: "url" },
assets: {
cesium: {
terrain: {
ionUrl: "https://assets.ion.cesium.com/1/tileset.json",
},
},
},
} as any),
).toBe(true);
});
test("returns false for non-ion terrain URL", () => {
expect(
computeHasCesiumIonAsset({
terrain: { enabled: true, type: "url" },
assets: {
cesium: { terrain: { ionUrl: "https://example.com/terrain" } },
},
} as any),
).toBe(false);
});
});
describe("layers", () => {
test("returns true for osm-buildings layer", () => {
expect(
computeHasCesiumIonAsset(undefined, [makeSimple({ type: "osm-buildings" })] as any),
).toBe(true);
});
test("returns true for google-photorealistic with cesium-ion provider", () => {
expect(
computeHasCesiumIonAsset(undefined, [
makeSimple({ type: "google-photorealistic", provider: "cesium-ion" }),
] as any),
).toBe(true);
});
test("returns false for google-photorealistic with reearth provider", () => {
expect(
computeHasCesiumIonAsset(undefined, [
makeSimple({ type: "google-photorealistic", provider: "reearth" }),
] as any),
).toBe(false);
});
test("returns false for google-photorealistic with no provider (google API path)", () => {
expect(
computeHasCesiumIonAsset(undefined, [makeSimple({ type: "google-photorealistic" })] as any),
).toBe(false);
});
test("returns true for layer with ion URL", () => {
expect(
computeHasCesiumIonAsset(undefined, [
makeSimple({
type: "3dtiles",
url: "https://assets.ion.cesium.com/123/tileset.json",
}),
] as any),
).toBe(true);
});
test("returns true for any layer type with ion URL", () => {
expect(
computeHasCesiumIonAsset(undefined, [
makeSimple({
type: "geojson",
url: "https://assets.ion.cesium.com/456/data.json",
}),
] as any),
).toBe(true);
});
test("returns false for layer with non-ion URL", () => {
expect(
computeHasCesiumIonAsset(undefined, [
makeSimple({
type: "3dtiles",
url: "https://example.com/tileset.json",
}),
] as any),
).toBe(false);
});
test("returns false for layer with no data", () => {
expect(computeHasCesiumIonAsset(undefined, [makeSimple()] as any)).toBe(false);
});
});
describe("layer groups (recursion)", () => {
test("returns true when nested layer uses ion", () => {
const group = makeGroup([makeSimple({ type: "osm-buildings" })]);
expect(computeHasCesiumIonAsset(undefined, [group] as any)).toBe(true);
});
test("returns false when nested layer does not use ion", () => {
const group = makeGroup([
makeSimple({ type: "geojson", url: "https://example.com/data.json" }),
]);
expect(computeHasCesiumIonAsset(undefined, [group] as any)).toBe(false);
});
test("returns true when deeply nested layer uses ion", () => {
const inner = makeGroup([makeSimple({ type: "osm-buildings" })]);
const outer = makeGroup([inner]);
expect(computeHasCesiumIonAsset(undefined, [outer] as any)).toBe(true);
});
});
describe("combined", () => {
test("returns false when nothing uses ion", () => {
expect(
computeHasCesiumIonAsset(
{
tiles: [{ type: "open_street_map" }],
terrain: { enabled: false, type: "cesium" },
},
[
makeSimple({
type: "geojson",
url: "https://example.com/data.json",
}),
] as any,
),
).toBe(false);
});
test("returns true when only tile uses ion", () => {
expect(
computeHasCesiumIonAsset({ tiles: [{ type: "default" }] }, [
makeSimple({ type: "geojson" }),
] as any),
).toBe(true);
});
test("returns true when only terrain uses ion", () => {
expect(
computeHasCesiumIonAsset({ terrain: { enabled: true, type: "cesium" } }, [
makeSimple({ type: "geojson" }),
] as any),
).toBe(true);
});
test("returns undefined-safe (no property, no layers)", () => {
expect(computeHasCesiumIonAsset()).toBe(false);
expect(computeHasCesiumIonAsset(undefined, undefined)).toBe(false);
expect(computeHasCesiumIonAsset(undefined, [])).toBe(false);
});
});
});