• 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 { TraceRow } from '../../../../src/trace/component/trace/base/TraceRow';
17import { Rect } from '../../../../src/trace/database/ui-worker/ProcedureWorkerCommon';
18import {
19  XpowerAppDetailRender,
20  XpowerAppDetailStruct,
21  drawLegend,
22} from '../../../../src/trace/database/ui-worker/ProcedureWorkerXpowerAppDetail';
23jest.mock('../../../../src/js-heap/model/DatabaseStruct', () => {
24  return {};
25});
26jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorkerSnapshot', () => {
27  return {};
28});
29jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorker', () => {
30  return {};
31});
32jest
33  .spyOn(require('../../../../src/trace/database/ui-worker/ProcedureWorkerCommon'), 'isFrameContainPoint')
34  .mockReturnValue(true);
35
36describe('XpowerAppDetailTest', () => {
37  TraceRow.range = {
38    startNS: 0,
39    endNS: 1000000,
40    totalNS: 1000000,
41  };
42  let mockRow = new TraceRow();
43  mockRow = TraceRow.skeleton<XpowerAppDetailStruct>();
44  mockRow.rowId = 'AppDetailDisplay';
45  mockRow.rowType = TraceRow.ROW_TYPE_XPOWER_APP_DETAIL_DISPLAY;
46  let context: CanvasRenderingContext2D;
47  let checked: boolean[];
48  let checkedValue: string[];
49  checked = [true, false, true];
50  checkedValue = ['C1HZ', 'C5HZ', 'C10HZ'];
51  context = {
52    save: jest.fn(),
53    translate: jest.fn(),
54    rect: jest.fn(),
55    clip: jest.fn(),
56    strokeStyle: '#000000',
57    strokeRect: jest.fn(),
58    fillRect: jest.fn(),
59    fillText: jest.fn(),
60    measureText: jest.fn().mockReturnValue({ width: 10 }),
61    beginPath: jest.fn(),
62    closePath: jest.fn(),
63    stroke: jest.fn(),
64    clearRect: jest.fn(),
65    fill: jest.fn(),
66    fillStyle: '#000000',
67    globalAlpha: 1,
68    font: '10px sans-serif',
69    canvas: {
70      clientWidth: 800,
71    },
72  } as unknown as CanvasRenderingContext2D;
73
74  mockRow.dataListCache = [
75    {
76      startTime: 1000,
77      c1hz: 10,
78      c5hz: 20,
79      c10hz: 30,
80      c15hz: 40,
81      c24hz: 50,
82      c30hz: 60,
83      c45hz: 70,
84      c60hz: 80,
85      c90hz: 90,
86      c120hz: 100,
87      c180hz: 110,
88      frame: new Rect(0, 0, 100, 100),
89    },
90  ];
91  mockRow.rowSettingCheckBoxList = [
92    'C1HZ',
93    'C5HZ',
94    'C10HZ',
95    'C15HZ',
96    'C24HZ',
97    'C30HZ',
98    'C45HZ',
99    'C60HZ',
100    'C90HZ',
101    'C120HZ',
102    'C180HZ',
103  ];
104  mockRow.addRowSettingCheckBox();
105  mockRow.frame = new Rect(0, 0, 500, 500);
106  mockRow.hoverX = 500;
107  mockRow.hoverY = 100;
108  mockRow.isHover = true;
109
110  TraceRow.range = {
111    startNS: 0,
112    endNS: 1000000000,
113    totalNS: 1000000000,
114  };
115
116  it('XpowerAppDetailTest01', () => {
117    let checked = new Array(11).fill(true);
118    const checkedValue = mockRow.rowSettingCheckBoxList;
119    drawLegend({ context: context, useCache: false }, checked, checkedValue!);
120
121    expect(context.fillRect).toHaveBeenCalled();
122    expect(context.fillText).toHaveBeenCalled();
123  });
124
125  it('XpowerAppDetailTest02', () => {
126    drawLegend({ context, useCache: false }, checked, checkedValue);
127
128    expect(context.fillRect).toHaveBeenCalled();
129    expect(context.fillText).toHaveBeenCalled();
130  });
131
132  it('XpowerAppDetailTest03', () => {
133    drawLegend({ context, useCache: false }, checked, checkedValue, true);
134
135    expect(context.fillStyle).toBe('#333');
136  });
137
138  it('XpowerAppDetailTest04', () => {
139    checked = [true];
140    checkedValue = ['C1HZ'];
141    drawLegend({ context, useCache: false }, checked, checkedValue);
142
143    expect(context.fillRect).toHaveBeenCalled();
144    expect(context.fillText).toHaveBeenCalled();
145  });
146
147  it('XpowerAppDetailTest05', () => {
148    XpowerAppDetailStruct.draw({ context, useCache: false }, mockRow.dataListCache[0], mockRow, false);
149    expect(context.globalAlpha).toEqual(0.8);
150    expect(context.lineWidth).toEqual(1);
151    expect(
152      XpowerAppDetailStruct.drawHistogram(
153        { context, useCache: false },
154        mockRow.dataListCache[0],
155        -1,
156        10,
157        0,
158        mockRow.frame
159      )
160    ).not.toBeUndefined();
161    expect(
162      XpowerAppDetailStruct.drawHistogram(
163        { context, useCache: false },
164        mockRow.dataListCache[0],
165        -1,
166        10,
167        5,
168        mockRow.frame
169      )
170    ).not.toBeUndefined();
171  });
172
173  it('XpowerAppDetailTest06', () => {
174    expect(
175      XpowerAppDetailStruct.setHoverHtml(mockRow.dataListCache[0], mockRow.rowSettingCheckBoxList)
176    ).toBeUndefined();
177  });
178
179  it('XpowerAppDetailTest07', () => {
180    XpowerAppDetailStruct.hoverXpowerStruct = mockRow.dataListCache[0];
181    XpowerAppDetailStruct.draw({ context, useCache: false }, mockRow.dataListCache[0], mockRow, true);
182    expect(context.strokeStyle).toEqual('#9899a0');
183  });
184
185  it('XpowerAppDetailTest08', () => {
186    expect(
187      XpowerAppDetailStruct.setXPowerAppDetailFrame(
188        mockRow.dataListCache[0],
189        5,
190        TraceRow.range?.startNS ?? 0,
191        TraceRow.range?.endNS ?? 0,
192        TraceRow.range?.totalNS ?? 0,
193        mockRow.frame
194      )
195    ).toBeUndefined();
196  });
197
198  it('XpowerAppDetailTest09', () => {
199    let data = new XpowerAppDetailStruct();
200    data.c1hz = 10;
201    expect(data.c1hz).toEqual(10);
202  });
203
204  it('XpowerAppDetailTest10', () => {
205    const render = new XpowerAppDetailRender();
206    render.renderMainThread({ context, useCache: false }, mockRow);
207    expect(XpowerAppDetailStruct.hoverXpowerStruct).toBeDefined();
208    expect(XpowerAppDetailStruct.hoverXpowerStruct!.startTime).toBe(1000);
209  });
210});
211