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 {SpHiSysEventChart} from "../../../../dist/trace/component/chart/SpHiSysEventChart.js" 18import "../../../../dist/trace/component/chart/SpHiSysEventChart.js"; 19// @ts-ignore 20import {SpChartManager} from "../../../../dist/trace/component/chart/SpChartManager.js"; 21import "../../../../dist/trace/component/chart/SpChartManager.js"; 22// @ts-ignore 23import {SpSystemTrace} from "../../../../dist/trace/component/SpSystemTrace.js"; 24import "../../../../dist/trace/component/SpSystemTrace.js"; 25// @ts-ignore 26import {LitPopover} from "../../../../dist/base-ui/popover/LitPopoverV.js"; 27 28window.ResizeObserver = window.ResizeObserver || 29 jest.fn().mockImplementation(() => ({ 30 disconnect: jest.fn(), 31 observe: jest.fn(), 32 unobserve: jest.fn(), 33 })); 34 35const sqlite = require("../../../../dist/trace/database/SqlLite.js") 36jest.mock("../../../../dist/trace/database/SqlLite.js"); 37 38describe('SpHiSysEventChart Test', () => { 39 let ss = new SpChartManager(); 40 let spHiSysEventChart = new SpHiSysEventChart(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 maxValue: 200, 51 type: "state" 52 }, { 53 maxValue: 300, 54 type: "sensor" 55 }] 56 maxStateValue.mockResolvedValue(max) 57 let MockExits = sqlite.queryHisystemEventExits 58 MockExits.mockResolvedValue(["trace_hisys_event"]) 59 let powerData = sqlite.queryPowerData; 60 let power = [ 61 { 62 startNS: 5999127353, 63 eventName: "POWER_IDE_AUDIO", 64 appkey: "APPNAME", 65 eventValue: "com.example.himusicdemo,com.example.himusicdemo_js,com.example.himusicdemo_app", 66 }, { 67 startNS: 5999127353, 68 eventName: "POWER_IDE_AUDIO", 69 appkey: "BACKGROUND_ENERGY", 70 eventValue: "854,258,141", 71 } 72 ] 73 powerData.mockResolvedValue(power) 74 75 let stateData = sqlite.queryStateData; 76 stateData.mockResolvedValue([]) 77 78 let sysEventAppName = sqlite.querySyseventAppName; 79 let appName = [{ 80 string_value: "app_name" 81 }] 82 sysEventAppName.mockResolvedValue(appName) 83 84 let systemData = sqlite.querySystemData; 85 let sys = [ 86 { 87 ts: 1005938319, 88 eventName: "WORK_ADD", 89 appkey: "TYPE", 90 Value: "1", 91 }, { 92 ts: 3005933657, 93 eventName: "POWER_RUNNINGLOCK", 94 appkey: "TAG", 95 Value: "DUBAI_TAG_RUNNINGLOCK_REMOVE", 96 } 97 ] 98 systemData.mockResolvedValue(sys) 99 100 it('spHiSysEventChartTest01', function () { 101 spHiSysEventChart.init(); 102 expect(SpHiSysEventChart.app_name).toBeUndefined(); 103 }); 104 105 it('spHiSysEventChartTest02', function () { 106 let result = [ 107 { 108 ts: 1005938319, 109 eventName: "WORK_ADD", 110 appkey: "TYPE", 111 Value: "1", 112 }, { 113 ts: 3005933657, 114 eventName: "POWER_RUNNINGLOCK", 115 appkey: "TAG", 116 Value: "DUBAI_TAG_RUNNINGLOCK_REMOVE", 117 }, { 118 ts: 4005938319, 119 eventName: "GNSS_STATE", 120 appkey: "STATE", 121 Value: "stop", 122 }, { 123 ts: 5005933657, 124 eventName: "POWER_RUNNINGLOCK", 125 appkey: "TAG", 126 Value: "DUBAI_TAG_RUNNINGLOCK_ADD", 127 }, { 128 ts: 6005938319, 129 eventName: "GNSS_STATE", 130 appkey: "STATE", 131 Value: "start", 132 }, { 133 ts: 9005938319, 134 eventName: "WORK_STOP", 135 appkey: "TYPE", 136 Value: "1", 137 }, { 138 ts: 10005938319, 139 eventName: "WORK_REMOVE", 140 appkey: "TYPE", 141 Value: "1", 142 } 143 ] 144 expect(spHiSysEventChart.getSystemData(result)).toEqual([{ 145 "dur": 3005933657, 146 "isHover": false, 147 "startNs": 0, 148 "type": 1 149 }, {"dur": 4005938319, "isHover": false, "startNs": 0, "type": 2}, { 150 "dur": 9000000000, 151 "isHover": false, 152 "startNs": 1005938319, 153 "type": 0 154 }, {"dur": 9000000000, "isHover": false, "startNs": 1005938319, "type": 0}, { 155 "dur": undefined, 156 "isHover": false, 157 "startNs": 5005933657, 158 "type": 1 159 }, {"dur": undefined, "isHover": false, "startNs": 6005938319, "type": 2}]); 160 }); 161 162 it('spHiSysEventChartTest03', function () { 163 expect(spHiSysEventChart.getSystemData([])).toEqual([]); 164 }); 165 166 it('spHiSysEventChartTest04', function () { 167 let result = [ 168 { 169 startNS: 5999127353, 170 eventName: "POWER_IDE_AUDIO", 171 appkey: "APPNAME", 172 eventValue: "com.example.himusicdemo,com.example.himusicdemo_js,com.example.himusicdemo_app", 173 }, { 174 startNS: 5999127353, 175 eventName: "POWER_IDE_AUDIO", 176 appkey: "BACKGROUND_ENERGY", 177 eventValue: "854,258,141", 178 }, { 179 startNS: 5999127353, 180 eventName: "POWER_IDE_BLUETOOTH", 181 appkey: "APPNAME", 182 eventValue: "com.ohos.settings,bt_switch,bt_switch_js,bt_switch_app", 183 }, { 184 startNS: 5999127353, 185 eventName: "POWER_IDE_BLUETOOTH", 186 appkey: "BACKGROUND_ENERGY", 187 eventValue: "76,12,43,431", 188 }, { 189 startNS: 5999127388, 190 eventName: "POWER_IDE_CAMERA", 191 appkey: "APPNAME", 192 eventValue: "com.ohos.camera,com.ohos.camera_app,com.ohos.camera_js,com.ohos.camera_ts", 193 }, { 194 startNS: 5999127388, 195 eventName: "POWER_IDE_CAMERA", 196 appkey: "BACKGROUND_ENERGY", 197 eventValue: "375,475,255,963", 198 } 199 ] 200 expect(spHiSysEventChart.getPowerData(result)).toStrictEqual(Promise.resolve()); 201 }); 202 203 it('spHiSysEventChartTest05', function () { 204 expect(spHiSysEventChart.getPowerData([])).toStrictEqual(Promise.resolve()); 205 }); 206 207 it('spHiSysEventChartTest6', function () { 208 expect(spHiSysEventChart.initHtml).toMatchInlineSnapshot(`undefined`); 209 }); 210 211 it('spHiSysEventChartTest7', function () { 212 expect(htmlDivElement.onclick).toBe(null); 213 }); 214})