• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 mockWifi() {
19  const linkedInfoMock = {
20    ssid: '[PC preview] unknow ssid',
21    bssid: '[PC preview] unknow bssid',
22    networkId: '[PC preview] unknow networkId',
23    rssi: '[PC preview] unknow rssi',
24    band: '[PC preview] unknow band',
25    linkSpeed: '[PC preview] unknow linkSpeed',
26    frequency: '[PC preview] unknow frequency',
27    isHidden: '[PC preview] unknow isHidden',
28    isRestricted: '[PC preview] unknow isRestricted',
29    chload: '[PC preview] unknow chload',
30    snr: '[PC preview] unknow snr',
31    macAddress: '[PC preview] unknow macAddress',
32    ipAddress: '[PC preview] unknow ipAddress',
33    suppState: '[PC preview] unknow suppState',
34    connState: '[PC preview] unknow connState'
35  }
36
37  const ipInfoMock = {
38    ipAddress: '[PC preview] unknow ipAddress',
39    gateway: '[PC preview] unknow gateway',
40    netmask: '[PC preview] unknow netmask',
41    primaryDns: '[PC preview] unknow primaryDns',
42    secondDns: '[PC preview] unknow secondDns',
43    serverIp: '[PC preview] unknow serverIp',
44    leaseDuration: '[PC preview] unknow leaseDuration'
45  }
46
47  const wifiScanInfoMock = {
48    ssid: '[PC preview] unknow ssid',
49    bssid: '[PC preview] unknow bssid',
50    securityType: '[PC preview] unknow securityType',
51    rssi: '[PC preview] unknow rssi',
52    band: '[PC preview] unknow band',
53    frequency: '[PC preview] unknow frequency',
54    timestamp: '[PC preview] unknow timestamp',
55  }
56
57  const wifiDeviceConfigMock = {
58    ssid: '[PC preview] unknow ssid',
59    bssid: '[PC preview] unknow bssid',
60    preSharedKey: '[PC preview] unknow preSharedKey',
61    isHiddenSsid: '[PC preview] unknow isHiddenSsid',
62    securityType: '[PC preview] unknow securityType',
63  }
64
65  const wifiHotspotConfigMock = {
66    ssid: '[PC preview] unknow ssid',
67    securityType: '[PC preview] unknow securityType',
68    band: '[PC preview] unknow band',
69    preSharedKey: '[PC preview] unknow preSharedKey',
70    maxConn: '[PC preview] unknow maxConn',
71  }
72
73  const wifiStationInfoMock = {
74    name: '[PC preview] unknow name',
75    macAddress: '[PC preview] unknow macAddress',
76    ipAddress: '[PC preview] unknow ipAddress',
77  }
78
79  const p2pLinkedInfoMock = {
80    connectState: '[PC preview] unknow connectState',
81    isGroupOwner: '[PC preview] unknow isGroupOwner',
82    groupOwnerAddr: '[PC preview] unknow groupOwnerAddr',
83  }
84
85  const WifiP2pDeviceMock = {
86    deviceName: '[PC preview] unknow deviceName',
87    deviceAddress: '[PC preview] unknow deviceAddress',
88    primaryDeviceType: '[PC preview] unknow primaryDeviceType',
89    deviceStatus: '[PC preview] unknow deviceStatus',
90    groupCapabilitys: '[PC preview] unknow groupCapabilitys',
91  }
92
93  const p2pGroupInfoMock = {
94    isP2pGo: '[PC preview] unknow connectState',
95    ownerInfo: WifiP2pDeviceMock,
96    passphrase: '[PC preview] unknow passphrase',
97    interface: '[PC preview] unknow interface',
98    groupName: '[PC preview] unknow groupName',
99    networkId: '[PC preview] unknow networkId',
100    frequency: '[PC preview] unknow frequency',
101    clientDevices: [WifiP2pDeviceMock],
102    goIpAddress: '[PC preview] unknow goIpAddress',
103  }
104
105  const wifi = {
106    enableWifi: function (...args) {
107      console.warn("wifi.enableWifi interface mocked in the Previewer. How this interface works on the Previewer" +
108        " may be different from that on a real device.")
109      return paramMock.paramBooleanMock;
110    },
111
112    disableWifi: function (...args) {
113      console.warn("wifi.disableWifi interface mocked in the Previewer. How this interface works on the Previewer" +
114        " may be different from that on a real device.")
115      return paramMock.paramBooleanMock;
116    },
117
118    isWifiActive: function (...args) {
119      console.warn("wifi.isWifiActive interface mocked in the Previewer. How this interface works on the Previewer" +
120        " may be different from that on a real device.")
121      return paramMock.paramBooleanMock;
122    },
123
124    scan: function (...args) {
125      console.warn("wifi.scan interface mocked in the Previewer. How this interface works on the Previewer" +
126        " may be different from that on a real device.")
127      return paramMock.paramBooleanMock;
128    },
129
130    getScanInfos: function (...args) {
131      console.warn("wifi.getScanInfos interface mocked in the Previewer. How this interface works on the Previewer" +
132        " may be different from that on a real device.")
133      const len = args.length
134      if (typeof args[len - 1] === 'function') {
135        args[len - 1].call(this, paramMock.businessErrorMock, [wifiScanInfoMock])
136      } else {
137        return new Promise((resolve) => {
138          resolve([wifiScanInfoMock])
139        })
140      }
141    },
142
143    addDeviceConfig: function (...args) {
144      console.warn("wifi.addDeviceConfig interface mocked in the Previewer." +
145        " How this interface works on the Previewer may be different from that on a real device.")
146      const len = args.length
147      if (typeof args[len - 1] === 'function') {
148        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock)
149      } else {
150        return new Promise((resolve) => {
151          resolve(paramMock.paramNumberMock)
152        })
153      }
154    },
155
156    connectToNetwork: function (...args) {
157      console.warn("wifi.connectToNetwork interface mocked in the Previewer. " +
158        "How this interface works on the Previewer may be different from that on a real device.")
159      return paramMock.paramBooleanMock;
160    },
161
162    connectToDevice: function (...args) {
163      console.warn("wifi.connectToDevice interface mocked in the Previewer. How this interface works on the Previewer" +
164        " may be different from that on a real device.")
165      return paramMock.paramBooleanMock;
166    },
167
168    disconnect: function (...args) {
169      console.warn("wifi.disconnect interface mocked in the Previewer. How this interface works on the Previewer" +
170        " may be different from that on a real device.")
171      return paramMock.paramBooleanMock;
172    },
173
174    getSignalLevel: function (...args) {
175      console.warn("wifi.getSignalLevel interface mocked in the Previewer. How this interface works on the Previewer" +
176        " may be different from that on a real device.")
177      return paramMock.paramNumberMock;
178    },
179
180    getLinkedInfo: function (...args) {
181      console.warn("wifi.getLinkedInfo interface mocked in the Previewer. How this interface works on the Previewer" +
182        " may be different from that on a real device.")
183      const len = args.length
184      if (typeof args[len - 1] === 'function') {
185        args[len - 1].call(this, paramMock.businessErrorMock, linkedInfoMock)
186      } else {
187        return new Promise((resolve) => {
188          resolve(linkedInfoMock)
189        })
190      }
191    },
192
193    isConnected: function (...args) {
194      console.warn("wifi.isConnected interface mocked in the Previewer. How this interface works on the Previewer" +
195        " may be different from that on a real device.")
196      return paramMock.paramBooleanMock;
197    },
198
199    getSupportedFeatures: function (...args) {
200      console.warn("wifi.getSupportedFeatures interface mocked in the Previewer." +
201        " How this interface works on the Previewer may be different from that on a real device.")
202      return paramMock.paramNumberMock;
203    },
204
205    isFeatureSupported: function (...args) {
206      console.warn("wifi.isFeatureSupported interface mocked in the Previewer." +
207        " How this interface works on the Previewer may be different from that on a real device.")
208      return paramMock.paramBooleanMock;
209    },
210
211    getDeviceMacAddress: function (...args) {
212      console.warn("wifi.getDeviceMacAddress interface mocked in the Previewer." +
213        " How this interface works on the Previewer may be different from that on a real device.")
214      return [paramMock.paramArrayMock];
215    },
216
217    getIpInfo: function (...args) {
218      console.warn("wifi.getIpInfo interface mocked in the Previewer. How this interface works on the Previewer" +
219        " may be different from that on a real device.")
220      return ipInfoMock;
221    },
222
223    getCountryCode: function (...args) {
224      console.warn("wifi.getCountryCode interface mocked in the Previewer. How this interface works on the Previewer" +
225        " may be different from that on a real device.")
226      return paramMock.paramStringMock;
227    },
228
229    reassociate: function (...args) {
230      console.warn("wifi.reassociate interface mocked in the Previewer." +
231        " How this interface works on the Previewer may be different from that on a real device.")
232      return paramMock.paramBooleanMock;
233    },
234
235    reconnect: function (...args) {
236      console.warn("wifi.reconnect interface mocked in the Previewer." +
237        " How this interface works on the Previewer may be different from that on a real device.")
238      return paramMock.paramBooleanMock;
239    },
240
241    getDeviceConfigs: function (...args) {
242      console.warn("wifi.getDeviceConfigs interface mocked in the Previewer." +
243        " How this interface works on the Previewer may be different from that on a real device.")
244      return [wifiDeviceConfigMock];
245    },
246
247    updateNetwork: function (...args) {
248      console.warn("wifi.updateNetwork interface mocked in the Previewer." +
249        " How this interface works on the Previewer may be different from that on a real device.")
250      return paramMock.paramNumberMock;
251    },
252
253    disableNetwork: function (...args) {
254      console.warn("wifi.disableNetwork interface mocked in the Previewer." +
255        " How this interface works on the Previewer may be different from that on a real device.")
256      return paramMock.paramBooleanMock;
257    },
258
259    removeAllNetwork: function (...args) {
260      console.warn("wifi.removeAllNetwork interface mocked in the Previewer." +
261        " How this interface works on the Previewer may be different from that on a real device.")
262      return paramMock.paramBooleanMock;
263    },
264
265    removeDevice: function (...args) {
266      console.warn("wifi.removeDevice interface mocked in the Previewer." +
267        " How this interface works on the Previewer may be different from that on a real device.")
268      return paramMock.paramBooleanMock;
269    },
270
271    enableHotspot: function (...args) {
272      console.warn("wifi.enableHotspot interface mocked in the Previewer." +
273        " How this interface works on the Previewer may be different from that on a real device.")
274      return paramMock.paramBooleanMock;
275    },
276
277    disableHotspot: function (...args) {
278      console.warn("wifi.disableHotspot interface mocked in the Previewer." +
279        " How this interface works on the Previewer may be different from that on a real device.")
280      return paramMock.paramBooleanMock;
281    },
282
283    isHotspotActive: function (...args) {
284      console.warn("wifi.isHotspotActive interface mocked in the Previewer." +
285        " How this interface works on the Previewer may be different from that on a real device.")
286      return paramMock.paramBooleanMock;
287    },
288
289    setHotspotConfig: function (...args) {
290      console.warn("wifi.setHotspotConfig interface mocked in the Previewer." +
291        " How this interface works on the Previewer may be different from that on a real device.")
292      return paramMock.paramBooleanMock;
293    },
294
295    getHotspotConfig: function (...args) {
296      console.warn("wifi.getHotspotConfig interface mocked in the Previewer." +
297        " How this interface works on the Previewer may be different from that on a real device.")
298      return wifiHotspotConfigMock;
299    },
300
301    getStations: function (...args) {
302      console.warn("wifi.getStations interface mocked in the Previewer." +
303        " How this interface works on the Previewer may be different from that on a real device.")
304      return [wifiStationInfoMock];
305    },
306
307    on: function (...args) {
308      console.warn("wifi.on interface mocked in the Previewer." +
309        " How this interface works on the Previewer may be different from that on a real device.")
310    },
311
312    off: function (...args) {
313      console.warn("wifi.off interface mocked in the Previewer." +
314        " How this interface works on the Previewer may be different from that on a real device.")
315    },
316
317    getP2pLinkedInfo: function (...args) {
318      console.warn("wifi.getP2pLinkedInfo interface mocked in the Previewer. " +
319        "How this interface works on the Previewer may be different from that on a real device.")
320      const len = args.length
321      if (typeof args[len - 1] === 'function') {
322        args[len - 1].call(this, paramMock.businessErrorMock, p2pLinkedInfoMock)
323      } else {
324        return new Promise((resolve) => {
325          resolve(p2pLinkedInfoMock)
326        })
327      }
328    },
329
330    getCurrentGroup: function (...args) {
331      console.warn("wifi.getCurrentGroup interface mocked in the Previewer. How this interface works on the Previewer" +
332        " may be different from that on a real device.")
333      const len = args.length
334      if (typeof args[len - 1] === 'function') {
335        args[len - 1].call(this, paramMock.businessErrorMock, p2pGroupInfoMock)
336      } else {
337        return new Promise((resolve) => {
338          resolve(p2pGroupInfoMock)
339        })
340      }
341    },
342
343    getP2pDevices: function (...args) {
344      console.warn("wifi.getP2pDevices interface mocked in the Previewer. How this interface works on the Previewer" +
345        " may be different from that on a real device.")
346      const len = args.length
347      if (typeof args[len - 1] === 'function') {
348        args[len - 1].call(this, paramMock.businessErrorMock, [WifiP2pDeviceMock])
349      } else {
350        return new Promise((resolve) => {
351          resolve([WifiP2pDeviceMock])
352        })
353      }
354    },
355
356    createGroup: function (...args) {
357      console.warn("wifi.createGroup interface mocked in the Previewer. How this interface works on the Previewer" +
358        " may be different from that on a real device.")
359      return paramMock.paramBooleanMock;
360    },
361
362    removeGroup: function (...args) {
363      console.warn("wifi.removeGroup interface mocked in the Previewer. How this interface works on the Previewer" +
364        " may be different from that on a real device.")
365      return paramMock.paramBooleanMock;
366    },
367
368    p2pConnect: function (...args) {
369      console.warn("wifi.p2pConnect interface mocked in the Previewer. How this interface works on the Previewer" +
370        " may be different from that on a real device.")
371      return paramMock.paramBooleanMock;
372    },
373
374    p2pCancelConnect: function (...args) {
375      console.warn("wifi.p2pCancelConnect interface mocked in the Previewer. " +
376        "How this interface works on the Previewer may be different from that on a real device.")
377      return paramMock.paramBooleanMock;
378    },
379
380    startDiscoverDevices: function (...args) {
381      console.warn("wifi.startDiscoverDevices interface mocked in the Previewer. " +
382        "How this interface works on the Previewer may be different from that on a real device.")
383      return paramMock.paramBooleanMock;
384    },
385
386    stopDiscoverDevices: function (...args) {
387      console.warn("wifi.stopDiscoverDevices interface mocked in the Previewer. " +
388        "How this interface works on the Previewer may be different from that on a real device.")
389      return paramMock.paramBooleanMock;
390    },
391
392    deletePersistentGroup: function (...args) {
393      console.warn("wifi.deletePersistentGroup interface mocked in the Previewer. " +
394        "How this interface works on the Previewer may be different from that on a real device.")
395      return paramMock.paramBooleanMock;
396    },
397
398    setDeviceName: function (...args) {
399      console.warn("wifi.setDeviceName interface mocked in the Previewer. How this interface works on the Previewer" +
400        " may be different from that on a real device.")
401      return paramMock.paramBooleanMock;
402    },
403  }
404  return wifi;
405}
406