1fb726d48Sopenharmony_ci/* 2fb726d48Sopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd. 3fb726d48Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4fb726d48Sopenharmony_ci * you may not use this file except in compliance with the License. 5fb726d48Sopenharmony_ci * You may obtain a copy of the License at 6fb726d48Sopenharmony_ci * 7fb726d48Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8fb726d48Sopenharmony_ci * 9fb726d48Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10fb726d48Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11fb726d48Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12fb726d48Sopenharmony_ci * See the License for the specific language governing permissions and 13fb726d48Sopenharmony_ci * limitations under the License. 14fb726d48Sopenharmony_ci */ 15fb726d48Sopenharmony_ci 16fb726d48Sopenharmony_ciimport { SpSdkChart } from '../../../../src/trace/component/chart/SpSdkChart'; 17fb726d48Sopenharmony_ciimport { SpSystemTrace } from '../../../../src/trace/component/SpSystemTrace'; 18fb726d48Sopenharmony_ci 19fb726d48Sopenharmony_cijest.mock('../../../../src/js-heap/model/DatabaseStruct'); 20fb726d48Sopenharmony_ciconst sqlit = require('../../../../src/trace/database/sql/SqlLite.sql'); 21fb726d48Sopenharmony_cijest.mock('../../../../src/trace/database/sql/SqlLite.sql'); 22fb726d48Sopenharmony_ciconst sdkSqlite = require('../../../../src/trace/database/sql/Sdk.sql'); 23fb726d48Sopenharmony_cijest.mock('../../../../src/trace/database/sql/Sdk.sql'); 24fb726d48Sopenharmony_ciconst intersectionObserverMock = () => ({ 25fb726d48Sopenharmony_ci observe: () => null, 26fb726d48Sopenharmony_ci}); 27fb726d48Sopenharmony_ciwindow.IntersectionObserver = jest.fn().mockImplementation(intersectionObserverMock); 28fb726d48Sopenharmony_ciwindow.ResizeObserver = 29fb726d48Sopenharmony_ci window.ResizeObserver || 30fb726d48Sopenharmony_ci jest.fn().mockImplementation(() => ({ 31fb726d48Sopenharmony_ci disconnect: jest.fn(), 32fb726d48Sopenharmony_ci observe: jest.fn(), 33fb726d48Sopenharmony_ci unobserve: jest.fn(), 34fb726d48Sopenharmony_ci })); 35fb726d48Sopenharmony_ci 36fb726d48Sopenharmony_cidescribe('SpSdkChart Test', () => { 37fb726d48Sopenharmony_ci let spSdkChart = new SpSdkChart(new SpSystemTrace()); 38fb726d48Sopenharmony_ci let MockStartTime = sqlit.queryStartTime; 39fb726d48Sopenharmony_ci MockStartTime.mockResolvedValue([ 40fb726d48Sopenharmony_ci { 41fb726d48Sopenharmony_ci start_ts: 0, 42fb726d48Sopenharmony_ci }, 43fb726d48Sopenharmony_ci ]); 44fb726d48Sopenharmony_ci 45fb726d48Sopenharmony_ci let counterMax = sdkSqlite.queryCounterMax; 46fb726d48Sopenharmony_ci counterMax.mockResolvedValue([ 47fb726d48Sopenharmony_ci { 48fb726d48Sopenharmony_ci startTime: 12, 49fb726d48Sopenharmony_ci tableName: '', 50fb726d48Sopenharmony_ci columns: '' 51fb726d48Sopenharmony_ci }, 52fb726d48Sopenharmony_ci ]); 53fb726d48Sopenharmony_ci 54fb726d48Sopenharmony_ci let sdkCount = sdkSqlite.querySdkCount; 55fb726d48Sopenharmony_ci sdkCount.mockResolvedValue([ 56fb726d48Sopenharmony_ci { 57fb726d48Sopenharmony_ci startTime: 15, 58fb726d48Sopenharmony_ci tableName: 'tableName', 59fb726d48Sopenharmony_ci columns: '' 60fb726d48Sopenharmony_ci }, 61fb726d48Sopenharmony_ci ]); 62fb726d48Sopenharmony_ci 63fb726d48Sopenharmony_ci let sdkCounterData = sdkSqlite.querySdkCounterData; 64fb726d48Sopenharmony_ci sdkCounterData.mockResolvedValue([ 65fb726d48Sopenharmony_ci { 66fb726d48Sopenharmony_ci startTime: 15, 67fb726d48Sopenharmony_ci tableName: 'tableName', 68fb726d48Sopenharmony_ci columns: '' 69fb726d48Sopenharmony_ci }, 70fb726d48Sopenharmony_ci ]); 71fb726d48Sopenharmony_ci 72fb726d48Sopenharmony_ci let sdkSliceData = sdkSqlite.querySdkSliceData; 73fb726d48Sopenharmony_ci sdkSliceData.mockResolvedValue([ 74fb726d48Sopenharmony_ci { 75fb726d48Sopenharmony_ci startTime: 152, 76fb726d48Sopenharmony_ci tableName: 'tableName', 77fb726d48Sopenharmony_ci columns: '' 78fb726d48Sopenharmony_ci }, 79fb726d48Sopenharmony_ci ]); 80fb726d48Sopenharmony_ci let map = new Map(); 81fb726d48Sopenharmony_ci let jsoSdknCofigStr = 82fb726d48Sopenharmony_ci '{"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' + 83fb726d48Sopenharmony_ci ' "type":"string"},"stop_gator":{"default":"true","description":"stop_gator","type":"boolean"},"version":{"default":"7","description":"gatordversion","type":"number"}},"name":"mailG77"},\n' + 84fb726d48Sopenharmony_ci ' "tableConfig":{"showType":[{"columns":[{"column":"ts","displayName":"TimeStamp","showType":[1,3],"type":"INTEGER"},{"column":"counter_id","displayName":"MonitorValue","showType":[1,3],"type":"INTEGER"},\n' + 85fb726d48Sopenharmony_ci ' {"column":"value","displayName":"Value","showType":[1,3],"type":"INTEGER"}],"inner":{"columns":[{"column":"counter_name","displayName":"","showType":[0],"type":"STRING"},\n' + 86fb726d48Sopenharmony_ci ' {"column":"counter_id","displayName":"","showType":[96,6],"type":"INTEGER"}],"tableName":"mock_plugin_counterobj_table"},"tableName":"mock_plugin_counter_table"},\n' + 87fb726d48Sopenharmony_ci ' {"columns":[{"column":"start_ts","displayName":"startts","showType":[2,3],"type":"INTEGER"},{"column":"end_ts","displayName":"endts","showType":[2,3],"type":"INTEGER"},\n' + 88fb726d48Sopenharmony_ci ' {"column":"slice_id","displayName":"slice_id","showType":[2,154,3],"type":"INTEGER"},{"column":"value","displayName":"Value","showType":[2,3],"type":"INTEGER"}],\n' + 89fb726d48Sopenharmony_ci ' "inner":{"columns":[{"column":"slice_name","displayName":"","showType":[313],"type":"STRING"},{"column":"slice_id","displayName":"","showType":[0],"type":"INTEGER"}],\n' + 90fb726d48Sopenharmony_ci ' "tableName":"mock_plugin_sliceobj_table"},"tableName":"mock_plugin_slice_table"}]}}'; 91fb726d48Sopenharmony_ci let dataSdkMap = { 92fb726d48Sopenharmony_ci jsonConfig: jsoSdknCofigStr, 93fb726d48Sopenharmony_ci disPlayName: 'common_mock', 94fb726d48Sopenharmony_ci pluginName: 'mock-plugin', 95fb726d48Sopenharmony_ci }; 96fb726d48Sopenharmony_ci map.set('1', dataSdkMap); 97fb726d48Sopenharmony_ci SpSystemTrace.SDK_CONFIG_MAP = map; 98fb726d48Sopenharmony_ci it('SpSdkChartTest01', function () { 99fb726d48Sopenharmony_ci expect(spSdkChart.createSliceSql(10, 8, [{length: 5}], '')).toBe('select undefined from 8 '); 100fb726d48Sopenharmony_ci }); 101fb726d48Sopenharmony_ci 102fb726d48Sopenharmony_ci it('SpSdkChartTest02', function () { 103fb726d48Sopenharmony_ci expect(spSdkChart.createMaxValueSql('', '')).toBe('select max(value) as max_value from '); 104fb726d48Sopenharmony_ci }); 105fb726d48Sopenharmony_ci 106fb726d48Sopenharmony_ci it('SpSdkChartTest03', function () { 107fb726d48Sopenharmony_ci expect(spSdkChart.createMaxValueSql('a', 'c')).toBe('select max(value) as max_value from a c'); 108fb726d48Sopenharmony_ci }); 109fb726d48Sopenharmony_ci 110fb726d48Sopenharmony_ci it('SpSdkChartTest04', function () { 111fb726d48Sopenharmony_ci expect(spSdkChart.createSql(3, 'c', [{length: 3}], 'a')).toBe('select undefined from c a'); 112fb726d48Sopenharmony_ci }); 113fb726d48Sopenharmony_ci 114fb726d48Sopenharmony_ci it('SpSdkChartTest05', function () { 115fb726d48Sopenharmony_ci expect(spSdkChart.createSql(0, 'c', [{length: 3}], '')).toBe('select undefined from c '); 116fb726d48Sopenharmony_ci }); 117fb726d48Sopenharmony_ci 118fb726d48Sopenharmony_ci it('SpSdkChartTest06', function () { 119fb726d48Sopenharmony_ci spSdkChart.init(); 120fb726d48Sopenharmony_ci expect(spSdkChart).toBeDefined(); 121fb726d48Sopenharmony_ci }); 122fb726d48Sopenharmony_ci 123fb726d48Sopenharmony_ci it('SpSdkChartTest07', function () { 124fb726d48Sopenharmony_ci spSdkChart.parseJson(58512, map); 125fb726d48Sopenharmony_ci }); 126fb726d48Sopenharmony_ci 127fb726d48Sopenharmony_ci it('SpSdkChartTest08', function () { 128fb726d48Sopenharmony_ci expect(spSdkChart.initSliceChartRow(true, 2, 3, 'name', 2)).not.toBeUndefined(); 129fb726d48Sopenharmony_ci }); 130fb726d48Sopenharmony_ci 131fb726d48Sopenharmony_ci it('SpSdkChartTest09', function () { 132fb726d48Sopenharmony_ci expect(spSdkChart.initCounterChartRow(5, true, 2, 'name')).not.toBeUndefined(); 133fb726d48Sopenharmony_ci }); 134fb726d48Sopenharmony_ci}); 135