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 {TabPaneCounter} from "../../../../../dist/trace/component/trace/sheet/TabPaneCounter.js" 18 19const sqlit = require("../../../../../dist/trace/database/SqlLite.js") 20jest.mock("../../../../../dist/trace/database/SqlLite.js"); 21describe('TabPaneCounter Test', () => { 22 let tabPaneCounter = new TabPaneCounter(); 23 it('TabPaneCounterTest01', function () { 24 expect(tabPaneCounter.groupByTrackIdToMap([{ 25 id: 0, 26 trackId: 0, 27 name: "", 28 value: 0, 29 startTime: 0, 30 }])) 31 }); 32 33 it('TabPaneCounterTest02', function () { 34 expect(tabPaneCounter.createSelectCounterData([{ 35 id: 0, 36 trackId: 0, 37 name: "", 38 value: 0, 39 startTime: 0, 40 }], 0, 1)) 41 }); 42 43 it('TabPaneCounterTest03', function () { 44 expect(tabPaneCounter.sortByColumn({ 45 key: 'name', 46 sort: () => { 47 } 48 })).toBeUndefined(); 49 }); 50 51 it('TabPaneCounterTest06', function () { 52 expect(tabPaneCounter.sortByColumn({ 53 key: 'number', 54 sort: () => { 55 } 56 })).toBeUndefined(); 57 }); 58 59 it('TabPaneCounterTest04', function () { 60 let mockgetTabCounters = sqlit.getTabCounters 61 mockgetTabCounters.mockResolvedValue( 62 {trackId : 11, 63 name: "test", 64 value:111, 65 startTime:142445, 66 },{trackId : 11, 67 name: "test", 68 value:222, 69 startTime:142446, 70 }) 71 let a = {rightNs: 1, trackIds: [11, 12, 13]} 72 expect(tabPaneCounter.data = a).toBeTruthy(); 73 }); 74 75 it('TabPaneCounterTest05', function () { 76 let mockgetTabCounters = sqlit.getTabCounters 77 mockgetTabCounters.mockResolvedValue([] 78 ) 79 let a = {rightNs: 1, trackIds: [11, 12, 13]} 80 expect(tabPaneCounter.data = a).toBeTruthy(); 81 }); 82 83 it('TabPaneCounterTest06', function () { 84 expect(tabPaneCounter.initHtml()).toMatchInlineSnapshot(` 85" 86 <style> 87 :host{ 88 display: flex; 89 flex-direction: column; 90 padding: 10px 10px; 91 } 92 </style> 93 <label id=\\"time-range\\" style=\\"width: 100%;height: 20px;text-align: end;font-size: 10pt;margin-bottom: 5px\\">Selected range:0.0 ms</label> 94 <lit-table id=\\"tb-counter\\" style=\\"height: auto\\"> 95 <lit-table-column width=\\"25%\\" title=\\"Name\\" data-index=\\"name\\" key=\\"name\\" align=\\"flex-start\\" order> 96 </lit-table-column> 97 <lit-table-column width=\\"1fr\\" title=\\"Delta value\\" data-index=\\"delta\\" key=\\"delta\\" align=\\"flex-start\\" order > 98 </lit-table-column> 99 <lit-table-column width=\\"1fr\\" title=\\"Rate /s\\" data-index=\\"rate\\" key=\\"rate\\" align=\\"flex-start\\" order > 100 </lit-table-column> 101 <lit-table-column width=\\"1fr\\" title=\\"Weighted avg value\\" data-index=\\"avgWeight\\" key=\\"avgWeight\\" align=\\"flex-start\\" order > 102 </lit-table-column> 103 <lit-table-column width=\\"1fr\\" title=\\"Count\\" data-index=\\"count\\" key=\\"count\\" align=\\"flex-start\\" order > 104 </lit-table-column> 105 <lit-table-column width=\\"1fr\\" title=\\"First value\\" data-index=\\"first\\" key=\\"first\\" align=\\"flex-start\\" order > 106 </lit-table-column> 107 <lit-table-column width=\\"1fr\\" title=\\"Last value\\" data-index=\\"last\\" key=\\"last\\" align=\\"flex-start\\" order > 108 </lit-table-column> 109 <lit-table-column width=\\"1fr\\" title=\\"Min value\\" data-index=\\"min\\" key=\\"min\\" align=\\"flex-start\\" order > 110 </lit-table-column> 111 <lit-table-column width=\\"1fr\\" title=\\"Max value\\" data-index=\\"max\\" key=\\"max\\" align=\\"flex-start\\" order > 112 </lit-table-column> 113 </lit-table> 114 " 115`); 116 }); 117}) 118