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 { TabPaneHiLogs } from '../../../../../../src/trace/component/trace/sheet/hilog/TabPaneHiLogs'; 17import { TraceSheet } from '../../../../../../src/trace/component/trace/base/TraceSheet'; 18import '../../../../../../src/base-ui/table/LitPageTable' 19import { TraceRow } from '../../../../../../src/trace/component/trace/base/TraceRow'; 20 21jest.mock('../../../../../../src/base-ui/table/lit-table', () => { 22 return { 23 recycleDataSource: (): void => { 24 }, 25 }; 26}); 27jest.mock('../../../../../../src/js-heap/model/DatabaseStruct', () => { 28}); 29 30const intersectionObserverMock = (): { observe: () => null } => ({ 31 observe: (): null => null, 32}); 33window.IntersectionObserver = jest.fn().mockImplementation(intersectionObserverMock); 34 35jest.mock('../../../../../../src/trace/component/trace/base/TraceSheet', () => { 36 return {}; 37}); 38jest.mock('../../../../../../src/trace/database/ui-worker/ProcedureWorkerSnapshot', () => { 39 return {}; 40}); 41jest.mock('../../../../../../src/trace/database/ui-worker/ProcedureWorker', () => { 42 return {}; 43}); 44jest.mock('../../../../../../src/trace/database/ui-worker/cpu/ProcedureWorkerCPU', () => { 45 return { 46 cpuCount: 1, 47 CpuRender: Object, 48 EmptyRender: Object, 49 }; 50}); 51 52const sqlit = require('../../../../../../src/trace/database/sql/SqlLite.sql'); 53jest.mock('../../../../../../src/trace/database/sql/SqlLite.sql'); 54 55window.ResizeObserver = 56 window.ResizeObserver || 57 jest.fn().mockImplementation(() => ({ 58 disconnect: jest.fn(), 59 observe: jest.fn(), 60 unobserve: jest.fn(), 61 })); 62 63describe('TabPaneHilogs Test', (): void => { 64 TraceRow.range = jest.fn(() => true); 65 TraceRow.range!.startNS = jest.fn(() => 0); 66 TraceRow.range!.endNS = jest.fn(() => 27763331331); 67 TraceRow.range!.totalNS = jest.fn(() => 27763331331); 68 let hiLogsTab = new TabPaneHiLogs(); 69 document.body.innerHTML = '<div id="vessel"></div>'; 70 let vessel = document.querySelector<HTMLDivElement>('#vessel'); 71 vessel!.append(hiLogsTab); 72 let logsData = { 73 leftNs: 0, 74 rightNs: 33892044011, 75 hiLogs: [{ 76 id: 2, 77 pid: 1119, 78 tid: 1172, 79 processName: 'process1119', 80 startTs: 33872275426, 81 level: 'I', 82 tag: 'C02d0c/Hiprofiler', 83 context: 'ParseTimeExtend: upd', 84 time: 0, 85 depth: 0, 86 dur: 0, 87 }, { 88 id: 3, 89 pid: 1119, 90 tid: 1172, 91 processName: 'process1119', 92 startTs: 33874375717, 93 level: 'W', 94 tag: 'C02d0c/Hiprofiler', 95 context: 'ParseTimeExtend: upd', 96 time: 0, 97 depth: 0, 98 dur: 0, 99 }, { 100 id: 4, 101 pid: 1119, 102 tid: 1172, 103 processName: 'process1119', 104 startTs: 33878711051, 105 level: 'D', 106 tag: 'C02d0c/Hiprofiler', 107 context: 'ParseTimeExtend: upd', 108 time: 0, 109 depth: 0, 110 dur: 0, 111 }, { 112 id: 5, 113 pid: 1119, 114 tid: 1172, 115 processName: 'process1119', 116 startTs: 33885632885, 117 level: 'E', 118 tag: 'C02d0c/Hiprofiler', 119 context: 'ParseTimeExtend: upd', 120 time: 0, 121 depth: 0, 122 dur: 0, 123 }, { 124 id: 6, 125 pid: 1119, 126 tid: 1172, 127 processName: 'process1119', 128 startTs: 33889724969, 129 level: 'F', 130 tag: 'C02d0c/Hiprofiler', 131 context: 'ParseTimeExtend: upd', 132 time: 0, 133 depth: 0, 134 dur: 0, 135 }, { 136 id: 7, 137 pid: 1119, 138 tid: 1172, 139 processName: 'process1119', 140 startTs: 33892044011, 141 level: 'A', 142 tag: 'C02d0c/Hiprofiler', 143 context: 'ParseTimeExtend: upd', 144 time: 0, 145 depth: 0, 146 dur: 0, 147 }] 148 }; 149 150 let logs = sqlit.queryLogAllData; 151 let logData = [ 152 { 153 id: 1, 154 startTs: 25, 155 level: "", 156 depth: 1, 157 tag: "", 158 context: "", 159 originTime: 15252, 160 pid: 258, 161 tid: 586, 162 processName: "processName", 163 dur: 1 164 } 165 ]; 166 logs.mockResolvedValue(logData); 167 168 it('TabPaneHilogsTest01', function () { 169 let htmlElement = document.createElement('div'); 170 let sheetEl = document.createElement('trace-sheet') as TraceSheet; 171 sheetEl!.systemLogFlag = undefined; 172 hiLogsTab.initTabSheetEl(htmlElement, sheetEl); 173 hiLogsTab.data = logsData; 174 }); 175}); 176