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