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 */
15import { SpArkTsChart } from '../../../../src/trace/component/chart/SpArkTsChart';
16jest.mock('../../../../src/trace/component/SpSystemTrace', () => {
17  return {};
18});
19
20jest.mock('../../../../src/js-heap/model/DatabaseStruct');
21const sqlite = require('../../../../src/trace/database/sql/Cpu.sql');
22jest.mock('../../../../src/trace/database/sql/Cpu.sql');
23const JsMemory = require('../../../../src/trace/database/sql/Memory.sql');
24jest.mock('../../../../src/trace/database/sql/Memory.sql');
25const intersectionObserverMock = () => ({
26  observe: () => null,
27});
28window.IntersectionObserver = jest.fn().mockImplementation(intersectionObserverMock);
29window.ResizeObserver =
30  window.ResizeObserver ||
31  jest.fn().mockImplementation(() => ({
32    disconnect: jest.fn(),
33    observe: jest.fn(),
34    unobserve: jest.fn(),
35  }));
36
37describe('SpArkTsChart Test', () => {
38  let htmlElement: any = document.createElement('sp-system-trace');
39  let arkTsChart = new SpArkTsChart(htmlElement);
40  let jsCpuProfilerConfig = sqlite.queryJsCpuProfilerConfig;
41  let cpuProfilerConfigData = [
42    {
43      enableCpuProfiler: 1,
44      pid: 1553,
45      type: -1,
46    },
47  ];
48  jsCpuProfilerConfig.mockResolvedValue(cpuProfilerConfigData);
49
50  let jsCpuProfiler = sqlite.queryJsCpuProfilerData;
51  let cpuProfilerData = [
52    {
53      1: 1,
54    },
55  ];
56  jsCpuProfiler.mockResolvedValue(cpuProfilerData);
57
58  let jsMemory = JsMemory.queryJsMemoryData;
59  let jsMemoryData = [{}];
60  jsMemory.mockResolvedValue(jsMemoryData);
61
62  it('SpArkTsChart01', function () {
63    expect(arkTsChart.initFolder()).not.toBeUndefined();
64  });
65  it('SpArkTsChart02', function () {
66    expect(arkTsChart.initTimelineChart()).not.toBeUndefined();
67  });
68  it('SpArkTsChart03', function () {
69    expect(arkTsChart.initSnapshotChart()).not.toBeUndefined();
70  });
71});
72