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