• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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';
17import { TraceRow } from '../../../../src/trace/component/trace/base/TraceRow';
18jest.mock('../../../../src/trace/component/SpSystemTrace', () => {
19  return {};
20});
21
22const clockSqlite = require('../../../../src/trace/database/sql/Clock.sql');
23jest.mock('../../../../src/trace/database/sql/Clock.sql');
24jest.mock('../../../../src/js-heap/model/DatabaseStruct');
25const sqlLite = require('../../../../src/trace/database/sql/dmaFence.sql');
26jest.mock('../../../../src/trace/database/sql/dmaFence.sql');
27jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorkerSnapshot', () => {
28  return {};
29});
30jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorker', () => {
31  return {};
32});
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('SpClockChart Test', () => {
46  let htmlElement: any = document.createElement('sp-system-trace');
47  let clockChart = new SpClockChart(htmlElement);
48  let queryClock = clockSqlite.queryClockData;
49  let queryClockData = [
50    {
51      name: 'Frequency',
52      num: 20,
53      srcname: 'Frequency',
54    },
55    {
56      name: 'State',
57      num: 10,
58      srcname: 'State',
59    },
60    {
61      name: 'ScreenState',
62      num: 10,
63      srcname: 'ScreenState',
64    },
65  ];
66  queryClock.mockResolvedValue(queryClockData);
67  let queryDmaFenceName = sqlLite.queryDmaFenceName;
68  let queryDmaFenceNameData = [
69    {
70      timeline: 'timeline1',
71    },
72    {
73      timeline: 'timeline2',
74    },
75    {
76      timeline: 'timeline3',
77    },
78  ];
79  queryDmaFenceName.mockResolvedValue(queryDmaFenceNameData);
80  it('SpClockChart01', function () {
81    expect(clockChart.init()).toBeDefined();
82  });
83  it('SpClockChart02', function () {
84    let traceRow = new TraceRow();
85    expect(clockChart.initDmaFence(traceRow)).toBeDefined();
86  });
87});
88