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});
19import { SpLtpoChart } from '../../../../src/trace/component/chart/SpLTPO';
20
21import { LtpoStruct } from "../../../../src/trace/database/ui-worker/ProcedureWorkerLTPO";
22import { Rect } from "../../../../src/trace/database/ui-worker/ProcedureWorkerCommon";
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});
30
31const intersectionObserverMock = () => ({
32  observe: () => null,
33});
34window.IntersectionObserver = jest.fn().mockImplementation(intersectionObserverMock);
35// @ts-ignore
36window.ResizeObserver = window.ResizeObserver ||
37  jest.fn().mockImplementation(() => ({
38    disconnect: jest.fn(),
39    observe: jest.fn(),
40    unobserve: jest.fn(),
41  }));
42const sqlit = require('../../../../src/trace/database/sql/Ltpo.sql');
43jest.mock('../../../../src/trace/database/sql/Ltpo.sql');
44
45describe('SpLtpoChart Test', () => {
46  let htmlElement: any = document.createElement('sp-system-trace');
47  let ltPoChart = new SpLtpoChart(htmlElement);
48  let fanceNameList = sqlit.queryFanceNameList;
49  fanceNameList.mockResolvedValue([
50    {
51      ts: 122,
52      dur: 245,
53      name:'Present Fence'
54    }
55  ]);
56
57  let fpsNameList = sqlit.queryFpsNameList;
58  fpsNameList.mockResolvedValue([
59    {
60      ts: 1224,
61      dur: 2445,
62      name: 'Layers,ra:te'
63    }
64  ]);
65
66  let realFpsList = sqlit.queryRealFpsList;
67  realFpsList.mockResolvedValue([
68    {
69      ts: 124,
70      dur: 445,
71      name:'CommitAndReleaseLayers SetScreenRefreshRate'
72    }
73  ]);
74  let ltpoArr: LtpoStruct[] = [{
75    translateY:2,
76    frame: new Rect(0, 14, 10, 40),
77    isHover:true,
78    dur: 2122,
79    name: 'name',
80    presentId: 125,
81    ts: 258,
82    fanceId: 1245,
83    fps: 52,
84    startTs: 125,
85    nextStartTs: 12,
86    nextDur: 321,
87    value: 10,
88    pid: 1,
89    itid: 23,
90    startTime: 0
91  }]
92  let presentInfo = sqlit.queryPresentInfo;
93  presentInfo.mockResolvedValue([
94    {
95      ts: 124,
96      dur: 445,
97      name: 'Present Fence'
98    }
99  ]);
100  let rSNowTimeListInfo = sqlit.queryRSNowTimeList;
101  rSNowTimeListInfo.mockResolvedValue([
102    {
103      ts: 124,
104      dur: 445,
105      name: 'Present Fence ffdf'
106    }
107  ]);
108  let signaledListInfo = sqlit.querySignaledList;
109  signaledListInfo.mockResolvedValue([
110    {
111      ts: 124,
112      dur: 445,
113      name: 'Present Fence ffdf'
114    }
115  ]);
116  let skipDataListInfo = sqlit.querySkipDataList;
117  skipDataListInfo.mockResolvedValue([
118    {
119      ts: 124,
120      dur: 445,
121      name: 'Present Fence ffdf'
122    }
123  ]);
124  it('SpLtpoChartTest01', function () {
125    ltPoChart.init();
126    expect(SpLtpoChart.ltpoDataArr).toEqual([]);
127  });
128  it('SpLtpoChartTest02', function () {
129    expect(ltPoChart.setRealFps()).toBeUndefined();
130  });
131  it('SpLtpoChartTest03', function () {
132    expect(ltPoChart.sendDataHandle(ltpoArr, ltpoArr).length).toEqual(0);
133  });
134
135  it('SpLtpoChartTest04', function () {
136    ltPoChart.initHitchTime();
137    expect(SpLtpoChart.presentArr).toEqual([]);
138  });
139});
140