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 {SpSdkChart} from "../../../../dist/trace/component/chart/SpSdkChart.js" 18const sqlit = require("../../../../dist/trace/database/SqlLite.js") 19jest.mock("../../../../dist/trace/database/SqlLite.js"); 20 21window.ResizeObserver = window.ResizeObserver || jest.fn().mockImplementation(() => ({ 22 disconnect: jest.fn(), 23 observe: jest.fn(), 24 unobserve: jest.fn(), 25})); 26 27describe('SpSdkChart Test', ()=> { 28 let spSdkChart = new SpSdkChart(); 29 let MockStartTime = sqlit.queryStartTime; 30 MockStartTime.mockResolvedValue([{ 31 start_ts:0 32 }]) 33 it('SpSdkChartTest01', function () { 34 let showType = { 35 columns:[{showType: 'counter'}] 36 } 37 expect(spSdkChart.getTableType(showType)).toBe(""); 38 }); 39 40 it('SpSdkChartTest02', function () { 41 expect(spSdkChart.createSliceSql(10,8,[{length:5}],"")).toBe("select undefined from 8 "); 42 }); 43 44 it('SpSdkChartTest03', function () { 45 expect(spSdkChart.createMaxValueSql("","")).toBe("select max(value) as max_value from "); 46 }); 47 48 it('SpSdkChartTest04', function () { 49 expect(spSdkChart.createMaxValueSql("a","c")).toBe("select max(value) as max_value from a c"); 50 }); 51 52 it('SpSdkChartTest06', function () { 53 expect(spSdkChart.createSql(3,"c",[{length:3}],"a")).toBe("select undefined from c a"); 54 }); 55 56 it('SpSdkChartTest07', function () { 57 expect(spSdkChart.createSql(0,"c",[{length:3}],"")).toBe("select undefined from c "); 58 }); 59 60 it('SpSdkChartTest08', function () { 61 spSdkChart.init() 62 expect(spSdkChart).toBeDefined(); 63 }); 64 65 it('SpSdkChartTest09', function () { 66 let showType = { 67 columns:[{showType: 'slice'}] 68 } 69 expect(spSdkChart.getTableType(showType)).toBe(""); 70 }); 71 72})