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 { TabPaneSystemDetails } from '../../../../../../src/trace/component/trace/sheet/energy/TabPaneSystemDetails'; 17import '../../../../../../src/trace/component/trace/sheet/energy/TabPaneSystemDetails'; 18import { SpHiSysEventChart } from '../../../../../../src/trace/component/chart/SpHiSysEventChart'; 19import '../../../../../../src/trace/component/chart/SpHiSysEventChart'; 20 21// @ts-ignore 22window.ResizeObserver = window.ResizeObserver || jest.fn().mockImplementation(() => ({ 23 observe: jest.fn(), 24 unobserve: jest.fn(), 25 disconnect: jest.fn(), 26 })); 27jest.mock('../../../../../../src/trace/database/ui-worker/ProcedureWorker', () => { 28 return {}; 29}); 30jest.mock('../../../../../../src/trace/database/ui-worker/ProcedureWorkerSnapshot', () => { 31 return {}; 32}); 33const sqlit = require('../../../../../../src/trace/database/sql/SqlLite.sql'); 34jest.mock('../../../../../../src/trace/database/sql/SqlLite.sql'); 35jest.mock('../../../../../../src/js-heap/model/DatabaseStruct', () => {}); 36 37describe('TabPanePowerBattery Test', () => { 38 it('TabPaneSystemDetailsTest01', function () { 39 let tabPaneSystemDetails = new TabPaneSystemDetails(); 40 tabPaneSystemDetails.tblSystemDetails = jest.fn(() => true); 41 tabPaneSystemDetails.detailsTbl = jest.fn(() => true); 42 tabPaneSystemDetails.tblSystemDetails!.recycleDataSource = jest.fn(() => []); 43 tabPaneSystemDetails.detailsTbl!.recycleDataSource = jest.fn(() => []); 44 let MockquerySystemWorkData = sqlit.querySystemWorkData; 45 SpHiSysEventChart.app_name = '111'; 46 47 let querySystemWorkData = [ 48 { 49 ts: 0, 50 eventName: 'WORK_ADD', 51 appKey: 'workid', 52 appValue: '1', 53 }, 54 { 55 ts: 1005938319, 56 eventName: 'WORK_ADD', 57 appKey: 'name', 58 appValue: 'nnnn', 59 }, 60 { 61 ts: 3005938319, 62 eventName: 'WORK_START', 63 appKey: 'workid', 64 appValue: '1', 65 }, 66 { 67 ts: 3005938319, 68 eventName: 'WORK_START', 69 appKey: 'name', 70 appValue: 'nnnn', 71 }, 72 { 73 ts: 5005938319, 74 eventName: 'WORK_STOP', 75 appKey: 'workid', 76 appValue: '1', 77 }, 78 { 79 ts: 5005938319, 80 eventName: 'WORK_STOP', 81 appKey: 'name', 82 appValue: 'nnnn', 83 }, 84 ]; 85 MockquerySystemWorkData.mockResolvedValue(querySystemWorkData); 86 87 let MockLockData = sqlit.querySysLockDetailsData; 88 let lockDetails = [ 89 { 90 ts: 1005938319, 91 eventName: 'POWER_RUNNINGLOCK', 92 appKey: 'tag', 93 appValue: 'DUBAI_TAG_RUNNINGLOCK_ADD', 94 }, 95 { 96 ts: 1005938319, 97 eventName: 'POWER_RUNNINGLOCK', 98 appKey: 'message', 99 appValue: 'token=123', 100 }, 101 { 102 ts: 3005933657, 103 eventName: 'POWER_RUNNINGLOCK', 104 appKey: 'tag', 105 appValue: 'DUBAI_TAG_RUNNINGLOCK_REMOVE', 106 }, 107 { 108 ts: 3005933657, 109 eventName: 'POWER_RUNNINGLOCK', 110 appKey: 'message', 111 appValue: 'token=123', 112 }, 113 ]; 114 MockLockData.mockResolvedValue(lockDetails); 115 116 let MockLocationData = sqlit.querySysLocationDetailsData; 117 let locationDetails = [ 118 { 119 ts: 1005938319, 120 eventName: 'GNSS_STATE', 121 appKey: 'state', 122 appValue: 'start', 123 }, 124 { 125 ts: 1005938319, 126 eventName: 'GNSS_STATE', 127 appKey: 'pid', 128 appValue: '11', 129 }, 130 { 131 ts: 3005933657, 132 eventName: 'GNSS_STATE', 133 appKey: 'state', 134 appValue: 'stop', 135 }, 136 { 137 ts: 3005933657, 138 eventName: 'GNSS_STATE', 139 appKey: 'pid', 140 appValue: '11', 141 }, 142 ]; 143 MockLocationData.mockResolvedValue(locationDetails); 144 145 let tabPaneSystemDetailsData = { 146 cpus: [1], 147 threadIds: [23, 6, 7], 148 trackIds: [57, 67, 1], 149 funTids: [56, 9], 150 heapIds: [9,0], 151 nativeMemory: [], 152 cpuAbilityIds: [78], 153 memoryAbilityIds: [], 154 diskAbilityIds: [43,98], 155 networkAbilityIds: [], 156 leftNs: 546, 157 rightNs: 300000000, 158 hasFps: false, 159 statisticsSelectData: undefined, 160 perfSampleIds: [], 161 perfCpus: [1,2], 162 perfProcess: [], 163 perfThread: [], 164 perfAll: false, 165 systemEnergy: [5,78,1], 166 powerEnergy: [54, 56, 0], 167 anomalyEnergy: [10, 5, 0, 0], 168 }; 169 170 tabPaneSystemDetails.data = tabPaneSystemDetailsData; 171 expect(tabPaneSystemDetails.data).toBeUndefined(); 172 }); 173 174 it('TabPaneSystemDetailsTest02', function () { 175 let tabPaneSystem = new TabPaneSystemDetails(); 176 tabPaneSystem.tblSystemDetails = jest.fn(() => true); 177 tabPaneSystem.detailsTbl = jest.fn(() => true); 178 tabPaneSystem.tblSystemDetails!.recycleDataSource = jest.fn(() => []); 179 tabPaneSystem.detailsTbl!.recycleDataSource = jest.fn(() => []); 180 let MockSystemWorkData = sqlit.querySystemWorkData; 181 MockSystemWorkData.mockResolvedValue([]); 182 let MockSystemLockData = sqlit.querySysLockDetailsData; 183 MockSystemLockData.mockResolvedValue([]); 184 let MockSystemLocationData = sqlit.querySysLocationDetailsData; 185 MockSystemLocationData.mockResolvedValue([]); 186 let tabPaneSystemDetailsData = { 187 cpus: [], 188 threadIds: [], 189 trackIds: [], 190 funTids: [], 191 heapIds: [], 192 nativeMemory: [], 193 cpuAbilityIds: [], 194 memoryAbilityIds: [], 195 diskAbilityIds: [], 196 networkAbilityIds: [], 197 leftNs: 0, 198 rightNs: 1000, 199 hasFps: false, 200 statisticsSelectData: undefined, 201 perfSampleIds: [], 202 perfCpus: [], 203 perfProcess: [], 204 perfThread: [], 205 perfAll: false, 206 systemEnergy: [0, 1, 2], 207 powerEnergy: [0, 1, 2], 208 anomalyEnergy: [0, 1, 2], 209 }; 210 211 tabPaneSystem.data = tabPaneSystemDetailsData; 212 expect(tabPaneSystem.data).toBeUndefined(); 213 }); 214 215 it('TabPaneSystemDetailsTest03', function () { 216 let tabPaneSystemDetails = new TabPaneSystemDetails(); 217 tabPaneSystemDetails.tblSystemDetails = jest.fn(() => true); 218 tabPaneSystemDetails.detailsTbl = jest.fn(() => true); 219 tabPaneSystemDetails.tblSystemDetails!.recycleDataSource = jest.fn(() => []); 220 tabPaneSystemDetails.detailsTbl!.recycleDataSource = jest.fn(() => []); 221 let data = { 222 ts: 0, 223 eventName: 'Event Name', 224 type: 'type', 225 pid: 2, 226 uid: 33, 227 state: 0, 228 workId: 567, 229 name: 'name', 230 interval: 112, 231 level: 31, 232 tag: 'tag:', 233 message: 'message', 234 log_level: 'log_level', 235 }; 236 237 expect(tabPaneSystemDetails.convertData(data)).toBeUndefined(); 238 }); 239 240 it('TabPaneSystemDetailsTest04', function () { 241 let tabPaneSystemDetails = new TabPaneSystemDetails(); 242 tabPaneSystemDetails.tblSystemDetails = jest.fn(() => true); 243 tabPaneSystemDetails.detailsTbl = jest.fn(() => true); 244 tabPaneSystemDetails.tblSystemDetails!.recycleDataSource = jest.fn(() => []); 245 tabPaneSystemDetails.detailsTbl!.recycleDataSource = jest.fn(() => []); 246 let data = { 247 ts: 0, 248 eventName: 'GNSS_STATE', 249 type: 'type', 250 pid: 23, 251 uid: 11, 252 state: 0, 253 workId: 123, 254 name: 'name', 255 interval: 1011, 256 level: 201, 257 tag: 'tag:', 258 message: 'message', 259 log_level: 'log_level', 260 }; 261 262 expect(tabPaneSystemDetails.convertData(data)).toBeUndefined(); 263 }); 264 265 it('TabPaneSystemDetailsTest05', function () { 266 let tabPaneSystemDetails = new TabPaneSystemDetails(); 267 tabPaneSystemDetails.tblSystemDetails = jest.fn(() => true); 268 tabPaneSystemDetails.detailsTbl = jest.fn(() => true); 269 tabPaneSystemDetails.tblSystemDetails!.recycleDataSource = jest.fn(() => []); 270 tabPaneSystemDetails.detailsTbl!.recycleDataSource = jest.fn(() => []); 271 let data = { 272 ts: 2444221, 273 eventName: 'POWER_RUNNINGLOCK', 274 type: 'type', 275 pid: 76, 276 uid: 23, 277 state: 1, 278 workId: 'workId', 279 name: 'name', 280 interval: 1223, 281 level: 3421, 282 tag: 'tag:', 283 message: 'message', 284 log_level: 'log_level', 285 }; 286 expect(tabPaneSystemDetails.convertData(data)).toBeUndefined(); 287 }); 288 289 it('TabPaneSystemDetailsTest06', function () { 290 let tabPaneSystemDetails = new TabPaneSystemDetails(); 291 tabPaneSystemDetails.tblSystemDetails = jest.fn(() => true); 292 tabPaneSystemDetails.detailsTbl = jest.fn(() => true); 293 tabPaneSystemDetails.tblSystemDetails!.recycleDataSource = jest.fn(() => []); 294 tabPaneSystemDetails.detailsTbl!.recycleDataSource = jest.fn(() => []); 295 let data = { 296 ts: 4442111, 297 eventName: 'POWER', 298 type: 'type', 299 pid: 23, 300 uid: 337, 301 state: 1, 302 workId: 'workId', 303 name: 'name', 304 interval: 10241, 305 level: 147754, 306 tag: 'tag:', 307 message: 'message', 308 log_level: 'log_level', 309 }; 310 311 expect(tabPaneSystemDetails.convertData(data)).toBeUndefined(); 312 }); 313 314 it('TabPaneSystemDetailsTest08', function () { 315 let tabPaneSystemDetails = new TabPaneSystemDetails(); 316 let cc = [ 317 { 318 ts: -14000, 319 workId: 44, 320 name: SpHiSysEventChart.app_name, 321 eventName: 'WORK_ADD', 322 }, 323 { 324 ts: 10000, 325 workId: 11, 326 name: SpHiSysEventChart.app_name, 327 eventName: 'WORK_START', 328 }, 329 { 330 ts: 12000, 331 workId: 22, 332 name: SpHiSysEventChart.app_name, 333 eventName: 'WORK_ADD', 334 }, 335 { 336 ts: 14000, 337 workId: 44, 338 name: SpHiSysEventChart.app_name, 339 eventName: 'WORK_START', 340 }, 341 { 342 ts: 20000, 343 workId: 11, 344 name: SpHiSysEventChart.app_name, 345 eventName: 'WORK_STOP', 346 }, 347 { 348 ts: 22000, 349 workId: 22, 350 name: SpHiSysEventChart.app_name, 351 eventName: 'WORK_START', 352 }, 353 { 354 ts: 30000, 355 workId: 11, 356 name: SpHiSysEventChart.app_name, 357 eventName: 'WORK_START', 358 }, 359 { 360 ts: 32000, 361 workId: 22, 362 name: SpHiSysEventChart.app_name, 363 eventName: 'WORK_STOP', 364 }, 365 { 366 ts: 40000, 367 workId: 11, 368 name: SpHiSysEventChart.app_name, 369 eventName: 'WORK_STOP', 370 }, 371 { 372 ts: 42000, 373 workId: 22, 374 name: SpHiSysEventChart.app_name, 375 eventName: 'WORK_START', 376 }, 377 { 378 ts: 50000, 379 workId: 11, 380 name: SpHiSysEventChart.app_name, 381 eventName: 'WORK_START', 382 }, 383 { 384 ts: 52000, 385 workId: 22, 386 name: SpHiSysEventChart.app_name, 387 eventName: 'WORK_STOP', 388 }, 389 { 390 ts: 60000, 391 workId: 11, 392 name: SpHiSysEventChart.app_name, 393 eventName: 'WORK_STOP', 394 }, 395 { 396 ts: 62000, 397 workId: 22, 398 name: SpHiSysEventChart.app_name, 399 eventName: 'WORK_REMOVE', 400 }, 401 { 402 ts: 64000, 403 workId: 44, 404 name: SpHiSysEventChart.app_name, 405 eventName: 'WORK_STOP', 406 }, 407 { 408 ts: 70000, 409 workId: 11, 410 name: SpHiSysEventChart.app_name, 411 eventName: 'WORK_REMOVE', 412 }, 413 ]; 414 tabPaneSystemDetails.getConvertData = jest.fn(() => cc); 415 let systemWorkData = tabPaneSystemDetails.getSystemWorkData(); 416 417 expect(systemWorkData).toStrictEqual([]); 418 }); 419}); 420