Merge branch 'master' of gitee.com:openharmony/third_party_jsframework into master

Signed-off-by: z00588131 <hw.zhangfeng@huawei.com>
This commit is contained in:
Zhangfeng
2021-12-27 02:30:28 +00:00
committed by z00588131
12 changed files with 2142 additions and 574 deletions
@@ -39,7 +39,6 @@ import {
import { mockNetwork } from './network'
import { mockOhosNfc } from './ohos/nfc'
import { mockNotification } from './notification'
import { mockOhosNotification } from './ohos/notification'
import { mockCommonEvent } from './ohos/commonEvent'
import { mockWantAgent } from './ohos/wantAgent'
import { mockOhosBatteryinfo } from './batteryinfo'
@@ -92,7 +91,6 @@ export function mockSystemPlugin() {
global.ohosplugin = {}
mockNotification()
mockOhosNotification()
mockCommonEvent()
mockWantAgent()
mockFetch()
@@ -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",
}
@@ -1,15 +1,242 @@
import { paramMock } from "../utils"
import {paramMock} from "../utils"
export function mockDistributedData() {
const SchemaClass = class Schema {
constructor() {
console.warn('Schema.constructor interface mocked in the Previewer. How this interface works on the' +
' Previewer may be different from that on a real device.');
this.toJsonString = function (...args) {
console.warn("Schema.toJsonString interface mocked in the Previewer. How this interface works" +
" on the Previewer may be different from that on a real device.")
return paramMock.paramStringMock;
}
}
};
const FieldNodeClass = class FieldNode {
constructor(...args) {
console.warn('FieldNode.constructor interface mocked in the Previewer. How this interface works on the' +
' Previewer may be different from that on a real device.');
this.appendChild = function (...args) {
console.warn("FieldNode.appendChild interface mocked in the Previewer. How this interface works" +
" on the Previewer may be different from that on a real device.")
return paramMock.paramBooleanMock;
};
this.toJson = function (...args) {
console.warn("FieldNode.toJson interface mocked in the Previewer. How this interface works" +
" on the Previewer may be different from that on a real device.")
return paramMock.paramStringMock;
};
}
};
const QueryClass = class Query {
constructor() {
console.warn('Query.constructor interface mocked in the Previewer. How this interface works on the' +
' Previewer may be different from that on a real device.');
this.reset = function (...args) {
console.warn("Query.reset interface mocked in the Previewer. How this interface works" +
" on the Previewer may be different from that on a real device.")
return QueryClass;
},
this.equalTo = function (...args) {
console.warn("Query.equalTo interface mocked in the Previewer. How this interface works" +
" on the Previewer may be different from that on a real device.")
return QueryClass;
},
this.notEqualTo = function (...args) {
console.warn("Query.notEqualTo interface mocked in the Previewer. How this interface works" +
" on the Previewer may be different from that on a real device.")
return QueryClass;
},
this.greaterThan = function (...args) {
console.warn("Query.greaterThan interface mocked in the Previewer. How this interface works" +
" on the Previewer may be different from that on a real device.")
return QueryClass;
},
this.lessThan = function (...args) {
console.warn("Query.lessThan interface mocked in the Previewer. How this interface works" +
" on the Previewer may be different from that on a real device.")
return QueryClass;
},
this.greaterThanOrEqualTo = function (...args) {
console.warn("Query.greaterThanOrEqualTo interface mocked in the Previewer. How this interface works" +
" on the Previewer may be different from that on a real device.")
return QueryClass;
},
this.lessThanOrEqualTo = function (...args) {
console.warn("Query.lessThanOrEqualTo interface mocked in the Previewer. How this interface works" +
" on the Previewer may be different from that on a real device.")
return QueryClass;
},
this.isNull = function (...args) {
console.warn("Query.isNull interface mocked in the Previewer. How this interface works" +
" on the Previewer may be different from that on a real device.")
return QueryClass;
},
this.inNumber = function (...args) {
console.warn("Query.inNumber interface mocked in the Previewer. How this interface works" +
" on the Previewer may be different from that on a real device.")
return QueryClass;
},
this.inString = function (...args) {
console.warn("Query.inString interface mocked in the Previewer. How this interface works" +
" on the Previewer may be different from that on a real device.")
return QueryClass;
},
this.notInNumber = function (...args) {
console.warn("Query.notInNumber interface mocked in the Previewer. How this interface works" +
" on the Previewer may be different from that on a real device.")
return QueryClass;
},
this.notInString = function (...args) {
console.warn("Query.notInString interface mocked in the Previewer. How this interface works" +
" on the Previewer may be different from that on a real device.")
return QueryClass;
},
this.like = function (...args) {
console.warn("Query.like interface mocked in the Previewer. How this interface works" +
" on the Previewer may be different from that on a real device.")
return QueryClass;
},
this.unlike = function (...args) {
console.warn("Query.unlike interface mocked in the Previewer. How this interface works" +
" on the Previewer may be different from that on a real device.")
return QueryClass;
},
this.and = function (...args) {
console.warn("Query.and interface mocked in the Previewer. How this interface works" +
" on the Previewer may be different from that on a real device.")
return QueryClass;
},
this.or = function (...args) {
console.warn("Query.or interface mocked in the Previewer. How this interface works" +
" on the Previewer may be different from that on a real device.")
return QueryClass;
},
this.orderByAsc = function (...args) {
console.warn("Query.orderByAsc interface mocked in the Previewer. How this interface works" +
" on the Previewer may be different from that on a real device.")
return QueryClass;
},
this.orderByDesc = function (...args) {
console.warn("Query.orderByDesc interface mocked in the Previewer. How this interface works" +
" on the Previewer may be different from that on a real device.")
return QueryClass;
},
this.limit = function (...args) {
console.warn("Query.limit interface mocked in the Previewer. How this interface works" +
" on the Previewer may be different from that on a real device.")
return QueryClass;
},
this.isNotNull = function (...args) {
console.warn("Query.isNotNull interface mocked in the Previewer. How this interface works" +
" on the Previewer may be different from that on a real device.")
return QueryClass;
},
this.beginGroup = function (...args) {
console.warn("Query.beginGroup interface mocked in the Previewer. How this interface works" +
" on the Previewer may be different from that on a real device.")
return QueryClass;
},
this.endGroup = function (...args) {
console.warn("Query.endGroup interface mocked in the Previewer. How this interface works" +
" on the Previewer may be different from that on a real device.")
return QueryClass;
},
this.prefixKey = function (...args) {
console.warn("Query.prefixKey interface mocked in the Previewer. How this interface works" +
" on the Previewer may be different from that on a real device.")
return QueryClass;
},
this.setSuggestIndex = function (...args) {
console.warn("Query.setSuggestIndex interface mocked in the Previewer. How this interface works" +
" on the Previewer may be different from that on a real device.")
return QueryClass;
},
this.deviceId = function (...args) {
console.warn("Query.deviceId interface mocked in the Previewer. How this interface works" +
" on the Previewer may be different from that on a real device.")
return QueryClass;
},
this.getSqlLike = function (...args) {
console.warn("Query.getSqlLike interface mocked in the Previewer. How this interface works" +
" on the Previewer may be different from that on a real device.")
return QueryClass;
}
}
};
const distributedDataMock = {
Schema: SchemaClass,
Query: QueryClass,
FieldNode: FieldNodeClass,
KVStoreType: {
DEVICE_COLLABORATION: 0,
SINGLE_VERSION: 1,
MULTI_VERSION: 2,
},
SecurityLevel: {
NO_LEVEL: 0,
S0: 1,
S1: 2,
S2: 3,
S3: 5,
S4: 6,
},
createKVManager: function (...args) {
console.warn("distributedData.createKVManager 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 (len > 0 && typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock, KVManager);
} else {
return new Promise((resolve, reject) => {
resolve(KVManager);
})
}
}
};
const userTypeMock = {
SAME_USER_ID: "[PC Preview] unknown SAME_USER_ID"
};
const userInfoMock = {
userId: "[PC Preview] unknown userId",
userType: userTypeMock
userType: "[PC Preview] unknown userType"
};
const kvManagerConfigMock = {
userInfo: userInfoMock,
userInfo: "[PC Preview] unknown userInfo",
bundleName: "[PC Preview] unknown bundleName"
};
const constantsMock = {
@@ -52,109 +279,620 @@ export function mockDistributedData() {
SUBSCRIBE_TYPE_REMOTE: "[PC Preview] unknown SUBSCRIBE_TYPE_REMOTE",
SUBSCRIBE_TYPE_ALL: "[PC Preview] unknown SUBSCRIBE_TYPE_ALL"
};
const kvStoreTypeMock = {
DEVICE_COLLABORATION: "[PC Preview] unknown DEVICE_COLLABORATION",
SINGLE_VERSION: "[PC Preview] unknown SINGLE_VERSION",
MULTI_VERSION: "[PC Preview] unknown MULTI_VERSION"
};
const securityLevelMock = {
NO_LEVEL: "[PC Preview] unknown NO_LEVEL",
S0: "[PC Preview] unknown S0",
S1: "[PC Preview] unknown S1",
S2: "[PC Preview] unknown S2",
S3: "[PC Preview] unknown S3",
S4: "[PC Preview] unknown S4"
};
const optionsMock = {
createIfMissing: "[PC Preview] unknown createIfMissing",
encrypt: "[PC Preview] unknown encrypt",
backup: "[PC Preview] unknown backup",
autoSync: "[PC Preview] unknown autoSync",
kvStoreType: kvStoreTypeMock,
securityLevel: securityLevelMock
kvStoreType: "[PC Preview] unknown kvStoreType",
securityLevel: "[PC Preview] unknown securityLevel",
};
const singleKVStoreMock = {
put: function (...args) {
console.warn("kvStore.put interface mocked in the Previewer." +
const KVStoreClass = class KVStore {
constructor() {
console.warn("KVStore.constructor interface mocked in the Previewer." +
" How this interface works on the Previewer may be different from that on a real device.")
this.put = function (...args) {
console.warn("KVStore.put 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()
})
}
},
this.delete = function (...args) {
console.warn("KVStore.delete 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()
})
}
},
this.setSyncRange = function (...args) {
console.warn("KVStore.setSyncRange 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()
})
}
},
this.on = function (...args) {
console.warn("KVStore.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] == 'dataChange') {
args[len - 1].call(this, paramMock.businessErrorMock, changeNotificationMock)
}
}
},
this.off = function (...args) {
console.warn("KVStore.off 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] == 'dataChange') {
args[len - 1].call(this, paramMock.businessErrorMock, changeNotificationMock)
}
}
},
this.putBatch = function (...args) {
console.warn("KVStore.putBatch 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()
})
}
},
this.deleteBatch = function (...args) {
console.warn("KVStore.deleteBatch 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()
})
}
},
this.startTransaction = function (...args) {
console.warn("KVStore.startTransaction 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()
})
}
},
this.commit = function (...args) {
console.warn("KVStore.commit 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()
})
}
},
this.rollback = function (...args) {
console.warn("KVStore.rollback 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()
})
}
},
this.enableSync = function (...args) {
console.warn("KVStore.enableSync 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()
})
}
}
}
};
const SingleKVStoreClass = class SingleKVStore extends KVStoreClass {
constructor() {
super();
console.warn("SingleKVStore.constructor interface mocked in the Previewer." +
" How this interface works on the Previewer may be different from that on a real device.")
this.put = function (...args) {
console.warn("SingleKVStore.put 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 (len > 0 && typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock);
} else {
return new Promise((resolve, reject) => {
resolve();
})
}
},
this.delete = function (...args) {
console.warn("SingleKVStore.delete 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 (len > 0 && typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock);
} else {
return new Promise((resolve, reject) => {
resolve();
})
}
},
this.on = function (...args) {
console.warn("SingleKVStore.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] === 'dataChange') {
args[len - 1].call(this, changeNotificationMock);
} else if (args[0] === 'syncComplete') {
var array = new Array([paramMock.paramStringMock, paramMock.paramNumberMock]);
args[len - 1].call(this, array);
}
}
},
this.off = function (...args) {
console.warn("SingleKVStore.off 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
var array = new Array([paramMock.paramStringMock, paramMock.paramNumberMock]);
if (typeof args[len - 1] === 'function') {
if (args[0] == 'syncComplete') {
args[len - 1].call(this, paramMock.businessErrorMock, array)
} else if (args[0] == 'dataChange') {
args[len - 1].call(this, paramMock.businessErrorMock, changeNotificationMock)
}
}
},
this.sync = function (...args) {
console.warn("SingleKVStore.sync interface mocked in the Previewer." +
" How this interface works on the Previewer may be different from that on a real device.")
},
this.get = function (...args) {
console.warn("SingleKVStore.get 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 | paramMock.paramStringMock | paramMock.paramNumberMock | paramMock.paramArrayMock)
} else {
return new Promise((resolve) => {
resolve(paramMock.paramBooleanMock | paramMock.paramStringMock | paramMock.paramNumberMock | paramMock.paramArrayMock)
})
}
},
this.getResultSet = function (...args) {
console.warn("SingleKVStore.getResultSet 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, KVStoreResultSet)
} else {
return new Promise((resolve) => {
resolve(KVStoreResultSet)
})
}
},
this.closeResultSet = function (...args) {
console.warn("SingleKVStore.closeResultSet 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()
})
}
},
this.getResultSize = function (...args) {
console.warn("SingleKVStore.getResultSize 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)
})
}
},
this.getEntries = function (...args) {
console.warn("SingleKVStore.getEntries 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
var array = new Array(entryMock)
if (typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock, array)
} else {
return new Promise((resolve) => {
resolve(array)
})
}
},
this.removeDeviceData = function (...args) {
console.warn("SingleKVStore.removeDeviceData 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()
})
}
},
this.setSyncParam = function (...args) {
console.warn("SingleKVStore.setSyncParam 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()
})
}
},
this.getSecurityLevel = function (...args) {
console.warn("SingleKVStore.getSecurityLevel 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()
})
}
}
}
};
const DeviceKVStoreClass = class DeviceKVStore extends KVStoreClass {
constructor() {
super();
console.warn('DeviceKVStore.constructor interface mocked in the Previewer. How this interface works on the' +
' Previewer may be different from that on a real device.');
this.get = function (...args) {
console.warn("DeviceKVStore.get 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 | paramMock.paramStringMock | paramMock.paramNumberMock | paramMock.paramArrayMock)
} else {
return new Promise((resolve) => {
resolve(paramMock.paramBooleanMock | paramMock.paramStringMock | paramMock.paramNumberMock | paramMock.paramArrayMock)
})
}
},
this.getEntries = function (...args) {
console.warn("DeviceKVStore.getEntries 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
var array = new Array(entryMock)
if (typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock, array)
} else {
return new Promise((resolve) => {
resolve(array)
})
}
},
this.getResultSet = function (...args) {
console.warn("DeviceKVStore.getResultSet 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, KVStoreResultSet)
} else {
return new Promise((resolve) => {
resolve(KVStoreResultSet)
})
}
},
this.closeResultSet = function (...args) {
console.warn("DeviceKVStore.closeResultSet 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()
})
}
},
this.getResultSize = function (...args) {
console.warn("DeviceKVStore.getResultSize 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)
})
}
},
this.removeDeviceData = function (...args) {
console.warn("DeviceKVStore.removeDeviceData 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()
})
}
},
this.sync = function (...args) {
console.warn("DeviceKVStore.sync interface mocked in the Previewer. How this interface works" +
" on the Previewer may be different from that on a real device.")
},
this.on = function (...args) {
console.warn("DeviceKVStore.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
var array = new Array([paramMock.paramStringMock, paramMock.paramNumberMock]);
if (typeof args[len - 1] === 'function') {
if (args[0] == 'syncComplete') {
args[len - 1].call(this, paramMock.businessErrorMock, array)
} else if (args[0] == 'dataChange') {
args[len - 1].call(this, paramMock.businessErrorMock, changeNotificationMock)
}
}
},
this.off = function (...args) {
console.warn("DeviceKVStore.off 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
var array = new Array([paramMock.paramStringMock, paramMock.paramNumberMock]);
if (typeof args[len - 1] === 'function') {
if (args[0] == 'syncComplete') {
args[len - 1].call(this, paramMock.businessErrorMock, array)
} else if (args[0] == 'dataChange') {
args[len - 1].call(this, paramMock.businessErrorMock, changeNotificationMock)
}
}
}
}
};
const KVManager = {
getKVStore: function (...args) {
console.warn("KVManager.getKVStore 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
var singleKVStoreClass = new SingleKVStoreClass
var deviceKVStoreClass = new DeviceKVStoreClass
if (len > 0 && typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock);
console.warn("getKVStore kvStoreType = " + args[1].kvStoreType);
if (args[1].kvStoreType == distributedDataMock.KVStoreType.DEVICE_COLLABORATION) {
args[len - 1].call(this, paramMock.businessErrorMock, deviceKVStoreClass);
} else if (args[1].kvStoreType == distributedDataMock.KVStoreType.SINGLE_VERSION) {
args[len - 1].call(this, paramMock.businessErrorMock, singleKVStoreClass);
}
} else {
return new Promise((resolve, reject) => {
resolve();
return new Promise((resolve) => {
if (args[1].kvStoreType == distributedDataMock.KVStoreType.DEVICE_COLLABORATION) {
resolve(deviceKVStoreClass);
} else if (args[1].kvStoreType == distributedDataMock.KVStoreType.SINGLE_VERSION) {
resolve(singleKVStoreClass);
}
})
}
},
delete: function (...args) {
console.warn("singleKVStore.delete 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 (len > 0 && typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock);
} else {
return new Promise((resolve, reject) => {
resolve();
})
}
},
on: function (...args) {
console.warn("singleKVStore.on interface mocked in the Previewer." +
" How this interface works on the Previewer may be different from that on a real device.")
closeKVStore: function (...args) {
console.warn("KVManager.closeKVStore 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] === 'dataChange') {
args[len - 1].call(this, changeNotificationMock);
} else if (args[0] === 'syncComplete') {
var array = new Array([paramMock.paramStringMock, paramMock.paramNumberMock]);
args[len - 1].call(this, array);
args[len - 1].call(this, paramMock.businessErrorMock)
} else {
return new Promise((resolve) => {
resolve()
})
}
},
deleteKVStore: function (...args) {
console.warn("KVManager.deleteKVStore 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()
})
}
},
getAllKVStoreId: function (...args) {
console.warn("KVManager.getAllKVStoreId 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
var array = new Array(paramMock.paramStringMock)
if (typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock, array)
} else {
return new Promise((resolve) => {
resolve(array)
})
}
},
on: function (...args) {
console.warn("KVManager.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] == 'distributedDataServiceDie') {
args[len - 1].call(this, paramMock.businessErrorMock)
}
}
},
get: function (...args) {
console.warn("singleKVStore.get 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("KVManager.off 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 (len > 0 && typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock);
} else {
return new Promise((resolve, reject) => {
resolve(paramMock.paramStringMock);
})
}
},
sync: function (...args) {
console.warn("singleKVStore.sync interface mocked in the Previewer." +
" How this interface works on the Previewer may be different from that on a real device.")
},
};
const kvManagerMock = {
getKVStore: function (...args) {
console.warn("kvManager.getKVStore 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 (len > 0 && typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock, singleKVStoreMock);
} else {
return new Promise((resolve, reject) => {
resolve(singleKVStoreMock);
})
if (typeof args[len - 1] === 'function') {
if (args[0] == 'distributedDataServiceDie') {
args[len - 1].call(this, paramMock.businessErrorMock)
}
}
}
};
const distributedData = {
createKVManager: function (...args) {
console.warn("distributedData.createKVManager 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 (len > 0 && typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock, kvManagerMock);
} else {
return new Promise((resolve, reject) => {
resolve(kvManagerMock);
})
}
const KVStoreResultSet = {
getCount: function (...args) {
console.warn("KVStoreResultSet.getCount interface mocked in the Previewer. How this interface works" +
" on the Previewer may be different from that on a real device.")
return paramMock.paramNumberMock;
},
getPosition: function (...args) {
console.warn("KVStoreResultSet.getPosition interface mocked in the Previewer. How this interface works" +
" on the Previewer may be different from that on a real device.")
return paramMock.paramNumberMock;
},
moveToFirst: function (...args) {
console.warn("KVStoreResultSet.moveToFirst interface mocked in the Previewer. How this interface works" +
" on the Previewer may be different from that on a real device.")
return paramMock.paramBooleanMock;
},
moveToLast: function (...args) {
console.warn("KVStoreResultSet.moveToLast interface mocked in the Previewer. How this interface works" +
" on the Previewer may be different from that on a real device.")
return paramMock.paramBooleanMock;
},
moveToNext: function (...args) {
console.warn("KVStoreResultSet.moveToNext interface mocked in the Previewer. How this interface works" +
" on the Previewer may be different from that on a real device.")
return paramMock.paramBooleanMock;
},
moveToPrevious: function (...args) {
console.warn("KVStoreResultSet.moveToPrevious interface mocked in the Previewer. How this interface works" +
" on the Previewer may be different from that on a real device.")
return paramMock.paramBooleanMock;
},
move: function (...args) {
console.warn("KVStoreResultSet.move interface mocked in the Previewer. How this interface works" +
" on the Previewer may be different from that on a real device.")
return paramMock.paramBooleanMock;
},
moveToPosition: function (...args) {
console.warn("KVStoreResultSet.moveToPosition interface mocked in the Previewer. How this interface works" +
" on the Previewer may be different from that on a real device.")
return paramMock.paramBooleanMock;
},
isFirst: function (...args) {
console.warn("KVStoreResultSet.isFirst interface mocked in the Previewer. How this interface works" +
" on the Previewer may be different from that on a real device.")
return paramMock.paramBooleanMock;
},
isLast: function (...args) {
console.warn("KVStoreResultSet.isLast interface mocked in the Previewer. How this interface works" +
" on the Previewer may be different from that on a real device.")
return paramMock.paramBooleanMock;
},
isBeforeFirst: function (...args) {
console.warn("KVStoreResultSet.isBeforeFirst interface mocked in the Previewer. How this interface works" +
" on the Previewer may be different from that on a real device.")
return paramMock.paramBooleanMock;
},
isAfterLast: function (...args) {
console.warn("KVStoreResultSet.isAfterLast interface mocked in the Previewer. How this interface works" +
" on the Previewer may be different from that on a real device.")
return paramMock.paramBooleanMock;
},
getEntry: function (...args) {
console.warn("KVStoreResultSet.getEntry interface mocked in the Previewer. How this interface works" +
" on the Previewer may be different from that on a real device.")
return entryMock;
}
};
return distributedData;
return distributedDataMock;
}
+10 -1
View File
@@ -3,6 +3,7 @@ import { mockAbility } from './applicationAbility'
import { mockFormExtension } from './applicationFormExtension'
import { mockServiceExtension } from './applicationServiceExtension'
import { mockAbilityStage } from './applicationAbilityStage'
import { mockNotification } from './notification'
import { mockFileio } from './fileio'
import { mockWorker } from './worker'
import { mockUtil } from './util'
@@ -29,6 +30,8 @@ import { mockInputDevice } from './inputDevice'
import { mockVibrator } from './vibrator'
import { mockSensor } from './sensor'
import { mockWifi } from './wifi'
import { mockBundle } from './bundle'
import { mockInnerBundle } from './innerBundleManager'
export function mockRequireNapiFun() {
global.requireNapi = function (...args) {
@@ -43,9 +46,11 @@ export function mockRequireNapiFun() {
return mockServiceExtension();
case "application.AbilityStage":
return mockAbilityStage();
case "notification":
return mockNotification();
case "fileio":
return mockFileio();
case "worker" :
case "worker":
return mockWorker();
case "util":
return mockUtil();
@@ -95,6 +100,10 @@ export function mockRequireNapiFun() {
return mockSensor();
case "wifi":
return mockWifi();
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;
}
@@ -0,0 +1,617 @@
import { paramMock } from "../utils"
export function mockNotification() {
const DateMock = {
toString: function () {
console.warn("Date.toString interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramStringMock
},
toDateString: function () {
console.warn("Date.toDateString interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramStringMock
},
toTimeString: function () {
console.warn("Date.toTimeString interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramStringMock
},
toLocaleString: function () {
console.warn("Date.toLocaleString interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramStringMock
},
toLocaleDateString: function () {
console.warn("Date.toLocaleDateString interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramStringMock
},
toLocaleTimeString: function () {
console.warn("Date.toLocaleTimeString interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramStringMock
},
valueOf: function () {
console.warn("Date.valueOf interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramNumberMock
},
getTime: function () {
console.warn("Date.getTime interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramNumberMock
},
getFullYear: function () {
console.warn("Date.getFullYear interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramNumberMock
},
getUTCFullYear: function () {
console.warn("Date.getUTCFullYear interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramNumberMock
},
getMonth: function () {
console.warn("Date.getMonth interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramNumberMock
},
getUTCMonth: function () {
console.warn("Date.getUTCMonth interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramNumberMock
},
getDate: function () {
console.warn("Date.getDate interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramNumberMock
},
getUTCDate: function () {
console.warn("Date.getUTCDate interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramNumberMock
},
getDay: function () {
console.warn("Date.getDay interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramNumberMock
},
getUTCDay: function () {
console.warn("Date.getUTCDay interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramNumberMock
},
getHours: function () {
console.warn("Date.getHours interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramNumberMock
},
getUTCHours: function () {
console.warn("Date.getUTCHours interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramNumberMock
},
getMinutes: function () {
console.warn("Date.getMinutes interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramNumberMock
},
getUTCMinutes: function () {
console.warn("Date.getUTCMinutes interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramNumberMock
},
getSeconds: function () {
console.warn("Date.getSeconds interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramNumberMock
},
getUTCSeconds: function () {
console.warn("Date.getUTCSeconds interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramNumberMock
},
getMilliseconds: function () {
console.warn("Date.getMilliseconds interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramNumberMock
},
getUTCMilliseconds: function () {
console.warn("Date.getUTCMilliseconds interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramNumberMock
},
getTimezoneOffset: function () {
console.warn("Date.getTimezoneOffset interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramNumberMock
},
setTime: function (...args) {
console.warn("Date.setTime interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramNumberMock
},
setMilliseconds: function (...args) {
console.warn("Date.setMilliseconds interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramNumberMock
},
setUTCMilliseconds: function (...args) {
console.warn("Date.setUTCMilliseconds interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramNumberMock
},
setSeconds: function (...args) {
console.warn("Date.setSeconds interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramNumberMock
},
setUTCSeconds: function (...args) {
console.warn("Date.setUTCSeconds interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramNumberMock
},
setMinutes: function (...args) {
console.warn("Date.setMinutes interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramNumberMock
},
setUTCMinutes: function (...args) {
console.warn("Date.setUTCMinutes interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramNumberMock
},
setHours: function (...args) {
console.warn("Date.setHours interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramNumberMock
},
setUTCHours: function (...args) {
console.warn("Date.setUTCHours interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramNumberMock
},
setDate: function (...args) {
console.warn("Date.setDate interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramNumberMock
},
setUTCDate: function (...args) {
console.warn("Date.setUTCDate interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramNumberMock
},
setMonth: function (...args) {
console.warn("Date.setMonth interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramNumberMock
},
setUTCMonth: function (...args) {
console.warn("Date.setUTCMonth interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramNumberMock
},
setFullYear: function (...args) {
console.warn("Date.setFullYear interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramNumberMock
},
setUTCFullYear: function (...args) {
console.warn("Date.setUTCFullYear interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramNumberMock
},
toUTCString: function () {
console.warn("Date.toUTCString interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramStringMock
},
toISOString: function () {
console.warn("Date.toISOString interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramStringMock
},
toJSON: function (...args) {
console.warn("Date.toJSON interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramStringMock
},
}
const DoNotDisturbDateMock = {
DoNotDisturbTypeMock:'[PC preview] unknow DoNotDisturbTypeMock',
begin: DateMock,
end: DateMock
}
const NotificationSlotMock = {
SlotTypeMock: '[PC preview] unknow SlotTypeMock',
SlotLevelMock: '[PC preview] unknow SlotLevelMock',
desc: '[PC preview] unknow desc',
badgeFlag: '[PC preview] unknow badgeFlag',
bypassDnd: '[PC preview] unknow bypassDnd',
lockscreenVisibility: '[PC preview] unknow lockscreenVisibility',
vibrationEnabled: '[PC preview] unknow vibrationEnabled',
sound: '[PC preview] unknow sound',
lightEnabled: '[PC preview] unknow lightEnabled',
lightColor: '[PC preview] unknow lightColor',
vibrationValues: [paramMock.paramNumberMock]
};
const NotificationActionButtonMock = {
title: '[PC preview] unknow title',
wantAgent: '[PC preview] unknow wantAgent',
extras: {},
userInput: '[PC preview] unknow userInput',
}
const NotificationRequestMock = {
content: '[PC preview] unknow content',
id: '[PC preview] unknow id',
slotTypeMock: '[PC preview] unknow slotTypeMock',
isOngoing: '[PC preview] unknow isOngoing',
isUnremovable: '[PC preview] unknow isUnremovable',
deliveryTime: '[PC preview] unknow deliveryTime',
tapDismissed: '[PC preview] unknow tapDismissed',
autoDeletedTime: '[PC preview] unknow autoDeletedTime',
wantAgent: '[PC preview] unknow wantAgent',
extraInfo: {},
color: '[PC preview] unknow color',
colorEnabled: '[PC preview] unknow colorEnabled',
isAlertOnce: '[PC preview] unknow isAlertOnce',
isStopwatch: '[PC preview] unknow isStopwatch',
isCountDown: '[PC preview] unknow isCountDown',
isFloatingIcon: '[PC preview] unknow isFloatingIcon',
label: '[PC preview] unknow label',
badgeIconStyle: '[PC preview] unknow badgeIconStyle',
showDeliveryTime: '[PC preview] unknow showDeliveryTime',
actionButtons: [NotificationActionButtonMock],
smallIcon: '[PC preview] unknow smallIcon',
largeIcon: '[PC preview] unknow largeIcon',
groupName: '[PC preview] unknow groupName',
creatorBundleName: '[PC preview] unknow creatorBundleName',
creatorUid: '[PC preview] unknow creatorUid',
creatorPid: '[PC preview] unknow creatorPid',
classification: '[PC preview] unknow classification',
hashCode: '[PC preview] unknow hashCode',
isRemveAllowd: '[PC preview] unknow isRemveAllowd',
source: '[PC preview] unknow source',
template: '[PC preview] unknow template'
};
const notification = {
publish: function(...args) {
console.warn('notification.publish 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();
});
}
},
cancel: function(...args) {
console.warn('notification.cancel 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();
});
}
},
cancelAll: function(...args) {
console.warn('notification.cancelAll 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();
});
}
},
addSlot: function(...args) {
console.warn('notification.addSlot 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();
});
}
},
addSlots: function(...args) {
console.warn('notification.addSlots 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();
});
}
},
getSlot: function(...args) {
console.warn('notification.getSlot 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, NotificationSlotMock);
} else {
return new Promise((resolve) => {
resolve(NotificationSlotMock);
});
}
},
getSlots: function(...args) {
console.warn('notification.getSlots 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, [NotificationSlotMock]);
} else {
return new Promise((resolve) => {
resolve([NotificationSlotMock]);
});
}
},
removeSlot: function(...args) {
console.warn('notification.removeSlot 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();
});
}
},
removeAllSlots: function(...args) {
console.warn('notification.removeAllSlots 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();
});
}
},
subscribe: function(...args) {
console.warn('notification.subscribe 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();
});
}
},
unsubscribe: function(...args) {
console.warn('notification.unsubscribe 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();
});
}
},
enableNotification: function(...args) {
console.warn('notification.enableNotification 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();
});
}
},
isNotificationEnabled: function(...args) {
console.warn('notification.isNotificationEnabled 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) => {
resolve(paramMock.paramBooleanMock);
});
}
},
displayBadge: function(...args) {
console.warn('notification.displayBadge 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();
});
}
},
isBadgeDisplayed: function(...args) {
console.warn('notification.isBadgeDisplayed 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) => {
resolve(paramMock.paramBooleanMock);
});
}
},
setSlotByBundle: function(...args) {
console.warn('notification.setSlotByBundle 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();
});
}
},
getSlotsByBundle: function(...args) {
console.warn('notification.getSlotsByBundle 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, [NotificationSlotMock]);
} else {
return new Promise((resolve) => {
resolve([NotificationSlotMock]);
});
}
},
getSlotNumByBundle: function(...args) {
console.warn('notification.getSlotNumByBundle 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);
});
}
},
remove: function(...args) {
console.warn('notification.remove 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();
});
}
},
removeAll: function(...args) {
console.warn('notification.removeAll 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();
});
}
},
getAllActiveNotifications: function(...args) {
console.warn('notification.getAllActiveNotifications 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, [NotificationRequestMock]);
} else {
return new Promise((resolve) => {
resolve([NotificationRequestMock]);
});
}
},
getActiveNotificationCount: function(...args) {
console.warn('notification.getActiveNotificationCount 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);
});
}
},
getActiveNotifications: function(...args) {
console.warn('notification.getActiveNotifications 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, [NotificationRequestMock]);
} else {
return new Promise((resolve) => {
resolve([NotificationRequestMock]);
});
}
},
cancelGroup: function (...args) {
console.warn("notification.cancelGroup 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 (len > 0 && typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock);
} else {
return new Promise((resolve, reject) => {
resolve();
})
}
},
removeGroupByBundle: function (...args) {
console.warn("notification.removeGroupByBundle 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 (len > 0 && typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock);
} else {
return new Promise((resolve, reject) => {
resolve();
})
}
},
setDoNotDisturbDate: function (...args) {
console.warn("notification.setDoNotDisturbDate 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 (len > 0 && typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock);
} else {
return new Promise((resolve, reject) => {
resolve();
})
}
},
getDoNotDisturbDate: function (...args) {
console.warn("notification.getDoNotDisturbDate 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 (len > 0 && typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock, DoNotDisturbDateMock);
} else {
return new Promise((resolve, reject) => {
resolve(DoNotDisturbDateMock);
})
}
},
supportDoNotDisturbMode: function (...args) {
console.warn("notification.supportDoNotDisturbMode 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 (len > 0 && typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock);
} else {
return new Promise((resolve, reject) => {
resolve(paramMock.paramBooleanMock);
})
}
}
}
return notification
}
@@ -1,487 +0,0 @@
import {paramMock} from '../utils';
export function mockOhosNotification() {
const NotificationSlotMock = {
type: '[PC preview] unknow type',
level: '[PC preview] unknow level',
desc: '[PC preview] unknow desc',
badgeFlag: '[PC preview] unknow badgeFlag',
bypassDnd: '[PC preview] unknow bypassDnd',
lockscreenVisibility: '[PC preview] unknow lockscreenVisibility',
vibrationEnabled: '[PC preview] unknow vibrationEnabled',
sound: '[PC preview] unknow sound',
lightEnabled: '[PC preview] unknow lightEnabled',
lightColor: '[PC preview] unknow lightColor',
vibrationValues: '[PC preview] unknow vibrationValues'
};
const DoNotDisturbDateMock = {
type: '[PC preview] unknow type',
begin: '[PC preview] unknow begin',
end: '[PC preview] unknow end'
};
const NotificationRequestMock = {
content: '[PC preview] unknow content',
id: '[PC preview] unknow id',
slotType: '[PC preview] unknow slotType',
isOngoing: '[PC preview] unknow isOngoing',
isUnremovable: '[PC preview] unknow isUnremovable',
deliveryTime: '[PC preview] unknow deliveryTime',
tapDismissed: '[PC preview] unknow tapDismissed',
autoDeletedTime: '[PC preview] unknow autoDeletedTime',
wantAgent: '[PC preview] unknow wantAgent',
extraInfo: '[PC preview] unknow extraInfo',
color: '[PC preview] unknow color',
colorEnabled: '[PC preview] unknow colorEnabled',
isAlertOnce: '[PC preview] unknow isAlertOnce',
isStopwatch: '[PC preview] unknow isStopwatch',
isCountDown: '[PC preview] unknow isCountDown',
isFloatingIcon: '[PC preview] unknow isFloatingIcon',
label: '[PC preview] unknow label',
badgeIconStyle: '[PC preview] unknow badgeIconStyle',
showDeliveryTime: '[PC preview] unknow showDeliveryTime',
actionButtons: '[PC preview] unknow actionButtons',
creatorBundleName: '[PC preview] unknow creatorBundleName',
creatorUid: '[PC preview] unknow creatorUid',
creatorPid: '[PC preview] unknow creatorPid',
classification: '[PC preview] unknow classification',
hashCode: '[PC preview] unknow hashCode',
groupName: '[PC preview] unknow groupName',
template: '[PC preview] unknow template'
};
global.ohosplugin.notification = {
SlotType: {
UNKNOWN_TYPE: 0,
SOCIAL_COMMUNICATION: 1,
SERVICE_INFORMATION: 2,
CONTENT_INFORMATION: 3,
OTHER_TYPES: 0xFFFF
},
ContentType: {
NOTIFICATION_CONTENT_BASIC_TEXT: 0,
NOTIFICATION_CONTENT_LONG_TEXT: 1,
NOTIFICATION_CONTENT_PICTURE: 2,
NOTIFICATION_CONTENT_CONVERSATION: 3,
NOTIFICATION_CONTENT_MULTILINE: 4
},
SlotLevel: {
LEVEL_NONE: 0,
LEVEL_MIN: 1,
LEVEL_LOW: 2,
LEVEL_DEFAULT: 3,
LEVEL_HIGH: 4
},
publish: function(...args) {
console.warn('notification.publish 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();
});
}
},
cancel: function(...args) {
console.warn('notification.cancel 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();
});
}
},
cancelAll: function(...args) {
console.warn('notification.cancelAll 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();
});
}
},
addSlot: function(...args) {
console.warn('notification.addSlot 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();
});
}
},
addSlots: function(...args) {
console.warn('notification.addSlots 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();
});
}
},
getSlot: function(...args) {
console.warn('notification.getSlot 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, NotificationSlotMock);
} else {
return new Promise((resolve) => {
resolve(NotificationSlotMock);
});
}
},
getSlots: function(...args) {
console.warn('notification.getSlots 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, [NotificationSlotMock]);
} else {
return new Promise((resolve) => {
resolve([NotificationSlotMock]);
});
}
},
removeSlot: function(...args) {
console.warn('notification.removeSlot 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();
});
}
},
removeAllSlots: function(...args) {
console.warn('notification.removeAllSlots 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();
});
}
},
subscribe: function(...args) {
console.warn('notification.subscribe 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();
});
}
},
unsubscribe: function(...args) {
console.warn('notification.unsubscribe 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();
});
}
},
enableNotification: function(...args) {
console.warn('notification.enableNotification 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();
});
}
},
isNotificationEnabled: function(...args) {
console.warn('notification.isNotificationEnabled 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) => {
resolve(paramMock.paramBooleanMock);
});
}
},
displayBadge: function(...args) {
console.warn('notification.displayBadge 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();
});
}
},
isBadgeDisplayed: function(...args) {
console.warn('notification.isBadgeDisplayed 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) => {
resolve(paramMock.paramBooleanMock);
});
}
},
setSlotByBundle: function(...args) {
console.warn('notification.setSlotByBundle 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();
});
}
},
getSlotsByBundle: function(...args) {
console.warn('notification.getSlotsByBundle 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, [NotificationSlotMock]);
} else {
return new Promise((resolve) => {
resolve([NotificationSlotMock]);
});
}
},
getSlotNumByBundle: function(...args) {
console.warn('notification.getSlotNumByBundle 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);
});
}
},
remove: function(...args) {
console.warn('notification.remove 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();
});
}
},
removeAll: function(...args) {
console.warn('notification.removeAll 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();
});
}
},
getAllActiveNotifications: function(...args) {
console.warn('notification.getAllActiveNotifications 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, [NotificationRequestMock]);
} else {
return new Promise((resolve) => {
resolve([NotificationRequestMock]);
});
}
},
getActiveNotificationCount: function(...args) {
console.warn('notification.getActiveNotificationCount 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);
});
}
},
getActiveNotifications: function(...args) {
console.warn('notification.getActiveNotifications 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, [NotificationRequestMock]);
} else {
return new Promise((resolve) => {
resolve([NotificationRequestMock]);
});
}
},
isDistributedEnabled: function(...args) {
console.warn('notification.isDistributedEnabled 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) => {
resolve(paramMock.paramBooleanMock);
});
}
},
enableDistributed: function(...args) {
console.warn('notification.enableDistributed 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();
});
}
},
enableDistributedSelf: function(...args) {
console.warn('notification.enableDistributedSelf 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();
});
}
},
enableDistributedByBundle: function(...args) {
console.warn('notification.enableDistributedByBundle 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();
});
}
},
isDistributedEnabledByBundle: function(...args) {
console.warn('notification.isDistributedEnabledByBundle 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) => {
resolve(paramMock.paramBooleanMock);
});
}
},
cancelGroup: function(...args) {
console.warn('notification.cancelGroup 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();
});
}
},
removeGroupByBundle: function(...args) {
console.warn('notification.removeGroupByBundle 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) => {
resolve(paramMock.paramBooleanMock);
});
}
},
isSupportDoNotDisturbMode: function(...args) {
console.warn('notification.isSupportDoNotDisturbMode 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) => {
resolve(paramMock.paramBooleanMock);
});
}
},
setDoNotDisturbDate: function(...args) {
console.warn('notification.setDoNotDisturbDate 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();
});
}
},
getDoNotDisturbDate: function(...args) {
console.warn('notification.getDoNotDisturbDate 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, DoNotDisturbDateMock);
} else {
return new Promise((resolve) => {
resolve(DoNotDisturbDateMock);
});
}
},
DoNotDisturbType: {
TYPE_NONE: 0,
TYPE_ONCE: 1,
TYPE_DAILY: 2,
TYPE_CLEARLY: 3
},
TemplateType: {
TYPE_NONE: 0,
TYPE_PROCESS_BAR: 0x100
},
DoNotDisturbMode: {
ALLOW_UNKNOWN: 0,
ALLOW_ALL: 1,
ALLOW_PRIORITY: 2,
ALLOW_NONE: 3,
ALLOW_ALARMS: 4
}
};
}
@@ -145,6 +145,20 @@ function ResourceManager(mgrId, module) {
console.warn("ResourceManager.getJsonConfig interface mocked in the Previewer. " +
"How this interface works on the Previewer may be different from that on a real device.")
}
this.getRawFile = getRawFile;
async function getRawFile(path, callback) {
var data = "mock raw file";
console.warn("ResourceManager.getRawFile interface mocked in the Previewer. " +
"How this interface works on the Previewer may be different from that on a real device.")
if (typeof callback === 'function') {
callback.call(this, null, data);
} else {
return new Promise((resolve) => {
resolve(data);
})
}
}
}
var resourceManager = {