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