• 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 */
15import { paramMock } from "../../utils"
16import { CommonEventSubscribeInfo } from "./commonEventSubscribeInfo"
17
18export const CommonEventSubscriber = {
19    getCode: function (...args) {
20      console.warn('CommonEventSubscriber.getCode interface mocked in the Previewer. How this interface works on the' +
21        ' Previewer may be different from that on a real device.');
22      const len = args.length;
23      if (typeof args[len - 1] === 'function') {
24        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock);
25      } else {
26        return new Promise((resolve) => {
27          resolve(paramMock.paramNumberMock);
28        });
29      }
30    },
31    setCode: function (...args) {
32      console.warn('CommonEventSubscriber.setCode interface mocked in the Previewer. How this interface works on the' +
33        ' Previewer may be different from that on a real device.');
34      const len = args.length;
35      if (typeof args[len - 1] === 'function') {
36        args[len - 1].call(this, paramMock.businessErrorMock);
37      } else {
38        return new Promise((resolve) => {
39          resolve();
40        });
41      }
42    },
43    getData: function (...args) {
44      console.warn('CommonEventSubscriber.getData interface mocked in the Previewer. How this interface works on the' +
45        ' Previewer may be different from that on a real device.');
46      const len = args.length;
47      if (typeof args[len - 1] === 'function') {
48        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock);
49      } else {
50        return new Promise((resolve) => {
51          resolve(paramMock.paramStringMock);
52        });
53      }
54    },
55    setData: function (...args) {
56      console.warn('CommonEventSubscriber.setData interface mocked in the Previewer. How this interface works on the' +
57        ' Previewer may be different from that on a real device.');
58      const len = args.length;
59      if (typeof args[len - 1] === 'function') {
60        args[len - 1].call(this, paramMock.businessErrorMock);
61      } else {
62        return new Promise((resolve) => {
63          resolve();
64        });
65      }
66    },
67    setCodeAndData: function (...args) {
68      console.warn('CommonEventSubscriber.setCodeAndData interface mocked in the Previewer. How this interface works on the' +
69        ' Previewer may be different from that on a real device.');
70      const len = args.length;
71      if (typeof args[len - 1] === 'function') {
72        args[len - 1].call(this, paramMock.businessErrorMock);
73      } else {
74        return new Promise((resolve) => {
75          resolve();
76        });
77      }
78    },
79    isOrderedCommonEvent: function (...args) {
80      console.warn('CommonEventSubscriber.isOrderedCommonEvent interface mocked in the Previewer. How this interface works on the' +
81        ' Previewer may be different from that on a real device.');
82      const len = args.length;
83      if (typeof args[len - 1] === 'function') {
84        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock);
85      } else {
86        return new Promise((resolve) => {
87          resolve(paramMock.paramBooleanMock);
88        });
89      }
90    },
91    isStickyCommonEvent: function (...args) {
92      console.warn('CommonEventSubscriber.isStickyCommonEvent interface mocked in the Previewer. How this interface works on the' +
93        ' Previewer may be different from that on a real device.');
94      const len = args.length;
95      if (typeof args[len - 1] === 'function') {
96        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock);
97      } else {
98        return new Promise((resolve) => {
99          resolve(paramMock.paramBooleanMock);
100        });
101      }
102    },
103    abortCommonEvent: function (...args) {
104      console.warn('CommonEventSubscriber.abortCommonEvent interface mocked in the Previewer. How this interface works on the' +
105        ' Previewer may be different from that on a real device.');
106      const len = args.length;
107      if (typeof args[len - 1] === 'function') {
108        args[len - 1].call(this, paramMock.businessErrorMock);
109      } else {
110        return new Promise((resolve) => {
111          resolve();
112        });
113      }
114    },
115    clearAbortCommonEvent: function (...args) {
116      console.warn('CommonEventSubscriber.clearAbortCommonEvent interface mocked in the Previewer. How this interface works on the' +
117        ' Previewer may be different from that on a real device.');
118      const len = args.length;
119      if (typeof args[len - 1] === 'function') {
120        args[len - 1].call(this, paramMock.businessErrorMock);
121      } else {
122        return new Promise((resolve) => {
123          resolve();
124        });
125      }
126    },
127    getAbortCommonEvent: function (...args) {
128      console.warn('CommonEventSubscriber.getAbortCommonEvent interface mocked in the Previewer. How this interface works on the' +
129        ' Previewer may be different from that on a real device.');
130      const len = args.length;
131      if (typeof args[len - 1] === 'function') {
132        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock);
133      } else {
134        return new Promise((resolve) => {
135          resolve(paramMock.paramBooleanMock);
136        });
137      }
138    },
139    getSubscribeInfo: function (...args) {
140      console.warn('CommonEventSubscriber.getSubscribeInfo interface mocked in the Previewer. How this interface works on the' +
141        ' Previewer may be different from that on a real device.');
142      const len = args.length;
143      if (typeof args[len - 1] === 'function') {
144        args[len - 1].call(this, paramMock.businessErrorMock, CommonEventSubscribeInfo);
145      } else {
146        return new Promise((resolve) => {
147          resolve(CommonEventSubscribeInfo);
148        });
149      }
150    },
151    finishCommonEvent: function (...args) {
152        console.warn('CommonEventSubscriber.finishCommonEvent interface mocked in the Previewer. How this interface works on the' +
153          ' Previewer may be different from that on a real device.');
154        const len = args.length;
155        if (typeof args[len - 1] === 'function') {
156          args[len - 1].call(this, paramMock.businessErrorMock);
157        } else {
158          return new Promise((resolve, reject) => {
159            resolve();
160         });
161      }
162    },
163}