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// @ts-ignore 17import {anomaly,EnergyAnomalyStruct,EnergyAnomalyRender} from "../../../../dist/trace/database/ui-worker/ProcedureWorkerEnergyAnomaly.js" 18 19describe('ProcedureWorkerEnergyAnomaly Test', () => { 20 21 it('ProcedureWorkerEnergyAnomalyTest01', function () { 22 let frame = { 23 x: 20, 24 y: 20, 25 width: 100, 26 height: 100 27 } 28 let dataList = new Array(); 29 dataList.push({startNS: 0, dur: 10,length:1, frame: {x:0, y:9, width:10, height:10}}) 30 dataList.push({startNS: 1, dur: 2,length:1}) 31 anomaly(dataList, [{length:1}], 1, 3, 2, frame, "",true) 32 }); 33 34 it('ProcedureWorkerEnergyAnomalyTest02', function () { 35 let frame = { 36 x: 20, 37 y: 20, 38 width: 100, 39 height: 100 40 } 41 let dataList = new Array(); 42 dataList.push({startNS: 0, dur: 10,length:1, frame: {x:0, y:9, width:10, height:10}}) 43 dataList.push({startNS: 1, dur: 2,length:1}) 44 anomaly(dataList, [{length:0}], 1, 3, 2, frame, "",false) 45 }); 46 47 it('ProcedureWorkerEnergyAnomalyTest03', function () { 48 const canvas = document.createElement('canvas'); 49 canvas.width = 1; 50 canvas.height = 1; 51 const ctx = canvas.getContext('2d'); 52 53 const data = { 54 frame: { 55 x: 20, 56 y: 20, 57 width: 100, 58 height: 100 59 } 60 } 61 let path = new Path2D() 62 expect(EnergyAnomalyStruct.draw(ctx, path, data)).toBeUndefined() 63 }); 64 65 it('ProcedureWorkerEnergyAnomalyTest04', function () { 66 let node = { 67 frame: { 68 x: 20, 69 y: 20, 70 width: 100, 71 height: 100 72 }, 73 startNS: 1, 74 value: 50, 75 startTs:3, 76 dur:3, 77 height:2 78 } 79 let frame = { 80 x: 20, 81 y: 20, 82 width: 100, 83 height: 100 84 } 85 expect(EnergyAnomalyStruct.setAnomalyFrame(node, 1,2,5, frame)).toBeUndefined() 86 }); 87 88 it('ProcedureWorkerEnergyAnomalyTest05', function () { 89 let node = { 90 frame: { 91 x: 20, 92 y: 20, 93 width: 100, 94 height: 100 95 }, 96 startNS: 6, 97 value: 50, 98 startTs:3, 99 dur:3, 100 height:2 101 } 102 let frame = { 103 x: 20, 104 y: 20, 105 width: 100, 106 height: 100 107 } 108 expect(EnergyAnomalyStruct.setAnomalyFrame(node, 1,2,5, frame)).toBeUndefined() 109 }); 110 111 it('ProcedureWorkerEnergyAnomalyTest06', function () { 112 let energyAnomalyRender = new EnergyAnomalyRender() 113 let req = { 114 lazyRefresh:true, 115 type:"", 116 startNS:1, 117 endNS:1, 118 totalNS:1, 119 frame: { 120 x: 20, 121 y: 20, 122 width: 100, 123 height: 100 124 }, 125 useCache:false, 126 range:{ 127 refresh:"", 128 }, 129 canvas:'', 130 context:{ 131 font:"11px sans-serif", 132 fillStyle:"#ec407a", 133 globalAlpha:0.6, 134 }, 135 lineColor:'', 136 isHover:'', 137 hoverX:1, 138 params:'', 139 wakeupBean:undefined, 140 flagMoveInfo:'', 141 flagSelectedInfo:'', 142 slicesTime:3, 143 id:1, 144 x: 20, 145 y: 20, 146 width: 100, 147 height: 100 148 } 149 window.postMessage = jest.fn(()=>true) 150 expect(energyAnomalyRender.render(req,[],[])).toBeUndefined() 151 }); 152})