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 { FrameChart } from '../../../../src/trace/component/chart/FrameChart'; 17import { ChartMode } from '../../../../src/trace/bean/FrameChartStruct'; 18 19jest.mock('../../../../src/trace/component/SpSystemTrace', () => { 20 return {}; 21}); 22jest.mock('../../../../src/js-heap/model/DatabaseStruct', () => {}); 23 24jest.mock('../../../../src/trace/component/trace/base/TraceRow', () => { 25 return {}; 26}); 27 28 29const intersectionObserverMock = () => ({ 30 observe: () => null, 31}); 32window.IntersectionObserver = jest.fn().mockImplementation(intersectionObserverMock); 33 34window.ResizeObserver = 35 window.ResizeObserver || 36 jest.fn().mockImplementation(() => ({ 37 disconnect: jest.fn(), 38 observe: jest.fn(), 39 unobserve: jest.fn(), 40 })); 41 42jest.mock('../../../../src/trace/component/trace/base/TraceRow', () => { 43 return {}; 44}); 45 46describe('FrameChart Test', () => { 47 let node = [{ children: '' }, { children: { length: 0 } }]; 48 document.body.innerHTML = '<sp-application><tab-framechart id="ccc"></tab-framechart></sp-application>'; 49 let frameChart = new FrameChart(); 50 frameChart.data = [{ 51 isDraw : false, 52 depth: 0, 53 symbol: '', 54 lib: '', 55 size: 0, 56 count: 0, 57 dur: 0, 58 searchSize: 0, 59 searchCount: 0, 60 searchDur: 0, 61 drawSize: 0, 62 drawCount: 0, 63 drawDur: 0, 64 parent: undefined, 65 children: [], 66 percent: 0, 67 addr: '', 68 isSearch: false, 69 isChartSelect: false, 70 isChartSelectParent: false 71 }] 72 it('FrameChartTest01', function () { 73 frameChart.tabPaneScrollTop = false; 74 expect(frameChart.tabPaneScrollTop).toBeFalsy(); 75 }); 76 77 it('FrameChartTest02', function () { 78 frameChart.createRootNode(); 79 let index = frameChart.scale(2); 80 expect(index).toBe(undefined); 81 }); 82 83 it('FrameChartTest03', function () { 84 frameChart.translationDraw = jest.fn(() => true); 85 expect(frameChart.translation()).toBeUndefined(); 86 }); 87 88 it('FrameChartTest04', function () { 89 frameChart.translationDraw = jest.fn(() => true); 90 expect(frameChart.translation(-1)).toBeUndefined(); 91 }); 92 93 it('FrameChartTest05', function () { 94 frameChart.selectTotalCount = false; 95 expect(frameChart.selectTotalCount).toBeFalsy(); 96 }); 97 98 it('FrameChartTest06', function () { 99 frameChart._mode = 1; 100 frameChart.drawScale = jest.fn(() => true); 101 expect(frameChart.calculateChartData()).not.toBeUndefined(); 102 }); 103 104 it('FrameChartTest07', function () { 105 expect(frameChart.updateCanvas(true, 23)).toBeUndefined(); 106 }); 107 108 it('FrameChartTest08', function () { 109 frameChart.translationDraw = jest.fn(() => true); 110 expect(frameChart.translationByScale()).toBe(undefined); 111 }); 112 113 it('FrameChartTest09', function () { 114 frameChart.translationDraw = jest.fn(() => true); 115 frameChart.canvasX = 4; 116 expect(frameChart.translationByScale()).toBe(undefined); 117 }); 118 119 it('FrameChartTest10', function () { 120 frameChart.translationDraw = jest.fn(() => true); 121 expect(frameChart.translationByScale(1)).toBe(undefined); 122 }); 123 124 it('FrameChartTest11', function () { 125 frameChart.calculateChartData = jest.fn(() => true); 126 frameChart.xPoint = 1; 127 frameChart.createRootNode(); 128 expect(frameChart.translationDraw()).toBeTruthy(); 129 }); 130 131 it('FrameChartTest12', function () { 132 expect(frameChart.onMouseClick({ button: 0 })).toBeUndefined(); 133 }); 134 135 it('FrameChartTest13', function () { 136 expect(frameChart.drawFrameChart(node)).toBeUndefined(); 137 }); 138 139 140 it('FrameChartTest14', function () { 141 expect(frameChart.onMouseClick({ button: 2 })).toBeUndefined(); 142 }); 143 144 it('FrameChartTest15 ', function () { 145 expect(frameChart.mode).toBeUndefined(); 146 }); 147 148 it('FrameChartTest16', function () { 149 expect(frameChart.data).toBeFalsy(); 150 }); 151 152 it('FrameChartTest18', function () { 153 expect(frameChart.addChartClickListener(() => {})).toBeUndefined(); 154 }); 155 156 it('FrameChartTest19', function () { 157 expect(frameChart.removeChartClickListener(() => {})).toBeUndefined(); 158 }); 159 160 it('FrameChartTest20', function () { 161 expect(frameChart.resetTrans()).toBeUndefined(); 162 }); 163 164 it('FrameChartTest21', function () { 165 expect(frameChart.onMouseClick({ button: 2 })).toBeUndefined(); 166 }); 167 168 it('FrameChartTest22', function () { 169 frameChart._mode = ChartMode.Byte; 170 frameChart.currentData = [ 171 { 172 drawSize: 10, 173 size: 20, 174 frame: { 175 x: 10, 176 y: 40, 177 width: 9, 178 height: 3, 179 }, 180 }, 181 ]; 182 expect(frameChart.calculateChartData()).not.toBeUndefined(); 183 }); 184 it('FrameChartTest23', function () { 185 frameChart._mode = ChartMode.Count; 186 frameChart.currentData = [ 187 { 188 drawSize: 23, 189 size: 12, 190 frame: { 191 x: 29, 192 y: 40, 193 width: 56, 194 height: 3, 195 }, 196 }, 197 ]; 198 expect(frameChart.calculateChartData()).not.toBeUndefined(); 199 }); 200 it('FrameChartTest24', function () { 201 frameChart._mode = ChartMode.Duration; 202 frameChart.currentData = [ 203 { 204 drawSize: 78, 205 size: 12, 206 frame: { 207 x: 29, 208 y: 50, 209 width: 56, 210 height: 12, 211 }, 212 }, 213 ]; 214 expect(frameChart.calculateChartData()).not.toBeUndefined(); 215 }); 216 it('FrameChartTest25 ', function () { 217 let node = [ 218 { 219 parent: [ 220 { 221 drawCount: 23, 222 drawDur: 12, 223 drawSize: 45, 224 }, 225 ], 226 }, 227 ]; 228 let module = [{ 229 drawCount: 0, 230 drawDur: 78, 231 drawSize: 9, 232 }] 233 expect(frameChart.setParentDisplayInfo(node, module)).toBeUndefined(); 234 }); 235 236 it('FrameChartTest26 ', function () { 237 let module = [{ 238 drawCount: 0, 239 drawDur: 78, 240 drawSize: 9, 241 }]; 242 let nodeData = { 243 children: [{ 244 isChartSelect: false, 245 drawCount: 0, 246 drawEventCount: 0, 247 drawSize: 0, 248 drawDur: 0, 249 children: [] 250 },{ 251 isChartSelect: true, 252 drawCount: 0, 253 drawEventCount: 0, 254 drawSize: 0, 255 drawDur: 0, 256 children: [] 257 }] 258 } 259 frameChart.selectInit(); 260 frameChart.setRootValue(); 261 frameChart.clearOtherDisplayInfo(nodeData); 262 frameChart.setParentDisplayInfo(nodeData, module, true); 263 frameChart.setChildrenDisplayInfo(nodeData); 264 frameChart.searchDataByCoord([nodeData], 20, 10); 265 frameChart.showTip(); 266 frameChart.setSelectStatusRecursive(nodeData, true); 267 frameChart.clickRedraw(); 268 frameChart.scale(0); 269 frameChart.translationDraw(); 270 frameChart.nodeInCanvas(nodeData); 271 frameChart.nodeInCanvas({ 272 frame: { 273 x: 0, 274 y: 2, 275 width: 20, 276 height: 30 277 } 278 }); 279 frameChart.onMouseClick({ 280 button: 0 281 }); 282 frameChart.updateTipContent(); 283 frameChart.getCurrentPercent(nodeData, true); 284 frameChart.getCurrentPercentOfThread(nodeData); 285 frameChart.resizeChange(); 286 expect(frameChart.getCurrentPercentOfProcess(nodeData)).toBe(''); 287 }); 288}); 289