• 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
16// @ts-ignore
17import {SdkCounterRender,CounterStruct} from "../../../../dist/trace/database/ui-worker/ProduceWorkerSdkCounter.js"
18
19describe('ProduceWorkerSdkCounter Test', () => {
20
21    it('ProduceWorkerSdkCounterTest01', function () {
22        let sdkCounterRender = new SdkCounterRender()
23        let List = [{
24            length:1,
25            ts:1,
26            frame:{
27                x: 20,
28                y: 20,
29                width: 100,
30                height: 100
31            },
32        }]
33        let arr = [{
34            frame:null,
35            length:1,
36        }]
37        let frame = {
38            x: 20,
39            y: 20,
40            width: 100,
41            height: 100
42        }
43        expect(sdkCounterRender.counter(List, arr, 1, 1, 1, frame, true)).toBeUndefined()
44    });
45
46    it('ProduceWorkerSdkCounterTest02', function () {
47        let sdkCounterRender = new SdkCounterRender()
48        let List = [{
49            length:1,
50            ts:1,
51            frame:{
52                x: 20,
53                y: 20,
54                width: 100,
55                height: 100
56            },
57        }]
58        let arr = [{
59            frame:null,
60            length:0,
61        }]
62        let frame = {
63            x: 20,
64            y: 20,
65            width: 100,
66            height: 100
67        }
68        expect(sdkCounterRender.counter(List, arr, 1, 1, 1, frame, false)).toBeUndefined()
69    });
70
71    it('ProduceWorkerSdkCounterTest03',()=>{
72        const data = {
73            startNs:1,
74            value:1,
75            frame:{
76                x: 20,
77                y: 20,
78                width: 100,
79                height: 100
80            },
81            startTime:1,
82            ts:1
83        }
84        const canvas = document.createElement('canvas');
85        canvas.width = 1;
86        canvas.height = 1;
87        const ctx = canvas.getContext('2d');
88        expect(CounterStruct.draw(ctx,data,1)).toBeUndefined();
89    });
90
91    it('ProduceWorkerSdkCounterTest04',()=>{
92        let node = {
93            startNs:1,
94            value:1,
95            frame:{
96                x: 20,
97                y: 20,
98                width: 100,
99                height: 100
100            },
101            ts:1,
102            dur:1
103        }
104        let frame = {
105            x: 20,
106            y: 20,
107            width: 100,
108            height: 100
109        }
110        expect(CounterStruct.setCounterFrame(node,2,1,2,2,frame)).toBeUndefined();
111    });
112
113    it('ProduceWorkerSdkCounterTest05',()=>{
114        let node = {
115            startNs:1,
116            value:1,
117            frame:{
118                x: 20,
119                y: 20,
120                width: 100,
121                height: 100
122            },
123            ts:0,
124            dur:3
125        }
126        let frame = {
127            x: 20,
128            y: 20,
129            width: 100,
130            height: 100
131        }
132        expect(CounterStruct.setCounterFrame(node,2,1,2,2,frame)).toBeUndefined();
133    });
134
135    it('ProduceWorkerSdkCounterTest06', function () {
136        let sdkCounterRender = new SdkCounterRender()
137        let  req = {
138            lazyRefresh:true,
139            type:"",
140            startNS:1,
141            endNS:1,
142            totalNS:1,
143            frame: {
144                x: 20,
145                y: 20,
146                width: 100,
147                height: 100
148            },
149            useCache:false,
150            range:{
151                refresh:"",
152            },
153            canvas:'',
154            context:{
155                font:"11px sans-serif",
156                fillStyle:"#ec407a",
157                globalAlpha:0.6,
158            },
159            lineColor:'',
160            isHover:'',
161            hoverX:1,
162            params:'',
163            wakeupBean:undefined,
164            flagMoveInfo:'',
165            flagSelectedInfo:'',
166            slicesTime:3,
167            id:1,
168            x: 20,
169            y: 20,
170            width: 100,
171            height: 100
172        }
173        window.postMessage = jest.fn(()=>true)
174        expect(sdkCounterRender.render(req,[],[])).toBeUndefined()
175    });
176})