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