• 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
16const intersectionObserverMock = () => ({
17  observe: () => null,
18});
19window.IntersectionObserver = jest.fn().mockImplementation(intersectionObserverMock);
20jest.mock('../../../../src/js-heap/model/DatabaseStruct');
21import { trace } from 'console';
22import {
23  SpChartManager,
24  folderSupplier,
25  getRowContext,
26  rowThreadHandler,
27} from '../../../../src/trace/component/chart/SpChartManager';
28import { TraceRow } from '../../../../src/trace/component/trace/base/TraceRow';
29import { BaseStruct } from '../../../../src/trace/database/ui-worker/ProcedureWorkerCommon';
30jest.mock('../../../../src/trace/component/SpSystemTrace', () => {
31  return {};
32});
33
34const sqlite = require('../../../../src/trace/database/sql/ProcessThread.sql');
35jest.mock('../../../../src/trace/database/sql/ProcessThread.sql');
36
37// @ts-ignore
38window.ResizeObserver =
39  window.ResizeObserver ||
40  jest.fn().mockImplementation(() => ({
41    disconnect: jest.fn(),
42    observe: jest.fn(),
43    unobserve: jest.fn(),
44  }));
45describe('SpChartManager Test', () => {
46  let htmlElement: any = document.createElement('sp-system-trace');
47  let chartManager = new SpChartManager(htmlElement);
48  let queryDataDICT = sqlite.queryDataDICT;
49  let dataDICT = [
50    {
51      id: 251,
52      data: 'delay',
53    },
54    {
55      id: 251,
56      data: 'caller',
57    },
58  ];
59  queryDataDICT.mockResolvedValue(dataDICT);
60  let funcNameArr = [
61    {
62      id: 1,
63      name: 'test1',
64      colorIndex: 1,
65    },
66    {
67      id: 2,
68      name: 'test2',
69      colorIndex: 2,
70    },
71  ];
72  let arr = [
73    {
74      id: 1,
75      name: 'test1',
76      type: 't',
77    },
78    {
79      id: 2,
80      name: 'test2',
81      type: 'p',
82    },
83  ];
84  it('SpChartManager01', function () {
85    expect(chartManager).not.toBeUndefined();
86  });
87  it('SpChartManager02', function () {
88    expect(chartManager.handleFuncName(funcNameArr)).toBeUndefined();
89    expect(chartManager.handleFuncName(funcNameArr, '1')).toBeUndefined();
90  });
91  it('SpChartManager03', function () {
92    expect(chartManager.handleProcessThread(arr, '1')).toBeUndefined();
93  });
94  it('SpChartManager04', function () {
95    let traceRow = new TraceRow<BaseStruct>();
96    traceRow.name = 'test';
97    traceRow.rowId = 'trace-1-1';
98    traceRow.rowType = 'trace-1';
99    traceRow.traceId = '1';
100    traceRow.setAttribute('disabled-check', '');
101    traceRow.folder = true;
102    traceRow.rowParentId = '';
103    traceRow.style.height = '40px';
104    expect(chartManager.createFolderRow('trace-1', 'trace-1', 'test', '1')).toStrictEqual(traceRow);
105  });
106  it('SpChartManager05', function () {
107    let obj = [{ id: 0, cat: '', seqno: 0, driver: '', context: '' }];
108    expect(chartManager.handleDmaFenceName(obj)).toBeUndefined();
109  });
110  it('SpChartManager06', function () {
111    expect(folderSupplier()).not.toBeUndefined();
112  });
113});
114