• 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 WorkInfoMock = {
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    };
36    const WorkInfoArrayMock = [WorkInfoMock]
37    const workScheduler = {
38        NetworkType : {
39            NETWORK_TYPE_ANY: 0,
40            NETWORK_TYPE_MOBILE: 1,
41            NETWORK_TYPE_WIFI: 2,
42            NETWORK_TYPE_BLUETOOTH: 3,
43            NETWORK_TYPE_WIFI_P2P: 4,
44            NETWORK_TYPE_ETHERNET: 5,
45        },
46        ChargingType : {
47            CHARGING_PLUGGED_ANY: 0,
48            CHARGING_PLUGGED_AC: 1,
49            CHARGING_PLUGGED_USB: 2,
50            CHARGING_PLUGGED_WIRELESS: 3,
51        },
52        BatteryStatus : {
53            BATTERY_STATUS_LOW: 0,
54            BATTERY_STATUS_OKAY: 1,
55            BATTERY_STATUS_LOW_OR_OKAY: 2,
56        },
57        StorageRequest : {
58            STORAGE_LEVEL_LOW: 0,
59            STORAGE_LEVEL_OKAY: 1,
60            STORAGE_LEVEL_LOW_OR_OKAY: 2,
61        },
62        startWork: function (...args) {
63            console.warn("workScheduler.startWork interface mocked in the Previewer. How this interface works on the" +
64                " Previewer may be different from that on a real device.")
65            return paramMock.paramBooleanMock;
66        },
67        stopWork: function (...args) {
68            console.warn("workScheduler.stopWork interface mocked in the Previewer. How this interface works on the" +
69                " Previewer may be different from that on a real device.")
70            return paramMock.paramBooleanMock;
71        },
72        getWorkStatus: function (...args) {
73            console.warn("workScheduler.getWorkStatus interface mocked in the Previewer. How this interface works on the" +
74                " Previewer may be different from that on a real device.")
75            const len = args.length;
76            if (typeof args[len - 1] === 'function') {
77                args[len - 1].call(this, paramMock.businessErrorMock, WorkInfoMock)
78            } else {
79                return new Promise(resolve => {
80                    resolve(WorkInfoMock);
81                })
82            }
83        },
84        obtainAllWorks: function (...args) {
85            console.warn("workScheduler.obtainAllWorks interface mocked in the Previewer. How this interface works on the" +
86                " Previewer may be different from that on a real device.")
87            const len = args.length;
88            if (typeof args[len - 1] === 'function') {
89                args[len - 1].call(this, paramMock.businessErrorMock, WorkInfoArrayMock)
90            } else {
91                return new Promise(resolve => {
92                  resolve(WorkInfoArrayMock);
93                })
94            }
95        },
96        stopAndClearWorks: function (...args) {
97            console.warn("workScheduler.stopAndClearWorks interface mocked in the Previewer. How this interface works on the" +
98                " Previewer may be different from that on a real device.")
99            return paramMock.paramBooleanMock;
100        },
101        isLastWorkTimeOut: function (...args) {
102            console.warn("workScheduler.isLastWorkTimeOut interface mocked in the Previewer. How this interface works on the" +
103                " Previewer may be different from that on a real device.")
104            const len = args.length;
105            if (typeof args[len - 1] === 'function') {
106                args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock)
107            } else {
108                return new Promise(resolve => {
109                    resolve(paramMock.paramBooleanMock);
110                })
111            }
112        }
113    }
114    return workScheduler;
115}