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" 17 18export function mockObserver() { 19 const SimStateData = { 20 type: "[PC Preview] unknow type", 21 state: "[PC Preview] unknow state", 22 } 23 const observer = { 24 on: function (...args) { 25 console.warn("telephony.observer.on interface mocked in the Previewer. How this interface works on the Previewer may " + 26 "be different from that on a real device.") 27 const len = args.length 28 if (typeof args[len - 1] === 'function') { 29 if (args[0] === 'networkStateChange') { 30 args[len - 1].call(this, NetworkState); 31 } else if (args[0] === 'signalInfoChange') { 32 args[len - 1].call(this, [SignalInformation]); 33 } else if (args[0] === 'cellInfoChange') { 34 args[len - 1].call(this, [CellInformation]); 35 } else if (args[0] === 'cellularDataConnectionStateChange') { 36 args[len - 1].call(this, paramMock.businessErrorMock, { 37 state: "[PC Preview] unknow state", 38 network: "[PC Preview] unknow network" 39 }); 40 } else if (args[0] === 'cellularDataFlowChange') { 41 args[len - 1].call(this, DataFlowType); 42 } else if (args[0] === 'callStateChange') { 43 args[len - 1].call(this, paramMock.businessErrorMock, { 44 state: "[PC Preview] unknow state", 45 number: "[PC Preview] unknow number" 46 }); 47 } else if (args[0] === 'cfuIndicatorChange' || 'voiceMailMsgIndicatorChange') { 48 args[len - 1].call(this, paramMock.paramBooleanMock); 49 } else if (args[0] === 'simStateChange') { 50 args[len - 1].call(this, SimStateData); 51 } 52 } 53 }, 54 off: function (...args) { 55 console.warn("telephony.observer.off interface mocked in the Previewer. How this interface works on the Previewer may " + 56 "be different from that on a real device.") 57 const len = args.length 58 if (typeof args[len - 1] === 'function') { 59 if (args[0] === 'networkStateChange') { 60 args[len - 1].call(this, NetworkState); 61 } else if (args[0] === 'signalInfoChange') { 62 args[len - 1].call(this, [SignalInformation]); 63 } else if (args[0] === 'cellInfoChange') { 64 args[len - 1].call(this, [CellInformation]); 65 } else if (args[0] === 'cellularDataConnectionStateChange') { 66 args[len - 1].call(this, paramMock.businessErrorMock, { 67 state: "[PC Preview] unknow state", 68 network: "[PC Preview] unknow network" 69 }); 70 } else if (args[0] === 'cellularDataFlowChange') { 71 args[len - 1].call(this, DataFlowType); 72 } else if (args[0] === 'callStateChange') { 73 args[len - 1].call(this, paramMock.businessErrorMock, { 74 state: "[PC Preview] unknow state", 75 number: "[PC Preview] unknow number" 76 }); 77 } else if (args[0] === 'cfuIndicatorChange' || 'voiceMailMsgIndicatorChange') { 78 args[len - 1].call(this, paramMock.paramBooleanMock); 79 } else if (args[0] === 'simStateChange') { 80 args[len - 1].call(this, SimStateData); 81 } 82 } 83 }, 84 once: function (...args) { 85 console.warn("telephony.observer.once interface mocked in the Previewer. How this interface works on the Previewer may " + 86 "be different from that on a real device.") 87 const len = args.length 88 if (typeof args[len - 1] === 'function') { 89 if (args[0] === 'networkStateChange') { 90 args[len - 1].call(this, NetworkState); 91 } else if (args[0] === 'signalInfoChange') { 92 args[len - 1].call(this, [SignalInformation]); 93 } else if (args[0] === 'cellInfoChange') { 94 args[len - 1].call(this, [CellInformation]); 95 } else if (args[0] === 'cellularDataConnectionStateChange') { 96 args[len - 1].call(this, paramMock.businessErrorMock, { 97 state: "[PC Preview] unknow state", 98 network: "[PC Preview] unknow network" 99 }); 100 } else if (args[0] === 'cellularDataFlowChange') { 101 args[len - 1].call(this, DataFlowType); 102 } else if (args[0] === 'callStateChange') { 103 args[len - 1].call(this, paramMock.businessErrorMock, { 104 state: "[PC Preview] unknow state", 105 number: "[PC Preview] unknow number" 106 }); 107 } else if (args[0] === 'cfuIndicatorChange' || 'voiceMailMsgIndicatorChange') { 108 args[len - 1].call(this, paramMock.paramBooleanMock); 109 } else if (args[0] === 'simStateChange') { 110 args[len - 1].call(this, SimStateData); 111 } 112 } 113 } 114 } 115 return observer 116}