1/* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { paramMock } from "../utils" 17 18export function mockFileManager() { 19 const FileInfo = { 20 name: '[PC preview] unknow name', 21 path: '[PC preview] unknow path', 22 type: '[PC preview] unknow type', 23 size: '[PC preview] unknow size', 24 addedTime: '[PC preview] unknow addedTime', 25 modifiedTime: '[PC preview] unknow modifiedTime' 26 }; 27 const DevInfo = { 28 name: '[PC preview] unknow name' 29 }; 30 const filemanager = { 31 FileInfo: FileInfo, 32 DevInfo: DevInfo, 33 getRoot: function (...args) { 34 console.warn("filemanager.getRoot interface mocked in the Previewer. How this interface works on the" + 35 " Previewer may be different from that on a real device.") 36 const len = args.length 37 if (typeof args[len - 1] === 'function') { 38 args[len - 1].call(this, paramMock.businessErrorMock, new Array(FileInfo)) 39 } else { 40 return new Promise((resolve, reject) => { 41 resolve(new Array(FileInfo)); 42 }) 43 } 44 }, 45 listFile: function (...args) { 46 console.warn("filemanager.listFile interface mocked in the Previewer. How this interface works on the" + 47 " Previewer may be different from that on a real device.") 48 const len = args.length 49 if (typeof args[len - 1] === 'function') { 50 args[len - 1].call(this, paramMock.businessErrorMock, new Array(FileInfo)) 51 } else { 52 return new Promise((resolve, reject) => { 53 resolve(new Array(FileInfo)); 54 }) 55 } 56 }, 57 createFile: function (...args) { 58 console.warn("filemanager.createFile interface mocked in the Previewer. How this interface works on the" + 59 " Previewer may be different from that on a real device.") 60 const len = args.length 61 if (typeof args[len - 1] === 'function') { 62 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) 63 } else { 64 return new Promise((resolve, reject) => { 65 resolve(paramMock.paramStringMock); 66 }) 67 } 68 } 69 } 70 return filemanager; 71} 72