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 { SpEBPFChart } from '../../../../src/trace/component/chart/SpEBPFChart';
17jest.mock('../../../../src/js-heap/model/DatabaseStruct');
18const sqlit = require('../../../../src/trace/database/sql/Memory.sql');
19jest.mock('../../../../src/trace/database/sql/Memory.sql');
20jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorker', () => {
21  return {};
22});
23jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorkerSnapshot', () => {
24  return {};
25});
26import { TraceRow } from '../../../../src/trace/component/trace/base/TraceRow';
27jest.mock('../../../../src/trace/component/SpSystemTrace', () => {
28  return {};
29});
30import { EBPFChartStruct } from '../../../../src/trace/database/ui-worker/ProcedureWorkerEBPF';
31const sqlite = require('../../../../src/trace/database/sql/SqlLite.sql');
32jest.mock('../../../../src/trace/database/sql/SqlLite.sql');
33const intersectionObserverMock = () => ({
34  observe: () => null,
35});
36window.IntersectionObserver = jest.fn().mockImplementation(intersectionObserverMock);
37window.ResizeObserver =
38  window.ResizeObserver ||
39  jest.fn().mockImplementation(() => ({
40    disconnect: jest.fn(),
41    observe: jest.fn(),
42    unobserve: jest.fn(),
43  }));
44
45describe('SpFileSystemChart Test', () => {
46  let hasFileSysData = sqlit.hasFileSysData;
47  hasFileSysData.mockResolvedValue([
48    {
49      fsCount: 2,
50      vmCount: 2,
51      ioCount: 2,
52    },
53  ]);
54  let getDiskIOProcess = sqlite.getDiskIOProcess;
55  getDiskIOProcess.mockResolvedValue([
56    {
57      name: 'kworker/u8:4',
58      ipid: 2,
59      pid: 186,
60    }
61  ]);
62  let htmlElement: any = document.createElement('sp-system-trace');
63  let spEBPFChart = new SpEBPFChart(htmlElement);
64  spEBPFChart.initFileCallchain = jest.fn(() => true);
65  it('SpMpsChart01', function () {
66    spEBPFChart.init();
67    expect(spEBPFChart).toBeDefined();
68  });
69  it('SpMpsChart02', function () {
70    spEBPFChart.trace.displayTip = jest.fn();
71    expect(spEBPFChart.focusHandler(new TraceRow<EBPFChartStruct>())).toBeUndefined();
72  });
73});
74