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('../../../../dist/trace/component/trace/base/TraceRow.js', () => { 17 return {}; 18}); 19 20// @ts-ignore 21import { TimerShaftElement, ns2s, ns2x } from '../../../../dist/trace/component/trace/TimerShaftElement.js'; 22// @ts-ignore 23import { Rect } from '../../../../dist/trace/database/ui-worker/ProcedureWorkerCommon'; 24 25// @ts-ignore 26import { EventCenter } from '../../../../dist/trace/component/trace/base/EventCenter.js'; 27 28jest.mock('../../../../dist/trace/database/ui-worker/ProcedureWorker.js', () => { 29 return {}; 30}); 31 32declare global { 33 interface Window { 34 SmartEvent: { 35 UI: { 36 RefreshCanvas: string; //selected menu trace 37 MenuTrace: string; //selected menu trace 38 TimeRange: string; //Set the timeline range 39 SliceMark: string; //Set the tag scope 40 TraceRowComplete: string; //Triggered after the row component has finished loading data 41 }; 42 }; 43 subscribe(evt: string, fn: (b: any) => void): void; 44 unsubscribe(evt: string, fn: (b: any) => void): void; 45 subscribeOnce(evt: string, fn: (b: any) => void): void; 46 publish(evt: string, data: any): void; 47 clearTraceRowComplete(): void; 48 } 49} 50 51window.SmartEvent = { 52 UI: { 53 RefreshCanvas: 'SmartEvent-UI-RefreshCanvas', 54 SliceMark: 'SmartEvent-UI-SliceMark', 55 TraceRowComplete: 'SmartEvent-UI-TraceRowComplete', 56 TimeRange: 'SmartEvent-UI-TimeRange', 57 MenuTrace: 'SmartEvent-UI-MenuTrace', 58 }, 59}; 60 61Window.prototype.subscribe = (ev, fn) => EventCenter.subscribe(ev, fn); 62Window.prototype.unsubscribe = (ev, fn) => EventCenter.unsubscribe(ev, fn); 63Window.prototype.publish = (ev, data) => EventCenter.publish(ev, data); 64Window.prototype.subscribeOnce = (ev, data) => EventCenter.subscribeOnce(ev, data); 65Window.prototype.clearTraceRowComplete = () => EventCenter.clearTraceRowComplete(); 66 67describe('TimerShaftElement Test', () => { 68 document.body.innerHTML = '<timer-shaft-element id="timerShaftEL"><timer-shaft-element>'; 69 let timerShaftElement = document.querySelector('#timerShaftEL') as TimerShaftElement; 70 timerShaftElement.totalNS = 1000; 71 timerShaftElement.startNS = 1000; 72 timerShaftElement.endNS = 2000; 73 74 timerShaftElement.cpuUsage = 'cpuUsage'; 75 76 it('TimerShaftElementTest01', function () { 77 timerShaftElement.rangeRuler = jest.fn(() => true); 78 timerShaftElement.rangeRuler.cpuUsage = jest.fn(() => true); 79 expect(timerShaftElement.cpuUsage).toBeUndefined(); 80 }); 81 82 it('TimerShaftElementTest03', function () { 83 timerShaftElement.timeRuler = jest.fn(() => false); 84 timerShaftElement.rangeRuler = jest.fn(() => false); 85 timerShaftElement.rangeRuler.getScale = jest.fn(() => true); 86 timerShaftElement.timeRuler.frame = jest.fn(() => { 87 return document.createElement('canvas') as HTMLCanvasElement; 88 }); 89 timerShaftElement.rangeRuler.frame = jest.fn(() => { 90 return document.createElement('canvas') as HTMLCanvasElement; 91 }); 92 expect(timerShaftElement.connectedCallback()).toBeUndefined(); 93 }); 94 95 it('TimerShaftElementTest05', function () { 96 expect(timerShaftElement.disconnectedCallback()).toBeUndefined(); 97 }); 98 99 it('TimerShaftElementTest06', function () { 100 expect(timerShaftElement.totalNS).toBe(1000); 101 }); 102 103 it('TimerShaftElementTest08', function () { 104 timerShaftElement.startNS = 'startNS'; 105 expect(timerShaftElement.startNS).toBe('startNS'); 106 }); 107 108 it('TimerShaftElementTest09', function () { 109 timerShaftElement.endNS = 'endNS'; 110 expect(timerShaftElement.endNS).toBe('endNS'); 111 }); 112 113 it('TimerShaftElementTest14', function () { 114 expect(ns2s(1_000_0000)).toBe('10.0 ms'); 115 }); 116 117 it('TimerShaftElementTest16', function () { 118 expect(ns2s(1)).toBe('1.0 ns'); 119 }); 120 121 it('TimerShaftElementTest17', function () { 122 expect(ns2s(1_000)).toBe('1.0 μs'); 123 }); 124 125 it('TimerShaftElementTest18', function () { 126 expect(ns2x(1, 3, 4, 4, { width: 1 })).toBe(0); 127 }); 128 129 it('TimerShaftElementTest19', function () { 130 expect(timerShaftElement.sportRuler).not.toBeUndefined(); 131 }); 132 133 it('TimerShaftElementTest20', function () { 134 expect(timerShaftElement.isScaling()).toBeFalsy(); 135 }); 136 137 it('TimerShaftElementTest21', function () { 138 timerShaftElement.rangeRuler = jest.fn(() => undefined); 139 timerShaftElement.rangeRuler.setRangeNS = jest.fn(() => true); 140 expect(timerShaftElement.setRangeNS()).toBeFalsy(); 141 }); 142 143 it('TimerShaftElementTest22', function () { 144 timerShaftElement.rangeRuler = jest.fn(() => undefined); 145 timerShaftElement.rangeRuler.getRange = jest.fn(() => true); 146 expect(timerShaftElement.getRange()).toBeTruthy(); 147 }); 148 149 it('TimerShaftElementTest23', function () { 150 timerShaftElement.rangeRuler = jest.fn(() => undefined); 151 timerShaftElement.rangeRuler.frame = jest.fn(() => Rect); 152 timerShaftElement.rangeRuler.frame.width = jest.fn(() => 1); 153 timerShaftElement._sportRuler = jest.fn(() => undefined); 154 timerShaftElement._sportRuler.frame = jest.fn(() => Rect); 155 timerShaftElement._sportRuler.frame.width = jest.fn(() => 1); 156 timerShaftElement.timeRuler = jest.fn(() => undefined); 157 timerShaftElement.timeRuler.frame = jest.fn(() => Rect); 158 timerShaftElement.timeRuler.frame.width = jest.fn(() => 1); 159 timerShaftElement.rangeRuler.fillX = jest.fn(() => true); 160 timerShaftElement.render = jest.fn(() => true); 161 expect(timerShaftElement.updateWidth()).toBeUndefined(); 162 }); 163 164 it('TimerShaftElementTest24', function () { 165 timerShaftElement._sportRuler = jest.fn(() => undefined); 166 timerShaftElement._sportRuler.modifyFlagList = jest.fn(() => true); 167 expect(timerShaftElement.modifyFlagList()).toBeUndefined(); 168 }); 169 170 it('TimerShaftElementTest25', function () { 171 timerShaftElement._sportRuler = jest.fn(() => undefined); 172 timerShaftElement._sportRuler.drawTriangle = jest.fn(() => true); 173 expect(timerShaftElement.drawTriangle()).toBeTruthy(); 174 }); 175 176 it('TimerShaftElementTest26', function () { 177 timerShaftElement._sportRuler = jest.fn(() => undefined); 178 timerShaftElement._sportRuler.removeTriangle = jest.fn(() => true); 179 expect(timerShaftElement.removeTriangle()).toBeUndefined(); 180 }); 181 182 it('TimerShaftElementTest27', function () { 183 timerShaftElement._sportRuler = jest.fn(() => undefined); 184 timerShaftElement._sportRuler.setSlicesMark = jest.fn(() => true); 185 expect(timerShaftElement.setSlicesMark()).toBe(true); 186 }); 187 188 it('TimerShaftElementTest28', function () { 189 timerShaftElement.rangeRuler = jest.fn(() => undefined); 190 timerShaftElement.rangeRuler.render = jest.fn(() => true); 191 expect(timerShaftElement.render()).not.toBeUndefined(); 192 }); 193 194 it('TimerShaftElementTest29', function () { 195 expect(ns2x(1, 3, 0, 4, { width: 1 })).toBe(0); 196 }); 197 198 it('TimerShaftElementTest30', function () { 199 timerShaftElement.rangeRuler = jest.fn(() => true); 200 timerShaftElement.rangeRuler.cpuUsage = jest.fn(() => true); 201 expect(timerShaftElement.cpuUsage).toBe(undefined); 202 }); 203 204 it('TimerShaftElementTest31', function () { 205 timerShaftElement.timeRuler = jest.fn(() => true); 206 expect(timerShaftElement.totalNS).toBe(1000); 207 }); 208 209 it('TimerShaftElementTest32', function () { 210 timerShaftElement.rangeRuler = jest.fn(() => true); 211 expect(timerShaftElement.totalNS).toBe(1000); 212 }); 213 214 it('TimerShaftElementTest33', function () { 215 timerShaftElement.timeTotalEL = jest.fn(() => true); 216 expect(timerShaftElement.totalNS).toBe(1000); 217 }); 218 219 it('TimerShaftElementTest35', function () { 220 timerShaftElement.rangeRuler = jest.fn(() => undefined); 221 timerShaftElement.rangeRuler.cancelPressFrame = jest.fn(() => undefined); 222 expect(timerShaftElement.cancelPressFrame()).toBeUndefined(); 223 }); 224 225 it('TimerShaftElementTest36', function () { 226 timerShaftElement.rangeRuler = jest.fn(() => undefined); 227 timerShaftElement.rangeRuler.cancelUpFrame = jest.fn(() => undefined); 228 expect(timerShaftElement.cancelUpFrame()).toBeUndefined(); 229 }); 230}); 231