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 { SpClockChart } from '../../../../src/trace/component/chart/SpClockChart';
17jest.mock('../../../../src/trace/component/SpSystemTrace', () => {
18  return {};
19});
20
21const sqlite = require('../../../../src/trace/database/sql/Clock.sql');
22jest.mock('../../../../src/trace/database/sql/Clock.sql');
23jest.mock('../../../../src/js-heap/model/DatabaseStruct');
24jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorkerSnapshot', () => {
25  return {};
26});
27jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorker', () => {
28  return {};
29});
30const intersectionObserverMock = () => ({
31  observe: () => null,
32});
33window.IntersectionObserver = jest.fn().mockImplementation(intersectionObserverMock);
34window.ResizeObserver =
35  window.ResizeObserver ||
36  jest.fn().mockImplementation(() => ({
37    disconnect: jest.fn(),
38    observe: jest.fn(),
39    unobserve: jest.fn(),
40  }));
41
42describe('SpClockChart Test', () => {
43  let htmlElement: any = document.createElement('sp-system-trace');
44  let clockChart = new SpClockChart(htmlElement);
45
46  let queryClock = sqlite.queryClockData;
47  let queryClockData = [
48    {
49      name: 'Frequency',
50      num: 20,
51    },
52    {
53      name: 'State',
54      num: 10,
55    },
56    {
57      name: 'ScreenState',
58      num: 10,
59    },
60  ];
61  queryClock.mockResolvedValue(queryClockData);
62
63  it('SpClockChart01', function () {
64    expect(clockChart.init()).toBeDefined();
65  });
66});
67