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