1/* 2 * Copyright (c) 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 mockVolumeManager() { 19 const Volume = { 20 id: '[PC preview] unknow id', 21 uuid: '[PC preview] unknow uuid', 22 description: '[PC preview] unknow description', 23 removeAble: '[PC preview] unknow removeAble', 24 path: '[PC preview] unknow path', 25 state: '[PC preview] unknow state' 26 }; 27 const volumeManager = { 28 Volume: Volume, 29 getAllVolumes: function (...args) { 30 console.warn("volumeManager.getAllVolumes interface mocked in the Previewer. How this interface works on the" + 31 " Previewer may be different from that on a real device."); 32 const len = args.length; 33 if (typeof args[len - 1] === 'function') { 34 args[len - 1].call(this, paramMock.businessErrorMock, new Array(Volume)); 35 } else { 36 return new Promise((resolve, reject) => { 37 resolve(new Array(Volume)); 38 }) 39 } 40 }, 41 mount: function (...args) { 42 console.warn("volumeManager.mount interface mocked in the Previewer. How this interface works on the" + 43 " Previewer may be different from that on a real device."); 44 const len = args.length; 45 if (typeof args[len - 1] === 'function') { 46 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); 47 } else { 48 return new Promise((resolve, reject) => { 49 resolve(paramMock.paramBooleanMock); 50 }) 51 } 52 }, 53 unmount: function (...args) { 54 console.warn("volumeManager.unmount interface mocked in the Previewer. How this interface works on the" + 55 " Previewer may be different from that on a real device."); 56 const len = args.length; 57 if (typeof args[len - 1] === 'function') { 58 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); 59 } else { 60 return new Promise((resolve, reject) => { 61 resolve(paramMock.paramBooleanMock); 62 }) 63 } 64 }, 65 getVolumeByUuid: function (...args) { 66 console.warn("volumeManager.getVolumeByUuid interface mocked in the Previewer. How this interface works on the" + 67 " Previewer may be different from that on a real device."); 68 const len = args.length; 69 if (typeof args[len - 1] === 'function') { 70 args[len - 1].call(this, paramMock.businessErrorMock, Volume); 71 } else { 72 return new Promise((resolve, reject) => { 73 resolve(Volume); 74 }) 75 } 76 }, 77 getVolumeById: function (...args) { 78 console.warn("volumeManager.getVolumeById interface mocked in the Previewer. How this interface works on the" + 79 " Previewer may be different from that on a real device."); 80 const len = args.length; 81 if (typeof args[len - 1] === 'function') { 82 args[len - 1].call(this, paramMock.businessErrorMock, Volume); 83 } else { 84 return new Promise((resolve, reject) => { 85 resolve(Volume); 86 }) 87 } 88 }, 89 setVolumeDescription: function (...args) { 90 console.warn("volumeManager.setVolumeDescription interface mocked in the Previewer. How this interface works on the" + 91 " Previewer may be different from that on a real device."); 92 const len = args.length; 93 if (typeof args[len - 1] === 'function') { 94 args[len - 1].call(this, paramMock.businessErrorMock); 95 } else { 96 return new Promise((resolve, reject) => { 97 resolve(); 98 }) 99 } 100 }, 101 format: function (...args) { 102 console.warn("volumeManager.format interface mocked in the Previewer. How this interface works on the" + 103 " Previewer may be different from that on a real device."); 104 const len = args.length; 105 if (typeof args[len - 1] === 'function') { 106 args[len - 1].call(this, paramMock.businessErrorMock); 107 } else { 108 return new Promise((resolve, reject) => { 109 resolve(); 110 }) 111 } 112 }, 113 partition: function (...args) { 114 console.warn("volumeManager.partition interface mocked in the Previewer. How this interface works on the" + 115 " Previewer may be different from that on a real device."); 116 const len = args.length; 117 if (typeof args[len - 1] === 'function') { 118 args[len - 1].call(this, paramMock.businessErrorMock); 119 } else { 120 return new Promise((resolve, reject) => { 121 resolve(); 122 }) 123 } 124 } 125 } 126 return volumeManager; 127} 128