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