1/* 2 * Copyright (c) 2021 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 mockInputMethod() { 19 const KeyboardType = { 20 labelId: 1, 21 iconId: 2, 22 language: "[PC Preview] unknow language", 23 inputSource: "[PC Preview] unknow inputSource", 24 customizedValue: { 25 key: 1 26 }, 27 supportsAscii: true 28 } 29 const KeyboardTypeArry = [ 30 { 31 labelId: 1, 32 iconId: 2, 33 language: "[PC Preview] unknow language", 34 inputSource: "[PC Preview] unknow inputSource", 35 customizedValue: { 36 key: 1 37 }, 38 supportsAscii: true 39 } 40 ] 41 const InputMethodProperty = { 42 packageName :"[PC Preview] unknow packageName", 43 methodId: "[PC Preview] unknow method id" 44 } 45 const InputMethodPropertyArry = [ 46 { 47 methodId: "[PC Preview] unknow method id", 48 bundleName: "[PC Preview] unknow bundle name", 49 abilityName: "[PC Preview] unknow ability name", 50 configurationPage: "[PC Preview] unknow configuration page", 51 isSystemIme: true, 52 typeCount: 1, 53 defaultImeId: 2, 54 keyboardTypes: KeyboardTypeArry 55 } 56 ] 57 const InputMethodControllerMock = { 58 stopInput: function (...args) { 59 console.warn("InputMethodController.stopInput interface mocked in the Previewer. How this interface works on" + 60 " the Previewer may be different from that on a real device.") 61 const len = args.length 62 if (typeof args[len - 1] === 'function') { 63 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); 64 } else { 65 return new Promise((resolve, reject) => { 66 resolve(paramMock.paramBooleanMock); 67 }) 68 } 69 }, 70 showSoftKeyboard: function (...args) { 71 console.warn("InputMethodController.showSoftKeyboard interface mocked in the Previewer. How this interface works on" + 72 " the Previewer may be different from that on a real device.") 73 const len = args.length 74 if (typeof args[len - 1] === 'function') { 75 args[len - 1].call(this, paramMock.businessErrorMock); 76 } else { 77 return new Promise((resolve, reject) => { 78 resolve(); 79 }) 80 } 81 }, 82 hideSoftKeyboard: function (...args) { 83 console.warn("InputMethodController.hideSoftKeyboard interface mocked in the Previewer. How this interface works on" + 84 " the Previewer may be different from that on a real device.") 85 const len = args.length 86 if (typeof args[len - 1] === 'function') { 87 args[len - 1].call(this, paramMock.businessErrorMock); 88 } else { 89 return new Promise((resolve, reject) => { 90 resolve(); 91 }) 92 } 93 } 94 } 95 const InputMethodSettingMock = { 96 getCurrentKeyboardType: function (...args) { 97 console.warn("InputMethodSetting.getCurrentKeyboardType interface mocked in the Previewer. How this interface works on" + 98 " the Previewer may be different from that on a real device.") 99 const len = args.length 100 if (typeof args[len - 1] === 'function') { 101 args[len - 1].call(this, paramMock.businessErrorMock, KeyboardType); 102 } else { 103 return new Promise((resolve, reject) => { 104 resolve(KeyboardType); 105 }) 106 } 107 }, 108 listInputMethodEnabled: function (...args) { 109 console.warn("InputMethodSetting.listInputMethodEnabled interface mocked in the Previewer. How this interface works on" + 110 " the Previewer may be different from that on a real device.") 111 const len = args.length 112 if (typeof args[len - 1] === 'function') { 113 args[len - 1].call(this, paramMock.businessErrorMock, InputMethodPropertyArry); 114 } else { 115 return new Promise((resolve, reject) => { 116 resolve(InputMethodPropertyArry); 117 }) 118 } 119 }, 120 listKeyboardType: function (...args) { 121 console.warn("InputMethodSetting.listKeyboardType interface mocked in the Previewer. How this interface works on" + 122 " the Previewer may be different from that on a real device.") 123 const len = args.length 124 if (typeof args[len - 1] === 'function') { 125 args[len - 1].call(this, paramMock.businessErrorMock, KeyboardTypeArry); 126 } else { 127 return new Promise((resolve, reject) => { 128 resolve(KeyboardTypeArry); 129 }) 130 } 131 }, 132 listInputMethod: function (...args) { 133 console.warn("InputMethodSetting.listInputMethod interface mocked in the Previewer. How this interface works on" + 134 " the Previewer may be different from that on a real device.") 135 const len = args.length 136 if (typeof args[len - 1] === 'function') { 137 args[len - 1].call(this, paramMock.businessErrorMock, InputMethodPropertyArry); 138 } else { 139 return new Promise((resolve, reject) => { 140 resolve(InputMethodPropertyArry); 141 }) 142 } 143 }, 144 displayOptionalInputMethod: function (...args) { 145 console.warn("InputMethodSetting.displayOptionalInputMethod interface mocked in the Previewer. How this interface works on" + 146 " the Previewer may be different from that on a real device.") 147 const len = args.length 148 if (typeof args[len - 1] === 'function') { 149 args[len - 1].call(this, paramMock.businessErrorMock); 150 } else { 151 return new Promise((resolve, reject) => { 152 resolve(); 153 }) 154 } 155 }, 156 } 157 const inputMethod = { 158 MAX_TYPE_NUM: 128, 159 getInputMethodController: function () { 160 console.warn("inputmethod.getInputMethodController interface mocked in the Previewer. How this interface works" + 161 " on the Previewer may be different from that on a real device.") 162 return InputMethodControllerMock; 163 }, 164 getInputMethodSetting: function () { 165 console.warn("inputmethod.getInputMethodSetting interface mocked in the Previewer. How this interface works" + 166 " on the Previewer may be different from that on a real device.") 167 return InputMethodSettingMock; 168 }, 169 getCurrentInputMethod: function () { 170 console.warn("inputmethod.getCurrentInputMethod interface mocked in the Previewer. How this interface works" + 171 " on the Previewer may be different from that on a real device.") 172 return InputMethodProperty; 173 }, 174 switchInputMethod: function (...args) { 175 console.warn("inputMethod.switchInputMethod interface mocked in the Previewer. How this interface works on" + 176 " the Previewer may be different from that on a real device.") 177 const len = args.length 178 if (typeof args[len - 1] === 'function') { 179 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); 180 } else { 181 return new Promise((resolve, reject) => { 182 resolve(paramMock.paramBooleanMock); 183 }) 184 } 185 }, 186 } 187 return inputMethod 188}