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// @ts-ignore 16window.ResizeObserver = window.ResizeObserver || 17 jest.fn().mockImplementation(() => ({ 18 disconnect: jest.fn(), observe: jest.fn(), unobserve: jest.fn(), 19 })); 20// @ts-ignore 21import { SpVirtualMemChart } from '../../../../dist/trace/component/chart/SpVirtualMemChart.js'; 22// @ts-ignore 23import { SpSystemTrace } from '../../../../dist/trace/component/SpSystemTrace.js'; 24// @ts-ignore 25import { TraceRow } from '../../../../dist/trace/component/trace/base/TraceRow.js'; 26// @ts-ignore 27import { SpChartManager } from '../../../../dist/trace/component/chart/SpChartManager.js'; 28 29jest.mock('../../../../dist/trace/database/ui-worker/ProcedureWorker.js', () => { 30 return {}; 31}); 32window.IntersectionObserver = jest.fn().mockImplementation(intersectionObserverMock); 33const sqlit = require('../../../../dist/trace/database/SqlLite.js'); 34jest.mock('../../../../dist/trace/database/SqlLite.js'); 35const intersectionObserverMock = () => ({ 36 observe: () => null, 37}); 38 39describe('SpVirtualMemChart Test', () => { 40 let manager = new SpChartManager(); 41 let spVirtualMemChart = new SpVirtualMemChart(manager); 42 let MockVirtualMemory = sqlit.queryVirtualMemory; 43 MockVirtualMemory.mockResolvedValue([ 44 { 45 id: 0, 46 name: 'name', 47 }, 48 ]); 49 50 let MockVirtualMemoryData = sqlit.queryVirtualMemoryData; 51 MockVirtualMemoryData.mockResolvedValue([ 52 { 53 startTime: 0, 54 value: 20, 55 filterID: 0, 56 }, 57 ]); 58 59 it('SpVirtualMemChart01', function () { 60 spVirtualMemChart.init(); 61 expect(spVirtualMemChart).toBeDefined(); 62 }); 63 64 it('SpVirtualMemChart02', function () { 65 let folder = new TraceRow({ 66 canvasNumber: 1, 67 alpha: false, 68 contextId: '2d', 69 isOffScreen: SpSystemTrace.isCanvasOffScreen, 70 }); 71 spVirtualMemChart.initVirtualMemoryRow(folder, 2, 'name', 2); 72 expect(spVirtualMemChart).toBeDefined(); 73 }); 74}); 75