• 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 mockWorkScheduler() {
19    const WorkInfo = {
20        workId: '[PC preview] unknown workId',
21        bundleName: '[PC preview] unknown bundleName',
22        abilityName: '[PC preview] unknown abilityName',
23        isPersisted: '[PC preview] unknown isPersisted',
24        networkType: '[PC preview] unknown networkType',
25        isCharging: '[PC preview] unknown isCharging',
26        chargerType: '[PC preview] unknown chargerType',
27        batteryLevel: '[PC preview] unknown batteryLevel',
28        batteryStatus: '[PC preview] unknown batteryStatus',
29        storageRequest: '[PC preview] unknown storageRequest',
30        repeatCycleTime: '[PC preview] unknown repeatCycleTime',
31        isRepeat: '[PC preview] unknown isRepeat',
32        repeatCount: '[PC preview] unknown repeatCount',
33        isDeepIdle: '[PC preview] unknown isDeepIdle',
34        idleWaitTime: '[PC preview] unknown idleWaitTime',
35        parameters: {"key": "unknown any"},
36    };
37    const WorkInfoArray = [WorkInfo]
38    const workScheduler = {
39        NetworkType : {
40            NETWORK_TYPE_ANY: 0,
41            NETWORK_TYPE_MOBILE: 1,
42            NETWORK_TYPE_WIFI: 2,
43            NETWORK_TYPE_BLUETOOTH: 3,
44            NETWORK_TYPE_WIFI_P2P: 4,
45            NETWORK_TYPE_ETHERNET: 5,
46        },
47        ChargingType : {
48            CHARGING_PLUGGED_ANY: 0,
49            CHARGING_PLUGGED_AC: 1,
50            CHARGING_PLUGGED_USB: 2,
51            CHARGING_PLUGGED_WIRELESS: 3,
52        },
53        BatteryStatus : {
54            BATTERY_STATUS_LOW: 0,
55            BATTERY_STATUS_OKAY: 1,
56            BATTERY_STATUS_LOW_OR_OKAY: 2,
57        },
58        StorageRequest : {
59            STORAGE_LEVEL_LOW: 0,
60            STORAGE_LEVEL_OKAY: 1,
61            STORAGE_LEVEL_LOW_OR_OKAY: 2,
62        },
63        startWork: function (...args) {
64            console.warn("workScheduler.startWork interface mocked in the Previewer. How this interface works on the" +
65                " Previewer may be different from that on a real device.")
66            return paramMock.paramBooleanMock;
67        },
68        stopWork: function (...args) {
69            console.warn("workScheduler.stopWork interface mocked in the Previewer. How this interface works on the" +
70                " Previewer may be different from that on a real device.")
71            return paramMock.paramBooleanMock;
72        },
73        getWorkStatus: function (...args) {
74            console.warn("workScheduler.getWorkStatus interface mocked in the Previewer. How this interface works on the" +
75                " Previewer may be different from that on a real device.")
76            const len = args.length;
77            if (typeof args[len - 1] === 'function') {
78                args[len - 1].call(this, paramMock.businessErrorMock, WorkInfo)
79            } else {
80                return new Promise(resolve => {
81                    resolve(WorkInfo);
82                })
83            }
84        },
85        obtainAllWorks: function (...args) {
86            console.warn("workScheduler.obtainAllWorks interface mocked in the Previewer. How this interface works on the" +
87                " Previewer may be different from that on a real device.")
88            const len = args.length;
89            if (typeof args[len - 1] === 'function') {
90                args[len - 1].call(this, paramMock.businessErrorMock, WorkInfoArray)
91            } else {
92                return new Promise(resolve => {
93                  resolve(WorkInfoArray);
94                })
95            }
96        },
97        stopAndClearWorks: function (...args) {
98            console.warn("workScheduler.stopAndClearWorks interface mocked in the Previewer. How this interface works on the" +
99                " Previewer may be different from that on a real device.")
100            return paramMock.paramBooleanMock;
101        },
102        isLastWorkTimeOut: function (...args) {
103            console.warn("workScheduler.isLastWorkTimeOut interface mocked in the Previewer. How this interface works on the" +
104                " Previewer may be different from that on a real device.")
105            const len = args.length;
106            if (typeof args[len - 1] === 'function') {
107                args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock)
108            } else {
109                return new Promise(resolve => {
110                    resolve(paramMock.paramBooleanMock);
111                })
112            }
113        }
114    }
115    return workScheduler;
116}