update js mock

Signed-off-by: zhangxingxia <zhangxingxia1@huawei.com>
This commit is contained in:
zhangxingxia
2022-07-18 10:26:18 +08:00
parent 0e19d76c78
commit bb5dc0721d
5 changed files with 174 additions and 15 deletions
@@ -390,13 +390,13 @@ export function mockRequireNapiFun() {
return mockConvertXml();
case "statfs":
return mockStatfs();
case "filemanager":
case "fileManager":
return mockFileManager();
case "environment":
return mockEnvironment();
case "storagestatistics":
case "storageStatistics":
return mockStorageStatistics();
case "volumemanager":
case "volumeManager":
return mockVolumeManager();
case "settings":
return mockSettings();
@@ -410,7 +410,7 @@ export function mockRequireNapiFun() {
return mockBackgroundTaskManager();
case "bundleState":
return mockBundleState();
case "securitylabel":
case "securityLabel":
return mockSecurityLabel();
case "workScheduler":
return mockWorkScheduler();
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -16,16 +16,29 @@
import { paramMock } from "../utils"
export function mockFileManager() {
const FileInfo = {
name: '[PC preview] unknow name',
path: '[PC preview] unknow path',
type: '[PC preview] unknow type',
size: '[PC preview] unknow size',
addedTime: '[PC preview] unknow addedTime',
modifiedTime: '[PC preview] unknow modifiedTime'
};
const DevInfo = {
name: '[PC preview] unknow name'
};
const filemanager = {
FileInfo: FileInfo,
DevInfo: DevInfo,
getRoot: function (...args) {
console.warn("filemanager.getRoot 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.paramArrayMock)
args[len - 1].call(this, paramMock.businessErrorMock, Array(FileInfo))
} else {
return new Promise((resolve, reject) => {
resolve(paramMock.paramArrayMock);
resolve(Array(FileInfo));
})
}
},
@@ -34,10 +47,10 @@ export function mockFileManager() {
" 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.paramArrayMock)
args[len - 1].call(this, paramMock.businessErrorMock, Array(FileInfo))
} else {
return new Promise((resolve, reject) => {
resolve(paramMock.paramArrayMock);
resolve(Array(FileInfo));
})
}
},
@@ -52,7 +65,7 @@ export function mockFileManager() {
resolve(paramMock.paramStringMock);
})
}
},
}
}
return filemanager;
}
@@ -29,6 +29,10 @@ export function mockSecurityLabel() {
})
}
},
setSecurityLabelSync: function (...args) {
console.warn("securitylabel.setSecurityLabelSync interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
},
getSecurityLabel: function (...args) {
console.warn("securitylabel.getSecurityLabel interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
@@ -41,6 +45,11 @@ export function mockSecurityLabel() {
})
}
},
getSecurityLabelSync: function (...args) {
console.warn("securitylabel.getSecurityLabelSync interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return paramMock.paramStringMock;
},
}
return securitylabel;
}
@@ -16,13 +16,22 @@
import { paramMock } from '../utils';
export function mockStorageStatistics() {
const BundleStatsMock = {
const BundleStats = {
appSize: '[PC preview] unknow appSize',
cacheSize: '[PC preview] unknow cacheSize',
dataSize: '[PC preview] unknow dataSize'
};
const StorageStats= {
total: '[PC preview] unknow total',
audio: '[PC preview] unknow audio',
video: '[PC preview] unknow video',
image: '[PC preview] unknow image',
file: '[PC preview] unknow file',
app: '[PC preview] unknow app'
}
const storageStatistics = {
BundleStats: BundleStatsMock,
BundleStats: BundleStats,
StorageStats: StorageStats,
getTotalSizeOfVolume: function(...args) {
console.warn('storageStatistics.getTotalSizeOfVolume interface mocked in the Previewer. How this interface works on the' +
' Previewer may be different from that on a real device.');
@@ -58,6 +67,66 @@ export function mockStorageStatistics() {
resolve(BundleStatsMock);
});
}
},
getCurrentBundleStats: function(...args) {
console.warn('storageStatistics.getCurrentBundleStats 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, BundleStats);
} else {
return new Promise((resolve, reject) => {
resolve(BundleStats);
});
}
},
getSystemSize: function(...args) {
console.warn('storageStatistics.getSystemSize 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, reject) => {
resolve(paramMock.paramNumberMock);
});
}
},
getUserStorageStats: function(...args) {
console.warn('storageStatistics.getUserStorageStats 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, StorageStats);
} else {
return new Promise((resolve, reject) => {
resolve(StorageStats);
});
}
},
getTotalSize: function(...args) {
console.warn('storageStatistics.getTotalSize 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, reject) => {
resolve(paramMock.paramNumberMock);
});
}
},
getFreeSize: function(...args) {
console.warn('storageStatistics.getFreeSize 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, reject) => {
resolve(paramMock.paramNumberMock);
});
}
}
};
return storageStatistics;
@@ -14,19 +14,27 @@
*/
import { paramMock } from "../utils"
import {VolumeMock} from './volume/volumeInfo'
export function mockVolumeManager() {
const Volume = {
id: '[PC preview] unknow id',
uuid: '[PC preview] unknow uuid',
description: '[PC preview] unknow description',
removeAble: '[PC preview] unknow removeAble',
path: '[PC preview] unknow path',
state: '[PC preview] unknow state'
};
const volumeManager = {
Volume: Volume,
getAllVolumes: function (...args) {
console.warn("volumeManager.getAllVolumes 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(VolumeMock));
args[len - 1].call(this, paramMock.businessErrorMock, Array(Volume));
} else {
return new Promise((resolve, reject) => {
resolve(Array(VolumeMock));
resolve(Array(Volume));
})
}
},
@@ -54,6 +62,66 @@ export function mockVolumeManager() {
})
}
},
getVolumeByUuid: function (...args) {
console.warn("volumeManager.getVolumeByUuid 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, Volume);
} else {
return new Promise((resolve, reject) => {
resolve(Volume);
})
}
},
getVolumeById: function (...args) {
console.warn("volumeManager.getVolumeById 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, Volume);
} else {
return new Promise((resolve, reject) => {
resolve(Volume);
})
}
},
setVolumeDescription: function (...args) {
console.warn("volumeManager.setVolumeDescription interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.");
const len = args.length;
if (typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock);
} else {
return new Promise((resolve, reject) => {
resolve();
})
}
},
format: function (...args) {
console.warn("volumeManager.format interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.");
const len = args.length;
if (typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock);
} else {
return new Promise((resolve, reject) => {
resolve();
})
}
},
partition: function (...args) {
console.warn("volumeManager.partition interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.");
const len = args.length;
if (typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock);
} else {
return new Promise((resolve, reject) => {
resolve();
})
}
}
}
return volumeManager;
}