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 { TabPaneEnergyAnomaly } from '../../../../../../src/trace/component/trace/sheet/energy/TabPaneEnergyAnomaly'; 17import '../../../../../../src/trace/component/trace/sheet/energy/TabPaneEnergyAnomaly'; 18 19window.ResizeObserver = 20 window.ResizeObserver || 21 jest.fn().mockImplementation(() => ({ 22 disconnect: jest.fn(), 23 observe: jest.fn(), 24 unobserve: jest.fn(), 25 })); 26 27jest.mock('../../../../../../src/trace/database/ui-worker/ProcedureWorker', () => { 28 return {}; 29}); 30const sqlit = require('../../../../../../src/trace/database/sql/ProcessThread.sql'); 31jest.mock('../../../../../../src/trace/database/sql/ProcessThread.sql'); 32jest.mock('../../../../../../src/js-heap/model/DatabaseStruct', () => {}); 33jest.mock('../../../../../../src/trace/database/ui-worker/ProcedureWorkerSnapshot', () => { 34 return {}; 35}); 36describe('TabPanePowerBattery Test', () => { 37 it('TabPaneEnergyAnomalyTest01', function () { 38 let tabPaneEnergyAnomaly = new TabPaneEnergyAnomaly(); 39 let MockAnomalyDetailedData = sqlit.queryAnomalyDetailedData; 40 let battery = [ 41 { 42 ts: 11611696002, 43 eventName: 'ANOMALY_SCREEN_OFF_ENERGY', 44 appKey: 'BATTERY_DRAIN', 45 Value: '10', 46 }, 47 { 48 ts: 11611696002, 49 eventName: 'ANOMALY_SCREEN_OFF_ENERGY', 50 appKey: 'BATTERY_GAS_GUAGE', 51 Value: '980', 52 }, 53 { 54 ts: 15612568649, 55 eventName: 'ANOMALY_RUNNINGLOCK', 56 appKey: 'APPNAME', 57 Value: 'com.example.powerhap', 58 }, 59 { 60 ts: 15612568649, 61 eventName: 'ANOMALY_RUNNINGLOCK', 62 appKey: 'COUNT', 63 Value: '1', 64 }, 65 { 66 ts: 17611804002, 67 eventName: 'ANORMALY_APP_ENERGY', 68 appKey: 'APPNAME', 69 Value: 70 '*dpm_others*,*dpm_rom*,/system/bin/hilogd,' + 71 '/system/bin/render_service,' + 72 '/system/bin/wifi_hal_service,' + 73 'bluetooth_servi,com.example.baseanimation,' + 74 'com.example.ohos_location_js,' + 75 'com.ohos.launcher,com.ohos.settings,' + 76 'hidumper_servic,hwc_host,' + 77 'kernel_kworker,softbus_server', 78 }, 79 { 80 ts: 17611804002, 81 eventName: 'ANORMALY_APP_ENERGY', 82 appKey: 'BGENERGY', 83 Value: '11726,79745,6209,249329,1680,8694,3061,457,402,17064,4087,16403,32965,2895', 84 }, 85 ]; 86 MockAnomalyDetailedData.mockResolvedValue(battery); 87 let tabPaneAnomalyDetailedData = { 88 cpus: [], 89 threadIds: [85,6,9], 90 trackIds: [46,0], 91 funTids: [8,0,76], 92 heapIds: [67,89], 93 nativeMemory: [], 94 cpuAbilityIds: [21, 54], 95 memoryAbilityIds: [54 ,78], 96 diskAbilityIds: [5,0], 97 networkAbilityIds: [9], 98 leftNs: 3200, 99 rightNs: 425900, 100 hasFps: false, 101 statisticsSelectData: undefined, 102 perfSampleIds: [45,85], 103 perfCpus: [], 104 perfProcess: [], 105 perfThread: [], 106 perfAll: false, 107 systemEnergy: [99,5], 108 powerEnergy: [0, 87, 65], 109 anomalyEnergy: [670, 18, 782], 110 }; 111 112 tabPaneEnergyAnomaly.data = tabPaneAnomalyDetailedData; 113 }); 114}); 115