-
Notifications
You must be signed in to change notification settings - Fork 362
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- log to analytics - handle empty result - add unit test
- Loading branch information
Showing
4 changed files
with
110 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
test/Models/SearchProviders/CesiumIonSearchProviderSpec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import CesiumIonSearchProvider from "../../../lib/Models/SearchProviders/CesiumIonSearchProvider"; | ||
import Terria from "../../../lib/Models//Terria"; | ||
import * as loadJson from "../../../lib/Core/loadJson"; | ||
|
||
const fixture = { | ||
features: [ | ||
{ | ||
properties: { | ||
label: "West End, Australia" | ||
}, | ||
bbox: [ | ||
152.99620056152344, -27.490509033203125, 153.0145721435547, | ||
-27.474090576171875 | ||
] | ||
} | ||
] | ||
}; | ||
|
||
describe("CesiumIonSearchProvider", () => { | ||
const searchProvider = new CesiumIonSearchProvider({ | ||
key: "testkey", | ||
url: "api.test.com", | ||
terria: { | ||
currentViewer: { | ||
zoomTo: () => {} | ||
} | ||
} as unknown as Terria | ||
}); | ||
it("Handles valid results", async () => { | ||
spyOn(loadJson, "default").and.returnValue( | ||
new Promise((resolve) => resolve(fixture)) | ||
); | ||
|
||
const result = await searchProvider.search("test"); | ||
expect(loadJson.default).toHaveBeenCalledWith( | ||
"api.test.com?text=test&access_token=testkey" | ||
); | ||
expect(result.results.length).toBe(1); | ||
expect(result.results[0].name).toBe("West End, Australia"); | ||
expect(result.results[0].location?.latitude).toBe(-27.4822998046875); | ||
}); | ||
|
||
it("Handles empty result", async () => { | ||
spyOn(loadJson, "default").and.returnValue( | ||
new Promise((resolve) => resolve([])) | ||
); | ||
const result = await searchProvider.search("test"); | ||
console.log(result); | ||
expect(result.results.length).toBe(0); | ||
expect(result.message).toBe("viewModels.searchNoLocations"); | ||
}); | ||
|
||
it("Handles error", async () => { | ||
spyOn(loadJson, "default").and.throwError("error"); | ||
const result = await searchProvider.search("test"); | ||
expect(result.results.length).toBe(0); | ||
expect(result.message).toBe("viewModels.searchErrorOccurred"); | ||
}); | ||
}); |