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
16jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorker', () => {
17  return {};
18});
19
20import { FrameAnimationRender } from '../../../../src/trace/database/ui-worker/ProcedureWorkerFrameAnimation';
21import { Rect } from '../../../../src/trace/component/trace/timer-shaft/Rect';
22import { TraceRow } from '../../../../src/trace/component/trace/base/TraceRow';
23import { FrameAnimationStruct } from '../../../../src/trace/database/ui-worker/ProcedureWorkerFrameAnimation';
24
25jest.mock('../../../../src/trace/component/SpSystemTrace', () => {
26  return {};
27});
28describe('FrameAnimation Test', () => {
29  let frameAnimationRender = new FrameAnimationRender();
30  let rect = new Rect(341, 2, 10, 10);
31  let canvas = document.createElement('canvas');
32  canvas.width = 1;
33  canvas.height = 1;
34  let ctx = canvas.getContext('2d');
35  let dataList = [
36    {
37      animationId: 1,
38      dur: 0,
39      dynamicEndTs: 4774481414,
40      dynamicStartTs: 4091445476,
41      frame: rect,
42      status: 'Response delay',
43      textMetricsWidth: 115.44140625,
44      ts: 4091445476,
45    },
46    {
47      animationId: 1,
48      dur: 683035938,
49      dynamicEndTs: 4774481414,
50      dynamicStartTs: 4091445476,
51      frame: rect,
52      status: 'Completion delay',
53      textMetricsWidth: 133.0703125,
54      ts: 4091445476,
55    },
56  ];
57  TraceRow.range = {
58    startNS: 0,
59    endNS: 16868000000,
60    totalNS: 16868000000,
61  };
62
63  it('FrameAnimationTest01', function () {
64    frameAnimationRender.frameAnimation(
65      dataList,
66      [],
67      TraceRow.range.startNS,
68      TraceRow.range.endNS,
69      TraceRow.range.totalNS,
70      TraceRow.skeleton(),
71      false
72    );
73    let node = {
74      animationId: 1,
75      dur: 0,
76      dynamicEndTs: 4774481414,
77      dynamicStartTs: 4091445476,
78      frame: rect,
79      status: 'Response delay',
80      textMetricsWidth: 115.44140625,
81      ts: 4091445476,
82    };
83    expect(FrameAnimationStruct.draw(ctx!, 1, node, TraceRow.skeleton())).toBeUndefined();
84  });
85  it('FrameAnimationTest02 ', function () {
86    let frameAnimationRender = new FrameAnimationRender();
87    let frameAnimationReq = {
88      lazyRefresh: true,
89      type: '',
90      startNS: 5,
91      endNS: 9,
92      totalNS: 4,
93      frame: {
94        x: 32,
95        y: 20,
96        width: 180,
97        height: 180,
98      },
99      useCache: true,
100      range: {
101        refresh: '',
102      },
103      canvas: 'a',
104      context: {
105        font: '12px sans-serif',
106        fillStyle: '#a1697d',
107        globalAlpha: 0.3,
108        measureText: jest.fn(() => true),
109        clearRect: jest.fn(() => true),
110        stroke: jest.fn(() => true),
111        closePath: jest.fn(() => false),
112        beginPath: jest.fn(() => true),
113        fillRect: jest.fn(() => false),
114        fillText: jest.fn(() => true),
115      },
116      lineColor: '',
117      isHover: 'true',
118      hoverX: 0,
119      params: '',
120      wakeupBean: undefined,
121      flagMoveInfo: '',
122      flagSelectedInfo: '',
123      slicesTime: 4,
124      id: 1,
125      x: 24,
126      y: 24,
127      width: 100,
128      height: 100,
129    }
130    window.postMessage = jest.fn(() => true);
131    expect(frameAnimationRender.renderMainThread(frameAnimationReq,new TraceRow<FrameAnimationStruct>())).toBeUndefined()
132  });
133});
134