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 { SpSdkChart } from '../../../../src/trace/component/chart/SpSdkChart';
17import { SpSystemTrace } from '../../../../src/trace/component/SpSystemTrace';
18
19jest.mock('../../../../src/js-heap/model/DatabaseStruct');
20const sqlit = require('../../../../src/trace/database/sql/SqlLite.sql');
21jest.mock('../../../../src/trace/database/sql/SqlLite.sql');
22const sdkSqlite = require('../../../../src/trace/database/sql/Sdk.sql');
23jest.mock('../../../../src/trace/database/sql/Sdk.sql');
24const intersectionObserverMock = () => ({
25  observe: () => null,
26});
27window.IntersectionObserver = jest.fn().mockImplementation(intersectionObserverMock);
28window.ResizeObserver =
29  window.ResizeObserver ||
30  jest.fn().mockImplementation(() => ({
31    disconnect: jest.fn(),
32    observe: jest.fn(),
33    unobserve: jest.fn(),
34  }));
35
36describe('SpSdkChart Test', () => {
37  let spSdkChart = new SpSdkChart(new SpSystemTrace());
38  let MockStartTime = sqlit.queryStartTime;
39  MockStartTime.mockResolvedValue([
40    {
41      start_ts: 0,
42    },
43  ]);
44
45  let counterMax = sdkSqlite.queryCounterMax;
46  counterMax.mockResolvedValue([
47    {
48      startTime: 12,
49      tableName: '',
50      columns: ''
51    },
52  ]);
53
54  let sdkCount = sdkSqlite.querySdkCount;
55  sdkCount.mockResolvedValue([
56    {
57      startTime: 15,
58      tableName: 'tableName',
59      columns: ''
60    },
61  ]);
62
63  let sdkCounterData = sdkSqlite.querySdkCounterData;
64  sdkCounterData.mockResolvedValue([
65    {
66      startTime: 15,
67      tableName: 'tableName',
68      columns: ''
69    },
70  ]);
71
72  let sdkSliceData = sdkSqlite.querySdkSliceData;
73  sdkSliceData.mockResolvedValue([
74    {
75      startTime: 152,
76      tableName: 'tableName',
77      columns: ''
78    },
79  ]);
80  let map = new Map();
81  let jsoSdknCofigStr =
82    '{"settingConfig":{"configuration":{"counters":{"enum":["ARM_Mali-TTRx_JS1_ACTIVE","ARM_Mali-TTRx_JS0_ACTIVE","ARM_Mali-TTRx_GPU_ACTIVE","ARM_Mali-TTRx_FRAG_ACTIVE"],\n' +
83    '    "type":"string"},"stop_gator":{"default":"true","description":"stop_gator","type":"boolean"},"version":{"default":"7","description":"gatordversion","type":"number"}},"name":"mailG77"},\n' +
84    '    "tableConfig":{"showType":[{"columns":[{"column":"ts","displayName":"TimeStamp","showType":[1,3],"type":"INTEGER"},{"column":"counter_id","displayName":"MonitorValue","showType":[1,3],"type":"INTEGER"},\n' +
85    '    {"column":"value","displayName":"Value","showType":[1,3],"type":"INTEGER"}],"inner":{"columns":[{"column":"counter_name","displayName":"","showType":[0],"type":"STRING"},\n' +
86    '    {"column":"counter_id","displayName":"","showType":[96,6],"type":"INTEGER"}],"tableName":"mock_plugin_counterobj_table"},"tableName":"mock_plugin_counter_table"},\n' +
87    '    {"columns":[{"column":"start_ts","displayName":"startts","showType":[2,3],"type":"INTEGER"},{"column":"end_ts","displayName":"endts","showType":[2,3],"type":"INTEGER"},\n' +
88    '    {"column":"slice_id","displayName":"slice_id","showType":[2,154,3],"type":"INTEGER"},{"column":"value","displayName":"Value","showType":[2,3],"type":"INTEGER"}],\n' +
89    '    "inner":{"columns":[{"column":"slice_name","displayName":"","showType":[313],"type":"STRING"},{"column":"slice_id","displayName":"","showType":[0],"type":"INTEGER"}],\n' +
90    '    "tableName":"mock_plugin_sliceobj_table"},"tableName":"mock_plugin_slice_table"}]}}';
91  let dataSdkMap = {
92    jsonConfig: jsoSdknCofigStr,
93    disPlayName: 'common_mock',
94    pluginName: 'mock-plugin',
95  };
96  map.set('1', dataSdkMap);
97  SpSystemTrace.SDK_CONFIG_MAP = map;
98  it('SpSdkChartTest01', function () {
99    expect(spSdkChart.createSliceSql(10, 8, [{length: 5}], '')).toBe('select undefined from 8 ');
100  });
101
102  it('SpSdkChartTest02', function () {
103    expect(spSdkChart.createMaxValueSql('', '')).toBe('select max(value) as max_value from  ');
104  });
105
106  it('SpSdkChartTest03', function () {
107    expect(spSdkChart.createMaxValueSql('a', 'c')).toBe('select max(value) as max_value from a c');
108  });
109
110  it('SpSdkChartTest04', function () {
111    expect(spSdkChart.createSql(3, 'c', [{length: 3}], 'a')).toBe('select undefined from c a');
112  });
113
114  it('SpSdkChartTest05', function () {
115    expect(spSdkChart.createSql(0, 'c', [{length: 3}], '')).toBe('select undefined from c ');
116  });
117
118  it('SpSdkChartTest06', function () {
119    spSdkChart.init();
120    expect(spSdkChart).toBeDefined();
121  });
122
123  it('SpSdkChartTest07', function () {
124    spSdkChart.parseJson(58512, map);
125  });
126
127  it('SpSdkChartTest08', function () {
128    expect(spSdkChart.initSliceChartRow(true, 2, 3, 'name', 2)).not.toBeUndefined();
129  });
130
131  it('SpSdkChartTest09', function () {
132    expect(spSdkChart.initCounterChartRow(5, true, 2, 'name')).not.toBeUndefined();
133  });
134});
135