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
16 jest.mock('../../../../src/trace/component/SpSystemTrace', () => {
17   return {};
18 });
19import { SpFreqChart } from '../../../../src/trace/component/chart/SpFreqChart';
20jest.mock('../../../../src/js-heap/model/DatabaseStruct');
21const sqlit = require('../../../../src/trace/database/sql/Cpu.sql');
22jest.mock('../../../../src/trace/database/sql/Cpu.sql');
23 const intersectionObserverMock = () => ({
24   observe: () => null,
25 });
26 window.IntersectionObserver = jest.fn().mockImplementation(intersectionObserverMock);
27 window.ResizeObserver = window.ResizeObserver ||
28   jest.fn().mockImplementation(() => ({
29     disconnect: jest.fn(),
30     observe: jest.fn(),
31     unobserve: jest.fn(),
32   }));
33describe('spFpsChart Test', () => {
34  let htmlElement: any = document.createElement('sp-system-trace');
35  let spFpsChart = new SpFreqChart(htmlElement);
36
37  let mockGetCpuLimitFreq = sqlit.getCpuLimitFreq;
38  mockGetCpuLimitFreq.mockResolvedValue([
39    {
40      startNs: 1000,
41      max: 100,
42      min: 20,
43      cpu: 0,
44    },
45    {
46      startNs: 2000,
47      max: 300,
48      min: 100,
49      cpu: 1,
50    },
51  ]);
52
53  let mockCpuLimitFreqId = sqlit.getCpuLimitFreqId;
54  mockCpuLimitFreqId.mockResolvedValue([
55    {
56      cpu: 0,
57      maxFilterId: 2,
58      minFilterId: 1,
59    },
60    {
61      cpu: 1,
62      maxFilterId: 2,
63      minFilterId: 1,
64    },
65  ]);
66
67  let mockCpuFreqData = sqlit.queryCpuFreqData;
68  mockCpuFreqData.mockResolvedValue([
69    {
70      cpu: 0,
71      value: 100,
72      startNS: 2000,
73    },
74    {
75      cpu: 1,
76      value: 100,
77      startNS: 3000,
78    },
79  ]);
80
81  let mockCpuState = sqlit.queryCpuState;
82  mockCpuState.mockResolvedValue([
83    {
84      startTs: 1000,
85      value: 100,
86    },
87    {
88      startTs: 2000,
89      value: 10,
90    },
91  ]);
92
93  let queryCpuFreqMock = sqlit.queryCpuFreq;
94  queryCpuFreqMock.mockResolvedValue([
95    {
96      cpu: 0,
97      filterId: 1,
98    },
99    {
100      cpu: 1,
101      filterId: 2,
102    },
103  ]);
104
105  let queryCpuStateFilter = sqlit.queryCpuStateFilter;
106  queryCpuStateFilter.mockResolvedValue([
107    {
108      cpu: 0,
109      filterId: 1,
110    },
111    {
112      cpu: 1,
113      filterId: 2,
114    },
115  ]);
116
117  let queryCpuMaxFreqMock = sqlit.queryCpuMaxFreq;
118  queryCpuMaxFreqMock.mockResolvedValue([{ maxFreq: 100 }]);
119
120  let MockgetCpuLimitFreqId = sqlit.getCpuLimitFreqId;
121  MockgetCpuLimitFreqId.mockResolvedValue([{ cpu: 1, maxFilterId: 9, minFilterId: 1 }]);
122
123  let MockgetCpuLimitFreqMax = sqlit.getCpuLimitFreqMax;
124  MockgetCpuLimitFreqMax.mockResolvedValue([{ maxValue: 100, filterId: 9 }]);
125
126  let MockgetCpuCount = sqlit.queryCpuCount;
127  MockgetCpuCount.mockResolvedValue([{ maxCount: 100, filterId: 9 }]);
128  it('spFpsChart01', function () {
129    expect(spFpsChart.init()).toBeDefined();
130  });
131});
132