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 { DataMessage } from '../../../../src/hdc/message/DataMessage'; 16 17window.ResizeObserver = 18 window.ResizeObserver || 19 jest.fn().mockImplementation(() => ({ 20 disconnect: jest.fn(), 21 observe: jest.fn(), 22 unobserve: jest.fn(), 23 })); 24 25import { SpWebHdcShell } from '../../../../src/trace/component/setting/SpWebHdcShell'; 26import { EventCenter } from '../../../../src/trace/component/trace/base/EventCenter'; 27import { USBHead } from '../../../../src/hdc/message/USBHead'; 28 29declare global { 30 interface Window { 31 SmartEvent: { 32 UI: { 33 DeviceConnect: string; 34 DeviceDisConnect: string; 35 }; 36 }; 37 subscribe(evt: string, fn: (b: any) => void): void; 38 unsubscribe(evt: string, fn: (b: any) => void): void; 39 subscribeOnce(evt: string, fn: (b: any) => void): void; 40 publish(evt: string, data: any): void; 41 clearTraceRowComplete(): void; 42 } 43} 44 45window.SmartEvent = { 46 UI: { 47 DeviceConnect: 'SmartEvent-DEVICE_CONNECT', 48 DeviceDisConnect: 'SmartEvent-DEVICE_DISCONNECT', 49 }, 50}; 51 52Window.prototype.subscribe = (ev, fn) => EventCenter.subscribe(ev, fn); 53Window.prototype.unsubscribe = (ev, fn) => EventCenter.unsubscribe(ev, fn); 54Window.prototype.publish = (ev, data) => EventCenter.publish(ev, data); 55Window.prototype.subscribeOnce = (ev, data) => EventCenter.subscribeOnce(ev, data); 56Window.prototype.clearTraceRowComplete = () => EventCenter.clearTraceRowComplete(); 57describe('SpWebHdcShell Test', () => { 58 let spWebHdcShell = new SpWebHdcShell(); 59 it('SpWebHdcShell Test01', function () { 60 expect(spWebHdcShell.initElements()).toBeUndefined(); 61 }); 62 63 it('SpWebHdcShell Test02', function () { 64 expect(spWebHdcShell.initHtml()).not.toBeNull(); 65 }); 66 67 it('SpWebHdcShell Test03', function () { 68 let arrayBufferA = new Uint8Array(1); 69 arrayBufferA.set([1]); 70 let arrayBufferB = [1, 2]; 71 expect(spWebHdcShell.arrayBufferCompare(arrayBufferA, arrayBufferB)).toBeFalsy(); 72 }); 73 74 it('SpWebHdcShell Test05', function () { 75 let arrayBufferA = new Uint8Array(1); 76 arrayBufferA.set([2]); 77 let arrayBufferB = [1, 2]; 78 expect(spWebHdcShell.arrayBufferCompare(arrayBufferA, arrayBufferB)).toBeFalsy(); 79 }); 80 81 it('SpWebHdcShell Test06', function () { 82 let dataHead = new USBHead([85, 66], 1, 77777, 0); 83 let dataMessage = new DataMessage(dataHead); 84 expect(spWebHdcShell.handleHdcRecvData(dataMessage)).toBeUndefined(); 85 }); 86 87 it('SpWebHdcShell Test07', function () { 88 let dataHead = new USBHead([85, 66], 1, 77777, 21); 89 let arrayBuffer = new Uint8Array(21); 90 arrayBuffer.set([72,87,0,0,2,0,8,0,0,0,2,8,2,16,10,24,0,32,9,35,32]); 91 let body = new DataView(arrayBuffer.buffer); 92 let dataMessage = new DataMessage(dataHead, body); 93 expect(spWebHdcShell.handleHdcRecvData(dataMessage)).toBeUndefined(); 94 }); 95 it('SpWebHdcShell Test011', function () { 96 expect(spWebHdcShell.clear()).toBeUndefined(); 97 }); 98 it('SpWebHdcShell Test012', function () { 99 let shellStr = '111111111111111111111111111111'; 100 let res = spWebHdcShell.singleLineToMultiLine(shellStr,1,10) 101 expect(res).toEqual(["1111111111","1111111111","1111111111"]) 102 }); 103 it('SpWebHdcShell Test013', function () { 104 expect(spWebHdcShell.forwardSelected(0,1120,0,1111)).toBeUndefined(); 105 }); 106}); 107