!433 fix: 电源服务jsmock补齐挑入beta2

Merge pull request !433 from qiuxiangdong/cherry-pick-1658109867
This commit is contained in:
openharmony_ci
2022-07-21 09:51:10 +00:00
committed by Gitee
6 changed files with 123 additions and 68 deletions
+61
View File
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { hasComplete } from "./utils"
export function mockBrightness() {
global.systemplugin.brightness = {
argsV: {
value: 80
},
argsM: {
mode: 0
},
getValue: function (...args) {
console.warn("brightness.getValue interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
args[0].success(this.argsV)
hasComplete(args[0].complete)
},
setValue: function (...args) {
console.warn("brightness.setValue interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
if (args[0].value) {
this.argsV.value = args[0].value
args[0].success()
hasComplete(args[0].complete)
}
},
getMode: function (...args) {
console.warn("brightness.getMode interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
args[0].success(this.argsM)
hasComplete(args[0].complete)
},
setMode: function (...args) {
console.warn("brightness.setMode interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
this.argsM.mode = args[0].mode
args[0].success()
hasComplete(args[0].complete)
},
setKeepScreenOn: function (...args) {
console.warn("brightness.setKeepScreenOn interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
args[0].success()
hasComplete(args[0].complete)
}
}
}
@@ -26,6 +26,7 @@ import {
import { mockAppAbilityManager } from './ohos/app'
import { mockBattery } from './battery'
import { mockBrightness } from './brightness'
import { mockOhosBluetooth } from './ohos/bluetooth'
import { mockDistributedSchedule } from './distributedSchedule'
import { mockFetch } from './fetch'
@@ -63,6 +64,7 @@ export function mockSystemPlugin() {
mockSensor()
mockGeolocation()
mockBattery()
mockBrightness()
mockSystemPackage()
mockFeatureAbility()
mockOhosBluetooth()
@@ -105,7 +105,7 @@ import { mockMultimediaAudio } from './ohos_multimedia_audio'
import { mockMultimediaImage } from './ohos_multimedia_image'
import { mockMultimediaMedia } from './ohos_multimedia_media'
import { mockMultimediaMediaLibrary } from './ohos_multimedia_mediaLibrary'
import { mockOhosBatteryinfo } from './ohos_batteryInfo'
import { mockBatteryinfo } from './ohos_batteryInfo'
import { mockBluetooth } from './ohos_bluetooth'
import { mockBrightness } from './ohos_brightness'
import { mockBytrace } from './ohos_bytrace'
@@ -263,8 +263,8 @@ export function mockRequireNapiFun() {
return mockBrightness();
case "bluetooth":
return mockBluetooth();
case "batteryInfo":
return mockOhosBatteryinfo();
case "batteryinfo":
return mockBatteryinfo();
case "systemParameter":
return mockSystemParameter();
case "ability.dataUriUtils":
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -13,39 +13,67 @@
* limitations under the License.
*/
export function mockOhosBatteryinfo() {
export function mockBatteryinfo() {
const BatteryPluggedType = {
NONE: '[PC preview] unknow NONE',
AC: '[PC preview] unknow AC',
USB: '[PC preview] unknow USB',
WIRELESS: '[PC preview] unknow WIRELESS'
NONE: 0,
AC: 1,
USB: 2,
WIRELESS: 3
}
const BatteryChargeState = {
NONE: '[PC preview] unknow NONE',
ENABLE: '[PC preview] unknow ENABLE',
DISABLE: '[PC preview] unknow DISABLE',
FULL: '[PC preview] unknow FULL'
NONE: 0,
ENABLE: 1,
DISABLE: 2,
FULL: 3
}
const BatteryHealthState = {
UNKNOWN: '[PC preview] unknow UNKNOWN',
GOOD: '[PC preview] unknow GOOD',
OVERHEAT: '[PC preview] unknow OVERHEAT',
OVERVOLTAGE: '[PC preview] unknow OVERVOLTAGE',
COLD: '[PC preview] unknow COLD',
DEAD: '[PC preview] unknow DEAD'
UNKNOWN: 0,
GOOD: 1,
OVERHEAT: 2,
OVERVOLTAGE: 3,
COLD: 4,
DEAD: 5
}
const BatteryCapacityLevel = {
LEVEL_NONE: 0,
LEVEL_FULL: 1,
LEVEL_HIGH: 2,
LEVEL_NORMAL: 3,
LEVEL_LOW: 4,
LEVEL_CRITICAL: 5
}
const CommonEventBatteryChangedCode = {
EXTRA_SOC: 0,
EXTRA_VOLTAGE: 1,
EXTRA_TEMPERATURE: 2,
EXTRA_HEALTH_STATE: 3,
EXTRA_PLUGGED_TYPE: 4,
EXTRA_MAX_CURRENT: 5,
EXTRA_MAX_VOLTAGE: 6,
EXTRA_CHARGE_STATE: 7,
EXTRA_CHARGE_COUNTER: 8,
EXTRA_PRESENT: 9,
EXTRA_TECHNOLOGY: 10,
}
const batteryInfo = {
BatteryPluggedType,
BatteryChargeState,
BatteryHealthState,
BatteryCapacityLevel,
CommonEventBatteryChangedCode,
batterySOC: "[PC Preview] unknow batterySOC",
chargingStatus: "[PC Preview] unknow chargingStatus",
healthStatus: "[PC Preview] unknow healthStatus",
pluggedType: "[PC Preview] unknow pluggedType",
chargingStatus: BatteryChargeState,
healthStatus: BatteryHealthState,
pluggedType: BatteryPluggedType,
voltage: "[PC Preview] unknow voltage",
technology: "[PC Preview] unknow technology",
batteryTemperature: "[PC Preview] unknow batteryTemperature",
isBatteryPresent: "[PC Preview] unknow isBatteryPresent"
isBatteryPresent: "[PC Preview] unknow isBatteryPresent",
batteryCapacityLevel: BatteryCapacityLevel,
estimatedRemainingChargeTime: "[PC Preview] unknow estimatedRemainingChargeTime",
totalEnergy: "[PC Preview] unknow totalEnergy",
nowCurrent: "[PC Preview] unknow nowCurrent",
remainingEnergy: "[PC Preview] unknow remainingEnergy"
}
return batteryInfo
}
@@ -29,14 +29,14 @@ export function mockBatteryStatistics() {
}
const BatteryStatsInfo = {
uid: '[PC preview] unknow uid',
type: '[PC preview] unknow type',
type: ConsumptionType,
power: '[PC preview] unknow power',
}
const batteryStatistics = {
const batteryStats = {
ConsumptionType,
BatteryStatsInfo,
getBatteryStats: function (...args) {
console.warn("batteryStatistics.getBatteryStats interface mocked in the Previewer. How this interface works on the" +
console.warn("batteryStats.getBatteryStats interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
var batteryStatsInfos = new Array(BatteryStatsInfo)
const len = args.length
@@ -49,27 +49,27 @@ export function mockBatteryStatistics() {
}
},
getAppPowerValue: function (...args) {
console.warn("batteryStatistics.getAppPowerValue interface mocked in the Previewer. How this interface works on the" +
console.warn("batteryStats.getAppPowerValue interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return paramMock.paramNumberMock;
},
getAppPowerPercent: function (...args) {
console.warn("batteryStatistics.getAppPowerPercent interface mocked in the Previewer. How this interface works on the" +
console.warn("batteryStats.getAppPowerPercent interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return paramMock.paramNumberMock;
},
getHardwareUnitPowerValue: function (...args) {
console.warn("batteryStatistics.getHardwareUnitPowerValue interface mocked in the Previewer. How this interface works on the" +
console.warn("batteryStats.getHardwareUnitPowerValue interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return paramMock.paramNumberMock;
},
getHardwareUnitPowerPercent: function (...args) {
console.warn("batteryStatistics.getHardwareUnitPowerPercent interface mocked in the Previewer. How this interface works on the" +
console.warn("batteryStats.getHardwareUnitPowerPercent interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return paramMock.paramNumberMock;
}
}
return batteryStatistics
return batteryStats
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -17,45 +17,9 @@ import { hasComplete } from "../utils"
export function mockBrightness() {
const brightness = {
argsV: {
value: 80
},
argsM: {
mode: 0
},
getValue: function (...args) {
console.warn("brightness.getValue interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
args[0].success(this.argsV)
hasComplete(args[0].complete)
},
setValue: function (...args) {
console.warn("brightness.setValue interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
if (args[0].value) {
this.argsV.value = args[0].value
args[0].success("brightness setValue successfully")
hasComplete(args[0].complete)
}
},
getMode: function (...args) {
console.warn("brightness.getMode interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
args[0].success(this.argsM)
hasComplete(args[0].complete)
},
setMode: function (...args) {
console.warn("brightness.setMode interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
this.argsM.mode = args[0].mode
args[0].success("brightness setMode successfully")
hasComplete(args[0].complete)
},
setKeepScreenOn: function (...args) {
console.warn("brightness.setKeepScreenOn interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
args[0].success("brightness setKeepScreenOn successfully")
hasComplete(args[0].complete)
}
}
return brightness