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 { FrameChart } from '../../../../dist/trace/component/chart/FrameChart.js'; 18// @ts-ignore 19import {TraceRow} from '../../../../dist/trace/component/trace/base/TraceRow.js'; 20// @ts-ignore 21import {ChartMode} from "../../../../dist/trace/bean/FrameChartStruct.js"; 22 23jest.mock('../../../../dist/trace/component/SpSystemTrace.js', () => { 24 return {}; 25}); 26jest.mock('../../../../dist/js-heap/model/DatabaseStruct.js', () => {}); 27 28const intersectionObserverMock = () => ({ 29 observe: () => null, 30}); 31window.IntersectionObserver = jest.fn().mockImplementation(intersectionObserverMock); 32 33window.ResizeObserver = 34 window.ResizeObserver || 35 jest.fn().mockImplementation(() => ({ 36 disconnect: jest.fn(), 37 observe: jest.fn(), 38 unobserve: jest.fn(), 39 })); 40 41jest.mock('../../../../dist/trace/component/trace/base/TraceRow.js', () => { 42 return {} 43}); 44 45describe('FrameChart Test', () => { 46 let node = [{ children: '' }, { children: { length: 0 } }]; 47 let node1 = [{ children: '' }, { children: { length: 10 } }]; 48 let selectData = [(length = 1)]; 49 document.body.innerHTML = '<tab-framechart id="ccc"></tab-framechart>'; 50 let frameChart = document.querySelector('#ccc') as FrameChart; 51 it('FrameChartTest01', function () { 52 frameChart.tabPaneScrollTop = false; 53 expect(frameChart.tabPaneScrollTop).toBeFalsy(); 54 }); 55 56 it('FrameChartTest02', function () { 57 expect(frameChart.updateFloatHint()).toBeUndefined(); 58 }); 59 60 it('FrameChartTest03', function () { 61 frameChart.calculateChartData = jest.fn(() => true); 62 frameChart.calMaxDepth = jest.fn(() => true); 63 expect(frameChart.redrawChart(selectData)).toBeUndefined(); 64 }); 65 66 it('FrameChartTest05', function () { 67 let index = frameChart.scale(2); 68 expect(index).toBe(undefined); 69 }); 70 71 it('FrameChartTest08', function () { 72 frameChart.translationDraw = jest.fn(() => true); 73 expect(frameChart.translation()).toBeUndefined(); 74 }); 75 76 it('FrameChartTest14', function () { 77 let frameChart = new FrameChart(); 78 frameChart.translationDraw = jest.fn(() => true); 79 expect(frameChart.translation(-1)).toBeUndefined(); 80 }); 81 82 it('FrameChartTest09', function () { 83 frameChart.selectTotalCount = false; 84 expect(frameChart.selectTotalCount).toBeFalsy(); 85 }); 86 87 it('FrameChartTest11', function () { 88 let frameChart = new FrameChart(); 89 frameChart._mode = 1; 90 frameChart.drawScale = jest.fn(() => true); 91 expect(frameChart.calculateChartData()).not.toBeUndefined(); 92 }); 93 94 it('FrameChartTest12', function () { 95 expect(frameChart.updateCanvas()).toBeUndefined(); 96 }); 97 98 it('FrameChartTest13', function () { 99 let frameChart = new FrameChart(); 100 frameChart.translationDraw = jest.fn(() => true); 101 frameChart.lastCanvasXInScale = 0; 102 expect(frameChart.translationByScale()).toBe(undefined); 103 }); 104 105 it('FrameChartTest21', function () { 106 let frameChart = new FrameChart(); 107 frameChart.translationDraw = jest.fn(() => true); 108 frameChart.canvasX = 4; 109 frameChart.lastCanvasXInScale = 1; 110 expect(frameChart.translationByScale()).toBe(undefined); 111 }); 112 113 it('FrameChartTest22', function () { 114 let frameChart = new FrameChart(); 115 frameChart.translationDraw = jest.fn(() => true); 116 expect(frameChart.translationByScale(1)).toBe(undefined); 117 }); 118 it('FrameChartTest23', function () { 119 expect(frameChart.searchData([], 2, 2)).toBeNull(); 120 }); 121 122 it('FrameChartTest15', function () { 123 let frameChart = new FrameChart(); 124 frameChart.calculateChartData = jest.fn(() => true); 125 frameChart.xPoint = 1; 126 expect(frameChart.translationDraw()).toBe(undefined); 127 }); 128 129 it('FrameChartTest16', function () { 130 expect(frameChart.onMouseClick({ button: 0 })).toBeUndefined(); 131 }); 132 133 134 it('FrameChartTest18', function () { 135 let frameChart = new FrameChart(); 136 expect(frameChart.drawFrameChart(node)).toBeUndefined(); 137 }); 138 139 it('FrameChartTest20', function () { 140 expect(frameChart.searchData([], 1, 1)).toBeNull(); 141 }); 142 143 it('FrameChartTest23', function () { 144 expect(frameChart.onMouseClick({ button: 2 })).toBeUndefined(); 145 }); 146 147 it('FrameChartTest24', function () { 148 document.body.innerHTML = `<sp-application></sp-application>`; 149 expect(frameChart.drawScale()).toBeUndefined(); 150 }); 151 152 it('FrameChartTest25', function () { 153 let frameChart = new FrameChart(); 154 frameChart.selectTotalSize = false; 155 expect(frameChart.selectTotalSize).toBeFalsy(); 156 }); 157 158 it('FrameChartTest26', function () { 159 let frameChart = new FrameChart(); 160 frameChart.maxDepth = false; 161 expect(frameChart.maxDepth).toBeFalsy(); 162 }); 163 164 it('FrameChartTest27 ', function () { 165 let frameChart = new FrameChart(); 166 expect(frameChart.calMaxDepth(node, 1)).toBeUndefined(); 167 }); 168 169 it('FrameChartTest28 ', function () { 170 let frameChart = new FrameChart(); 171 expect(frameChart.mode).toBeUndefined(); 172 }); 173 174 it('FrameChartTest29', function () { 175 let frameChart = new FrameChart(); 176 frameChart.mode = false; 177 expect(frameChart.mode).toBeFalsy(); 178 }); 179 180 it('FrameChartTest30', function () { 181 frameChart.caldrawArgs = jest.fn(() => true); 182 expect(frameChart.caldrawArgs()).toBeTruthy(); 183 }); 184 185 it('FrameChartTest31', function () { 186 let frameChart = new FrameChart(); 187 frameChart.data = []; 188 expect(frameChart.data).toBeFalsy(); 189 }); 190 191 it('FrameChartTest32', function () { 192 let frameChart = new FrameChart(); 193 expect(frameChart.addChartClickListener(() => {})).toBeUndefined(); 194 }); 195 196 it('FrameChartTest33', function () { 197 let frameChart = new FrameChart(); 198 expect(frameChart.removeChartClickListener(() => {})).toBeUndefined(); 199 }); 200 201 it('FrameChartTest34', function () { 202 let frameChart = new FrameChart(); 203 expect(frameChart.calMaxDepth(node1, 10)).toBeUndefined(); 204 }); 205 206 it('FrameChartTest35', function () { 207 let frameChart = new FrameChart(); 208 frameChart.drawTriangleOnScale = jest.fn(() => true); 209 expect(frameChart.drawTriangleOnScale()).toBeTruthy(); 210 }); 211 212 it('FrameChartTest36', function () { 213 frameChart._mode = 1; 214 frameChart.drawScale = jest.fn(() => true); 215 expect(frameChart.drawScale()).toBeTruthy(); 216 }); 217 218 it('FrameChartTest37', function () { 219 frameChart._mode = 2; 220 frameChart.drawScale = jest.fn(() => true); 221 expect(frameChart.drawScale()).toBeTruthy(); 222 }); 223 224 it('FrameChartTest38', function () { 225 frameChart._mode = 3; 226 frameChart.drawScale = jest.fn(() => true); 227 expect(frameChart.drawScale()).toBeTruthy(); 228 }); 229 230 it('FrameChartTest39', function () { 231 expect(frameChart.resetTrans()).toBeUndefined(); 232 }); 233 234 it('FrameChartTest40', function () { 235 expect(frameChart.onMouseClick({ button: 2 })).toBeUndefined(); 236 }); 237 238 it('FrameChartTest41', function () { 239 expect(frameChart.drawDataSet(node, true)).toBeUndefined(); 240 }); 241 it('FrameChartTest42', function () { 242 let frameChart = new FrameChart(); 243 frameChart._mode = ChartMode.Byte; 244 frameChart.drawScale = jest.fn(() => true); 245 expect(frameChart.calculateChartData()).not.toBeUndefined(); 246 }); 247 it('FrameChartTest44', function () { 248 let frameChart = new FrameChart(); 249 frameChart._mode = ChartMode.Count; 250 frameChart.drawScale = jest.fn(() => true); 251 expect(frameChart.calculateChartData()).not.toBeUndefined(); 252 }); 253 it('FrameChartTest45', function () { 254 let frameChart = new FrameChart(); 255 frameChart._mode = ChartMode.Duration; 256 frameChart.drawScale = jest.fn(() => true); 257 expect(frameChart.calculateChartData()).not.toBeUndefined(); 258 }); 259}); 260