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 { SpHiSysEventChart } from '../../../../src/trace/component/chart/SpHiSysEventChart';
17jest.mock('../../../../src/trace/component/SpSystemTrace', () => {
18  return {};
19});
20jest.mock('../../../../src/js-heap/model/DatabaseStruct');
21const sqlite = require('../../../../src/trace/database/sql/Perf.sql');
22jest.mock('../../../../src/trace/database/sql/Perf.sql');
23jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorkerSnapshot', () => {
24  return {};
25});
26jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorker', () => {
27  return {};
28});
29const intersectionObserverMock = () => ({
30  observe: () => null,
31});
32window.IntersectionObserver = jest.fn().mockImplementation(intersectionObserverMock);
33window.ResizeObserver =
34  window.ResizeObserver ||
35  jest.fn().mockImplementation(() => ({
36    disconnect: jest.fn(),
37    observe: jest.fn(),
38    unobserve: jest.fn(),
39  }));
40
41describe('SpHiSysEventChart Test', () => {
42  let spHiSysEvent;
43  let hiSysEventList;
44  let hiSysEventListData;
45  beforeEach(() => {
46    let htmlElement: any = document.createElement('sp-system-trace');
47    spHiSysEvent = new SpHiSysEventChart(htmlElement);
48    hiSysEventList = jest.spyOn(sqlite, 'queryHiSysEventData');
49    hiSysEventListData = [{
50      id: 1,
51      domain: 'STARTUP',
52      eventName: 'PROCESS_EXIT',
53      eventType: '4',
54      ts: 1,
55      tz: 'dad',
56      pid: 1,
57      tid: 1,
58      uid: 1,
59      info: '',
60      level: 'MINOR',
61      seq: '92860',
62      contents: 'APP_PID',
63      dur: 1,
64      depth: 1,
65    }];
66    hiSysEventList.mockResolvedValue(hiSysEventListData);
67  });
68  it('SpHiSysEventChartTest01', function () {
69    expect(spHiSysEvent.init()).toBeTruthy();
70  });
71});
72