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
16jest.mock('../../../../src/trace/component/SpSystemTrace', () => {
17  return {};
18});
19
20import { SpAllAppStartupsChart } from "../../../../src/trace/component/chart/SpAllAppStartups";
21
22jest.mock('../../../../src/js-heap/model/DatabaseStruct');
23jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorkerSnapshot', () => {
24  return {};
25});
26jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorker', () => {
27  return {};
28});
29
30const intersectionObserverMock = () => ({
31  observe: () => null,
32});
33window.IntersectionObserver = jest.fn().mockImplementation(intersectionObserverMock);
34// @ts-ignore
35window.ResizeObserver = window.ResizeObserver ||
36  jest.fn().mockImplementation(() => ({
37    disconnect: jest.fn(),
38    observe: jest.fn(),
39    unobserve: jest.fn(),
40  }));
41const sqlite = require('../../../../src/trace/database/sql/ProcessThread.sql');
42jest.mock('../../../../src/trace/database/sql/ProcessThread.sql');
43describe('SpAllAppStartupsChart Test', () => {
44  let htmlElement: any = document.createElement('sp-system-trace');
45  let appStartUpsChart = new SpAllAppStartupsChart(htmlElement);
46  let ids = sqlite.queryAppStartupProcessIds;
47  ids.mockResolvedValue([
48    {
49      pid: 12
50    }
51  ]);
52  let processStartup = sqlite.queryProcessStartup;
53  processStartup.mockResolvedValue([
54    {
55      pid: 12,
56      tid: 125,
57      itid: 56
58    }
59  ]);
60  let startupsName = sqlite.querySingleAppStartupsName;
61  startupsName.mockResolvedValue([
62    {
63      name: 'name'
64    }
65  ]);
66  it('SpLtpoChartTest01', function () {
67    appStartUpsChart.init();
68    expect(SpAllAppStartupsChart.APP_STARTUP_PID_ARR).toEqual([]);
69  });
70  it('SpLtpoChartTest02', function () {
71    appStartUpsChart.initFolder();
72    expect(SpAllAppStartupsChart.trace.rowsEL).toBeUndefined();
73  });
74});
75