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