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 { TabPaneSdkCounter } from '../../../../../../src/trace/component/trace/sheet/sdk/TabPaneSdkCounter'; 17import '../../../../../../src/trace/component/trace/sheet/sdk/TabPaneSdkCounter'; 18import { SpSystemTrace } from '../../../../../../src/trace/component/SpSystemTrace'; 19 20import { LitTable } from '../../../../../../src/base-ui/table/lit-table'; 21import {TabUtil} from "../../../../../../src/trace/component/trace/sheet/sdk/TabUtil.js"; 22 23window.ResizeObserver = 24 window.ResizeObserver || 25 jest.fn().mockImplementation(() => ({ 26 disconnect: jest.fn(), 27 observe: jest.fn(), 28 unobserve: jest.fn(), 29 })); 30 31const sqlite = require('../../../../../../src/trace/database/SqlLite'); 32jest.mock('../../../../../../src/trace/database/SqlLite'); 33 34describe('TabPaneSdkCounter Test', () => { 35 document.body.innerHTML = `<lit-table id="tb-counter"></lit-table>`; 36 let litTable = document.querySelector('#tb-counter') as LitTable; 37 it('TabPaneSdkCounterTest00', () => { 38 let tabPaneSdkCounter = new TabPaneSdkCounter(); 39 tabPaneSdkCounter.tblSdkCounter = jest.fn(() => litTable); 40 let a = new Map(); 41 let jsonCofigStr = 42 '{"settingConfig":{"configuration":{"counters":{"enum":["ARM_Mali-TTRx_JS1_ACTIVE","ARM_Mali-TTRx_JS0_ACTIVE","ARM_Mali-TTRx_GPU_ACTIVE","ARM_Mali-TTRx_FRAG_ACTIVE"],\n' + 43 ' "type":"string"},"stop_gator":{"default":"true","description":"stop_gator","type":"boolean"},"version":{"default":"1","description":"gatordversion","type":"number"}},"name":"mailG77"},\n' + 44 ' "tableConfig":{"showType":[{"columns":[{"column":"ts","displayName":"TimeStamp","showType":[1,3],"type":"INTEGER"},{"column":"counter_id","displayName":"MonitorValue","showType":[1,3],"type":"INTEGER"},\n' + 45 ' {"column":"value","displayName":"Value","showType":[1,3],"type":"INTEGER"}],"inner":{"columns":[{"column":"counter_name","displayName":"","showType":[0],"type":"STRING"},\n' + 46 ' {"column":"counter_id","displayName":"","showType":[0],"type":"INTEGER"}],"tableName":"mock_plugin_counterobj_table"},"tableName":"mock_plugin_counter_table"},\n' + 47 ' {"columns":[{"column":"start_ts","displayName":"startts","showType":[2,3],"type":"INTEGER"},{"column":"end_ts","displayName":"endts","showType":[2,3],"type":"INTEGER"},\n' + 48 ' {"column":"slice_id","displayName":"slice_id","showType":[2,3],"type":"INTEGER"},{"column":"value","displayName":"Value","showType":[2,3],"type":"INTEGER"}],\n' + 49 ' "inner":{"columns":[{"column":"slice_name","displayName":"","showType":[0],"type":"STRING"},{"column":"slice_id","displayName":"","showType":[0],"type":"INTEGER"}],\n' + 50 ' "tableName":"mock_plugin_sliceobj_table"},"tableName":"mock_plugin_slice_table"}]}}'; 51 let datamap = { 52 jsonConfig: jsonCofigStr, 53 disPlayName: 'common_mock', 54 pluginName: 'mock-plugin', 55 }; 56 a.set(1, datamap); 57 SpSystemTrace.SDK_CONFIG_MAP = a; 58 let startTime = sqlite.queryStartTime; 59 let dataTime: Array<any> = [ 60 { 61 start_ts: 1000, 62 }, 63 ]; 64 startTime.mockResolvedValue(dataTime); 65 66 let tabSdkCounterLeftData = sqlite.getTabSdkCounterLeftData; 67 let data = [ 68 { 69 max_value: 1000, 70 }, 71 { 72 max_value: 2000, 73 }, 74 { 75 max_value: 3000, 76 }, 77 ]; 78 tabSdkCounterLeftData.mockResolvedValue(data); 79 80 let tabSdkCounterData = sqlite.getTabSdkCounterData; 81 let counter = [ 82 { 83 ts: 1000, 84 counter_id: 0, 85 value: 100, 86 }, 87 { 88 ts: 2000, 89 counter_id: 0, 90 value: 100, 91 }, 92 { 93 ts: 3000, 94 counter_id: 0, 95 value: 100, 96 }, 97 { 98 ts: 4000, 99 counter_id: 0, 100 value: 100, 101 }, 102 { 103 ts: 5000, 104 counter_id: 0, 105 value: 100, 106 }, 107 ]; 108 tabSdkCounterData.mockResolvedValue(counter); 109 110 let d = { 111 cpus: [45,1], 112 threadIds: [], 113 trackIds: [45,1,22], 114 funTids: [], 115 heapIds: [78,7], 116 nativeMemory: [], 117 cpuAbilityIds: [41,1], 118 memoryAbilityIds: [], 119 diskAbilityIds: [45,5], 120 networkAbilityIds: [], 121 leftNs: 23, 122 rightNs: 67, 123 hasFps: false, 124 statisticsSelectData: [], 125 perfSampleIds: [145,56,6], 126 perfCpus: [3], 127 perfProcess: [], 128 perfThread: [], 129 perfAll: false, 130 sdkCounterIds: ['a-1', 'b-1', 'd-1'], 131 }; 132 tabPaneSdkCounter.tblSdkCounter.recycleDataSource = jest.fn(() => d); 133 tabPaneSdkCounter.tblSdkCounter.appendChild = jest.fn(() => true); 134 tabPaneSdkCounter.data = d; 135 expect(tabPaneSdkCounter.data).toBeUndefined(); 136 }); 137 138 it('TabPaneSdkCounterTest01', () => { 139 let tabPaneSdkCounter = new TabPaneSdkCounter(); 140 expect(tabPaneSdkCounter.parseJson(new Map())).toBe(''); 141 }); 142 143 it('TabPaneSdkCounterTest02', () => { 144 let tabPaneSdkCounter = new TabPaneSdkCounter(); 145 let type = { 146 columns: [{ showType: 'counter' }], 147 }; 148 expect(TabUtil.getTableType(type)).toBe(''); 149 }); 150 151 it('TabPaneSdkCounterTest03', () => { 152 let tabPaneSdkCounter = new TabPaneSdkCounter(); 153 expect(tabPaneSdkCounter.initDataElement()).toBeUndefined(); 154 }); 155 156 157 it('TabPaneSdkCounterTest04', function () { 158 let tabPaneSdkCounter = new TabPaneSdkCounter(); 159 tabPaneSdkCounter.tblSdkCounter = jest.fn(() => true); 160 tabPaneSdkCounter.tblSdkCounter!.recycleDataSource = jest.fn(() => true); 161 expect( 162 tabPaneSdkCounter.sortByColumn({ 163 key: '', 164 sort: '', 165 }) 166 ).toBeUndefined(); 167 }); 168}); 169