• 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 mockDistributedBundle() {
19    const RemoteAbilityInfo = [
20        {
21          elementName: {
22            deviceId: "[PC preview] unknown deviceId",
23            bundleName: "[PC preview] unknown bundleName",
24            abilityName: "[PC preview] unknown abilityName",
25            uri: "[PC preview] unknown uri",
26            shortName: "[PC preview] unknown shortName",
27            moduleName: "[PC preview] unknown moduleName",
28          },
29          label: "[PC preview] unknown app label",
30          icon: "[PC preview] unknown icon",
31        },
32    ]
33
34    const DistributedBundle = {
35        getRemoteAbilityInfo: function (...args) {
36            console.warn("distributedBundle.getRemoteAbilityInfo interface mocked in the Previewer. How this interface works on the" +
37                " Previewer may be different from that on a real device.")
38            const len = args.length
39            if (typeof args[len - 1] === 'function') {
40                args[len - 1].call(this, paramMock.businessErrorMock, Array(RemoteAbilityInfo))
41            } else {
42                return new Promise((resolve) => {
43                resolve(Array(RemoteAbilityInfo))
44                });
45            }
46            },
47            getRemoteAbilityInfos: function (...args) {
48            console.warn("distributedBundle.getRemoteAbilityInfos interface mocked in the Previewer. How this interface works on the" +
49                " Previewer may be different from that on a real device.")
50            const len = args.length
51            if (typeof args[len - 1] === 'function') {
52                args[len - 1].call(this, paramMock.businessErrorMock,  Array(RemoteAbilityInfo))
53            } else {
54                return new Promise((resolve) => {
55                resolve(Array(RemoteAbilityInfo))
56                });
57            }
58            }
59    };
60    return DistributedBundle;
61}