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