• 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"
17
18export function mockContinationManager() {
19  const ContinuationMode = {
20    COLLABORATION_SINGLE: 0,
21    COLLABORATION_MULTIPLE: 1
22  }
23  const ContinuationExtraParams = {
24    deviceType: [paramMock.paramStringMock],
25    targetBundle: '[PC preview] unknown targetBundle',
26    description: '[PC preview] unknown description',
27    filter: '[PC preview] unknown filter',
28    continuationMode: ContinuationMode,
29    authInfo: '[PC preview] unknown authInfo'
30  }
31
32  const ContinuationResult = {
33    id: '[PC preview] unknown id',
34    type: '[PC preview] unknown type',
35    name: '[PC preview] unknown name'
36  }
37
38  const continuationManager = {
39    ContinuationMode,
40    DeviceConnectState: {
41      IDLE: 0,
42      CONNECTING: 1,
43      CONNECTED: 2,
44      DISCONNECTING: 3
45    },
46
47    on: function (...args) {
48      console.warn("continuationManager.on interface mocked in the Previewer. How this interface works on the Previewer may" +
49        " be different from that on a real device.")
50      const len = args.length;
51      if (typeof args[len - 1] === 'function') {
52        if (args[0] == 'deviceConnect') {
53          args[len - 1].call(this, new Array(ContinuationResult));
54        } else if (args[0] == 'deviceDisconnect') {
55          args[len - 1].call(this, new Array(paramMock.paramStringMock));
56        }
57      }
58    },
59
60    off: function (...args) {
61      console.warn("continuationManager.off interface mocked in the Previewer. How this interface works on the Previewer may" +
62        " be different from that on a real device.")
63    },
64
65    register: function (...args) {
66      console.warn("continuationManager.register interface mocked in the Previewer. How this interface works on the Previewer" +
67      " may be different from that on a real device.")
68      const len = args.length;
69      if (typeof args[len - 1] === 'function') {
70        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock);
71      } else {
72        return new Promise((resolve) => {
73          resolve(paramMock.paramNumberMock);
74        });
75      }
76    },
77
78    unregister: function (...args) {
79      console.warn("continuationManager.unregister interface mocked in the Previewer. How this interface works on the Previewer" +
80      " may be different from that on a real device.")
81      const len = args.length;
82      if (typeof args[len - 1] === 'function') {
83        args[len - 1].call(this, paramMock.businessErrorMock);
84      } else {
85        return new Promise((resolve) => {
86          resolve();
87        });
88      }
89    },
90
91    updateConnectStatus: function (...args) {
92      console.warn("continuationManager.updateConnectStatus interface mocked in the Previewer. How this interface works on the Previewer" +
93      " 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);
97      } else {
98        return new Promise((resolve) => {
99          resolve();
100        });
101      }
102    },
103
104    startDeviceManager: function (...args) {
105      console.warn("continuationManager.startDeviceManager interface mocked in the Previewer. How this interface works on the Previewer" +
106      " may be different from that on a real device.")
107      const len = args.length;
108      if (typeof args[len - 1] === 'function') {
109        args[len - 1].call(this, paramMock.businessErrorMock);
110      } else {
111        return new Promise((resolve) => {
112          resolve();
113        });
114      }
115    },
116
117    registerContinuation: function (...args) {
118      console.warn("continuationManager.registerContinuation interface mocked in the Previewer. How this interface works on the Previewer" +
119      " 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, paramMock.paramNumberMock);
123      } else {
124        return new Promise((resolve) => {
125          resolve(paramMock.paramNumberMock);
126        });
127      }
128    },
129
130    unregisterContinuation: function (...args) {
131      console.warn("continuationManager.unregisterContinuation 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);
136      } else {
137        return new Promise((resolve) => {
138          resolve();
139        });
140      }
141    },
142
143    updateContinuationState: function (...args) {
144      console.warn("continuationManager.updateContinuationState interface mocked in the Previewer. How this interface works on the Previewer" +
145      " 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);
149      } else {
150        return new Promise((resolve) => {
151          resolve();
152        });
153      }
154    },
155
156    startContinuationDeviceManager: function (...args) {
157      console.warn("continuationManager.startContinuationDeviceManager interface mocked in the Previewer. How this interface works on the Previewer" +
158      " may be different from that on a real device.")
159      const len = args.length;
160      if (typeof args[len - 1] === 'function') {
161        args[len - 1].call(this, paramMock.businessErrorMock);
162      } else {
163        return new Promise((resolve) => {
164          resolve();
165        });
166      }
167    },
168  }
169  return continuationManager
170}