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