update jsmock

Signed-off-by: zhangxingxia <zhangxingxia1@huawei.com>
This commit is contained in:
zhangxingxia
2022-07-14 14:50:23 +08:00
parent 18ad3d513a
commit 3ad391576d
5 changed files with 152 additions and 33 deletions
@@ -394,9 +394,9 @@ export function mockRequireNapiFun() {
return mockFileManager();
case "environment":
return mockEnvironment();
case "storagestatistics":
case "storageStatistics":
return mockStorageStatistics();
case "volumemanager":
case "volumeManager":
return mockVolumeManager();
case "settings":
return mockSettings();
@@ -16,24 +16,29 @@
import { paramMock } from "../utils"
export function mockFileManager() {
const fileInfoMock = {
const FileInfoMock = {
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',
modifiedTime: '[PC preview] unknow modifiedTime'
};
const DevInfoMock = {
name: '[PC preview] unknow name'
};
const filemanager = {
FileInfo: FileInfoMock,
DevInfo: DevInfoMock,
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, Array(fileInfoMock))
args[len - 1].call(this, paramMock.businessErrorMock, Array(FileInfoMock))
} else {
return new Promise((resolve, reject) => {
resolve(Array(fileInfoMock));
resolve(Array(FileInfoMock));
})
}
},
@@ -42,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, Array(fileInfoMock))
args[len - 1].call(this, paramMock.businessErrorMock, Array(FileInfoMock))
} else {
return new Promise((resolve, reject) => {
resolve(Array(fileInfoMock));
resolve(Array(FileInfoMock));
})
}
},
@@ -60,7 +65,7 @@ export function mockFileManager() {
resolve(paramMock.paramStringMock);
})
}
},
}
}
return filemanager;
}
@@ -21,8 +21,17 @@ export function mockStorageStatistics() {
cacheSize: '[PC preview] unknow cacheSize',
dataSize: '[PC preview] unknow dataSize'
};
const StorageStatsMock = {
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,
StorageStats: StorageStatsMock,
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, BundleStatsMock);
} else {
return new Promise((resolve, reject) => {
resolve(BundleStatsMock);
});
}
},
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, StorageStatsMock);
} else {
return new Promise((resolve, reject) => {
resolve(StorageStatsMock);
});
}
},
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,10 +14,18 @@
*/
import { paramMock } from "../utils"
import {VolumeMock} from './volume/volumeInfo'
export function mockVolumeManager() {
const VolumeMock = {
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: VolumeMock,
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.");
@@ -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, VolumeMock);
} else {
return new Promise((resolve, reject) => {
resolve(VolumeMock);
})
}
},
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, VolumeMock);
} else {
return new Promise((resolve, reject) => {
resolve(VolumeMock);
})
}
},
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;
}
@@ -1,23 +0,0 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export const VolumeMock = {
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',
};