• 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 */
15import { TabPaneGpuClickSelectComparison } from '../../../../../../src/trace/component/trace/sheet/gpu/TabPaneGpuClickSelectComparison';
16const sqlite = require('../../../../../../src/trace/database/sql/Gpu.sql');
17jest.mock('../../../../../../src/trace/database/sql/Gpu.sql');
18jest.mock('../../../../../../src/base-ui/select/LitSelect', () => {
19  return {};
20});
21jest.mock('../../../../../../src/base-ui/table/lit-table', () => {
22  return {
23    snapshotDataSource: () => {},
24    removeAttribute: () => {},
25  };
26});
27jest.mock('../../../../../../src/js-heap/model/DatabaseStruct', () => {});
28jest.mock('../../../../../../src/trace/database/ui-worker/ProcedureWorker', () => {
29  return {};
30});
31
32// @ts-ignore
33window.ResizeObserver =
34  window.ResizeObserver ||
35  jest.fn().mockImplementation(() => ({
36    disconnect: jest.fn(),
37    observe: jest.fn(),
38    unobserve: jest.fn(),
39  }));
40
41describe('TabPaneGpuClickSelectComparison Test', () => {
42  document.body.innerHTML = `<div><tabpane-gpu-click-select-comparsion id="tree"></tabpane-gpu-click-select-comparsion></div>`;
43  let tabPaneGpuClickSelectComparison = document.querySelector<TabPaneGpuClickSelectComparison>('#tree');
44  let queryGpuDataByTs = sqlite.queryGpuDataByTs;
45  queryGpuDataByTs.mockResolvedValue([
46    {
47      windowId: 1,
48      moduleId: 2,
49      categoryId: 0,
50      size: 123,
51    },
52    {
53      windowId: 7,
54      moduleId: 8,
55      categoryId: 2,
56      size: 1213,
57    },
58  ]);
59  it('TabPaneGpuClickSelectComparisonTest01', () => {
60    let type = 'total';
61    let startTs = 10;
62    let tabPaneGpuClickSelectComparison = new TabPaneGpuClickSelectComparison();
63    expect(tabPaneGpuClickSelectComparison.queryDataByDB(type, startTs)).toBeTruthy();
64  });
65  it('TabPaneGpuClickSelectComparisonTest02', () => {
66    let type = 'total';
67    let targetStartNs = 10;
68    let tabPaneGpuClickSelectComparison = new TabPaneGpuClickSelectComparison();
69    expect(tabPaneGpuClickSelectComparison.getComparisonData(targetStartNs, type)).toBeTruthy();
70  });
71  it('TabPaneGpuClickSelectComparisonTest03', () => {
72    let type = 'total';
73    let dataList = [
74      {
75        name: 'Snapshot2',
76        startNs: 9800526561,
77        value: 0,
78      },
79      {
80        name: 'Snapshot1',
81        startNs: 4778214061,
82        value: 0,
83      },
84    ];
85    let tabPaneGpuClickSelectComparison = new TabPaneGpuClickSelectComparison();
86    expect(tabPaneGpuClickSelectComparison.selectStamps(dataList, type)).toBeUndefined();
87  });
88  it('TabPaneGpuClickSelectComparisonTest04', () => {
89    let tabPaneGpuClickSelectComparison = new TabPaneGpuClickSelectComparison();
90    expect(tabPaneGpuClickSelectComparison.sortGpuByColumn(0, '')).toBeUndefined();
91  });
92  it('TabPaneGpuClickSelectComparisonTest05', () => {
93    let tabPaneGpuClickSelectComparison = new TabPaneGpuClickSelectComparison();
94    expect(tabPaneGpuClickSelectComparison.sortGpuByColumn(1, 'name')).toBeUndefined();
95  });
96  it('TabPaneGpuClickSelectComparisonTest06', () => {
97    let tabPaneGpuClickSelectComparison = new TabPaneGpuClickSelectComparison();
98    expect(tabPaneGpuClickSelectComparison.sortGpuByColumn(1, 'sizeDelta')).toBeUndefined();
99  });
100});
101