-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcompatibility.integration.test.ts
More file actions
210 lines (176 loc) · 6.94 KB
/
Copy pathcompatibility.integration.test.ts
File metadata and controls
210 lines (176 loc) · 6.94 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
import { describe, expect, it } from "vitest";
import type { SceneProperty } from "../Engine/ref";
import { applyBackwardCompatibility } from "./backwardCompatibility";
import { applyFallbacks } from "./fallbacks";
describe("Backward Compatibility + Fallbacks Integration", () => {
it("should apply both backward compatibility and fallbacks when no token", () => {
// Old format with no Cesium Ion token
const input: SceneProperty = {
default: {},
tiles: [
{ id: "tile-1", tile_type: "default" },
{ id: "tile-2", tile_type: "black_marble" },
{ id: "tile-3", tile_type: "stamen_toner" },
],
terrain: {
terrain: true,
},
};
// Step 1: Apply backward compatibility
const afterBackwardCompat = applyBackwardCompatibility(input);
expect(afterBackwardCompat?.tiles).toEqual([
{ id: "tile-1", tile_type: "cesium_ion", cesium_ion_asset_id: 2 },
{ id: "tile-2", tile_type: "cesium_ion", cesium_ion_asset_id: 3812 },
{ id: "tile-3", tile_type: "open_street_map" },
]);
expect(afterBackwardCompat?.terrain).toEqual({
terrain: true,
terrainType: "reearth_terrain", // Default added when missing
});
// Step 2: Apply fallbacks (no token, so fallbacks apply)
const final = applyFallbacks(afterBackwardCompat);
expect(final?.tiles).toEqual([
{ id: "tile-1", tile_type: "google_satellite", cesium_ion_asset_id: 2 },
{ id: "tile-2", tile_type: "nasa_black_marble", cesium_ion_asset_id: 3812 },
{ id: "tile-3", tile_type: "open_street_map" }, // No change (not cesium_ion)
]);
expect(final?.terrain).toEqual({
terrain: true,
terrainType: "reearth_terrain", // Default was added in backward compat step
});
});
it("should apply backward compatibility but NOT fallbacks when token is present", () => {
// Old format with Cesium Ion token
const input: SceneProperty = {
default: {
ion: "my-cesium-ion-token",
},
tiles: [
{ id: "tile-1", tile_type: "default" },
{ id: "tile-2", tile_type: "default_label" },
],
terrain: {
terrain: true,
},
};
// Step 1: Apply backward compatibility
const afterBackwardCompat = applyBackwardCompatibility(input);
expect(afterBackwardCompat?.tiles).toEqual([
{ id: "tile-1", tile_type: "cesium_ion", cesium_ion_asset_id: 2 },
{ id: "tile-2", tile_type: "cesium_ion", cesium_ion_asset_id: 3 },
]);
expect(afterBackwardCompat?.terrain).toEqual({
terrain: true,
terrainType: "reearth_terrain", // Default added when missing
});
// Step 2: Apply fallbacks (has token, so NO fallbacks)
const final = applyFallbacks(afterBackwardCompat);
// Should remain as cesium_ion because token is present
expect(final?.tiles).toEqual([
{ id: "tile-1", tile_type: "cesium_ion", cesium_ion_asset_id: 2 },
{ id: "tile-2", tile_type: "cesium_ion", cesium_ion_asset_id: 3 },
]);
expect(final?.terrain).toEqual({
terrain: true,
terrainType: "reearth_terrain", // Default was added in backward compat step
});
});
it("should handle tile without tile_type (adds google_satellite default)", () => {
const input: SceneProperty = {
tiles: [{ id: "tile-1", tile_url: "https://example.com" }],
};
// Step 1: Backward compatibility (adds google_satellite default)
const afterBackwardCompat = applyBackwardCompatibility(input);
expect(afterBackwardCompat?.tiles?.[0]).toEqual({
id: "tile-1",
tile_url: "https://example.com",
tile_type: "google_satellite", // Default added
});
// Step 2: Apply fallbacks (google_satellite doesn't need fallback)
const final = applyFallbacks(afterBackwardCompat);
expect(final?.tiles?.[0]).toEqual({
id: "tile-1",
tile_url: "https://example.com",
tile_type: "google_satellite", // Remains google_satellite
});
});
it("should handle esri_world_topo migration without fallback", () => {
const input: SceneProperty = {
tiles: [{ id: "tile-1", tile_type: "esri_world_topo" }],
};
// Step 1: Backward compatibility
const afterBackwardCompat = applyBackwardCompatibility(input);
expect(afterBackwardCompat?.tiles?.[0]).toEqual({
id: "tile-1",
tile_type: "open_street_map",
});
// Step 2: Fallbacks (no cesium_ion, so no fallback needed)
const final = applyFallbacks(afterBackwardCompat);
expect(final?.tiles?.[0]).toEqual({
id: "tile-1",
tile_type: "open_street_map",
});
});
it("should handle arcgis (legacy) terrain migration without fallback", () => {
const input: SceneProperty = {
terrain: {
terrain: true,
terrainType: "arcgis" as any, // Legacy type not in current union
},
};
// Step 1: Backward compatibility
const afterBackwardCompat = applyBackwardCompatibility(input);
expect(afterBackwardCompat?.terrain).toEqual({
terrain: true,
terrainType: "reearth_terrain",
});
// Step 2: Fallbacks (not "cesium", so no fallback applies)
const final = applyFallbacks(afterBackwardCompat);
expect(final?.terrain).toEqual({
terrain: true,
terrainType: "reearth_terrain",
});
});
it("should handle mixed scenario: some tiles need fallback, some don't", () => {
const input: SceneProperty = {
tiles: [
{ id: "tile-1", tile_type: "default" }, // → cesium_ion → google_satellite
{ id: "tile-2", tile_type: "esri_world_topo" }, // → open_street_map (no fallback)
{ id: "tile-3", tile_type: "default_road" }, // → cesium_ion → google_roadmap
],
};
// Apply both transformations
const afterBackwardCompat = applyBackwardCompatibility(input);
const final = applyFallbacks(afterBackwardCompat);
expect(final?.tiles).toEqual([
{ id: "tile-1", tile_type: "google_satellite", cesium_ion_asset_id: 2 },
{ id: "tile-2", tile_type: "open_street_map" },
{ id: "tile-3", tile_type: "google_roadmap", cesium_ion_asset_id: 4 },
]);
});
it("should preserve properties through both transformations", () => {
const input: SceneProperty = {
default: {
camera: { lat: 35, lng: 139, height: 1000, heading: 0, pitch: -45, roll: 0, fov: 1 },
bgcolor: "#1a1a1a",
},
tiles: [{ id: "tile-1", tile_type: "default", tile_opacity: 0.8 }],
atmosphere: {
enable_sun: true,
enable_lighting: true,
},
};
const afterBackwardCompat = applyBackwardCompatibility(input);
const final = applyFallbacks(afterBackwardCompat);
// Non-tile/terrain properties should be preserved
expect(final?.default).toEqual(input.default);
expect(final?.atmosphere).toEqual(input.atmosphere);
// Tile should be transformed with opacity preserved
expect(final?.tiles?.[0]).toEqual({
id: "tile-1",
tile_type: "google_satellite",
cesium_ion_asset_id: 2,
tile_opacity: 0.8,
});
});
});