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 16// @ts-ignore 17import {SpApplication} from "../../dist/trace/SpApplication.js"; 18 19window.ResizeObserver = window.ResizeObserver || 20 jest.fn().mockImplementation(() => ({ 21 disconnect: jest.fn(), 22 observe: jest.fn(), 23 unobserve: jest.fn(), 24 })); 25 26describe('spApplication Test', ()=>{ 27 28 it('spApplicationTest01',function (){ 29 document.body.innerHTML= `<sp-application></sp-application>` 30 let element = new SpApplication(); 31 element.dark = 'dark' 32 expect(element.dark).toBeTruthy() 33 }) 34 35 it('spApplicationTest02',function (){ 36 document.body.innerHTML= `<sp-application></sp-application>` 37 let element = new SpApplication(); 38 element.dark = '' 39 expect(element.dark).toBeFalsy() 40 }) 41 42 it('spApplicationTest03',function (){ 43 document.body.innerHTML= `<sp-application></sp-application>` 44 let element = new SpApplication(); 45 element.vs = 'vs' 46 expect(element.vs).toBeTruthy() 47 }) 48 49 it('spApplicationTest04',function (){ 50 document.body.innerHTML= `<sp-application></sp-application>` 51 let element = new SpApplication(); 52 element.vs = '' 53 expect(element.vs).toBeFalsy() 54 }) 55 56 it('spApplicationTest05',function (){ 57 document.body.innerHTML= `<sp-application></sp-application>` 58 let element = new SpApplication(); 59 element.server = "server" 60 expect(element.server).toBeTruthy() 61 }) 62 63 it('spApplicationTest06',function (){ 64 document.body.innerHTML= `<sp-application></sp-application>` 65 let element = new SpApplication(); 66 element.server = "" 67 expect(element.server).toBeFalsy() 68 }) 69 70 it('spApplicationTest07',function (){ 71 document.body.innerHTML= `<sp-application></sp-application>` 72 let element = new SpApplication(); 73 element.querySql = "querySql" 74 expect(element.querySql).toBeTruthy() 75 }) 76 77 it('spApplicationTest08',function (){ 78 document.body.innerHTML= `<sp-application></sp-application>` 79 let element = new SpApplication(); 80 element.querySql = "" 81 expect(element.querySql).toBeFalsy() 82 }) 83 84 it('spApplicationTest09',function (){ 85 document.body.innerHTML= `<sp-application></sp-application>` 86 let element = new SpApplication(); 87 element.search = "search" 88 expect(element.querySql).toBeTruthy() 89 }) 90 91 it('spApplicationTest10',function (){ 92 document.body.innerHTML= `<sp-application></sp-application>` 93 let element = new SpApplication(); 94 element.search = "" 95 expect(element.search).toBeFalsy() 96 }) 97 98 it('spApplicationTest11',function (){ 99 document.body.innerHTML= `<sp-application></sp-application>` 100 let element = new SpApplication(); 101 expect(element.removeSkinListener()).toBeUndefined() 102 }) 103 104 it('spApplicationTest15',function (){ 105 document.body.innerHTML = '<sp-application id="sss"></sp-application>'; 106 let spApplication = document.querySelector('#sss') as SpApplication; 107 expect(spApplication.freshMenuDisable()).toBeUndefined(); 108 }) 109 110 it('spApplicationTest16',function (){ 111 document.body.innerHTML = '<sp-application id="sss"></sp-application>'; 112 let spApplication = document.querySelector('#sss') as SpApplication; 113 expect(spApplication.addSkinListener()).toBeUndefined(); 114 }) 115 116 it('spApplicationTest17',function (){ 117 document.body.innerHTML = '<sp-application id="sss"></sp-application>'; 118 let spApplication = document.querySelector('#sss') as SpApplication; 119 expect(spApplication.removeSkinListener()).toBeUndefined() 120 }) 121 122 it('spApplicationTest18',function (){ 123 document.body.innerHTML= "<sp-application id='sp'></sp-application>" 124 let element = document.querySelector("#sp") as SpApplication; 125 element.dispatchEvent(new Event("dragleave")) 126 }) 127 128 it('spApplicationTest19',function (){ 129 document.body.innerHTML= "<sp-application id='sp'></sp-application>" 130 let element = document.querySelector("#sp") as SpApplication; 131 element.dispatchEvent(new Event("drop")) 132 SpApplication.removeSkinListener = jest.fn(()=>undefined) 133 expect(SpApplication.removeSkinListener()).toBeUndefined() 134 }) 135 it('spApplicationTest21', function () { 136 document.body.innerHTML= "<sp-application id='sp'></sp-application>" 137 let element = document.querySelector("#sp") as SpApplication; 138 expect(element.vsDownload()).toBeUndefined() 139 }); 140 141 it('spApplicationTest22', function () { 142 document.body.innerHTML = '<sp-application id="sss"></sp-application>'; 143 let spApplication = document.querySelector('#sss') as SpApplication; 144 spApplication.showConten = false; 145 expect(spApplication.showContent).toBeFalsy() 146 }); 147 148 it('spApplicationTest23', function () { 149 let spApplication = new SpApplication(); 150 spApplication.openTraceFile = true; 151 expect(spApplication.openTraceFile).toBeTruthy() 152 }); 153 154 it('spApplicationTest24', function () { 155 let spApplication = new SpApplication(); 156 spApplication.openTraceFile = false; 157 expect(spApplication.openTraceFile).toBeFalsy() 158 }); 159 160 it('spApplicationTest25', function () { 161 document.body.innerHTML = '<sp-application id="sss"></sp-application>'; 162 let spApplication = document.querySelector('#sss') as SpApplication; 163 expect(spApplication.initHtml()).toMatchInlineSnapshot(` 164" 165 <style> 166 :host{ 167 168 } 169 .dark{ 170 --dark-background: #272C34; 171 --dark-background1: #424851; 172 --dark-background2: #262f3c; 173 --dark-background3: #292D33; 174 --dark-background4: #323841; 175 --dark-background5: #333840; 176 --dark-background6: rgba(82,145,255,0.2); 177 --dark-background7: #494d52; 178 --dark-background8: #5291FF; 179 --dark-color: rgba(255,255,255,0.6); 180 --dark-color1: rgba(255,255,255,0.86); 181 --dark-color2: rgba(255,255,255,0.9); 182 --dark-border: #474F59; 183 --dark-color3:#4694C2; 184 --dark-color4:#5AADA0; 185 --dark-border1: #454E5A; 186 --bark-expansion:#0076FF; 187 --bark-prompt:#9e9e9e; 188 --dark-icon:#adafb3; 189 --dark-img: url('img/dark_pic.png'); 190 background: #272C34; 191 color: #FFFFFF; 192 } 193 .root{ 194 display: grid; 195 grid-template-rows: min-content 1fr; 196 grid-template-columns: min-content 1fr; 197 grid-template-areas: 'm s' 198 'm b'; 199 height: 100vh; 200 width: 100vw; 201 } 202 .filedrag::after { 203 content: 'Drop the trace file to open it'; 204 position: fixed; 205 z-index: 2001; 206 top: 0; 207 left: 0; 208 right: 0; 209 bottom: 0; 210 border: 5px dashed var(--dark-color1,#404854); 211 text-align: center; 212 font-size: 3rem; 213 line-height: 100vh; 214 background: rgba(255, 255, 255, 0.5); 215 } 216 .menu{ 217 grid-area: m; 218 /*transition: all 0.2s;*/ 219 box-shadow: 4px 0px 20px rgba(0,0,0,0.05); 220 z-index: 2000; 221 } 222 .search-container{ 223 z-index: 10; 224 position: relative; 225 } 226 .progress{ 227 bottom: 0; 228 position: absolute; 229 height: 1px; 230 left: 0; 231 right: 0; 232 } 233 :host(:not([search])) .search-container { 234 display: none; 235 } 236 237 :host(:not([search])) .search-container .search { 238 background-color: var(--dark-background5,#F6F6F6); 239 } 240 .search{ 241 grid-area: s; 242 background-color: var(--dark-background,#FFFFFF); 243 height: 48px; 244 display: flex; 245 justify-content: center; 246 align-items: center; 247 248 } 249 .search .search-bg{ 250 background-color: var(--dark-background5,#fff); 251 border-radius: 40px; 252 padding: 3px 20px; 253 display: flex; 254 justify-content: center; 255 align-items: center; 256 border: 1px solid var(--dark-border,#c5c5c5); 257 } 258 .search input{ 259 outline: none; 260 border: 0px; 261 background-color: transparent; 262 font-size: inherit; 263 color: var(--dark-color,#666666); 264 width: 30vw; 265 height: auto; 266 vertical-align:middle; 267 line-height:inherit; 268 height:inherit; 269 padding: 6px 6px 6px 6px}; 270 max-height: inherit; 271 box-sizing: border-box; 272 273 } 274 ::placeholder { /* CSS 3 標準 */ 275 color: #b5b7ba; 276 font-size: 1em; 277 } 278 .search input::placeholder { 279 color: #b5b7ba; 280 font-size: 1em; 281 } 282 .content{ 283 grid-area: b; 284 background-color: #ffffff; 285 height: 100%; 286 overflow: auto; 287 position:relative; 288 } 289 .sheet{ 290 291 } 292 .sidebar-button{ 293 position: absolute; 294 top: 0; 295 left: 0; 296 background-color: var(--dark-background1,#FFFFFF); 297 height: 100%; 298 border-radius: 0 5px 5px 0; 299 width: 48px; 300 display: flex; 301 align-content: center; 302 justify-content: center; 303 cursor: pointer; 304 } 305 :host{ 306 font-size: inherit; 307 display: inline-block; 308 transition: .3s; 309 } 310 :host([spin]){ 311 animation: rotate 1.75s linear infinite; 312 } 313 @keyframes rotate { 314 to{ 315 transform: rotate(360deg); 316 } 317 } 318 .icon{ 319 display: block; 320 width: 1em; 321 height: 1em; 322 margin: auto; 323 fill: currentColor; 324 overflow: hidden; 325 font-size: 20px; 326 color: var(--dark-color1,#4D4D4D); 327 } 328 </style> 329 <div class=\\"root\\"> 330 <lit-main-menu id=\\"main-menu\\" class=\\"menu\\" data=''></lit-main-menu> 331 <div class=\\"search-container\\"> 332 <div class=\\"search\\" style=\\"position: relative;\\"> 333 <div class=\\"sidebar-button\\" style=\\"width: 0\\"> 334 <svg class=\\"icon\\" id=\\"icon\\" aria-hidden=\\"true\\" viewBox=\\"0 0 1024 1024\\"> 335 <use id=\\"use\\" xlink:href=\\"./base-ui/icon.svg#icon-menu\\"></use> 336 </svg> 337 </div> 338 <lit-search id=\\"lit-search\\"></lit-search> 339 </div> 340 <lit-progress-bar class=\\"progress\\"></lit-progress-bar> 341 </div> 342 <div id=\\"app-content\\" class=\\"content\\"> 343 <sp-welcome style=\\"visibility:visible;top:0px;left:0px;position:absolute;z-index: 100\\" id=\\"sp-welcome\\"> 344 </sp-welcome> 345 <sp-system-trace style=\\"visibility:visible;\\" id=\\"sp-system-trace\\"> 346 </sp-system-trace> 347 <sp-record-trace style=\\"width:100%;height:100%;overflow:auto;visibility:hidden;top:0px;left:0px;right:0;bottom:0px;position:absolute;z-index: 102\\" id=\\"sp-record-trace\\"> 348 </sp-record-trace> 349 <sp-metrics style=\\"width:100%;height:100%;overflow:auto;visibility:hidden;top:0;left:0;right:0;bottom:0;position:absolute;z-index: 97\\" id=\\"sp-metrics\\"> 350 </sp-metrics> 351 <sp-query-sql style=\\"width:100%;height:100%;overflow:auto;visibility:hidden;top:0;left:0;right:0;bottom:0;position:absolute;z-index: 98\\" id=\\"sp-query-sql\\"> 352 </sp-query-sql> 353 <sp-info-and-stats style=\\"width:100%;height:100%;overflow:auto;visibility:hidden;top:0;left:0;right:0;bottom:0;position:absolute;z-index: 99\\" id=\\"sp-info-and-stats\\"> 354 </sp-info-and-stats> 355 <sp-help style=\\"width:100%;height:100%;overflow:auto;visibility:hidden;top:0px;left:0px;right:0;bottom:0px;position:absolute;z-index: 103\\" id=\\"sp-help\\"> 356 </sp-help> 357 </div> 358 </div> 359 " 360`); 361 }); 362 363 it('spApplicationTest26', function () { 364 document.body.innerHTML = '<SpApplication id="sss"></SpApplication>'; 365 let spApplication = document.querySelector('#sss') as SpApplication; 366 spApplication.dark = false; 367 spApplication.skinChangeArray = ['item']; 368 expect(spApplication.dark).toBeFalsy(); 369 }); 370 371 it('spApplicationTest27', function () { 372 document.body.innerHTML = '<SpApplication id="sss"></SpApplication>'; 373 let spApplication = document.querySelector('#sss') as SpApplication; 374 spApplication.dark = true; 375 spApplication.skinChange = jest.fn(()=>true); 376 expect(spApplication.dark).toBeTruthy(); 377 }); 378 379 it('spApplicationTest28', function () { 380 document.body.innerHTML = '<SpApplication id="sss"></SpApplication>'; 381 let spApplication = document.querySelector('#sss') as SpApplication; 382 spApplication.dark = false; 383 spApplication.skinChange2 = jest.fn(()=>true); 384 expect(spApplication.dark).toBeFalsy(); 385 }); 386 387 it('spApplicationTest29', function () { 388 document.body.innerHTML = '<sp-application id="sss"></sp-application>'; 389 let spApplication = document.querySelector('#sss') as SpApplication; 390 spApplication.querySql = false; 391 expect(spApplication.querySql).toBeFalsy(); 392 }); 393 394 395}) 396