• 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';
18const sqlit = require('../../../../src/trace/database/SqlLite');
19jest.mock('../../../../src/trace/database/SqlLite');
20
21window.ResizeObserver =
22  window.ResizeObserver ||
23  jest.fn().mockImplementation(() => ({
24    disconnect: jest.fn(),
25    observe: jest.fn(),
26    unobserve: jest.fn(),
27  }));
28
29describe('SpSdkChart Test', () => {
30  let spSdkChart = new SpSdkChart();
31  let MockStartTime = sqlit.queryStartTime;
32  MockStartTime.mockResolvedValue([
33    {
34      start_ts: 0,
35    },
36  ]);
37  it('SpSdkChartTest01', function () {
38    expect(spSdkChart.createSliceSql(10, 8, [{ length: 5 }], '')).toBe('select undefined from 8 ');
39  });
40
41  it('SpSdkChartTest02', function () {
42    expect(spSdkChart.createMaxValueSql('', '')).toBe('select max(value) as max_value from  ');
43  });
44
45  it('SpSdkChartTest03', function () {
46    expect(spSdkChart.createMaxValueSql('a', 'c')).toBe('select max(value) as max_value from a c');
47  });
48
49  it('SpSdkChartTest04', function () {
50    expect(spSdkChart.createSql(3, 'c', [{ length: 3 }], 'a')).toBe('select undefined from c a');
51  });
52
53  it('SpSdkChartTest05', function () {
54    expect(spSdkChart.createSql(0, 'c', [{ length: 3 }], '')).toBe('select undefined from c ');
55  });
56
57  it('SpSdkChartTest06', function () {
58    spSdkChart.init();
59    expect(spSdkChart).toBeDefined();
60  });
61
62  it('SpSdkChartTest07', function () {
63    let spSystemTrace = new SpSdkChart();
64    let sdkChart = new SpSdkChart(spSystemTrace);
65    let map = new Map();
66    let jsoSdknCofigStr =
67      '{"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' +
68      '    "type":"string"},"stop_gator":{"default":"true","description":"stop_gator","type":"boolean"},"version":{"default":"7","description":"gatordversion","type":"number"}},"name":"mailG77"},\n' +
69      '    "tableConfig":{"showType":[{"columns":[{"column":"ts","displayName":"TimeStamp","showType":[1,3],"type":"INTEGER"},{"column":"counter_id","displayName":"MonitorValue","showType":[1,3],"type":"INTEGER"},\n' +
70      '    {"column":"value","displayName":"Value","showType":[1,3],"type":"INTEGER"}],"inner":{"columns":[{"column":"counter_name","displayName":"","showType":[0],"type":"STRING"},\n' +
71      '    {"column":"counter_id","displayName":"","showType":[96,6],"type":"INTEGER"}],"tableName":"mock_plugin_counterobj_table"},"tableName":"mock_plugin_counter_table"},\n' +
72      '    {"columns":[{"column":"start_ts","displayName":"startts","showType":[2,3],"type":"INTEGER"},{"column":"end_ts","displayName":"endts","showType":[2,3],"type":"INTEGER"},\n' +
73      '    {"column":"slice_id","displayName":"slice_id","showType":[2,154,3],"type":"INTEGER"},{"column":"value","displayName":"Value","showType":[2,3],"type":"INTEGER"}],\n' +
74      '    "inner":{"columns":[{"column":"slice_name","displayName":"","showType":[313],"type":"STRING"},{"column":"slice_id","displayName":"","showType":[0],"type":"INTEGER"}],\n' +
75      '    "tableName":"mock_plugin_sliceobj_table"},"tableName":"mock_plugin_slice_table"}]}}';
76    let dataSdkMap = {
77      jsonConfig: jsoSdknCofigStr,
78      disPlayName: 'common_mock',
79      pluginName: 'mock-plugin',
80    };
81    map.set('1', dataSdkMap);
82    SpSystemTrace.SDK_CONFIG_MAP = map;
83    sdkChart.parseJson(58512, map);
84  });
85});
86