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 { SpCpuChart } from '../../../../src/trace/component/chart/SpCpuChart'; 17import { HeapNode } from '../../../../src/js-heap/model/DatabaseStruct'; 18jest.mock('../../../../src/trace/component/SpSystemTrace', () => { 19 return {}; 20}); 21 22jest.mock('../../../../src/js-heap/model/DatabaseStruct'); 23const sqlit = require('../../../../src/trace/database/sql/Cpu.sql'); 24jest.mock('../../../../src/trace/database/sql/Cpu.sql'); 25const intersectionObserverMock = () => ({ 26 observe: () => null, 27}); 28window.IntersectionObserver = jest.fn().mockImplementation(intersectionObserverMock); 29window.ResizeObserver = 30 window.ResizeObserver || 31 jest.fn().mockImplementation(() => ({ 32 disconnect: jest.fn(), 33 observe: jest.fn(), 34 unobserve: jest.fn(), 35 })); 36 37jest.mock('../../../../src/js-heap/utils/Utils', () => { 38 return { 39 HeapNodeToConstructorItem: (node: HeapNode) => { 40 }, 41 }; 42}); 43describe('SpCpuChart Test', () => { 44 let MockqueryCpuMax = sqlit.queryCpuMax; 45 MockqueryCpuMax.mockResolvedValue([{cpu: 1}]); 46 47 let mockCpuSlice = sqlit.queryCpuSchedSlice; 48 mockCpuSlice.mockResolvedValue([]); 49 let queryCpuData = sqlit.queryCpuDataCount; 50 queryCpuData.mockResolvedValue([ 51 { 52 count: 2, 53 cpu: 3, 54 }, 55 ]); 56 let htmlElement: any = document.createElement('sp-system-trace'); 57 let trace = new SpCpuChart(htmlElement); 58 it('SpMpsChart01', async function () { 59 await trace.init(); 60 expect(trace).toBeDefined(); 61 }); 62}); 63