mirror of
https://github.com/openharmony/third_party_jsframework.git
synced 2026-07-21 01:45:24 -04:00
8b01c6866b
Description:add input js api mock Sig:jsframework Feature or Bugfix:Bugfix Binary Source:No Signed-off-by: wangdengjia <wangdengjia@huawei.com> Change-Id: Ic0f030c38b4be925c61289bb6e9c5ad9d0e12f60 Signed-off-by: wangdengjia <wangdengjia@huawei.com> Signed-off-by: root <root@W00584994.china.huawei.com>
137 lines
5.2 KiB
JavaScript
137 lines
5.2 KiB
JavaScript
import { paramMock } from "./utils"
|
|
|
|
export function mockInputMethod() {
|
|
const KeyboardType = {
|
|
labelId: 1,
|
|
iconId: 2,
|
|
language: "[PC Preview] unknow language",
|
|
inputSource: "[PC Preview] unknow inputSource",
|
|
customizedValue: {
|
|
key: 1
|
|
},
|
|
supportsAscii: true
|
|
}
|
|
const KeyboardTypeArry = [
|
|
{
|
|
labelId: 1,
|
|
iconId: 2,
|
|
language: "[PC Preview] unknow language",
|
|
inputSource: "[PC Preview] unknow inputSource",
|
|
customizedValue: {
|
|
key: 1
|
|
},
|
|
supportsAscii: true
|
|
}
|
|
]
|
|
const InputMethodProperty = {
|
|
methodId: "[PC Preview] unknow method id",
|
|
bundleName: "[PC Preview] unknow bundle name",
|
|
abilityName: "[PC Preview] unknow ability name",
|
|
configurationPage: "[PC Preview] unknow configuration page",
|
|
isSystemIme: true,
|
|
typeCount: 1,
|
|
defaultImeId: 2,
|
|
keyboardTypes: KeyboardTypeArry
|
|
}
|
|
const InputMethodPropertyArry = [
|
|
{
|
|
methodId: "[PC Preview] unknow method id",
|
|
bundleName: "[PC Preview] unknow bundle name",
|
|
abilityName: "[PC Preview] unknow ability name",
|
|
configurationPage: "[PC Preview] unknow configuration page",
|
|
isSystemIme: true,
|
|
typeCount: 1,
|
|
defaultImeId: 2,
|
|
keyboardTypes: KeyboardTypeArry
|
|
}
|
|
]
|
|
const InputMethodControllerMock = {
|
|
stopInput: function (...args) {
|
|
console.warn("InputMethodController.stopInput interface mocked in the Previewer. How this interface works on" +
|
|
" the Previewer may be different from that on a real device.")
|
|
const len = args.length
|
|
if (typeof args[len - 1] === 'function') {
|
|
args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock);
|
|
} else {
|
|
return new Promise((resolve, reject) => {
|
|
resolve(paramMock.paramBooleanMock);
|
|
})
|
|
}
|
|
}
|
|
}
|
|
const InputMethodSettingMock = {
|
|
getCurrentKeyboardType: function (...args) {
|
|
console.warn("InputMethodSetting.getCurrentKeyboardType interface mocked in the Previewer. How this interface works on" +
|
|
" the Previewer may be different from that on a real device.")
|
|
const len = args.length
|
|
if (typeof args[len - 1] === 'function') {
|
|
args[len - 1].call(this, paramMock.businessErrorMock, KeyboardType);
|
|
} else {
|
|
return new Promise((resolve, reject) => {
|
|
resolve(KeyboardType);
|
|
})
|
|
}
|
|
},
|
|
listInputMethodEnabled: function (...args) {
|
|
console.warn("InputMethodSetting.listInputMethodEnabled interface mocked in the Previewer. How this interface works on" +
|
|
" the Previewer may be different from that on a real device.")
|
|
const len = args.length
|
|
if (typeof args[len - 1] === 'function') {
|
|
args[len - 1].call(this, paramMock.businessErrorMock, InputMethodPropertyArry);
|
|
} else {
|
|
return new Promise((resolve, reject) => {
|
|
resolve(InputMethodPropertyArry);
|
|
})
|
|
}
|
|
},
|
|
listKeyboardType: function (...args) {
|
|
console.warn("InputMethodSetting.listKeyboardType interface mocked in the Previewer. How this interface works on" +
|
|
" the Previewer may be different from that on a real device.")
|
|
const len = args.length
|
|
if (typeof args[len - 1] === 'function') {
|
|
args[len - 1].call(this, paramMock.businessErrorMock, KeyboardTypeArry);
|
|
} else {
|
|
return new Promise((resolve, reject) => {
|
|
resolve(KeyboardTypeArry);
|
|
})
|
|
}
|
|
},
|
|
listInputMethod: function (...args) {
|
|
console.warn("InputMethodSetting.listInputMethod interface mocked in the Previewer. How this interface works on" +
|
|
" the Previewer may be different from that on a real device.")
|
|
const len = args.length
|
|
if (typeof args[len - 1] === 'function') {
|
|
args[len - 1].call(this, paramMock.businessErrorMock, InputMethodPropertyArry);
|
|
} else {
|
|
return new Promise((resolve, reject) => {
|
|
resolve(InputMethodPropertyArry);
|
|
})
|
|
}
|
|
},
|
|
displayOptionalInputMethod: function (...args) {
|
|
console.warn("InputMethodSetting.displayOptionalInputMethod interface mocked in the Previewer. How this interface works on" +
|
|
" the Previewer may be different from that on a real device.")
|
|
const len = args.length
|
|
if (typeof args[len - 1] === 'function') {
|
|
args[len - 1].call(this, paramMock.businessErrorMock);
|
|
} else {
|
|
return new Promise((resolve, reject) => {
|
|
resolve();
|
|
})
|
|
}
|
|
},
|
|
}
|
|
global.systemplugin.inputMethod = {
|
|
MAX_TYPE_MUN: 128,
|
|
getInputMethodController: function () {
|
|
console.warn("inputmethod.getInputMethodController interface mocked in the Previewer. How this interface works" +
|
|
" on the Previewer may be different from that on a real device.")
|
|
return InputMethodControllerMock;
|
|
},
|
|
getInputMethodSetting: function () {
|
|
console.warn("inputmethod.getInputMethodSetting interface mocked in the Previewer. How this interface works" +
|
|
" on the Previewer may be different from that on a real device.")
|
|
return InputMethodSettingMock;
|
|
}
|
|
}
|
|
} |