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 mockEnterpriseDeviceManager() { 19 const EnterpriseInfoMock = { 20 name: "[PC preview] unknown name", 21 description: "[PC preview] unknown description", 22 } 23 24 const DeviceSettingsManagerMock = { 25 setDateTime: function (...args) { 26 console.warn('DeviceSettingsManager.setDateTime interface mocked in the Previewer. How this interface works on the' + 27 ' Previewer may be different from that on a real device.'); 28 const len = args.length; 29 if (typeof args[len - 1] === 'function') { 30 args[len - 1].call(this, paramMock.businessErrorMock); 31 } else { 32 return new Promise((resolve) => { 33 resolve(); 34 }); 35 } 36 }, 37 } 38 const enterpriseDeviceManager = { 39 AdminType: { 40 ADMIN_TYPE_NORMAL: 0, 41 ADMIN_TYPE_SUPER: 1, 42 }, 43 44 enableAdmin: function (...args) { 45 console.warn("enterpriseDeviceManager.enableAdmin interface mocked in the Previewer. How this interface works on the" + 46 " Previewer may be different from that on a real device.") 47 const len = args.length; 48 if (typeof args[len - 1] === 'function') { 49 args[len - 1].call(this, paramMock.businessErrorMock); 50 } else { 51 return new Promise((resolve) => { 52 resolve(); 53 }) 54 } 55 }, 56 disableAdmin: function (...args) { 57 console.warn("enterpriseDeviceManager.disableAdmin interface mocked in the Previewer. How this interface works on the" + 58 " Previewer may be different from that on a real device.") 59 const len = args.length; 60 if (typeof args[len - 1] === 'function') { 61 args[len - 1].call(this, paramMock.businessErrorMock); 62 } else { 63 return new Promise((resolve) => { 64 resolve(); 65 }) 66 } 67 }, 68 disableSuperAdmin: function (...args) { 69 console.warn("enterpriseDeviceManager.disableSuperAdmin interface mocked in the Previewer. How this interface works on the" + 70 " Previewer may be different from that on a real device.") 71 const len = args.length; 72 if (typeof args[len - 1] === 'function') { 73 args[len - 1].call(this, paramMock.businessErrorMock); 74 } else { 75 return new Promise((resolve) => { 76 resolve(); 77 }) 78 } 79 }, 80 isAdminEnabled: function (...args) { 81 console.warn("enterpriseDeviceManager.isAdminEnabled interface mocked in the Previewer. How this interface works on the" + 82 " Previewer may be different from that on a real device.") 83 const len = args.length; 84 if (typeof args[len - 1] === 'function') { 85 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); 86 } else { 87 return new Promise((resolve) => { 88 resolve(paramMock.paramBooleanMock); 89 }) 90 } 91 }, 92 getEnterpriseInfo: function (...args) { 93 console.warn("enterpriseDeviceManager.getEnterpriseInfo interface mocked in the Previewer. How this interface works on the" + 94 " Previewer may be different from that on a real device.") 95 const len = args.length; 96 if (typeof args[len - 1] === 'function') { 97 args[len - 1].call(this, paramMock.businessErrorMock, EnterpriseInfoMock); 98 } else { 99 return new Promise((resolve) => { 100 resolve(EnterpriseInfoMock); 101 }) 102 } 103 }, 104 setEnterpriseInfo: function (...args) { 105 console.warn("enterpriseDeviceManager.setEnterpriseInfo interface mocked in the Previewer. How this interface works on the" + 106 " Previewer may be different from that on a real device.") 107 const len = args.length; 108 if (typeof args[len - 1] === 'function') { 109 args[len - 1].call(this, paramMock.businessErrorMock); 110 } else { 111 return new Promise((resolve) => { 112 resolve(); 113 }) 114 } 115 }, 116 isSuperAdmin: function (...args) { 117 console.warn("enterpriseDeviceManager.isSuperAdmin interface mocked in the Previewer. How this interface works on the" + 118 " Previewer may be different from that on a real device.") 119 const len = args.length; 120 if (typeof args[len - 1] === 'function') { 121 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); 122 } else { 123 return new Promise((resolve) => { 124 resolve(paramMock.paramBooleanMock); 125 }) 126 } 127 }, 128 getDeviceSettingsManager: function (...args) { 129 console.warn("enterpriseDeviceManager.getDeviceSettingsManager interface mocked in the Previewer. How this interface works on the" + 130 " Previewer may be different from that on a real device.") 131 const len = args.length; 132 if (typeof args[len - 1] === 'function') { 133 args[len - 1].call(this, paramMock.businessErrorMock, DeviceSettingsManagerMock); 134 } else { 135 return new Promise((resolve) => { 136 resolve(DeviceSettingsManagerMock); 137 }) 138 } 139 } 140 }; 141 return enterpriseDeviceManager; 142}