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('../../../../../../src/trace/component/trace/base/TraceRow', () => { 17 return {}; 18}); 19import { TabPaneSPT } from '../../../../../../src/trace/component/trace/sheet/cpu/TabPaneSPT'; 20import { LitTable } from '../../../../../../src/base-ui/table/lit-table'; 21 22jest.mock('../../../../../../src/js-heap/model/DatabaseStruct', () => {}); 23jest.mock('../../../../../../src/trace/bean/NativeHook', () => { 24 return {}; 25}); 26 27window.ResizeObserver = 28 window.ResizeObserver || 29 jest.fn().mockImplementation(() => ({ 30 disconnect: jest.fn(), 31 unobserve: jest.fn(), 32 observe: jest.fn(), 33 })); 34 35describe('TabPaneSPT Test', () => { 36 document.body.innerHTML = `<lit-table id="tb-states"><</lit-table>`; 37 let tab = document.querySelector('#tb-states') as LitTable; 38 39 document.body.innerHTML = `<div><tabpane-spt class="SPT"></tabpane-spt></div>`; 40 let tabPane = document.querySelector('.SPT') as TabPaneSPT; 41 let tabPaneSPT = new TabPaneSPT(); 42 tabPaneSPT.sptTbl = jest.fn(() => tab); 43 let dataList = [ 44 { 45 id: 78, 46 pid: 55, 47 title: '', 48 children: [], 49 process: '', 50 processId: 1380, 51 thread: 'com.ohos.callui', 52 threadId: 1380, 53 state: '', 54 wallDuration: 5220, 55 avgDuration: '', 56 count: 5, 57 minDuration: 440, 58 maxDuration: 36220, 59 stdDuration: '', 60 }, 61 ]; 62 63 let dataArray = [ 64 { 65 id: 885, 66 pid: 12, 67 title: '', 68 children: [], 69 process: '', 70 processId: 1387, 71 thread: 'com.ohos.callui', 72 threadId: 1387, 73 state: '', 74 wallDuration: 666240, 75 avgDuration: '', 76 count: 40, 77 minDuration: 2330, 78 maxDuration: 524660, 79 stdDuration: '', 80 }, 81 ]; 82 83 it('TabPaneSPTTest01', function () { 84 expect(tabPane.getDataBySPT(0, 0, [])).toBeUndefined(); 85 }); 86 87 it('TabPaneSPTTest02', function () { 88 let source = [ 89 { 90 process: 'com.ohos.callui 1387', 91 processId: 1387, 92 thread: 'com.ohos.callui', 93 threadId: 1387, 94 state: '', 95 dur: 66654, 96 start_ts: 4, 97 end_ts: 66650, 98 cpu: 0, 99 priority: '154', 100 note: '-', 101 }, 102 ]; 103 expect(tabPane.getDataBySPT(10, 100_000, source)).toBeUndefined(); 104 }); 105}); 106