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 */
15import { TraceRow } from '../../../../src/trace/component/trace/base/TraceRow';
16jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorker', () => {
17  return {};
18});
19import {
20  CpuFreqExtendStruct,
21  FreqExtendRender
22} from '../../../../src/trace/database/ui-worker/ProcedureWorkerFreqExtend';
23import { SpSegmentationChart } from '../../../../src/trace/component/chart/SpSegmentationChart';
24jest.mock('../../../../src/trace/database/ui-worker/cpu/ProcedureWorkerCPU', () => {
25  return {};
26});
27jest.mock('../../../../src/trace/component/SpSystemTrace', () => {
28  return {};
29});
30describe('ProcedureWorkerFreqExtend Test',()=>{
31  SpSegmentationChart.trace = jest.fn();
32  SpSegmentationChart.trace.traceSheetEL = jest.fn();
33  SpSegmentationChart.trace.traceSheetEL.systemLogFlag = jest.fn();
34
35  it('ProcedureWorkerFreqExtendTest01 ', function () {
36    const data = {
37      frame: {
38        x: 20,
39        y: 19,
40        width: 10,
41        height: 3,
42      },
43      dur: 1,
44      value: 'aa',
45      startTs: 12,
46      pid: 2,
47      process: 'null',
48      itid: 12,
49      endItid: 13,
50      tid: 3,
51      startName: '23',
52      stepName: 'st',
53    };
54    const canvas = document.createElement('canvas');
55    canvas.width = 1;
56    canvas.height = 1;
57    const ctx = canvas.getContext('2d');
58    expect(CpuFreqExtendStruct.draw(ctx,data)).toBeUndefined()
59  });
60  it('ProcedureWorkerFreqExtendTest02 ', function () {
61    let freqExtendRender = new FreqExtendRender();
62    let freqReq = {
63      lazyRefresh: true,
64      type: '',
65      startNS: 5,
66      endNS: 9,
67      totalNS: 4,
68      frame: {
69        x: 32,
70        y: 20,
71        width: 180,
72        height: 180,
73      },
74      useCache: true,
75      range: {
76        refresh: '',
77      },
78      canvas: 'a',
79      context: {
80        font: '12px sans-serif',
81        fillStyle: '#a1697d',
82        globalAlpha: 0.3,
83        measureText: jest.fn(() => true),
84        clearRect: jest.fn(() => true),
85        stroke: jest.fn(() => true),
86        closePath: jest.fn(() => false),
87        beginPath: jest.fn(() => true),
88        fillRect: jest.fn(() => false),
89        fillText: jest.fn(() => true),
90      },
91      lineColor: '',
92      isHover: 'true',
93      hoverX: 0,
94      params: '',
95      wakeupBean: undefined,
96      flagMoveInfo: '',
97      flagSelectedInfo: '',
98      slicesTime: 4,
99      id: 1,
100      x: 24,
101      y: 24,
102      width: 100,
103      height: 100,
104    };
105    window.postMessage = jest.fn(() => true);
106    expect(freqExtendRender.renderMainThread(freqReq, new TraceRow<CpuFreqExtendStruct>()))
107  });
108})
109