• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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"
17import { FormInfo, FormStateInfo } from "./ohos_application_formInfo"
18
19export function mockFormHost() {
20  const formHost = {
21    deleteForm: function (...args) {
22      console.warn('formHost.deleteForm interface mocked in the Previewer. How this interface works on the' +
23        ' Previewer may be different from that on a real device.');
24      const len = args.length;
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    releaseForm: function (...args) {
34      console.warn('formHost.releaseForm 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);
39      } else {
40        return new Promise((resolve) => {
41          resolve();
42        });
43      }
44    },
45    requestForm: function (...args) {
46      console.warn('formHost.requestForm 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);
51      } else {
52        return new Promise((resolve) => {
53          resolve();
54        });
55      }
56    },
57    castTempForm: function (...args) {
58      console.warn('formHost.castTempForm 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);
63      } else {
64        return new Promise((resolve) => {
65          resolve();
66        });
67      }
68    },
69    notifyVisibleForms: function (...args) {
70        console.warn('formHost.notifyVisibleForms interface mocked in the Previewer. How this interface works on the' +
71          ' Previewer may be different from that on a real device.');
72        const len = args.length;
73        if (typeof args[len - 1] === 'function') {
74          args[len - 1].call(this, paramMock.businessErrorMock);
75        } else {
76          return new Promise((resolve) => {
77            resolve();
78          });
79        }
80    },
81    notifyInvisibleForms: function (...args) {
82        console.warn('formHost.notifyInvisibleForms interface mocked in the Previewer. How this interface works on the' +
83          ' Previewer may be different from that on a real device.');
84        const len = args.length;
85        if (typeof args[len - 1] === 'function') {
86          args[len - 1].call(this, paramMock.businessErrorMock);
87        } else {
88          return new Promise((resolve) => {
89            resolve();
90          });
91        }
92    },
93    enableFormsUpdate: function (...args) {
94        console.warn('formHost.enableFormsUpdate interface mocked in the Previewer. How this interface works on the' +
95          ' Previewer may be different from that on a real device.');
96        const len = args.length;
97        if (typeof args[len - 1] === 'function') {
98          args[len - 1].call(this, paramMock.businessErrorMock);
99        } else {
100          return new Promise((resolve) => {
101            resolve();
102          });
103        }
104    },
105    disableFormsUpdate: function (...args) {
106        console.warn('formHost.disableFormsUpdate interface mocked in the Previewer. How this interface works on the' +
107          ' Previewer may be different from that on a real device.');
108        const len = args.length;
109        if (typeof args[len - 1] === 'function') {
110          args[len - 1].call(this, paramMock.businessErrorMock);
111        } else {
112          return new Promise((resolve) => {
113            resolve();
114          });
115        }
116    },
117    isSystemReady: function (...args) {
118        console.warn('formHost.isSystemReady interface mocked in the Previewer. How this interface works on the' +
119          ' Previewer may be different from that on a real device.');
120        const len = args.length;
121        if (typeof args[len - 1] === 'function') {
122          args[len - 1].call(this, paramMock.businessErrorMock);
123        } else {
124          return new Promise((resolve) => {
125            resolve();
126          });
127        }
128    },
129    getAllFormsInfo: function (...args) {
130        console.warn('formHost.getAllFormsInfo interface mocked in the Previewer. How this interface works on the' +
131          ' Previewer may be different from that on a real device.');
132        const len = args.length;
133        if (typeof args[len - 1] === 'function') {
134          args[len - 1].call(this, paramMock.businessErrorMock, [FormInfo]);
135        } else {
136          return new Promise((resolve) => {
137            resolve([FormInfo]);
138          });
139        }
140    },
141    getFormsInfo: function (...args) {
142        console.warn('formHost.getFormsInfo interface mocked in the Previewer. How this interface works on the' +
143          ' Previewer may be different from that on a real device.');
144        const len = args.length;
145        if (typeof args[len - 1] === 'function') {
146          args[len - 1].call(this, paramMock.businessErrorMock, [FormInfo]);
147        } else {
148          return new Promise((resolve) => {
149            resolve([FormInfo]);
150          });
151        }
152    },
153    deleteInvalidForms: function (...args) {
154        console.warn('formHost.deleteInvalidForms interface mocked in the Previewer. How this interface works on the' +
155          ' Previewer may be different from that on a real device.');
156        const len = args.length;
157        if (typeof args[len - 1] === 'function') {
158          args[len - 1].call(this, paramMock.businessErrorMock, [paramMock.paramNumberMock]);
159        } else {
160          return new Promise((resolve) => {
161            resolve([paramMock.paramNumberMock]);
162          });
163        }
164    },
165    acquireFormState: function (...args) {
166        console.warn('formHost.acquireFormState interface mocked in the Previewer. How this interface works on the' +
167          ' Previewer may be different from that on a real device.');
168        const len = args.length;
169        if (typeof args[len - 1] === 'function') {
170          args[len - 1].call(this, paramMock.businessErrorMock, FormStateInfo);
171        } else {
172          return new Promise((resolve) => {
173            resolve(FormStateInfo);
174          });
175        }
176    },
177    on: function (...args) {
178        console.warn("formHost.on interface mocked in the Previewer. How this interface works on the Previewer" +
179          " may be different from that on a real device.")
180        const len = args.length
181        if (typeof args[len - 1] === 'function') {
182          args[len - 1].call(this, paramMock.paramStringMock);
183        }
184    },
185    off: function (...args) {
186        console.warn("formHost.off interface mocked in the Previewer. How this interface works on the Previewer" +
187          " may be different from that on a real device.")
188        const len = args.length
189        if (typeof args[len - 1] === 'function') {
190          args[len - 1].call(this, paramMock.paramStringMock);
191        }
192    },
193    notifyFormsVisible: function (...args) {
194        console.warn('formHost.notifyFormsVisible interface mocked in the Previewer. How this interface works on the' +
195          ' Previewer may be different from that on a real device.');
196        const len = args.length;
197        if (typeof args[len - 1] === 'function') {
198          args[len - 1].call(this, paramMock.businessErrorMock);
199        } else {
200          return new Promise((resolve) => {
201            resolve();
202          });
203        }
204    },
205    notifyFormsEnableUpdate: function (...args) {
206        console.warn('formHost.notifyFormsEnableUpdate interface mocked in the Previewer. How this interface works on the' +
207          ' Previewer may be different from that on a real device.');
208        const len = args.length;
209        if (typeof args[len - 1] === 'function') {
210          args[len - 1].call(this, paramMock.businessErrorMock);
211        } else {
212          return new Promise((resolve) => {
213            resolve();
214          });
215        }
216    },
217    shareForm: function (...args) {
218      console.warn('formHost.shareForm interface mocked in the Previewer. How this interface works on the' +
219        ' Previewer may be different from that on a real device.');
220      const len = args.length;
221      if (typeof args[len - 1] === 'function') {
222        args[len - 1].call(this, paramMock.businessErrorMock);
223      } else {
224        return new Promise((resolve) => {
225          resolve();
226        });
227      }
228  },
229  }
230  return formHost
231}