@@ -9,6 +9,7 @@ vi.mock('../../robot');
99import { EventDispatcher } from '../../events' ;
1010import {
1111 GetInternalStateResponse ,
12+ GetPointCloudMapRequest ,
1213 GetPointCloudMapResponse ,
1314} from '../../gen/service/slam/v1/slam_pb' ;
1415import { SlamClient } from './client' ;
@@ -39,21 +40,34 @@ export class TestResponseStream<T> extends EventDispatcher {
3940
4041let pcdStream : ResponseStream < GetPointCloudMapResponse > ;
4142let testPcdStream : TestResponseStream < GetPointCloudMapResponse > | undefined ;
43+ let testPcdStreamEdited :
44+ | TestResponseStream < GetPointCloudMapResponse >
45+ | undefined ;
4246let internalStream : ResponseStream < GetInternalStateResponse > ;
4347let testInternalStream :
4448 | TestResponseStream < GetInternalStateResponse >
4549 | undefined ;
4650
51+ const pointCloudMapMockfn = (
52+ requestMessage : GetPointCloudMapRequest
53+ ) : TestResponseStream < GetPointCloudMapResponse > | undefined => {
54+ if ( requestMessage . getReturnEditedMap ( ) ) {
55+ return testPcdStreamEdited ;
56+ }
57+ return testPcdStream ;
58+ } ;
59+
4760beforeEach ( ( ) => {
4861 testPcdStream = new TestResponseStream ( pcdStream ) ;
62+ testPcdStreamEdited = new TestResponseStream ( pcdStream ) ;
4963 testInternalStream = new TestResponseStream ( internalStream ) ;
5064 RobotClient . prototype . createServiceClient = vi
5165 . fn ( )
5266 . mockImplementation ( ( ) => new SLAMServiceClient ( 'myslam' ) ) ;
5367
5468 SLAMServiceClient . prototype . getPointCloudMap = vi
5569 . fn ( )
56- . mockImplementation ( ( ) => testPcdStream ) ;
70+ . mockImplementation ( pointCloudMapMockfn ) ;
5771 SLAMServiceClient . prototype . getInternalState = vi
5872 . fn ( )
5973 . mockImplementation ( ( ) => testInternalStream ) ;
@@ -83,6 +97,24 @@ describe('getPointCloudMap tests', () => {
8397
8498 const array = new Uint8Array ( [ 4 , 13 , 16 , 25 ] ) ;
8599 expect ( promise ) . resolves . toStrictEqual ( array ) ;
100+
101+ // test map edit bool
102+ const promiseEdit = slam . getPointCloudMap ( true ) ;
103+ // unused chunk
104+ const response3 = new GetPointCloudMapResponse ( ) ;
105+ const chunk3 = new Uint8Array ( [ 4 , 27 ] ) ;
106+ response3 . setPointCloudPcdChunk ( chunk3 ) ;
107+ testPcdStream ?. emit ( 'data' , response3 ) ;
108+ testPcdStream ?. emit ( 'end' , { code : 0 } ) ;
109+ // used chunk
110+ const response3Edited = new GetPointCloudMapResponse ( ) ;
111+ const chunk3Edited = new Uint8Array ( [ 5 , 38 ] ) ;
112+ response3Edited . setPointCloudPcdChunk ( chunk3Edited ) ;
113+ testPcdStreamEdited ?. emit ( 'data' , response3Edited ) ;
114+ testPcdStreamEdited ?. emit ( 'end' , { code : 0 } ) ;
115+
116+ const arrayEdit = new Uint8Array ( [ 5 , 38 ] ) ;
117+ expect ( promiseEdit ) . resolves . toStrictEqual ( arrayEdit ) ;
86118 } ) ;
87119
88120 it ( 'end getPcdMap stream with wrong code' , ( ) => {
0 commit comments