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 { SpQuerySQL } from '../../../dist/trace/component/SpQuerySQL.js'; 18// @ts-ignore 19import { queryCustomizeSelect } from '../../../dist/trace/database/SqlLite.js'; 20// @ts-ignore 21import { SpStatisticsHttpUtil } from '../../../dist/statistics/util/SpStatisticsHttpUtil.js'; 22const sqlite = require('../../../dist/trace/database/SqlLite.js'); 23jest.mock('../../../dist/trace/database/SqlLite.js'); 24 25window.ResizeObserver = window.ResizeObserver || jest.fn().mockImplementation(() => ({ 26 disconnect: jest.fn(), 27 observe: jest.fn(), 28 unobserve: jest.fn(), 29})); 30 31SpStatisticsHttpUtil.addOrdinaryVisitAction = jest.fn(() => true); 32describe('SpQuerySQL Test', () => { 33 let spQuerySQL = new SpQuerySQL(); 34 35 it('SpQuerySQLTest01', function () { 36 expect(spQuerySQL.checkSafetySelectSql()).toBeFalsy(); 37 }); 38 39 it('SpQuerySQLTest02', function () { 40 expect(spQuerySQL.initDataElement()).toBeUndefined(); 41 }); 42 43 it('SpQuerySQLTest03', function () { 44 expect(spQuerySQL.attributeChangedCallback()).toBeUndefined(); 45 }); 46 47 it('SpQuerySQLTest005', function () { 48 expect(spQuerySQL.freshTableHeadResizeStyle()).toBeUndefined(); 49 }); 50 51 it('SpQuerySQLTest06', function () { 52 expect(spQuerySQL.reset()).toBeUndefined(); 53 }); 54 55 it('SpQuerySQLTest007', function () { 56 expect(spQuerySQL.initDataElement()).toBeUndefined(); 57 }); 58 59 it('SpQuerySQLTest008', function () { 60 expect(spQuerySQL.connectedCallback()).toBeUndefined(); 61 }); 62 63 it('SpQuerySQLTest009', function () { 64 expect(spQuerySQL.disconnectedCallback()).toBeUndefined(); 65 }); 66 67 it('SpQuerySQLTest010', function () { 68 expect(spQuerySQL.attributeChangedCallback('', '', '')).toBeUndefined(); 69 }); 70 71 it('SpQuerySQLTest011', function () { 72 document.body.innerHTML = ` 73 <sp-query-sql id="query-sql"></sp-query-sql> 74 `; 75 let spQuerySql = document.getElementById('query-sql') as SpQuerySQL; 76 spQuerySql.queryStr = 'select * from trace_range'; 77 let range = sqlite.queryCustomizeSelect; 78 let dataTime: Array<any> = [ 79 { 80 start_ts: 1000, 81 end_ts: 12000, 82 }, 83 ]; 84 range.mockResolvedValue(dataTime); 85 let keyboardEvent: KeyboardEvent = new KeyboardEvent('keydown', <KeyboardEventInit>{ ctrlKey: true, keyCode: 13 }); 86 spQuerySql.dispatchEvent(keyboardEvent); 87 expect(spQuerySQL.attributeChangedCallback('', '', '')).toBeUndefined(); 88 }); 89}); 90