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 { HangType } from '../../../../src/trace/component/chart/SpHangChart'; 21import { HangStruct, HangRender } from '../../../../src/trace/database/ui-worker/ProcedureWorkerHang'; 22import { Rect } from '../../../../src/trace/component/trace/timer-shaft/Rect'; 23jest.mock('../../../../src/trace/component/SpSystemTrace', () => { 24 return {}; 25}); 26jest 27 .spyOn(require('../../../../src/trace/database/ui-worker/ProcedureWorkerCommon'), 'isFrameContainPoint') 28 .mockReturnValue(true); 29describe('Test', () => { 30 let row: TraceRow<HangStruct>; 31 let context: CanvasRenderingContext2D; 32 33 row = TraceRow.skeleton<HangStruct>(); 34 row.isHover = true; 35 TraceRow.range = { 36 startNS: 0, 37 endNS: 1000000, 38 totalNS: 1000000, 39 }; 40 let type: HangType = "Instant"; 41 42 row.dataList = [ 43 { 44 id: 100, 45 startTime: 50, 46 dur: 100, 47 frame: new Rect(0, 0, 100, 100), 48 pid: 5, 49 tid: 8, 50 pname: 'f', 51 content: 'gr', 52 name: 'gt', 53 type: type 54 }, 55 { 56 id: 100, 57 startTime: 50, 58 dur: 100, 59 frame: new Rect(0, 0, 100, 100), 60 pid: 5, 61 tid: 8, 62 }, 63 ]; 64 65 context = { 66 save: jest.fn(), 67 translate: jest.fn(), 68 rect: jest.fn(), 69 clip: jest.fn(), 70 strokeStyle: '#000000', 71 strokeRect: jest.fn(), 72 fillRect: jest.fn(), 73 fillText: jest.fn(), 74 measureText: jest.fn().mockReturnValue({ width: 10 }), 75 beginPath: jest.fn(), 76 closePath: jest.fn(), 77 stroke: jest.fn(), 78 clearRect: jest.fn(), 79 fill: jest.fn(), 80 fillStyle: '#000000', 81 globalAlpha: 0.5, 82 font: '10px sans-serif', 83 canvas: { 84 clientWidth: 800, 85 }, 86 } as unknown as CanvasRenderingContext2D; 87 88 it('HangRenderTest01', () => { 89 const xpowerStatisticRender = new HangRender(); 90 xpowerStatisticRender.renderMainThread({ context, useCache: false, type: 'cpu', index: 5 }, row); 91 expect(context.beginPath).toHaveBeenCalled(); 92 expect(context.closePath).toHaveBeenCalled(); 93 }); 94 95 it('HangRenderTest02', () => { 96 HangStruct.hoverHangStruct = row.dataList[0]; 97 HangStruct.selectHangStruct = row.dataList[0]; 98 expect(HangStruct.draw(context, row.dataList[0])).toBeUndefined(); 99 }); 100 101 it('HangRenderTest03', () => { 102 expect(HangStruct.getFrameColor(row.dataList[0])).toEqual('#559CFF'); 103 }); 104}); 105