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//@ts-ignore 16import { TabPaneComparison } from '../../../../../../dist/trace/component/trace/sheet/ark-ts/TabPaneComparison.js'; 17import '../../../../../../dist/trace/component/trace/sheet/ark-ts/TabPaneComparison.js'; 18 19//@ts-ignore 20import { HeapDataInterface } from '../../../../../../dist/js-heap/HeapDataInterface.js'; 21 22jest.mock('../../../../../../dist/base-ui/select/LitSelect.js', () => { 23 return {}; 24}); 25jest.mock('../../../../../../dist/base-ui/table/lit-table.js', () => { 26 return { 27 snapshotDataSource: () => {}, 28 removeAttribute: () => {}, 29 }; 30}); 31 32jest.mock('../../../../../../dist/js-heap/model/DatabaseStruct.js', () => {}); 33 34// @ts-ignore 35window.ResizeObserver = 36 window.ResizeObserver || 37 jest.fn().mockImplementation(() => ({ 38 disconnect: jest.fn(), 39 observe: jest.fn(), 40 unobserve: jest.fn(), 41 })); 42 43describe('TabPaneComparison Test', () => { 44 let data = { 45 end_time: 5373364415, 46 file_name: 'Snapshot1', 47 frame: { height: 40, width: 24, x: 272, y: 0 }, 48 id: 1, 49 pid: 4243, 50 start_time: 4937360912, 51 textMetricsWidth: 60.697265625, 52 }; 53 let dataList = [ 54 { 55 id: 0, 56 file_name: 'Snapshot0', 57 start_time: 0, 58 end_time: 435811002, 59 pid: 4243, 60 textMetricsWidth: 50.5810546875, 61 }, 62 ]; 63 64 let childenData = [ 65 { 66 addedCount: 6061, 67 addedIndx: [319, 16], 68 addedSize: 2036, 69 childCount: 1326, 70 children: [], 71 classChildren: [], 72 deletedIdx: [11, 338], 73 deltaCount: 2, 74 deltaSize: -16, 75 distance: -1, 76 edgeCount: 11, 77 edgeName: '12', 78 fileId: 10, 79 hasNext: true, 80 id: 124, 81 index: 45, 82 isAdd: false, 83 isHover: true, 84 isSelected: false, 85 nextId: [], 86 nodeName: 'InternalAccessor', 87 objectName: 'InternalAccessor@123', 88 removedCount: 612, 89 removedSize: 3632, 90 retainedSize: 154, 91 retains: [], 92 shallowSize: 632, 93 showBox: false, 94 showCut: true, 95 status: true, 96 targetFileId: 1, 97 traceNodeId: 32, 98 type: 43, 99 }, 100 { 101 addedCount: 659, 102 addedIndx: [5, 3256], 103 addedSize: 1356, 104 childCount: 396, 105 children: [], 106 classChildren: [], 107 deletedIdx: [11, 308], 108 deltaCount: 88, 109 deltaSize: -16, 110 distance: 56, 111 edgeCount: 80, 112 edgeName: 'a', 113 fileId: 1, 114 hasNext: true, 115 id: 12, 116 index: 310, 117 isAdd: false, 118 isHover: false, 119 isSelected: false, 120 nextId: [1], 121 nodeName: 'JSNativePointer', 122 objectName: 'JSNativePointerX56', 123 removedCount: 6118, 124 removedSize: 3832, 125 retainedSize: 59, 126 retains: [], 127 shallowSize: 121, 128 showBox: true, 129 showCut: false, 130 status: true, 131 targetFileId: 1, 132 traceNodeId: 87, 133 type: 74, 134 }, 135 ]; 136 let ddd = [ 137 { 138 addedCount: 6432, 139 addedIndx: [19, 16], 140 addedSize: 316, 141 childCount: 1196, 142 children: [], 143 classChildren: [], 144 deletedIdx: [1, 318], 145 deltaCount: 0, 146 deltaSize: -16, 147 distance: 43, 148 edgeCount: 30, 149 edgeName: 'Accessor12', 150 fileId: 0, 151 hasNext: true, 152 id: 103, 153 index: 130, 154 isAdd: false, 155 isHover: false, 156 isSelected: false, 157 nextId: [], 158 nodeName: 'AccessorData', 159 objectName: 'AccessorDataX32', 160 removedCount: 6328, 161 removedSize: 33252, 162 retainedSize: 21, 163 retains: [], 164 shallowSize: 23, 165 showBox: false, 166 showCut: false, 167 status: true, 168 targetFileId: 231, 169 traceNodeId: 3, 170 type: 234, 171 isString: jest.fn(() => true), 172 }, 173 { 174 addedCount: 6563, 175 addedIndx: [14, 306], 176 addedSize: 336, 177 childCount: 136, 178 children: [], 179 classChildren: [], 180 deletedIdx: [23, 18], 181 deltaCount: 0, 182 deltaSize: -16, 183 distance: -1, 184 edgeCount: 31, 185 edgeName: 'GlobalObject56', 186 fileId: 41, 187 hasNext: true, 188 id: 54, 189 index: 40, 190 isAdd: false, 191 isHover: false, 192 isSelected: false, 193 nextId: [], 194 nodeName: 'GlobalObject', 195 objectName: 'GlobalObjectX21', 196 removedCount: 648, 197 removedSize: 32, 198 retainedSize: 8, 199 retains: [], 200 shallowSize: -1, 201 showBox: false, 202 showCut: true, 203 status: true, 204 targetFileId: 31, 205 traceNodeId: 45, 206 type: 424, 207 isString: jest.fn(() => true), 208 }, 209 { 210 addedCount: 5, 211 addedIndx: [67, 326], 212 addedSize: 316, 213 childCount: 66, 214 children: [], 215 classChildren: [], 216 deletedIdx: [325, 91], 217 deltaCount: 0, 218 deltaSize: -16, 219 distance: 33, 220 edgeCount: 0, 221 edgeName: 'ProtoChangeDetails', 222 fileId: 34, 223 hasNext: true, 224 id: -1, 225 index: 20, 226 isAdd: false, 227 isHover: false, 228 isSelected: false, 229 nextId: [], 230 nodeName: 'ProtoChangeDetails', 231 objectName: 'ProtoChangeDetailsX12', 232 removedCount: 648, 233 removedSize: 312, 234 retainedSize: 34, 235 retains: [], 236 shallowSize: 56, 237 showBox: false, 238 showCut: false, 239 status: true, 240 targetFileId: 61, 241 traceNodeId: 651, 242 type: 40, 243 isString: jest.fn(() => true), 244 }, 245 ]; 246 let rowObjectData = { 247 top: 2, 248 height: 0, 249 rowIndex: 2, 250 data: { 251 status: true, 252 targetFileId: 121, 253 children: childenData, 254 getChildren: () => {}, 255 }, 256 expanded: true, 257 rowHidden: false, 258 children: childenData, 259 depth: -1, 260 }; 261 262 let iconClick = new CustomEvent('icon-click', <CustomEventInit>{ 263 detail: { 264 ...rowObjectData.data, 265 data: rowObjectData.data, 266 }, 267 composed: true, 268 }); 269 let iconRowClick = new CustomEvent('row-click', <CustomEventInit>{ 270 detail: { 271 ...rowObjectData.data, 272 data: ddd[0], 273 }, 274 composed: true, 275 }); 276 let iconColumnClickData = new CustomEvent('column-click', <CustomEventInit>{ 277 detail: { 278 key: 'addedCount', 279 sort: 1, 280 }, 281 composed: true, 282 }); 283 let iconColumnClick = new CustomEvent('column-click', <CustomEventInit>{ 284 detail: { 285 key: 'addedCount', 286 sort: 1, 287 }, 288 composed: true, 289 }); 290 let iconkeyUpClick = new CustomEvent('keyup', <CustomEventInit>{ 291 detail: { 292 key: 'addedCount', 293 sort: 1, 294 }, 295 composed: true, 296 }); 297 document.body.innerHTML = ` 298 <tabpane-comparison id="sss"></tabpane-comparison>`; 299 let tabPaneComparisons = document.getElementById('sss') as TabPaneComparison; 300 301 HeapDataInterface.getInstance().getClassListForComparison = jest.fn(() => []); 302 HeapDataInterface.getInstance().getNextForComparison = jest.fn(() => ddd); 303 let htmlInputElement = document.createElement('input'); 304 htmlInputElement.value = 'input'; 305 tabPaneComparisons.search = jest.fn(() => htmlInputElement); 306 let heapDataInterface = new HeapDataInterface(); 307 heapDataInterface.fileStructs = [data]; 308 let htmlDivElement = document.createElement('div'); 309 tabPaneComparisons.leftTheadTable = jest.fn(() => htmlDivElement); 310 tabPaneComparisons.comparisonTable = jest.fn(() => htmlDivElement); 311 tabPaneComparisons.rightTheadTable = jest.fn(() => htmlDivElement); 312 tabPaneComparisons.rightTheadTable.removeAttribute = jest.fn(() => true); 313 tabPaneComparisons.rightTheadTable.hasAttribute = jest.fn(() => {}); 314 tabPaneComparisons.leftTheadTable = jest.fn(() => htmlDivElement); 315 tabPaneComparisons.leftTheadTable.hasAttribute = jest.fn(() => {}); 316 tabPaneComparisons.leftTheadTable.removeAttribute = jest.fn(() => true); 317 318 it('TabPaneComparisonTest01', () => { 319 tabPaneComparisons.comparisonsData = jest.fn(() => ddd); 320 tabPaneComparisons.comparisonTableEl.reMeauseHeight = jest.fn(() => true); 321 tabPaneComparisons.initComparison(data, dataList); 322 323 let retainsData = [ 324 { 325 shallowSize: 10, 326 retainedSize: 10, 327 shallowPercent: 10, 328 retainedPercent: 10, 329 distance: 1000000001, 330 nodeName: 'nodeName', 331 objectName: 'objectName', 332 edgeName: 'edgeName', 333 children: childenData, 334 }, 335 { 336 shallowSize: 4, 337 retainedSize: 1, 338 shallowPercent: 4, 339 retainedPercent: 1, 340 distance: 100000000, 341 nodeName: 'TSObjectType', 342 objectName: 'TSObjectTypeX23', 343 edgeName: 'TSObjectType', 344 children: childenData, 345 }, 346 ]; 347 HeapDataInterface.getInstance().getRetains = jest.fn(() => retainsData); 348 349 tabPaneComparisons.comparisonTableEl!.dispatchEvent(iconClick); 350 tabPaneComparisons.comparisonTableEl!.dispatchEvent(iconRowClick); 351 tabPaneComparisons.comparisonTableEl!.dispatchEvent(iconColumnClickData); 352 tabPaneComparisons.retainerTableEl.reMeauseHeight = jest.fn(() => true); 353 tabPaneComparisons.retainerTableEl!.dispatchEvent(iconColumnClick); 354 355 tabPaneComparisons.sortComprisonByColumn('addedCount', 0); 356 tabPaneComparisons.sortComprisonByColumn('removedCount', 1); 357 tabPaneComparisons.sortComprisonByColumn('addedCount', 1); 358 tabPaneComparisons.sortComprisonByColumn('deltaCount', 1); 359 tabPaneComparisons.sortComprisonByColumn('objectName', 1); 360 tabPaneComparisons.sortComprisonByColumn('addedSize', 1); 361 tabPaneComparisons.sortComprisonByColumn('removedSize', 1); 362 tabPaneComparisons.sortComprisonByColumn('deltaSize', 1); 363 364 tabPaneComparisons.sortRetainerByColumn('distance', 0); 365 tabPaneComparisons.sortRetainerByColumn('shallowSize', 1); 366 tabPaneComparisons.sortRetainerByColumn('retainedSize', 1); 367 tabPaneComparisons.sortRetainerByColumn('objectName', 1); 368 expect(tabPaneComparisons.comparisonTableEl!.snapshotDataSource).toEqual([]); 369 }); 370 371 it('TabPaneComparisonTest02', () => { 372 tabPaneComparisons.retainsData = [ 373 { 374 distance: 1, 375 }, 376 ]; 377 tabPaneComparisons.retainerTableEl!.dispatchEvent(iconClick); 378 expect(tabPaneComparisons.retainsData).not.toBe([]); 379 }); 380}); 381