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 '../../../../src/trace/component/chart/SpHiSysEnergyChart'; 17import { SpChartManager } from '../../../../src/trace/component/chart/SpChartManager'; 18import '../../../../src/trace/component/chart/SpChartManager'; 19import '../../../../src/trace/component/SpSystemTrace'; 20import { LitPopover } from '../../../../src/base-ui/popover/LitPopoverV'; 21import { SpHiSysEnergyChart } from '../../../../src/trace/component/chart/SpHiSysEnergyChart'; 22 23jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorker', () => { 24 return {}; 25}); 26 27window.ResizeObserver = 28 window.ResizeObserver || 29 jest.fn().mockImplementation(() => ({ 30 disconnect: jest.fn(), 31 observe: jest.fn(), 32 unobserve: jest.fn(), 33 })); 34 35const sqlite = require('../../../../src/trace/database/SqlLite'); 36jest.mock('../../../../src/trace/database/SqlLite'); 37 38describe('SpHiSysEnergyChart Test', () => { 39 let ss = new SpChartManager(); 40 let spHiSysEnergyChart = new SpHiSysEnergyChart(ss); 41 42 let htmlDivElement = document.createElement<LitPopover>('div'); 43 htmlDivElement.setAttribute('id', 'appNameList'); 44 45 let anomalyData = sqlite.queryAnomalyData; 46 anomalyData.mockResolvedValue([]); 47 48 let maxStateValue = sqlite.queryMaxStateValue; 49 let max = [ 50 { 51 maxValue: 200, 52 type: 'state', 53 }, 54 { 55 maxValue: 300, 56 type: 'sensor', 57 }, 58 ]; 59 maxStateValue.mockResolvedValue(max); 60 let MockExits = sqlite.queryEnergyEventExits; 61 MockExits.mockResolvedValue(['trace_hisys_event']); 62 let powerData = sqlite.queryPowerData; 63 let power = [ 64 { 65 startNS: 5999127351, 66 eventName: 'POWER_IDE_AUDIO', 67 appKey: 'APPNAME', 68 eventValue: 'com.example.himusicdemo,com.example.himusicdemo_js,com.example.himusicdemo_app', 69 }, 70 { 71 startNS: 1291120516, 72 eventName: 'POWER_IDE_AUDIO', 73 appKey: 'BACKGROUND_ENERGY', 74 eventValue: '854,258,141', 75 }, 76 ]; 77 powerData.mockResolvedValue(power); 78 79 let stateData = sqlite.queryStateData; 80 stateData.mockResolvedValue([]); 81 82 let sysEventAppName = sqlite.queryEnergyAppName; 83 let appName = [ 84 { 85 string_value: 'app_name', 86 }, 87 ]; 88 sysEventAppName.mockResolvedValue(appName); 89 90 let querySystemLocationData = sqlite.querySystemLocationData; 91 let querySystemLockData = sqlite.querySystemLockData; 92 let querySystemSchedulerData = sqlite.querySystemSchedulerData; 93 let queryConfigSysEventAppName = sqlite.queryConfigEnergyAppName; 94 let location = [ 95 { 96 ts: 100652222, 97 eventName: 'GNSS_STATE', 98 appKey: 'TYPE', 99 Value: '1', 100 }, 101 { 102 ts: 3333332224, 103 eventName: 'GNSS_STATE', 104 appKey: 'TAG', 105 Value: '2', 106 }, 107 ]; 108 109 let lock = [ 110 { 111 ts: 96555551, 112 eventName: 'POWER_RUNNINGLOCK', 113 appKey: 'TYPE', 114 Value: '1', 115 }, 116 { 117 ts: 333234222, 118 eventName: 'POWER_RUNNINGLOCK', 119 appKey: 'TAG', 120 Value: '2', 121 }, 122 ]; 123 124 let work = [ 125 { 126 ts: 100593835619, 127 eventName: 'WORK_ADD', 128 appKey: 'TYPE', 129 Value: '1', 130 }, 131 { 132 ts: 2315652241, 133 eventName: 'WORK_STOP', 134 appKey: 'TAG', 135 Value: '2', 136 }, 137 ]; 138 139 let process = [ 140 { 141 process_name: 'process1', 142 }, 143 ]; 144 querySystemLocationData.mockResolvedValue(location); 145 querySystemLockData.mockResolvedValue(lock); 146 querySystemSchedulerData.mockResolvedValue(work); 147 queryConfigSysEventAppName.mockResolvedValue(process); 148 149 it('SpHiSysEnergyChartTest01', function () { 150 spHiSysEnergyChart.init(); 151 expect(SpHiSysEnergyChart.app_name).toBeUndefined(); 152 }); 153 154 it('SpHiSysEnergyChartTest04', function () { 155 let result = [ 156 { 157 startNS: 33255112, 158 eventName: 'POWER_IDE_AUDIO', 159 appKey: 'APPNAME', 160 eventValue: 'com.example.himusicdemo,com.example.himusicdemo_js,com.example.himusicdemo_app', 161 }, 162 { 163 startNS: 5999127352, 164 eventName: 'POWER_IDE_AUDIO', 165 appKey: 'BACKGROUND_ENERGY', 166 eventValue: '854,258,141', 167 }, 168 { 169 startNS: 223224352, 170 eventName: 'POWER_IDE_BLUETOOTH', 171 appKey: 'APPNAME', 172 eventValue: 'com.ohos.settings,bt_switch,bt_switch_js,bt_switch_app', 173 }, 174 { 175 startNS: 86222222, 176 eventName: 'POWER_IDE_BLUETOOTH', 177 appKey: 'BACKGROUND_ENERGY', 178 eventValue: '76,12,43,431', 179 }, 180 { 181 startNS: 5999127382, 182 eventName: 'POWER_IDE_CAMERA', 183 appKey: 'APPNAME', 184 eventValue: 'com.ohos.camera,com.ohos.camera_app,com.ohos.camera_js,com.ohos.camera_ts', 185 }, 186 { 187 startNS: 264166822, 188 eventName: 'POWER_IDE_CAMERA', 189 appKey: 'BACKGROUND_ENERGY', 190 eventValue: '375,475,255,963', 191 }, 192 ]; 193 expect(spHiSysEnergyChart.getPowerData(result)).toStrictEqual(Promise.resolve()); 194 }); 195 196 it('SpHiSysEnergyChartTest05', function () { 197 expect(spHiSysEnergyChart.getPowerData([])).toStrictEqual(Promise.resolve()); 198 }); 199 200 it('SpHiSysEnergyChartTest6', function () { 201 expect(spHiSysEnergyChart.initHtml).toMatchInlineSnapshot(`undefined`); 202 }); 203 204 it('SpHiSysEnergyChartTest7', function () { 205 expect(htmlDivElement.onclick).toBe(null); 206 }); 207}); 208