• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  }
71  const InputMethodSettingMock = {
72    getCurrentKeyboardType: function (...args) {
73      console.warn("InputMethodSetting.getCurrentKeyboardType interface mocked in the Previewer. How this interface works on" +
74        " the Previewer may be different from that on a real device.")
75      const len = args.length
76      if (typeof args[len - 1] === 'function') {
77        args[len - 1].call(this, paramMock.businessErrorMock, KeyboardType);
78      } else {
79        return new Promise((resolve, reject) => {
80          resolve(KeyboardType);
81        })
82      }
83    },
84    listInputMethodEnabled: function (...args) {
85      console.warn("InputMethodSetting.listInputMethodEnabled interface mocked in the Previewer. How this interface works on" +
86        " the Previewer may be different from that on a real device.")
87      const len = args.length
88      if (typeof args[len - 1] === 'function') {
89        args[len - 1].call(this, paramMock.businessErrorMock, InputMethodPropertyArry);
90      } else {
91        return new Promise((resolve, reject) => {
92          resolve(InputMethodPropertyArry);
93        })
94      }
95    },
96    listKeyboardType: function (...args) {
97      console.warn("InputMethodSetting.listKeyboardType 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, KeyboardTypeArry);
102      } else {
103        return new Promise((resolve, reject) => {
104          resolve(KeyboardTypeArry);
105        })
106      }
107    },
108    listInputMethod: function (...args) {
109      console.warn("InputMethodSetting.listInputMethod 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    displayOptionalInputMethod: function (...args) {
121      console.warn("InputMethodSetting.displayOptionalInputMethod 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);
126      } else {
127        return new Promise((resolve, reject) => {
128          resolve();
129        })
130      }
131    },
132  }
133  const inputMethod = {
134    MAX_TYPE_NUM: 128,
135    getInputMethodController: function () {
136      console.warn("inputmethod.getInputMethodController interface mocked in the Previewer. How this interface works" +
137        " on the Previewer may be different from that on a real device.")
138      return InputMethodControllerMock;
139    },
140    getInputMethodSetting: function () {
141      console.warn("inputmethod.getInputMethodSetting interface mocked in the Previewer. How this interface works" +
142        " on the Previewer may be different from that on a real device.")
143      return InputMethodSettingMock;
144    },
145    getCurrentInputMethod: function () {
146      console.warn("inputmethod.getCurrentInputMethod interface mocked in the Previewer. How this interface works" +
147        " on the Previewer may be different from that on a real device.")
148      return InputMethodProperty;
149    },
150    switchInputMethod: function (...args) {
151      console.warn("inputMethod.switchInputMethod interface mocked in the Previewer. How this interface works on" +
152        " the Previewer may be different from that on a real device.")
153      const len = args.length
154      if (typeof args[len - 1] === 'function') {
155        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock);
156      } else {
157        return new Promise((resolve, reject) => {
158          resolve(paramMock.paramBooleanMock);
159        })
160      }
161    },
162  }
163  return inputMethod
164}