• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021 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
18function buildMockInfo(interfaceName) {
19  return interfaceName + " interface mocked in the Previewer. How this interface works on the Previewer" +
20    " may be different from that on a real device.";
21}
22
23const AppEventPackage = {
24  packageId: paramMock.paramNumberMock,
25  row: paramMock.paramNumberMock,
26  size: paramMock.paramNumberMock,
27  data: paramMock.paramArrayMock
28}
29
30const AppEventPackageHolderClass = class AppEventPackageHolder {
31  constructor(...args) {
32    console.warn(buildMockInfo("AppEventPackageHolder.constructor"));
33    this.setSize = function (...arg) {
34      console.warn(buildMockInfo("AppEventPackageHolder.setSize"));
35    };
36    this.takeNext = function (...arg) {
37      console.warn(buildMockInfo("AppEventPackageHolder.takeNext"));
38      return AppEventPackage;
39    };
40  }
41}
42
43export function mockHiAppEvent() {
44  const EventTypeMock = {
45    FAULT: paramMock.paramNumberMock,
46    STATISTIC: paramMock.paramNumberMock,
47    SECURITY: paramMock.paramNumberMock,
48    BEHAVIOR: paramMock.paramNumberMock
49  }
50  const EventMock = {
51    USER_LOGIN: paramMock.paramStringMock,
52    USER_LOGOUT: paramMock.paramStringMock,
53    DISTRIBUTED_SERVICE_START: paramMock.paramStringMock
54  }
55  const ParamMock = {
56    USER_ID: paramMock.paramStringMock,
57    DISTRIBUTED_SERVICE_NAME: paramMock.paramStringMock,
58    DISTRIBUTED_SERVICE_INSTANCE_ID: paramMock.paramStringMock
59  }
60
61  const hiAppEvent = {
62    EventType: EventTypeMock,
63    Event: EventMock,
64    Param: ParamMock,
65    AppEventPackageHolder: AppEventPackageHolderClass,
66    write: function (...args) {
67      console.warn(buildMockInfo("hiAppEvent.write"))
68      const len = args.length
69      if (typeof args[len - 1] === 'function') {
70        args[len - 1].call(this, paramMock.businessErrorMock)
71      } else {
72        return new Promise((resolve) => {
73          resolve()
74        })
75      }
76    },
77    configure: function (...args) {
78      console.warn(buildMockInfo("hiAppEvent.configure"));
79      return paramMock.paramBooleanMock
80    },
81    addWatcher: function (...args) {
82      console.warn(buildMockInfo("hiAppEvent.addWatcher"));
83      return new AppEventPackageHolderClass();
84    },
85    removeWatcher: function (...args) {
86      console.warn(buildMockInfo("hiAppEvent.removeWatcher"));
87    },
88    clearData: function (...args) {
89      console.warn(buildMockInfo("hiAppEvent.clearData"));
90    }
91  }
92  return hiAppEvent
93}
94