add continuation manager api mock

Signed-off-by: zhangmingxiang <zhangmingxiang@huawei.com>
Change-Id: If660ec05d40930636aaa61b1063028f986108ea4
Signed-off-by: zhangmingxiang <zhangmingxiang@huawei.com>
This commit is contained in:
zhangmingxiang
2022-07-04 15:29:24 +08:00
parent f257d2be72
commit 28c3545c9e
2 changed files with 121 additions and 0 deletions
@@ -162,6 +162,7 @@ import { mockKeyEvent } from './ohos_multimodalInput_keyEvent'
import { mockMouseEvent } from './ohos_multimodalInput_mouseEvent'
import { mockTouchEvent } from './ohos_multimodalInput_touchEvent'
import { mockUiAppearance } from './ohos_uiappearance'
import { mockContinationManager } from './ohos_continuation_continuationManager'
export function mockRequireNapiFun() {
global.requireNapi = function (...args) {
switch (args[0]) {
@@ -463,6 +464,8 @@ export function mockRequireNapiFun() {
return mockMouseEvent();
case "multimodalInput.touchEvent":
return mockTouchEvent();
case "continuation.continuationManager":
return mockContinationManager();
default:
return global.requireNapiPreview(...args);
}
@@ -0,0 +1,118 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { paramMock } from "../utils"
export function mockContinationManager() {
const ContinuationExtraParams = {
deviceType: [paramMock.paramStringMock],
targetBundle: '[PC preview] unknown targetBundle',
description: '[PC preview] unknown description',
filter: '[PC preview] unknown filter',
continuationMode: continuationManager.ContinuationMode,
authInfo: '[PC preview] unknown authInfo'
}
const ContinuationResult = {
id: '[PC preview] unknown id',
type: '[PC preview] unknown type',
name: '[PC preview] unknown name'
}
const continuationManager = {
DeviceConnectState: {
IDLE: 0,
CONNECTING: 1,
CONNECTED: 2,
DISCONNECTING: 3
},
ContinuationMode: {
COLLABORATION_SINGLE: 0,
COLLABORATION_MULTIPLE: 1
},
on: function (...args) {
console.warn("continuationManager.on 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') {
if (args[0] == 'deviceConnect') {
args[len - 1].call(this, new Array(ContinuationResult));
} else if (args[0] == 'deviceDisconnect') {
args[len - 1].call(this, new Array(paramMock.paramStringMock));
}
}
},
off: function (...args) {
console.warn("continuationManager.off interface mocked in the Previewer. How this interface works on the Previewer may" +
" be different from that on a real device.")
},
register: function (...args) {
console.warn("continuationManager.register 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.paramNumberMock);
} else {
return new Promise((resolve) => {
resolve(paramMock.paramNumberMock);
});
}
},
unregister: function (...args) {
console.warn("continuationManager.unregister 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) => {
resolve();
});
}
},
updateConnectStatus: function (...args) {
console.warn("continuationManager.updateConnectStatus 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) => {
resolve();
});
}
},
startDeviceManager: function (...args) {
console.warn("continuationManager.startDeviceManager 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) => {
resolve();
});
}
},
}
return continuationManager
}