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 16// @ts-ignore 17import {TabPaneEnergyAnomaly} from "../../../../../../dist/trace/component/trace/sheet/energy/TabPaneEnergyAnomaly.js" 18import "../../../../../../dist/trace/component/trace/sheet/energy/TabPaneEnergyAnomaly.js" 19 20window.ResizeObserver = window.ResizeObserver || 21 jest.fn().mockImplementation(() => ({ 22 disconnect: jest.fn(), 23 observe: jest.fn(), 24 unobserve: jest.fn(), 25 })); 26const sqlit = require("../../../../../../dist/trace/database/SqlLite.js") 27jest.mock("../../../../../../dist/trace/database/SqlLite.js"); 28 29describe('TabPanePowerBattery Test', () => { 30 it('TabPaneEnergyAnomalyTest01', function () { 31 let tabPaneEnergyAnomaly = new TabPaneEnergyAnomaly(); 32 let MockAnomalyDetailedData = sqlit.queryAnomalyDetailedData; 33 let battery = [ 34 { 35 ts: 11611696002, 36 eventName: "ANOMALY_SCREEN_OFF_ENERGY", 37 appKey: "BATTERY_DRAIN", 38 Value: "10" 39 }, { 40 ts: 11611696002, 41 eventName: "ANOMALY_SCREEN_OFF_ENERGY", 42 appKey: "BATTERY_GAS_GUAGE", 43 Value: "980" 44 }, { 45 ts: 15612568649, 46 eventName: "ANOMALY_RUNNINGLOCK", 47 appKey: "APPNAME", 48 Value: "com.example.powerhap" 49 }, { 50 ts: 15612568649, 51 eventName: "ANOMALY_RUNNINGLOCK", 52 appKey: "COUNT", 53 Value: "1" 54 }, { 55 ts: 17611804002, 56 eventName: "ANORMALY_APP_ENERGY", 57 appKey: "APPNAME", 58 Value: "*dpm_others*,*dpm_rom*,/system/bin/hilogd," + 59 "/system/bin/render_service," + 60 "/system/bin/wifi_hal_service," + 61 "bluetooth_servi,com.example.baseanimation," + 62 "com.example.ohos_location_js," + 63 "com.ohos.launcher,com.ohos.settings," + 64 "hidumper_servic,hwc_host," + 65 "kernel_kworker,softbus_server" 66 }, { 67 ts: 17611804002, 68 eventName: "ANORMALY_APP_ENERGY", 69 appKey: "BGENERGY", 70 Value: "11726,79745,6209,249329,1680,8694,3061,457,402,17064,4087,16403,32965,2895" 71 }] 72 MockAnomalyDetailedData.mockResolvedValue(battery) 73 let tabPaneAnomalyDetailedData = { 74 cpus: [], 75 threadIds: [], 76 trackIds: [], 77 funTids: [], 78 heapIds: [], 79 nativeMemory: [], 80 cpuAbilityIds: [], 81 memoryAbilityIds: [], 82 diskAbilityIds: [], 83 networkAbilityIds: [], 84 leftNs: 0, 85 rightNs: 1000, 86 hasFps: false, 87 statisticsSelectData: undefined, 88 perfSampleIds: [], 89 perfCpus: [], 90 perfProcess: [], 91 perfThread: [], 92 perfAll: false, 93 systemEnergy: [0, 1, 2], 94 powerEnergy: [0, 1, 2], 95 anomalyEnergy: [0, 1, 2] 96 } 97 98 tabPaneEnergyAnomaly.data = tabPaneAnomalyDetailedData 99 }) 100 101 102 it('TabPaneEnergyAnomalyTest02', function () { 103 let tabPaneEnergyAnomaly = new TabPaneEnergyAnomaly(); 104 expect(tabPaneEnergyAnomaly.initHtml()).toMatchInlineSnapshot(` 105" 106 <style> 107 .current-title{ 108 width: 95%; 109 display: flex; 110 top: 0; 111 background: var(--dark-background,#ffffff); 112 position: sticky; 113 } 114 .current-title h2{ 115 width: 50%; 116 padding: 0 10px; 117 font-size: 16px; 118 font-weight: 400; 119 visibility: visible; 120 } 121 .bottom-scroll-area{ 122 display: flex; 123 height: auto; 124 overflow-y: auto; 125 } 126 .left-table{ 127 width: 50%; 128 padding: 0 10px; 129 } 130 </style> 131 <div style=\\"width: 100%;height: auto;position: relative\\"> 132 <div id=\\"anomaly-details\\" class=\\"current-title\\" style=\\"margin-left: 12px;display: block\\"> 133 <h2 id=\\"leftTitle\\"></h2> 134 </div> 135 <div class=\\"bottom-scroll-area\\"> 136 <div class=\\"left-table\\"> 137 <lit-table id=\\"anomalyselectionTbl\\" no-head style=\\"height: auto\\"> 138 <lit-table-column title=\\"name\\" data-index=\\"name\\" key=\\"name\\" align=\\"flex-start\\" width=\\"180px\\"> 139 </lit-table-column> 140 <lit-table-column title=\\"value\\" data-index=\\"value\\" key=\\"value\\" align=\\"flex-start\\" > 141 </lit-table-column> 142 </lit-table> 143 </div> 144 </div> 145 </div> 146 " 147`); 148 }); 149})