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