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 { TraceRowConfig } from '../../../../../src/trace/component/trace/base/TraceRowConfig'; 17import '../../../../../src/trace/component/trace/base/TraceRowConfig'; 18import { TraceRow } from '../../../../../src/trace/component/trace/base/TraceRow'; 19import '../../../../../src/trace/component/trace/base/TraceRow'; 20import { BaseStruct } from '../../../../../src/trace/bean/BaseStruct'; 21import '../../../../../src/trace/bean/BaseStruct'; 22import { LitCheckBox } from "../../../../../src/base-ui/checkbox/LitCheckBox"; 23 24jest.mock('../../../../../src/trace/database/ui-worker/cpu/ProcedureWorkerCPU', () => { 25 return { 26 CpuStruct: { 27 wakeupBean: undefined 28 } 29 } 30}); 31jest.mock('../../../../../src/trace/component/trace/TimerShaftElement', () => { 32}); 33 34describe('TraceRowConfig Test', () => { 35 document.body.innerHTML = `<div><sp-application><lit-search id="lit-search"></lit-search></sp-application><trace-row-config id="config"></trace-row-config> 36 <sp-system-trace></sp-system-trace></div>`; 37 38 let spSystemTrace = document.querySelector('sp-system-trace'); 39 let shadowRoot = spSystemTrace.attachShadow({mode: 'open'}); 40 let rowsPaneDiv = document.createElement('div'); 41 rowsPaneDiv.classList.add('rows-pane'); 42 let traceRow = TraceRow.skeleton<BaseStruct>(); 43 traceRow.setAttribute('row-parent-id', ''); 44 traceRow.addTemplateTypes('Memory'); 45 shadowRoot.appendChild(rowsPaneDiv); 46 rowsPaneDiv.appendChild(traceRow); 47 48 let nodes = [{ 49 children: [ 50 { 51 children: [ 52 { 53 children: [], 54 depth: 3, 55 id: 3, 56 isCheck: true, 57 nodeName: "Cpu chart", 58 scene: [] 59 } 60 ], 61 depth: 2, 62 id: 2, 63 isCheck: false, 64 nodeName: "Cpu", 65 parent: { 66 id: 1, nodeName: 'Cpu', children: [], depth: 1, isCheck: false, 67 scene: [] 68 }, 69 scene: [] 70 } 71 ], 72 depth: 1, 73 id: 1, 74 isCheck: false, 75 nodeName: "Cpu", 76 scene: [] 77 }] 78 79 let json = { 80 "subsystems": [ 81 { 82 "subsystem": "Cpu", 83 "components": [ 84 { 85 "component": "Cpu", 86 "charts": [ 87 { 88 "chartName": "Cpu", 89 "chartId": "" 90 } 91 ] 92 } 93 ] 94 } 95 ] 96 } 97 98 let traceRowConfig = document.querySelector<TraceRowConfig>('#config'); 99 100 it('TraceRowConfig Test01', () => { 101 traceRowConfig.init(); 102 expect(traceRowConfig.selectTypeList.length).toBe(0); 103 }); 104 105 it('TraceRowConfig Test02', () => { 106 traceRowConfig.init(); 107 let checkBox = new LitCheckBox; 108 checkBox.checked = true; 109 let node = { 110 children: [], 111 depth: 3, 112 id: 6, 113 isCheck: true, 114 nodeName: "Cpu", 115 scene: [] 116 } 117 traceRowConfig.displayRow(node, checkBox); 118 expect(traceRowConfig.subsystemSelectList.length).toBe(2) 119 }); 120 it('TraceRowConfig Test03', () => { 121 traceRowConfig.init(); 122 let checkBox = new LitCheckBox; 123 let node = { 124 children: [], 125 depth: 3, 126 id: 6, 127 isCheck: false, 128 nodeName: "Cpu", 129 scene: [] 130 } 131 traceRowConfig.displayRow(node, checkBox); 132 expect(traceRowConfig.subsystemSelectList.length).toBe(0) 133 }); 134 135 136 it('TraceRowConfig Test04', () => { 137 expect(traceRowConfig.refreshSelectList(nodes)).toBeUndefined(); 138 }); 139 140 it('TraceRowConfig Test05', () => { 141 traceRowConfig.init() 142 let favoriteRow = new TraceRow<any>; 143 traceRowConfig.spSystemTrace.collectRows = [favoriteRow]; 144 traceRowConfig.spSystemTrace.rowsPaneEL = jest.fn(); 145 traceRowConfig.spSystemTrace.rowsPaneEL.scroll = jest.fn(() => true); 146 traceRowConfig.spSystemTrace.canvasPanel = jest.fn(); 147 traceRowConfig.spSystemTrace.refreshFavoriteCanvas = jest.fn(() => true); 148 traceRowConfig.spSystemTrace.refreshCanvas = jest.fn(() => true); 149 traceRowConfig.resetChartTable(); 150 expect(traceRowConfig.traceRowList.length).toBe(1); 151 }); 152 153 it('TraceRowConfig Test06', () => { 154 traceRowConfig.refreshNodes(nodes); 155 expect(nodes[0].isCheck).toBeTruthy(); 156 }); 157 158 it('TraceRowConfig Test07', () => { 159 traceRowConfig.clearSearchAndFlag(); 160 expect(traceRowConfig.spSystemTrace.hoverFlag ).toBeUndefined(); 161 }); 162 163 it('TraceRowConfig Test08', () => { 164 traceRowConfig.expandedNodeList = new Set([1, 2, 3]); 165 traceRowConfig.changeNode(1); 166 expect(traceRowConfig.expandedNodeList.has(1)).toBeFalsy() 167 }); 168 169 it('TraceRowConfig Test09', () => { 170 traceRowConfig.expandedNodeList = new Set([2, 3]); 171 traceRowConfig.changeNode(1); 172 expect(traceRowConfig.expandedNodeList.has(1)).toBeTruthy(); 173 }); 174 175 it('TraceRowConfig Test10', () => { 176 traceRowConfig.treeNodes = []; 177 traceRowConfig.loadTempConfig(JSON.stringify(json)); 178 expect(traceRowConfig.treeNodes.length).toBe(2); 179 }); 180 181 it('TraceRowConfig Test11', () => { 182 let node = { 183 children: [], 184 depth: 3, 185 id: 6, 186 isCheck: false, 187 nodeName: "Cpu", 188 scene: [], 189 parent: { 190 id: 8, nodeName: 'Cpu', children: [], depth: 2, isCheck: false, 191 scene: [] 192 }, 193 } 194 traceRowConfig.setParentSelect(node, false); 195 expect(node.isCheck).toBeFalsy(); 196 traceRowConfig.setParentSelect(node, true); 197 expect(node.parent.isCheck).toBeTruthy(); 198 }); 199}); 200