• 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 {state,EnergyStateStruct,EnergyStateRender} from "../../../../dist/trace/database/ui-worker/ProcedureWorkerEnergyState.js"
18
19describe('ProcedureWorkerEnergyState Test', () => {
20
21    it('ProcedureWorkerEnergyStateTest01', function () {
22        let frame = {
23                x: 20,
24                y: 20,
25                width: 100,
26                height: 100
27        }
28        let dataList = new Array();
29        dataList.push({startNS: 0, dur: 10,length:1, frame: {x:0, y:9, width:10, height:10}})
30        dataList.push({startNS: 1, dur: 2,length:1})
31        state(dataList, [{length:1}],1,3,2, frame,true)
32    });
33
34    it('ProcedureWorkerEnergyStateTest02', function () {
35        let frame = {
36            x: 20,
37            y: 20,
38            width: 100,
39            height: 100
40        }
41        let dataList = new Array();
42        dataList.push({startNS: 0, dur: 10,length:1, frame: {x:0, y:9, width:10, height:10}})
43        dataList.push({startNS: 1, dur: 2,length:1})
44        state(dataList, [{length:0}],1,3,2, frame,false)
45    });
46
47    it('ProcedureWorkerEnergyStateTest03', function () {
48        const canvas = document.createElement('canvas');
49        canvas.width = 1;
50        canvas.height = 1;
51        const ctx = canvas.getContext('2d');
52
53        const data = {
54            type :"",
55            value: 0,
56            startNs: 1,
57            frame: {
58                x: 20,
59                y: 20,
60                width: 100,
61                height: 100
62            }
63        }
64        expect(EnergyStateStruct.draw(ctx , data)).toBeUndefined()
65    });
66
67    it('ProcedureWorkerEnergyStateTest04', function () {
68        expect(EnergyStateStruct.setDrawColor('BRIGHTNESS_NIT')).toBe("#92D6CC")
69    });
70
71    it('ProcedureWorkerEnergyStateTest05', function () {
72        expect(EnergyStateStruct.setDrawColor('SIGNAL_LEVEL')).toBe("#61CFBE")
73    });
74
75    it('ProcedureWorkerEnergyStateTest06', function () {
76        expect(EnergyStateStruct.setDrawColor('WIFI_EVENT_RECEIVED')).toBe("#46B1E3")
77    });
78
79    it('ProcedureWorkerEnergyStateTest07', function () {
80        expect(EnergyStateStruct.setDrawColor('AUDIO_STREAM_CHANGE')).toBe("#ED6F21")
81    });
82
83    it('ProcedureWorkerEnergyStateTest08', function () {
84        expect(EnergyStateStruct.setDrawColor('WIFI_STATE')).toBe("#61CFBE")
85    });
86
87    it('ProcedureWorkerEnergyStateTest09', function () {
88        expect(EnergyStateStruct.setDrawColor('LOCATION_SWITCH_STATE')).toBe("#61CFBE")
89    });
90
91    it('ProcedureWorkerEnergyStateTest10', function () {
92        expect(EnergyStateStruct.setDrawColor('SENSOR_STATE')).toBe("#61CFBE")
93    });
94
95    it('ProcedureWorkerEnergyStateTest11', function () {
96        expect(EnergyStateStruct.setDrawColor('aaaa')).toBe("#61CFBE")
97    });
98
99    it('ProcedureWorkerEnergyStateTest12', function () {
100        let energyStateRender = new EnergyStateRender()
101        let  req = {
102            lazyRefresh:true,
103            type:"",
104            startNS:1,
105            endNS:1,
106            totalNS:1,
107            frame: {
108                x: 20,
109                y: 20,
110                width: 100,
111                height: 100
112            },
113            useCache:false,
114            range:{
115                refresh:"",
116            },
117            canvas:'',
118            context:{
119                font:"11px sans-serif",
120                fillStyle:"#ec407a",
121                globalAlpha:0.6,
122                height:150,
123                width:100
124            },
125            lineColor:'',
126            isHover:'',
127            hoverX:1,
128            wakeupBean:undefined,
129            flagMoveInfo:'',
130            flagSelectedInfo:'',
131            slicesTime:3,
132            id:1,
133            x: 20,
134            y: 20,
135            width: 100,
136            height: 100,
137            params:{
138                isLive:false,
139                maxHeight:2,
140                dpr:1,
141                hoverFuncStruct:'',
142                selectFuncStruct:undefined,
143            },
144        }
145        window.postMessage = jest.fn(()=>true)
146        expect(energyStateRender.render(req,[{}],[])).toBeUndefined()
147    });
148
149})