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 16jest.mock('../../../../src/trace/component/SpSystemTrace', () => { 17 return {}; 18}); 19import { SpChartManager } from '../../../../src/trace/component/chart/SpChartManager'; 20import { SpLogChart } from '../../../../src/trace/component/chart/SpLogChart'; 21 22jest.mock('../../../../src/js-heap/model/DatabaseStruct'); 23const sqlite = require('../../../../src/trace/database/sql/SqlLite.sql'); 24jest.mock('../../../../src/trace/database/sql/SqlLite.sql'); 25 26window.ResizeObserver = 27 window.ResizeObserver || 28 jest.fn().mockImplementation(() => ({ 29 disconnect: jest.fn(), 30 observe: jest.fn(), 31 unobserve: jest.fn(), 32 })); 33 34describe('SpLogChart Test', () => { 35 let htmlElement: any = document.createElement('sp-system-trace'); 36 let logChart = new SpLogChart(new SpChartManager(htmlElement)); 37 let queryLog = sqlite.queryLogData; 38 let queryLogData = [ 39 { 40 id: 2, 41 startTs: 0, 42 level: 'I', 43 depth: 1, 44 tag: 'C02d0c/Hiprofiler', 45 context: 'ParseTimeExtend: update ts with 0 to 33727453411', 46 time: 1502029274737385200, 47 pid: 1119, 48 tid: 1172, 49 processName: 'hiprofiler_plug', 50 dur: 1, 51 frame: { 52 x: 0, 53 y: 7, 54 width: 1, 55 height: 7, 56 }, 57 }, 58 { 59 id: 37, 60 startTs: 76402674, 61 level: 'W', 62 depth: 2, 63 tag: 'C01300/AbilityManagerService', 64 context: '[ability_manager_service.cpp(UpdateCallerInfo:6178)]UpdateCallerInfo caller abilityRecord is null.', 65 time: 1502029274813788000, 66 pid: 558, 67 tid: 558, 68 processName: 'foundation', 69 dur: 1, 70 frame: { 71 x: 3, 72 y: 14, 73 width: 1, 74 height: 7, 75 }, 76 }, 77 { 78 id: 99, 79 startTs: 579581683, 80 level: 'E', 81 depth: 3, 82 tag: 'C01300/AbilityManagerService', 83 context: '[ability_interceptor.cpp(CheckCrowdtest:104)]GetApplicaionInfo from bms failed.', 84 time: 1502029275316967000, 85 pid: 558, 86 tid: 558, 87 processName: 'foundation', 88 dur: 1, 89 frame: { 90 x: 29, 91 y: 21, 92 width: 1, 93 height: 7, 94 }, 95 }, 96 ]; 97 queryLog.mockResolvedValue(queryLogData); 98 it('SpLogChart01', function () { 99 expect(logChart.init()).toBeDefined(); 100 }); 101}); 102