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 16jest.mock('../../../../dist/trace/component/trace/base/TraceRow.js', () => { 17 return {}; 18}); 19 20// @ts-ignore 21import { 22 system, 23 EnergySystemStruct, 24 EnergySystemRender, 25} from '../../../../dist/trace/database/ui-worker/ProcedureWorkerEnergySystem.js'; 26 27describe('ProcedureWorkerEnergySystem Test', () => { 28 it('ProcedureWorkerEnergySystemTest01', function () { 29 let frame = { 30 x: 20, 31 y: 20, 32 width: 100, 33 height: 100, 34 }; 35 let dataList = new Array(); 36 dataList.push({ 37 startNs: 0, 38 dur: 10, 39 length: 1, 40 frame: { x: 0, y: 9, width: 10, height: 10 }, 41 }); 42 dataList.push({ startNs: 1, dur: 2, length: 1 }); 43 system(dataList, [{ length: 1 }], 1, 3, 2, frame, true); 44 }); 45 46 it('ProcedureWorkerEnergySystemTest02', function () { 47 let frame = { 48 x: 20, 49 y: 20, 50 width: 100, 51 height: 100, 52 }; 53 54 let aa: any = []; 55 let dataList = new Array(); 56 dataList.push({ 57 startNs: 0, 58 dur: 10, 59 frame: { x: 0, y: 9, width: 10, height: 10 }, 60 }); 61 dataList.push({ startNs: 1, dur: 2 }); 62 aa[0] = dataList; 63 aa[1] = dataList; 64 aa[2] = dataList; 65 system(aa, [], 1, 3, 2, frame, false); 66 }); 67 68 it('ProcedureWorkerEnergyStateTest04', function () { 69 const canvas = document.createElement('canvas'); 70 canvas.width = 1; 71 canvas.height = 1; 72 const ctx = canvas.getContext('2d'); 73 74 const data = { 75 type: 0, 76 frame: { 77 x: 20, 78 y: 20, 79 width: 100, 80 height: 100, 81 }, 82 }; 83 expect(EnergySystemStruct.draw(ctx, data)).toBeUndefined(); 84 }); 85 86 it('ProcedureWorkerEnergyStateTest05', function () { 87 const canvas = document.createElement('canvas'); 88 canvas.width = 1; 89 canvas.height = 1; 90 const ctx = canvas.getContext('2d'); 91 92 const data = { 93 type: 1, 94 frame: { 95 x: 20, 96 y: 20, 97 width: 100, 98 height: 100, 99 }, 100 }; 101 expect(EnergySystemStruct.draw(ctx, data)).toBeUndefined(); 102 }); 103 104 it('ProcedureWorkerEnergyStateTest06', function () { 105 const canvas = document.createElement('canvas'); 106 canvas.width = 1; 107 canvas.height = 1; 108 const ctx = canvas.getContext('2d'); 109 110 const data = { 111 type: 2, 112 frame: { 113 x: 20, 114 y: 20, 115 width: 100, 116 height: 100, 117 }, 118 }; 119 expect(EnergySystemStruct.draw(ctx, data)).toBeUndefined(); 120 }); 121 122 it('ProcedureWorkerEnergyStateTest07', function () { 123 let node = { 124 frame: { 125 x: 10, 126 y: 30, 127 width: 202, 128 height: 202, 129 }, 130 startNS: 10, 131 value: 22, 132 startTs: 64, 133 dur: 66, 134 height: 2, 135 type: 2, 136 }; 137 let frame = { 138 x: 20, 139 y: 20, 140 width: 100, 141 height: 100, 142 }; 143 expect(EnergySystemStruct.setSystemFrame(node, 1, 1, 3, 2, frame)).toBeUndefined(); 144 }); 145 146 it('ProcedureWorkerEnergyStateTest08', function () { 147 let node = { 148 frame: { 149 x: 20, 150 y: 20, 151 width: 100, 152 height: 100, 153 }, 154 startNS: 3, 155 value: 50, 156 startTs: 3, 157 dur: 3, 158 height: 2, 159 type: 1, 160 }; 161 let frame = { 162 x: 20, 163 y: 20, 164 width: 100, 165 height: 100, 166 }; 167 expect(EnergySystemStruct.setSystemFrame(node, 1, 2, 3, 1, frame)).toBeUndefined(); 168 }); 169 170 it('ProcedureWorkerEnergyStateTest09', function () { 171 let node = { 172 frame: { 173 x: 50, 174 y: 50, 175 width: 700, 176 height: 170, 177 }, 178 startNS: 73, 179 value: 77, 180 startTs: 3, 181 dur: 13, 182 height: 12, 183 type: 12, 184 }; 185 let frame = { 186 x: 20, 187 y: 20, 188 width: 100, 189 height: 100, 190 }; 191 expect(EnergySystemStruct.setSystemFrame(node, 1, 1, 3, 2, frame)).toBeUndefined(); 192 }); 193 194 it('ProcedureWorkerEnergyStateTest10', function () { 195 let energySystemRender = new EnergySystemRender(); 196 let energySystemReq = { 197 lazyRefresh: true, 198 type: '', 199 startNS: 1, 200 endNS: 22, 201 totalNS: 21, 202 frame: { 203 x: 23, 204 y: 30, 205 width: 190, 206 height: 960, 207 }, 208 useCache: false, 209 range: { 210 refresh: '', 211 }, 212 canvas: 'sd', 213 context: { 214 font: '11px sans-serif', 215 fillStyle: '#320011', 216 globalAlpha: 0.6, 217 height: 50, 218 width: 100, 219 canvas: { 220 clientWidth: 10, 221 }, 222 beginPath: jest.fn(() => true), 223 clearRect: jest.fn(() => true), 224 stroke: jest.fn(() => true), 225 fillText: jest.fn(() => true), 226 closePath: jest.fn(() => true), 227 fillRect: jest.fn(() => false), 228 measureText: jest.fn(() => []), 229 }, 230 lineColor: '#655f01', 231 isHover: '', 232 hoverX: 31, 233 wakeupBean: undefined, 234 flagMoveInfo: '', 235 flagSelectedInfo: '', 236 slicesTime: 39, 237 id: 98, 238 x: 80, 239 y: 80, 240 width: 400, 241 height: 140, 242 params: { 243 isLive: true, 244 maxHeight: 20, 245 dpr: 21, 246 hoverFuncStruct: '', 247 selectFuncStruct: undefined, 248 }, 249 }; 250 window.postMessage = jest.fn(() => true); 251 expect(energySystemRender.render(energySystemReq, [{}], [])).toBeUndefined(); 252 }); 253}); 254