1/* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { paramMock } from "../utils" 17import { MissionInfo as _MissionInfo } from "./application/MissionInfo" 18import { MissionSnapshot as _MissionSnapshot } from "./application/MissionSnapshot" 19import { MissionListener as _MissionListener } from "./application/MissionListener" 20 21export function mockMissionManager() { 22 const missionManager = { 23 registerMissionListener: function (...args) { 24 console.warn("missionManager.registerMissionListener interface mocked in the Previewer. How this interface works on the Previewer" + 25 " may be different from that on a real device.") 26 return paramMock.paramNumberMock; 27 }, 28 unregisterMissionListener: function (...args) { 29 console.warn('missionManager.unregisterMissionListener interface mocked in the Previewer. How this interface works on the' + 30 ' Previewer may be different from that on a real device.'); 31 const len = args.length; 32 if (typeof args[len - 1] === 'function') { 33 args[len - 1].call(this, paramMock.businessErrorMock); 34 } else { 35 return new Promise((resolve) => { 36 resolve(); 37 }); 38 } 39 }, 40 getMissionInfo: function (...args) { 41 console.warn('missionManager.getMissionInfo interface mocked in the Previewer. How this interface works on the' + 42 ' Previewer may be different from that on a real device.'); 43 const len = args.length; 44 if (typeof args[len - 1] === 'function') { 45 args[len - 1].call(this, paramMock.businessErrorMock, _MissionInfo); 46 } else { 47 return new Promise((resolve) => { 48 resolve(_MissionInfo); 49 }); 50 } 51 }, 52 getMissionInfos: function (...args) { 53 console.warn('missionManager.getMissionInfos interface mocked in the Previewer. How this interface works on the' + 54 ' Previewer may be different from that on a real device.'); 55 const len = args.length; 56 if (typeof args[len - 1] === 'function') { 57 args[len - 1].call(this, paramMock.businessErrorMock, [_MissionInfo]); 58 } else { 59 return new Promise((resolve) => { 60 resolve([_MissionInfo]); 61 }); 62 } 63 }, 64 getMissionSnapShot: function (...args) { 65 console.warn('missionManager.getMissionSnapShot interface mocked in the Previewer. How this interface works on the' + 66 ' Previewer may be different from that on a real device.'); 67 const len = args.length; 68 if (typeof args[len - 1] === 'function') { 69 args[len - 1].call(this, paramMock.businessErrorMock, _MissionSnapshot); 70 } else { 71 return new Promise((resolve) => { 72 resolve(_MissionSnapshot); 73 }); 74 } 75 }, 76 getLowResolutionMissionSnapShot: function (...args) { 77 console.warn('missionManager.getLowResolutionMissionSnapShot interface mocked in the Previewer. How this interface works on the' + 78 ' Previewer may be different from that on a real device.'); 79 const len = args.length; 80 if (typeof args[len - 1] === 'function') { 81 args[len - 1].call(this, paramMock.businessErrorMock, _MissionSnapshot); 82 } else { 83 return new Promise((resolve) => { 84 resolve(_MissionSnapshot); 85 }); 86 } 87 }, 88 lockMission: function (...args) { 89 console.warn('missionManager.lockMission interface mocked in the Previewer. How this interface works on the' + 90 ' Previewer may be different from that on a real device.'); 91 const len = args.length; 92 if (typeof args[len - 1] === 'function') { 93 args[len - 1].call(this, paramMock.businessErrorMock); 94 } else { 95 return new Promise((resolve) => { 96 resolve(); 97 }); 98 } 99 }, 100 unlockMission: function (...args) { 101 console.warn('missionManager.unlockMission interface mocked in the Previewer. How this interface works on the' + 102 ' Previewer may be different from that on a real device.'); 103 const len = args.length; 104 if (typeof args[len - 1] === 'function') { 105 args[len - 1].call(this, paramMock.businessErrorMock); 106 } else { 107 return new Promise((resolve) => { 108 resolve(); 109 }); 110 } 111 }, 112 clearMission: function (...args) { 113 console.warn('missionManager.clearMission interface mocked in the Previewer. How this interface works on the' + 114 ' Previewer may be different from that on a real device.'); 115 const len = args.length; 116 if (typeof args[len - 1] === 'function') { 117 args[len - 1].call(this, paramMock.businessErrorMock); 118 } else { 119 return new Promise((resolve) => { 120 resolve(); 121 }); 122 } 123 }, 124 clearAllMissions: function (...args) { 125 console.warn('missionManager.clearAllMissions interface mocked in the Previewer. How this interface works on the' + 126 ' Previewer may be different from that on a real device.'); 127 const len = args.length; 128 if (typeof args[len - 1] === 'function') { 129 args[len - 1].call(this, paramMock.businessErrorMock); 130 } else { 131 return new Promise((resolve) => { 132 resolve(); 133 }); 134 } 135 }, 136 moveMissionToFront: function (...args) { 137 console.warn('missionManager.moveMissionToFront interface mocked in the Previewer. How this interface works on the' + 138 ' Previewer may be different from that on a real device.'); 139 const len = args.length; 140 if (typeof args[len - 1] === 'function') { 141 args[len - 1].call(this, paramMock.businessErrorMock); 142 } else { 143 return new Promise((resolve) => { 144 resolve(); 145 }); 146 } 147 }, 148 MissionInfo: _MissionInfo, 149 MissionListener: _MissionListener, 150 MissionSnapshot: _MissionSnapshot 151 } 152 return missionManager 153}