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