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 {SpAbilityMonitorChart} from "../../../../dist/trace/component/chart/SpAbilityMonitorChart.js"; 18import "../../../../dist/trace/component/chart/SpAbilityMonitorChart.js"; 19// @ts-ignore 20import {SpSystemTrace} from "../../../../dist/trace/component/SpSystemTrace.js"; 21import { 22 queryCPuAbilityMaxData, 23 queryMemoryMaxData, 24 queryNetWorkMaxData 25} from "../../../../src/trace/database/SqlLite.js"; 26const sqlit = require("../../../../dist/trace/database/SqlLite.js") 27jest.mock("../../../../dist/trace/database/SqlLite.js"); 28 29window.ResizeObserver = window.ResizeObserver || 30 jest.fn().mockImplementation(() => ({ 31 disconnect: jest.fn(), 32 observe: jest.fn(), 33 unobserve: jest.fn(), 34 })); 35describe('SpAbilityMonitorChart Test', () => { 36 let MockqueryAbilityExits = sqlit.queryAbilityExits; 37 MockqueryAbilityExits.mockResolvedValue([ 38 { 39 event_name: "trace_cpu_usage", 40 stat_type: "received", 41 count: 1 42 }, 43 { 44 event_name: "sys_memory", 45 stat_type: "received", 46 count: 1 47 }, 48 { 49 event_name: "trace_diskio", 50 stat_type: "received", 51 count: 1 52 }, 53 { 54 event_name: "trace_diskio", 55 stat_type: "received", 56 count: 1 57 } 58 ]) 59 let cpudata = sqlit.queryCPuAbilityMaxData; 60 cpudata.mockResolvedValue([{ 61 totalLoad: 1, 62 userLoad: 1, 63 systemLoad: 1 64 }]) 65 let memorydata = sqlit.queryMemoryMaxData; 66 memorydata.mockResolvedValue([{ 67 maxValue: 1, 68 filter_id: 1 69 }]) 70 71 let queryDiskIo = sqlit.queryDiskIoMaxData; 72 queryDiskIo.mockResolvedValue([{ 73 bytesRead: 1, 74 bytesWrite: 1, 75 readOps: 1, 76 writeOps:1 77 }]) 78 79 let netWorkDiskIo = sqlit.queryNetWorkMaxData; 80 netWorkDiskIo.mockResolvedValue([{ 81 maxIn: 1, 82 maxOut: 1, 83 maxPacketIn: 1, 84 maxPacketOut:1 85 }]) 86 let spSystemTrace = new SpSystemTrace(); 87 let trace = new SpAbilityMonitorChart(spSystemTrace); 88 it('SpAbilityMonitorChart01', function () { 89 trace.init() 90 expect(trace).toBeDefined(); 91 }); 92 93})