mirror of
https://github.com/openharmony/third_party_jsframework.git
synced 2026-07-19 22:43:32 -04:00
add bundle mock
Signed-off-by: longwei <longwei27@huawei.com> Change-Id: Id3c26c12c52f86fa6d756dd65107bad4a1763d27
This commit is contained in:
@@ -0,0 +1,198 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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"
|
||||
import {resolve} from 'path/posix'
|
||||
import {BundleInfoMock} from './bundle/bundleInfo'
|
||||
import {ApplicationInfoMock} from './bundle/applicationInfo'
|
||||
import {AbilityInfoMock} from './bundle/abilityInfo'
|
||||
import {WantMock} from './bundle/applicationInfo'
|
||||
import {ShortcutInfoMock} from './bundle/applicationInfo'
|
||||
import {ModuleUsageRecordMock} from './bundle/applicationInfo'
|
||||
|
||||
export function mockBundle() {
|
||||
|
||||
const bundle = {
|
||||
getBundleInfo: function(...args) {
|
||||
console.warn("bundle.getBundleInfo 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, BundleInfoMock);
|
||||
} else {
|
||||
return new Promise((resolve) => {
|
||||
resolve(BundleInfoMock);
|
||||
})
|
||||
}
|
||||
},
|
||||
getBundleInstaller: function(...args) {
|
||||
console.warn("bundle.getBundleInstaller 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(paramMock.paramNumberMock);
|
||||
})
|
||||
}
|
||||
},
|
||||
getApplicationInfo: function(...args) {
|
||||
console.warn("bundle.getApplicationInfo 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, ApplicationInfoMock);
|
||||
} else {
|
||||
return new Promise((resolve) => {
|
||||
resolve(ApplicationInfoMock);
|
||||
})
|
||||
}
|
||||
},
|
||||
checkPermission: function(...args) {
|
||||
console.warn("bundle.checkPermission 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);
|
||||
})
|
||||
}
|
||||
},
|
||||
queryAbilityByWant: function(...args) {
|
||||
console.warn("bundle.queryAbilityByWant 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, Array(BundleInfoMock));
|
||||
} else {
|
||||
return new Promise((resolve) => {
|
||||
resolve(Array(BundleInfoMock));
|
||||
})
|
||||
}
|
||||
},
|
||||
getAllApplicationInfo: function(...args){
|
||||
console.warn("bundle.getAllApplicationInfo 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, Array(BundleInfoMock));
|
||||
} else {
|
||||
return new Promise((resolve) => {
|
||||
resolve(Array(BundleInfoMock));
|
||||
})
|
||||
}
|
||||
},
|
||||
getAllBundleInfo: function(...args) {
|
||||
console.warn("bundle.getAllBundleInfo 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, Array(ApplicationInfoMock));
|
||||
} else {
|
||||
return new Promise((resolve) => {
|
||||
resolve(Array(ApplicationInfoMock));
|
||||
})
|
||||
}
|
||||
},
|
||||
getBundleArchiveInfo: function(...args) {
|
||||
console.warn("bundle.getBundleArchiveInfo 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, Array(BundleInfoMock));
|
||||
} else {
|
||||
return new Promise((resolve) => {
|
||||
resolve(Array(BundleInfoMock));
|
||||
})
|
||||
}
|
||||
},
|
||||
getLaunchWantForBundle: function(...args) {
|
||||
console.warn("bundle.getBundleArchiveInfo 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, Array(WantMock));
|
||||
} else {
|
||||
return new Promise((resolve) => {
|
||||
resolve(Array(WantMock));
|
||||
})
|
||||
}
|
||||
},
|
||||
getAllShortcutInfo: function(...args) {
|
||||
console.warn("bundle.getAllShortcutInfo 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, Array(ShortcutInfoMock));
|
||||
} else {
|
||||
return new Promise((resolve) => {
|
||||
resolve(Array(ShortcutInfoMock));
|
||||
})
|
||||
}
|
||||
},
|
||||
getModuleUsageRecords: function(...args) {
|
||||
console.warn("bundle.getAllShortcutInfo 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, Array(ModuleUsageRecordMock));
|
||||
} else {
|
||||
return new Promise((resolve) => {
|
||||
resolve(Array(ModuleUsageRecordMock));
|
||||
})
|
||||
}
|
||||
},
|
||||
cleanBundleCacheFiles: function(...args) {
|
||||
console.warn("bundle.cleanBundleCacheFiles 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(paramMock.paramNumberMock);
|
||||
})
|
||||
}
|
||||
},
|
||||
setApplicationEnabled: function(...args) {
|
||||
console.warn("bundle.setApplicationEnabled 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(paramMock.paramNumberMock);
|
||||
})
|
||||
}
|
||||
},
|
||||
setAbilityEnabled: function(...args) {
|
||||
console.warn("bundle.setApplicationEnabled 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(paramMock.paramNumberMock);
|
||||
})
|
||||
}
|
||||
}
|
||||
};
|
||||
return bundle;
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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.
|
||||
*/
|
||||
|
||||
export const AbilityInfoMock = {
|
||||
bundleName: "string",
|
||||
name: "string",
|
||||
label: "string",
|
||||
description: "string",
|
||||
icon: "string",
|
||||
labelId: 1,
|
||||
descriptionId: 2,
|
||||
iconId: 3,
|
||||
moduleName: "string",
|
||||
process: "string",
|
||||
targetAbility: "string",
|
||||
backgroundModes: 4,
|
||||
isVisible: true,
|
||||
formEnabled: true,
|
||||
type: "bundle.AbilityType",
|
||||
subType: "bundle.AbilitySubType",
|
||||
orientation: "bundle.DisplayOrientation",
|
||||
launchMode: "bundle.LaunchMode",
|
||||
permissions: ["1"],
|
||||
deviceTypes: ["2"],
|
||||
deviceCapabilities: ["3"],
|
||||
readPermission: "string",
|
||||
writePermission: "string",
|
||||
applicationInfo: {
|
||||
packageName: "[PC preview] unknown package name",
|
||||
className: "[PC preview] unknown class name",
|
||||
name: "[PC preview] unknown name",
|
||||
labelId: 1,
|
||||
iconId: 2,
|
||||
sourceDir: "[PC preview] unknown source dir",
|
||||
flags: 3,
|
||||
customizeData: {
|
||||
key: "[PC preview] unknown key",
|
||||
value: {
|
||||
CustomizeData: {
|
||||
name: "[PC preview] unknown name",
|
||||
value: "[PC preview] unknown value",
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
formEntity: 5,
|
||||
minFormHeight: 6,
|
||||
defaultFormHeight: 7,
|
||||
minFormWidth: 8,
|
||||
defaultFormWidth: 9,
|
||||
uri: "string",
|
||||
customizeData: {
|
||||
key: "[PC preview] unknown key",
|
||||
value: [
|
||||
{
|
||||
CustomizeData: {
|
||||
name: "[PC preview] unknown name",
|
||||
value: "[PC preview] unknown value",
|
||||
},
|
||||
},
|
||||
{
|
||||
CustomizeData: {
|
||||
name: "[PC preview] unknown name",
|
||||
value: "[PC preview] unknown value",
|
||||
},
|
||||
}
|
||||
]
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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.
|
||||
*/
|
||||
|
||||
export const ApplicationInfoMock = {
|
||||
packageName: "[PC preview] unknown package name",
|
||||
className: "[PC preview] unknown class name",
|
||||
name: "[PC preview] unknown name",
|
||||
labelId: 1,
|
||||
iconId: 2,
|
||||
sourceDir: "[PC preview] unknown source dir",
|
||||
flags: 3,
|
||||
customizeData: {
|
||||
key: "[PC preview] unknown key",
|
||||
value: {
|
||||
CustomizeData: {
|
||||
name: "[PC preview] unknown name",
|
||||
value: "[PC preview] unknown value",
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const WantMock = {
|
||||
deviceId: "[PC Preview] unknow deviceId",
|
||||
bundleName: "[PC Preview] unknow bundleName",
|
||||
abilityName: "[PC Preview] unknow abilityName",
|
||||
uri: "[PC Preview] unknow uri",
|
||||
type: "[PC Preview] unknow type",
|
||||
flag: "[PC Preview] unknow flag",
|
||||
action: "[PC Preview] unknow action",
|
||||
parameters: "[PC Preview] unknow parameters",
|
||||
entities: "[PC Preview] unknow entities"
|
||||
}
|
||||
|
||||
export const ShortcutInfoMock = {
|
||||
id: "[PC preview] unknown id",
|
||||
bundleName: "[PC preview] unknown bundle name",
|
||||
hostAbility: "[PC preview] unknown host ability",
|
||||
icon: "[PC preview] unknown icon",
|
||||
label: "[PC preview] unknown label",
|
||||
disableMessage: "[PC preview] unknown disable message",
|
||||
wants: [
|
||||
{
|
||||
targetBundle: "[PC preview] unknown target bundle",
|
||||
targetClass: "[PC preview] unknown target class",
|
||||
}],
|
||||
isStatic: "[PC preview] unknown is static",
|
||||
isHomeShortcut: "[PC preview] unknown is home shortcut",
|
||||
isEnabled: "[PC preview] unknown is enabled",
|
||||
}
|
||||
|
||||
export const ModuleUsageRecordMock = {
|
||||
bundleName: "[PC preview] unknown bundleName",
|
||||
appLabelId: "[PC preview] unknown appLabelId",
|
||||
name: "[PC preview] unknown name",
|
||||
labelId: "[PC preview] unknown labelId",
|
||||
descriptionId: "[PC preview] unknown descriptionId",
|
||||
abilityName: "[PC preview] unknown abilityName",
|
||||
abilityLabelId: "[PC preview] unknown abilityLabelId",
|
||||
abilityDescriptionId: "[PC preview] unknown abilityDescriptionId",
|
||||
abilityIconId: "[PC preview] unknown abilityIconId",
|
||||
launchedCount: "[PC preview] unknown launchedCount",
|
||||
lastLaunchTime: "[PC preview] unknown lastLaunchTime",
|
||||
isRemoved: "[PC preview] unknown isRemoved",
|
||||
installationFreeSupported: "[PC preview] unknown installationFreeSupported",
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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.
|
||||
*/
|
||||
|
||||
export const BundleInfoMock = {
|
||||
name: "[PC preview] unknown name",
|
||||
type: "[PC preview] unknown type",
|
||||
appId: "[PC preview] unknown app id",
|
||||
uid: "[PC preview] unknown uid",
|
||||
installTime: "[PC preview] unknown install time",
|
||||
updateTime: "[PC preview] unknown up date time",
|
||||
appInfo: {
|
||||
packageName: "[PC preview] unknown package name",
|
||||
className: "[PC preview] unknown class name",
|
||||
name: "[PC preview] unknown name",
|
||||
labelId: "[PC preview] unknown label id",
|
||||
iconId: "[PC preview] unknown icon id",
|
||||
sourceDir: "[PC preview] unknown source dir",
|
||||
flags: "[PC preview] unknown flags",
|
||||
customizeData: {
|
||||
key: "[PC preview] unknown key",
|
||||
value: {
|
||||
CustomizeData: {
|
||||
name: "[PC preview] unknown name",
|
||||
value: "[PC preview] unknown value",
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
abilityInfo: [
|
||||
{
|
||||
name: "[PC preview] unknown name",
|
||||
type: '[[PC Preview] unknow type]',
|
||||
appId: '[[PC Preview] unknow appId]',
|
||||
label: "[PC preview] unknown label",
|
||||
description: "[PC preview] unknown description",
|
||||
uid: '[[PC Preview] unknow uid]',
|
||||
installTime: '[[PC Preview] unknow installTime]',
|
||||
updateTime: '[[PC Preview] unknow updateTime]',
|
||||
applicationInfo: {
|
||||
packageName: "[PC preview] unknown package name",
|
||||
className: "[PC preview] unknown class name",
|
||||
name: "[PC preview] unknown name",
|
||||
labelId: "[PC preview] unknown label id",
|
||||
iconId: "[PC preview] unknown icon id",
|
||||
sourceDir: "[PC preview] unknown source dir",
|
||||
flags: "[PC preview] unknown flags",
|
||||
customizeData: {
|
||||
key: "[PC preview] unknown key",
|
||||
value: {
|
||||
CustomizeData: {
|
||||
name: "[PC preview] unknown name",
|
||||
value: "[PC preview] unknown value",
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
formEntity: "[PC preview] unknown form entity",
|
||||
minFormHeight: "[PC preview] unknown min form height",
|
||||
defaultFormHeight: "[PC preview] unknown default form height",
|
||||
minFormWidth: "[PC preview] unknown min form width",
|
||||
defaultFormWidth: "[PC preview] unknown default form width",
|
||||
uri: "[PC preview] unknown uri",
|
||||
customizeData: {
|
||||
key: "[PC preview] unknown key",
|
||||
value: [
|
||||
{
|
||||
CustomizeData: {
|
||||
name: "[PC preview] unknown name",
|
||||
value: "[PC preview] unknown value",
|
||||
},
|
||||
},
|
||||
{
|
||||
CustomizeData: {
|
||||
name: "[PC preview] unknown name",
|
||||
value: "[PC preview] unknown value",
|
||||
},
|
||||
}
|
||||
]
|
||||
},
|
||||
}
|
||||
],
|
||||
reqPermissions: ["[PC preview] unknown repermission"],
|
||||
reqPermissionDetails: [
|
||||
{
|
||||
name: "[PC preview] unknown name",
|
||||
reason: "[PC preview] unknown reason",
|
||||
usedScene: {
|
||||
abilities: ["[PC preview] unknown ability"],
|
||||
when: "[PC preview] unknown when",
|
||||
}
|
||||
}
|
||||
],
|
||||
vendor: "[PC preview] unknown vendor",
|
||||
versionCode: "[PC preview] unknown versionCode",
|
||||
versionName: "[PC preview] unknown versionName",
|
||||
compatibleVersion: "[PC preview] unknown compatibleVersion",
|
||||
targetVersion: "[PC preview] unknown targetVersion",
|
||||
isCompressNativeLibs: "[PC preview] unknown isCompressNativeLibs",
|
||||
hapModuleInfo: [
|
||||
{
|
||||
name: "string",
|
||||
description: "string",
|
||||
descriptionId: 1,
|
||||
icon: "string",
|
||||
label: "string",
|
||||
labelId: 2,
|
||||
iconId: 3,
|
||||
backgroundImg: "string",
|
||||
supportedModes: 4,
|
||||
reqCapabilities: ["1", "2"],
|
||||
deviceTypes: ["1", "2"],
|
||||
abilityInfo: [
|
||||
{
|
||||
bundleName: "string",
|
||||
name: "string",
|
||||
label: "string",
|
||||
description: "string",
|
||||
icon: "string",
|
||||
labelId: 1,
|
||||
descriptionId: 2,
|
||||
iconId: 3,
|
||||
moduleName: "string",
|
||||
process: "string",
|
||||
targetAbility: "string",
|
||||
backgroundModes: 4,
|
||||
isVisible: true,
|
||||
formEnabled: true,
|
||||
type: "bundle.AbilityType",
|
||||
subType: "bundle.AbilitySubType",
|
||||
orientation: "bundle.DisplayOrientation",
|
||||
launchMode: "bundle.LaunchMode",
|
||||
permissions: ["1"],
|
||||
deviceTypes: ["2"],
|
||||
deviceCapabilities: ["3"],
|
||||
readPermission: "string",
|
||||
writePermission: "string",
|
||||
applicationInfo: {
|
||||
packageName: "[PC preview] unknown package name",
|
||||
className: "[PC preview] unknown class name",
|
||||
name: "[PC preview] unknown name",
|
||||
labelId: 2,
|
||||
iconId: 3,
|
||||
sourceDir: "[PC preview] unknown source dir",
|
||||
flags: 1,
|
||||
customizeData: {
|
||||
key: "[PC preview] unknown key",
|
||||
value: {
|
||||
CustomizeData: {
|
||||
name: "[PC preview] unknown name",
|
||||
value: "[PC preview] unknown value",
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
formEntity: 5,
|
||||
minFormHeight: 6,
|
||||
defaultFormHeight: 7,
|
||||
minFormWidth: 8,
|
||||
defaultFormWidth: 9,
|
||||
uri: "string",
|
||||
customizeData: {
|
||||
key: "[PC preview] unknown key",
|
||||
value: [
|
||||
{
|
||||
CustomizeData: {
|
||||
name: "[PC preview] unknown name",
|
||||
value: "[PC preview] unknown value",
|
||||
},
|
||||
},
|
||||
{
|
||||
CustomizeData: {
|
||||
name: "[PC preview] unknown name",
|
||||
value: "[PC preview] unknown value",
|
||||
},
|
||||
}
|
||||
]
|
||||
},
|
||||
}
|
||||
],
|
||||
moduleName: "string",
|
||||
mainAbilityName: "string",
|
||||
installationFree: true,
|
||||
}
|
||||
],
|
||||
entryModuleName: "string",
|
||||
cpuAbi: "string",
|
||||
isSilentInstallation: "string",
|
||||
minCompatibleVersionCode: 7,
|
||||
entryInstallationFree: true,
|
||||
};
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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.
|
||||
*/
|
||||
|
||||
export const LauncherAbilityInfoMock = {
|
||||
applicationInfo: {
|
||||
packageName: "[PC preview] unknown package name",
|
||||
className: "[PC preview] unknown class name",
|
||||
name: "[PC preview] unknown name",
|
||||
labelId: 1,
|
||||
iconId: 2,
|
||||
sourceDir: "[PC preview] unknown source dir",
|
||||
flags: 3,
|
||||
customizeData: {
|
||||
key: "[PC preview] unknown key",
|
||||
value: {
|
||||
CustomizeData: {
|
||||
name: "[PC preview] unknown name",
|
||||
value: "[PC preview] unknown value",
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
elementName: {
|
||||
deviceId: "[PC preview] unknown deviceId",
|
||||
bundleName: "[PC preview] unknown bundleName",
|
||||
abilityName: "[PC preview] unknown abilityName",
|
||||
uri: "[PC preview] unknown uri",
|
||||
shortName: "[PC preview] unknown shortName",
|
||||
},
|
||||
labelId: "[PC preview] unknown labelId",
|
||||
iconId: "[PC preview] unknown iconId",
|
||||
userId: "[PC preview] unknown userId",
|
||||
installTime: "[PC preview] unknown installTime",
|
||||
}
|
||||
@@ -29,6 +29,8 @@ import { mockInputDevice } from './inputDevice'
|
||||
import { mockLight } from './light'
|
||||
import { mockVibrator } from './vibrator'
|
||||
import { mockSensor } from './sensor'
|
||||
import { mockBundle } from './bundle'
|
||||
import { mockInnerBundle } from './innerBundleManager'
|
||||
|
||||
export function mockRequireNapiFun() {
|
||||
global.requireNapi = function (...args) {
|
||||
@@ -95,6 +97,10 @@ export function mockRequireNapiFun() {
|
||||
return mockVibrator();
|
||||
case "sensor":
|
||||
return mockSensor();
|
||||
case "bundle":
|
||||
return mockBundle();
|
||||
case "bundle.innerBundleManager":
|
||||
return mockInnerBundle();
|
||||
default:
|
||||
return global.requireNapiPreview(...args);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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"
|
||||
import {resolve} from 'path/posix'
|
||||
import {BundleInfoMock} from './bundle/bundleInfo'
|
||||
import {ApplicationInfoMock} from './bundle/applicationInfo'
|
||||
import {AbilityInfoMock} from './bundle/abilityInfo'
|
||||
import {WantMock} from './bundle/applicationInfo'
|
||||
import {ShortcutInfoMock} from './bundle/applicationInfo'
|
||||
import {ModuleUsageRecordMock} from './bundle/applicationInfo'
|
||||
import {LauncherAbilityInfoMock} from './bundle/launcherAbilityInfo'
|
||||
|
||||
export function mockInnerBundle() {
|
||||
const innerBundleManager = {
|
||||
getLauncherAbilityInfos: function(...args){
|
||||
console.warn("innerBundle.getLauncherAbilityInfos 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, LauncherAbilityInfoMock);
|
||||
} else {
|
||||
return new Promise((resolve) => {
|
||||
resolve(LauncherAbilityInfoMock);
|
||||
})
|
||||
}
|
||||
},
|
||||
on: function(...args) {
|
||||
console.warn("innerBundle.on interface mocked in the Previewer. How this interface works on the" +
|
||||
" Previewer may be different from that on a real device.")
|
||||
},
|
||||
off: function(...args) {
|
||||
console.warn("innerBundle.off interface mocked in the Previewer. How this interface works on the" +
|
||||
" Previewer may be different from that on a real device.")
|
||||
},
|
||||
getAllLauncherAbilityInfos: function(...args){
|
||||
console.warn("innerBundle.getAllLauncherAbilityInfos 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, Array(LauncherAbilityInfoMock));
|
||||
} else {
|
||||
return new Promise((resolve) => {
|
||||
resolve(Array(LauncherAbilityInfoMock));
|
||||
})
|
||||
}
|
||||
},
|
||||
getShortcutInfos: function(...args){
|
||||
console.warn("innerBundle.getShortcutInfos 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, Array(ShortcutInfoMock));
|
||||
} else {
|
||||
return new Promise((resolve) => {
|
||||
resolve(Array(ShortcutInfoMock));
|
||||
})
|
||||
}
|
||||
},
|
||||
};
|
||||
return innerBundleManager;
|
||||
}
|
||||
Reference in New Issue
Block a user