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 '../../../../../../src/trace/component/trace/sheet/bpftrace/TabPaneSampleInstruction'; 17import { TabPaneSampleInstruction } from '../../../../../../src/trace/component/trace/sheet/bpftrace/TabPaneSampleInstruction'; 18jest.mock('../../../../../../src/trace/database/ui-worker/ProcedureWorkerSnapshot', () => { 19 return {}; 20}); 21jest.mock('../../../../../../src/trace/database/ui-worker/ProcedureWorker', () => { 22 return {}; 23}); 24jest.mock('../../../../../../src/trace/component/trace/base/TraceRow', () => { 25 return {}; 26}); 27jest.mock('../../../../../../src/js-heap/model/DatabaseStruct', () => { 28 return {}; 29}); 30window.ResizeObserver = 31 window.ResizeObserver || 32 jest.fn().mockImplementation(() => ({ 33 disconnect: jest.fn(), 34 observe: jest.fn(), 35 unobserve: jest.fn(), 36 })); 37 38describe('TabPaneSampleInstruction Test', () => { 39 let map = new Map(); 40 map.set('clock', [ 41 { 42 filterId: 255, 43 value: 1252, 44 startNS: 4515, 45 dur: 5255, 46 delta: 415, 47 }, 48 ]); 49 let clockCounterData = { 50 leftNs: 253, 51 rightNs: 1252, 52 clockMapData: map, 53 }; 54 let sampleInstruction = new TabPaneSampleInstruction(); 55 const canvas = document.createElement('canvas'); 56 canvas.width = 1; 57 canvas.height = 1; 58 const ctx = canvas.getContext('2d'); 59 it('TabPaneSampleInstructionTest01', function () { 60 sampleInstruction.updateCanvas(10); 61 let clickData = { 62 begin: 0 63 }; 64 let reqProperty = { 65 uniqueProperty: [[{ 66 begin: 0, 67 func_name: 'cpu' 68 },{ 69 begin: 1, 70 func_name: 'memory' 71 }]], 72 flattenTreeArray: [{ 73 name: 'tree', 74 instructions: 2 75 },{ 76 name: 'cpu', 77 instructions: 3 78 },{ 79 name: 'memory', 80 instructions: 5 81 },{ 82 name: 'unknown', 83 instructions: 5 84 }] 85 } 86 sampleInstruction.isChecked = true; 87 sampleInstruction.drawInstructionData = jest.fn(); 88 sampleInstruction.setSampleInstructionData(clickData, reqProperty); 89 expect(sampleInstruction.instructionData).toStrictEqual([[{ 90 begin: 0, 91 func_name: 'cpu' 92 },{ 93 begin: 1, 94 func_name: 'memory' 95 }]]) 96 }); 97 98 it('TabPaneSampleInstructionTest02', function () { 99 // sampleInstruction.floatHint = true; 100 sampleInstruction.hideTip(); 101 sampleInstruction.showTip(); 102 sampleInstruction.updateTipContent(); 103 let sampleNode = { 104 frame: undefined, 105 } 106 sampleInstruction.setSampleFrame(sampleNode, 10, 20); 107 sampleInstruction.updateCanvasCoord(); 108 document.body.innerHTML = `<sp-application></sp-application>` 109 let drawData = { 110 frame: { 111 x: 0, 112 y: 2, 113 width: 20, 114 height: 30 115 }, 116 name: 'cpu', 117 depth: 2 118 } 119 sampleInstruction.draw(ctx, drawData); 120 expect(sampleInstruction.instructionEle.getBoundingClientRect()).toBeTruthy() 121 }); 122}); 123