From 1960cbde3cffada680ec253b5153965998da2b7b Mon Sep 17 00:00:00 2001 From: zhangxingxia Date: Thu, 14 Jul 2022 15:18:43 +0800 Subject: [PATCH] update jsmock Signed-off-by: zhangxingxia --- .../main/extend/systemplugin/napi/index.js | 4 +- .../systemplugin/napi/ohos_fileManager.js | 21 ++++-- .../napi/ohos_storageStatistics.js | 73 +++++++++++++++++- .../systemplugin/napi/ohos_volumeManager.js | 74 ++++++++++++++++++- 4 files changed, 157 insertions(+), 15 deletions(-) diff --git a/runtime/main/extend/systemplugin/napi/index.js b/runtime/main/extend/systemplugin/napi/index.js index 0ac50157..53294599 100644 --- a/runtime/main/extend/systemplugin/napi/index.js +++ b/runtime/main/extend/systemplugin/napi/index.js @@ -345,9 +345,9 @@ export function mockRequireNapiFun() { return mockFileManager(); case "environment": return mockEnvironment(); - case "storagestatistics": + case "storageStatistics": return mockStorageStatistics(); - case "volumemanager": + case "volumemManager": return mockVolumeManager(); case "settings": return mockSettings(); diff --git a/runtime/main/extend/systemplugin/napi/ohos_fileManager.js b/runtime/main/extend/systemplugin/napi/ohos_fileManager.js index 47ae70a4..6491bda7 100644 --- a/runtime/main/extend/systemplugin/napi/ohos_fileManager.js +++ b/runtime/main/extend/systemplugin/napi/ohos_fileManager.js @@ -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,24 +16,29 @@ import { paramMock } from "../utils" export function mockFileManager() { - const fileInfoMock = { + 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', + 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, Array(fileInfoMock)) + args[len - 1].call(this, paramMock.businessErrorMock, Array(FileInfo)) } else { return new Promise((resolve, reject) => { - resolve(Array(fileInfoMock)); + resolve(Array(FileInfo)); }) } }, @@ -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(FileInfo)) } else { return new Promise((resolve, reject) => { - resolve(Array(fileInfoMock)); + resolve(Array(FileInfo)); }) } }, @@ -60,7 +65,7 @@ export function mockFileManager() { resolve(paramMock.paramStringMock); }) } - }, + } } return filemanager; } diff --git a/runtime/main/extend/systemplugin/napi/ohos_storageStatistics.js b/runtime/main/extend/systemplugin/napi/ohos_storageStatistics.js index c954be1e..4f4c7511 100644 --- a/runtime/main/extend/systemplugin/napi/ohos_storageStatistics.js +++ b/runtime/main/extend/systemplugin/napi/ohos_storageStatistics.js @@ -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; diff --git a/runtime/main/extend/systemplugin/napi/ohos_volumeManager.js b/runtime/main/extend/systemplugin/napi/ohos_volumeManager.js index 9adf2ac3..412dda53 100644 --- a/runtime/main/extend/systemplugin/napi/ohos_volumeManager.js +++ b/runtime/main/extend/systemplugin/napi/ohos_volumeManager.js @@ -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; }