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 16import '../../../../../../src/trace/component/trace/sheet/file-system/TabpaneFilesystemCalltree'; 17import { TabpaneFilesystemCalltree } from '../../../../../../src/trace/component/trace/sheet/file-system/TabpaneFilesystemCalltree'; 18import { TabPaneFilter } from '../../../../../../src/trace/component/trace/sheet/TabPaneFilter'; 19 20jest.mock('../../../../../../src/trace/database/ui-worker/ProcedureWorker', () => { 21 return {}; 22}); 23jest.mock('../../../../../../src/trace/component/trace/base/TraceRow', () => { 24 return {}; 25}); 26jest.mock('../../../../../../src/trace/database/ui-worker/cpu/ProcedureWorkerCPU', () => { 27 return { 28 cpuCount: 1, 29 CpuRender: Object, 30 EmptyRender: Object, 31 }; 32}); 33 34const intersectionObserverMock = () => ({ 35 observe: () => null, 36}); 37window.IntersectionObserver = jest.fn().mockImplementation(intersectionObserverMock); 38 39import crypto from 'crypto'; 40// @ts-ignore 41window.ResizeObserver = 42 window.ResizeObserver || 43 jest.fn().mockImplementation(() => ({ 44 observe: jest.fn(), 45 })); 46 47Object.defineProperty(global.self, 'crypto', { 48 value: { 49 getRandomValues: (arr: string | any[]) => crypto.randomBytes(arr.length), 50 }, 51}); 52describe('TabpaneFilesystemCalltree Test', () => { 53 document.body.innerHTML = `<tabpane-filesystem-calltree id="tree"></tabpane-filesystem-calltree>`; 54 let tabpaneFilesystemCalltree = document.querySelector<TabpaneFilesystemCalltree>('#tree'); 55 let val = { 56 anomalyEnergy: [], 57 clockMapData: { size: 16 }, 58 cpuAbilityIds: [12, 155, 223], 59 cpuFreqFilterIds: [52, 122, 22], 60 cpuFreqLimitDatas: [], 61 cpuStateFilterIds: [52, 566, 115], 62 cpus: [1, 2], 63 diskAbilityIds: [451, 22], 64 diskIOLatency: false, 65 diskIOReadIds: [522, 4, 5, 6], 66 diskIOWriteIds: [2, 5621, 5, 6], 67 diskIOipids: [2, 120, 5, 6], 68 fileSysVirtualMemory: true, 69 fileSystemType: [], 70 fsCount: 32, 71 funAsync: [], 72 funTids: [120, 55], 73 hasFps: false, 74 irqMapData: { size: 85 }, 75 jsMemory: [], 76 leftNs: 555123, 77 memoryAbilityIds: [], 78 nativeMemory: [], 79 nativeMemoryStatistic: [], 80 networkAbilityIds: [], 81 perfAll: true, 82 perfCpus: [1, 2], 83 perfProcess: [], 84 perfSampleIds: [], 85 perfThread: ['hiprofiler_cmd', ''], 86 powerEnergy: [], 87 processTrackIds: [552, 123], 88 promiseList: [], 89 recordStartNs: 780423789228, 90 rightNs: 966666666, 91 sdkCounterIds: [120, 451, 52], 92 sdkSliceIds: [154], 93 smapsType: [], 94 systemEnergy: [], 95 threadIds: [101, 2122, 4], 96 virtualTrackIds: [412, 85], 97 vmCount: 3, 98 }; 99 100 it('TabpaneFilesystemCalltreeTest02', function () { 101 tabpaneFilesystemCalltree!.showButtonMenu = jest.fn(() => ''); 102 tabpaneFilesystemCalltree.fsCallTreeFilter = jest.fn(() => ''); 103 tabpaneFilesystemCalltree.fsCallTreeFilter.setAttribute = jest.fn(() => ''); 104 expect(tabpaneFilesystemCalltree.showButtonMenu(true)).toBe(''); 105 }); 106 107 it('TabpaneFilesystemCalltreeTest03', function () { 108 TabpaneFilesystemCalltree.getParentTree = jest.fn(() => true); 109 let call = { 110 id: '1', 111 children: [], 112 }; 113 let target = { 114 id: '1', 115 }; 116 expect(tabpaneFilesystemCalltree.getParentTree([call], { target }, [])).toBeFalsy(); 117 }); 118 119 it('TabpaneFilesystemCalltreeTest04', function () { 120 TabpaneFilesystemCalltree.getParentTree = jest.fn(() => true); 121 let call = { 122 children: [], 123 }; 124 expect(tabpaneFilesystemCalltree.getParentTree([call], '', [])).not.toBeUndefined(); 125 }); 126 127 it('TabpaneFilesystemCalltreeTest05', function () { 128 TabpaneFilesystemCalltree.getChildTree = jest.fn(() => true); 129 let call = { 130 id: '1', 131 children: [], 132 }; 133 let id = '1'; 134 expect(tabpaneFilesystemCalltree.getChildTree([call], { id }, [])).not.toBeUndefined(); 135 }); 136 137 it('TabpaneFilesystemCalltreeTest06', function () { 138 TabpaneFilesystemCalltree.getChildTree = jest.fn(() => true); 139 let call = { 140 children: [], 141 }; 142 expect(tabpaneFilesystemCalltree.getChildTree([call], '', [])).not.toBeUndefined(); 143 }); 144 145 it('TabpaneFilesystemCalltreeTest07', function () { 146 let filter = new TabPaneFilter(); 147 tabpaneFilesystemCalltree.fsCallTreeFilter = filter; 148 tabpaneFilesystemCalltree.data = val; 149 expect(tabpaneFilesystemCalltree.currentSelection).not.toBeUndefined(); 150 }); 151 152 it('TabpaneFilesystemCalltreeTest08', function () { 153 let resultData = [ 154 { 155 addr: 'SpSystemTrace', 156 canCharge: false, 157 count: 56, 158 depth: 1, 159 drawCount: 23, 160 drawDur: 32, 161 drawSize: 33, 162 dur: 43331564310, 163 frame: { x: 10, y: 32, width: 522, height: 10 }, 164 id: '1', 165 ip: '12', 166 isDraw: false, 167 isSearch: true, 168 isSelected: false, 169 isStore: 1, 170 lib: '', 171 libName: 'file', 172 parentId: '12', 173 path: '', 174 pathId: 2, 175 percent: 0.36425651150324375, 176 pid: 23, 177 processName: '', 178 searchShow: true, 179 self: '5s', 180 selfDur: 54, 181 size: 443, 182 symbol: 'symsdbl', 183 symbolName: 'symbols', 184 symbolsId: 210, 185 textMetricsWidth: 62.7712033125, 186 type: 10, 187 weight: '66.33s ', 188 weightPercent: '23.4%', 189 children: [], 190 }, 191 ]; 192 tabpaneFilesystemCalltree.setLTableData(resultData); 193 expect(tabpaneFilesystemCalltree.fsCallTreeDataSource.length).toEqual(1); 194 }); 195 196 it('TabpaneFilesystemCalltreeTest09', function () { 197 let switchData = { 198 firstSelect: '', 199 icon: 'tree', 200 inputValue: 'kk', 201 mark: false, 202 secondSelect: '', 203 thirdSelect: '', 204 type: 'inputValue', 205 }; 206 tabpaneFilesystemCalltree.fsCallTreeTbl.reMeauseHeight = jest.fn(() => true); 207 tabpaneFilesystemCalltree.switchFlameChart(switchData); 208 expect(tabpaneFilesystemCalltree.isChartShow).toBeFalsy(); 209 }); 210 211 it('TabpaneFilesystemCalltreeTest10', function () { 212 let call = { 213 id: '1', 214 dur: 1, 215 children: [], 216 }; 217 expect(tabpaneFilesystemCalltree.setRightTableData(call)).toBeUndefined(); 218 }); 219 it('TabpaneFilesystemCalltreeTest11', function () { 220 let filterData = { 221 callTree: [{}, {}], 222 dataMining: { 223 concat: jest.fn(() => true), 224 }, 225 callTreeConstraints: { 226 checked: false, 227 }, 228 }; 229 expect(tabpaneFilesystemCalltree.refreshAllNode(filterData)).toBeUndefined(); 230 }); 231}); 232