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 { TraceRow } from '../../../../src/trace/component/trace/base/TraceRow'; 17jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorker', () => { 18 return {}; 19}); 20import { PerfToolStruct, PerfToolRender } from '../../../../src/trace/database/ui-worker/ProcedureWorkerPerfTool'; 21import { Rect } from '../../../../src/trace/component/trace/timer-shaft/Rect'; 22jest.mock('../../../../src/trace/component/SpSystemTrace', () => { 23 return {}; 24}); 25jest 26 .spyOn(require('../../../../src/trace/database/ui-worker/ProcedureWorkerCommon'), 'isFrameContainPoint') 27 .mockReturnValue(true); 28describe('Test', () => { 29 let row: TraceRow<PerfToolStruct>; 30 let context: CanvasRenderingContext2D; 31 32 row = TraceRow.skeleton<PerfToolStruct>(); 33 row.isHover = true; 34 TraceRow.range = { 35 startNS: 0, 36 endNS: 1000000, 37 totalNS: 1000000, 38 }; 39 40 row.dataList = [ 41 { 42 count: '100', 43 startTs: 50, 44 frame: new Rect(0, 0, 100, 100), 45 name: 'all-state', 46 dur: 88, 47 id: 55, 48 }, 49 ]; 50 51 row.dataListCache = [ 52 { 53 count: '100', 54 startTs: 50, 55 frame: new Rect(0, 0, 100, 100), 56 name: 'all-state', 57 dur: 88, 58 id: 55, 59 }, 60 ]; 61 62 context = { 63 save: jest.fn(), 64 translate: jest.fn(), 65 rect: jest.fn(), 66 clip: jest.fn(), 67 strokeStyle: '#000000', 68 strokeRect: jest.fn(), 69 fillRect: jest.fn(), 70 fillText: jest.fn(), 71 measureText: jest.fn().mockReturnValue({ width: 10 }), 72 beginPath: jest.fn(), 73 closePath: jest.fn(), 74 stroke: jest.fn(), 75 clearRect: jest.fn(), 76 fill: jest.fn(), 77 fillStyle: '#000000', 78 globalAlpha: 0.5, 79 font: '10px sans-serif', 80 canvas: { 81 clientWidth: 800, 82 }, 83 } as unknown as CanvasRenderingContext2D; 84 85 it('SamplerTest01', () => { 86 const render = new PerfToolRender(); 87 render.renderMainThread({ context, useCache: false, type: 'cpu', index: 5 }, row); 88 expect(context.beginPath).toHaveBeenCalled(); 89 expect(context.closePath).toHaveBeenCalled(); 90 }); 91 92 it('SamplerTest02', () => { 93 PerfToolStruct.selectPerfToolStruct = row.dataList[0]; 94 expect(PerfToolStruct.draw(context, row.dataList[0])).toBeUndefined(); 95 }); 96}); 97