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 { TabPaneFileStatistics } from '../../../../../../src/trace/component/trace/sheet/file-system/TabPaneFilesystemStatistics'; 17import '../../../../../../src/trace/component/trace/sheet/file-system/TabPaneFilesystemStatistics'; 18import { Utils } from '../../../../../../src/trace/component/trace/base/Utils'; 19import '../../../../../../src/trace/component/trace/base/Utils'; 20 21import crypto from 'crypto'; 22import { LitTable } from '../../../../../../src/base-ui/table/lit-table'; 23 24import '../../../../../../src/base-ui/table/lit-table'; 25import { TabPaneFilter } from '../../../../../../src/trace/component/trace/sheet/TabPaneFilter'; 26import '../../../../../../src/trace/component/trace/sheet/TabPaneFilter'; 27const sqlit = require('../../../../../../src/trace/database/sql/SqlLite.sql'); 28jest.mock('../../../../../../src/trace/database/sql/SqlLite.sql'); 29Object.defineProperty(global.self, 'crypto', { 30 value: { 31 getRandomValues: (arr: string | any[]) => crypto.randomBytes(arr.length), 32 }, 33}); 34// @ts-ignore 35window.ResizeObserver = 36 window.ResizeObserver || 37 jest.fn().mockImplementation(() => ({ 38 disconnect: jest.fn(), 39 observe: jest.fn(), 40 unobserve: jest.fn(), 41 })); 42 43describe('TabPaneFileStatistics Test', () => { 44 document.body.innerHTML = `<div><tabpane-file-statistics id="statistics"></tabpane-file-statistics></div>`; 45 let tabPaneFileStatistics = document.querySelector<TabPaneFileStatistics>('#statistics'); 46 let param = { 47 anomalyEnergy: [], 48 clockMapData: { size: 50 }, 49 cpuAbilityIds: [23, 25], 50 cpuFreqFilterIds: [34, 66], 51 cpuFreqLimitDatas: [], 52 cpuStateFilterIds: [77, 96], 53 cpus: [0], 54 diskAbilityIds: [10, 34], 55 diskIOLatency: false, 56 diskIOReadIds: [2, 11, 4, 12], 57 diskIOWriteIds: [2, 54, 64], 58 diskIOipids: [25, 7, 58, 6], 59 fileSysVirtualMemory: true, 60 fileSystemType: [], 61 fsCount: 30, 62 funAsync: [], 63 funTids: [45, 22], 64 hasFps: false, 65 irqMapData: { size: 32 }, 66 jsMemory: [], 67 leftNs: 964667689, 68 memoryAbilityIds: [23, 78, 9], 69 nativeMemory: [], 70 nativeMemoryStatistic: [], 71 networkAbilityIds: [10, 154, 55], 72 perfAll: false, 73 perfCpus: [1], 74 perfProcess: [], 75 perfSampleIds: [233, 120, 4], 76 perfThread: [], 77 powerEnergy: [], 78 processTrackIds: [34, 21], 79 promiseList: [], 80 recordStartNs: 780423722428, 81 rightNs: 33236556624, 82 sdkCounterIds: [12, 56], 83 sdkSliceIds: [45, 98], 84 smapsType: [], 85 systemEnergy: [], 86 threadIds: [88, 12], 87 virtualTrackIds: [34, 87], 88 vmCount: 31, 89 }; 90 91 it('TabPaneFileStatisticsTest01', function () { 92 tabPaneFileStatistics.setInitDua = jest.fn(() => true); 93 let item = { 94 allDuration: '', 95 minDuration: '', 96 avgDuration: '', 97 maxDuration: '', 98 }; 99 expect(tabPaneFileStatistics.setInitDua(item)).toBeTruthy(); 100 }); 101 102 it('TabPaneFileStatisticsTest02', function () { 103 tabPaneFileStatistics.getInitData = jest.fn(() => true); 104 let item = { 105 allDuration: '', 106 minDuration: '', 107 avgDuration: '', 108 maxDuration: '', 109 }; 110 expect(tabPaneFileStatistics.getInitData(item)).toBeTruthy(); 111 }); 112 113 it('TabPaneFileStatisticsTest04', function () { 114 tabPaneFileStatistics.showButtomMenu = jest.fn(() => true); 115 let isShow = { 116 filter: { 117 setAttribute: 'tree, input, inputLeftText', 118 }, 119 }; 120 expect(tabPaneFileStatistics.showButtomMenu(isShow)).toBeTruthy(); 121 }); 122 123 it('TabPaneFileStatisticsTest08', function () { 124 let FileStatistics = new TabPaneFileStatistics(); 125 let item = { 126 allDuration: '', 127 minDuration: '', 128 avgDuration: '', 129 maxDuration: '', 130 name: 'as', 131 logicalWrites: '', 132 logicalReads: '', 133 otherFile: '0 Bytes', 134 pid: 1, 135 }; 136 Utils.getBinaryByteWithUnit = jest.fn(() => true); 137 expect(FileStatistics.getInitData(item)).toEqual({ 138 allDuration: '', 139 avgDuration: '', 140 logicalReads: true, 141 logicalWrites: true, 142 maxDuration: '', 143 minDuration: '', 144 name: 'as', 145 node: { 146 allDuration: '', 147 avgDuration: '', 148 children: [], 149 logicalReads: '', 150 logicalWrites: '', 151 maxDuration: '', 152 minDuration: '', 153 name: 'as', 154 otherFile: '0 Bytes', 155 pid: 1, 156 }, 157 otherFile: true, 158 pid: 1, 159 title: 'as(1)', 160 }); 161 }); 162 163 it('TabPaneFileStatisticsTest09', function () { 164 let FileStatistics = new TabPaneFileStatistics(); 165 let node = { 166 children: [], 167 }; 168 expect(FileStatistics.sortTable(node, '')).toBeUndefined(); 169 }); 170 it('TabPaneFileStatisticsTest10', function () { 171 let FileStatistics = new TabPaneFileStatistics(); 172 let tabPaneFilesystemStatistics = sqlit.getTabPaneFilesystemStatistics; 173 let result = [ 174 { 175 pid: 1, 176 name: '', 177 type: 1, 178 count: 34, 179 size: 22, 180 logicalReads: 32, 181 logicalWrites: 12, 182 otherFile: 55, 183 allDuration: 12, 184 minDuration: 1, 185 maxDuration: 7, 186 avgDuration: 2, 187 }, 188 ]; 189 FileStatistics.fileStatisticsTbl = jest.fn(() => true); 190 FileStatistics.fileStatisticsTbl.recycleDataSource = jest.fn(() => true); 191 tabPaneFilesystemStatistics.mockResolvedValue(result); 192 expect(FileStatistics.queryDataByDB(param)).toBeUndefined(); 193 }); 194}); 195