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