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 */ 15import { paramMock } from "../utils" 16import { FormInfo } from "./ohos_application_formInfo" 17 18export function mockFormProvider() { 19 const formProvider = { 20 setFormNextRefreshTime: function (...args) { 21 console.warn('formProvider.setFormNextRefreshTime interface mocked in the Previewer. How this interface works on' + 22 ' the Previewer may be different from that on a real device.'); 23 const len = args.length; 24 // callback 25 if (typeof args[len - 1] === 'function') { 26 args[len - 1].call(this, paramMock.businessErrorMock); 27 } else { 28 return new Promise((resolve) => { 29 resolve(); 30 }); 31 } 32 }, 33 updateForm: function (...args) { 34 console.warn('formProvider.updateForm interface mocked in the Previewer. How this interface works on' + 35 ' the Previewer may be different from that on a real device.'); 36 const len = args.length; 37 // callback 38 if (typeof args[len - 1] === 'function') { 39 args[len - 1].call(this, paramMock.businessErrorMock); 40 } else { 41 return new Promise((resolve) => { 42 resolve(); 43 }); 44 } 45 }, 46 getFormsInfo: function (...args) { 47 console.warn('formProvider.getFormsInfo interface mocked in the Previewer. How this interface works on the' + 48 ' Previewer may be different from that on a real device.'); 49 const len = args.length; 50 var array = new Array(); 51 array.push(FormInfo); 52 // promise without option. 53 if (len == 0) { 54 return new Promise((resolve) => { 55 resolve(array); 56 }); 57 } 58 // callback 59 if (typeof args[len - 1] === 'function') { 60 args[len - 1].call(this, paramMock.businessErrorMock, array); 61 } else { 62 return new Promise((resolve) => { 63 resolve(array); 64 }); 65 } 66 }, 67 requestPublishForm: function (...args) { 68 console.warn('formProvider.requestPublishForm interface mocked in the Previewer. How this interface works on' + 69 ' the Previewer may be different from that on a real device.'); 70 const len = args.length; 71 // callback 72 if (typeof args[len - 1] === 'function') { 73 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); 74 } else { 75 return new Promise((resolve) => { 76 resolve(paramMock.paramStringMock); 77 }); 78 } 79 }, 80 isRequestPublishFormSupported: function (...args) { 81 console.warn('formProvider.isRequestPublishFormSupported interface mocked in the Previewer. How this interface works on' + 82 ' the Previewer may be different from that on a real device.'); 83 // callback 84 const len = args.length; 85 if (typeof args[len - 1] === 'function') { 86 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); 87 } else { 88 return new Promise((resolve) => { 89 resolve(paramMock.paramBooleanMock); 90 }); 91 } 92 } 93 } 94 return formProvider; 95}