-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RSDK-4434 Update get location wrapper (#160)
- Loading branch information
1 parent
c590886
commit aada6aa
Showing
8 changed files
with
122 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export type { Navigation } from './navigation/navigation'; | ||
export type { ModeMap, Waypoint } from './navigation/types'; | ||
export type { ModeMap, Waypoint, NavigationPosition } from './navigation/types'; | ||
export { NavigationClient } from './navigation/client'; |
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,95 @@ | ||
// @vitest-environment happy-dom | ||
|
||
import { type Mock, beforeEach, describe, expect, test, vi } from 'vitest'; | ||
import { NavigationServiceClient } from '../../gen/service/navigation/v1/navigation_pb_service'; | ||
vi.mock('../../gen/service/navigation/v1/navigation_pb_service'); | ||
import { RobotClient } from '../../robot'; | ||
vi.mock('../../robot'); | ||
|
||
import { NavigationClient } from './client'; | ||
|
||
const navigationClientName = 'test-navigation'; | ||
|
||
let navigation: NavigationClient; | ||
|
||
beforeEach(() => { | ||
RobotClient.prototype.createServiceClient = vi | ||
.fn() | ||
.mockImplementation( | ||
() => new NavigationServiceClient(navigationClientName) | ||
); | ||
|
||
navigation = new NavigationClient( | ||
new RobotClient('host'), | ||
navigationClientName | ||
); | ||
}); | ||
|
||
const testLatitude = 50; | ||
const testLongitude = 75; | ||
const testCompassHeading = 90; | ||
|
||
describe('getLocation', () => { | ||
let latitude: Mock<[], number>; | ||
let longitude: Mock<[], number>; | ||
let compassHeading: Mock<[], number>; | ||
let location: Mock<[], { latitude: number; longitude: number }>; | ||
|
||
beforeEach(() => { | ||
location = vi.fn(() => ({ | ||
latitude: latitude(), | ||
longitude: longitude(), | ||
})); | ||
|
||
NavigationServiceClient.prototype.getLocation = vi | ||
.fn() | ||
.mockImplementation((_req, _md, cb) => { | ||
cb(null, { | ||
toObject: () => ({ | ||
compassHeading: compassHeading(), | ||
location: location(), | ||
}), | ||
}); | ||
}); | ||
}); | ||
|
||
test('null location', async () => { | ||
location = vi.fn(); | ||
compassHeading = vi.fn(); | ||
|
||
await expect(navigation.getLocation()).rejects.toThrowError( | ||
/^no location$/u | ||
); | ||
|
||
expect(location).toHaveBeenCalledOnce(); | ||
expect(compassHeading).toHaveBeenCalledOnce(); | ||
}); | ||
|
||
test('valid geopoint', async () => { | ||
latitude = vi.fn(() => testLatitude); | ||
longitude = vi.fn(() => testLongitude); | ||
compassHeading = vi.fn(() => testCompassHeading); | ||
|
||
const expected = { | ||
location: { latitude: testLatitude, longitude: testLongitude }, | ||
compassHeading: testCompassHeading, | ||
}; | ||
|
||
await expect(navigation.getLocation()).resolves.toStrictEqual(expected); | ||
|
||
expect(location).toHaveBeenCalledOnce(); | ||
expect(compassHeading).toHaveBeenCalledOnce(); | ||
}); | ||
|
||
test('invalid geopoint', async () => { | ||
latitude = vi.fn(() => Number.NaN); | ||
longitude = vi.fn(() => Number.NaN); | ||
|
||
await expect(navigation.getLocation()).rejects.toThrowError( | ||
/^invalid location$/u | ||
); | ||
|
||
expect(location).toHaveBeenCalledOnce(); | ||
expect(compassHeading).toHaveBeenCalledOnce(); | ||
}); | ||
}); |
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
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