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 { TabPaneBinders } from '../../../../../../src/trace/component/trace/sheet/binder/TabPaneBinders';
17import { LitTable } from '../../../../../../src/base-ui/table/lit-table';
18window.ResizeObserver =
19  window.ResizeObserver ||
20  jest.fn().mockImplementation(() => ({
21    disconnect: jest.fn(),
22    observe: jest.fn(),
23    unobserve: jest.fn(),
24  }));
25const sqlite = require('../../../../../../src/trace/database/sql/ProcessThread.sql');
26jest.mock('../../../../../../src/trace/database/sql/ProcessThread.sql');
27jest.mock('../../../../../../src/trace/component/trace/base/TraceRow', () => {
28  return {};
29});
30jest.mock('../../../../../../src/base-ui/table/lit-table');
31describe('TabPaneBinders Test', () => {
32  let tabPaneBinders = new TabPaneBinders();
33  let threadBindersTbl = new LitTable();
34  jest.clearAllMocks();
35  tabPaneBinders['threadBindersTbl'] = threadBindersTbl;
36  const data = [
37    {
38      pid: 1,
39      tid: 2,
40      title: 'P-Render',
41      totalCount: 3,
42      children: [
43        {
44          binderAsyncRcvCount: 2,
45          binderReplyCount: 2,
46          binderTransactionAsyncCount: 2,
47          binderTransactionCount: 2,
48          pid: 1,
49          tid: 2,
50          title: 'T-Render',
51          totalCount: 1
52        }
53      ]
54    },{
55      pid: 1,
56      tid: 2,
57      title: 'P-Service',
58      totalCount: 1,
59      children: [
60        {
61          binderAsyncRcvCount: 1,
62          binderReplyCount: 1,
63          binderTransactionAsyncCount: 1,
64          binderTransactionCount: 1,
65          pid: 1,
66          tid: 2,
67          title: 'T-Service',
68          totalCount: 2
69        }
70      ]
71    }
72  ];
73
74  it('TabPaneBindersTest01', () => {
75    let binder = sqlite.queryBinderByThreadId;
76    binder.mockResolvedValue(data);
77    const threadStatesParam = {
78      threadIds: [1, 2],
79      processIds: [1, 2],
80      leftNs: 0,
81      rightNs: 100
82    };
83    tabPaneBinders.initBinderData(threadStatesParam);
84    tabPaneBinders.data = data;
85    expect(tabPaneBinders.data).toBeUndefined();
86    expect(threadBindersTbl.recycleDataSource).toEqual([]);
87    expect(tabPaneBinders['threadBindersTblSource']).toEqual([]);
88    expect(threadBindersTbl.loading).toBe(true);
89  });
90
91  it('TabPaneBindersTest02', () => {
92    let binder = sqlite.queryBinderByThreadId;
93    binder.mockResolvedValue([]);
94    const threadStatesParam = {
95      threadIds: [1, 2],
96      processIds: [1, 2],
97      leftNs: 0,
98      rightNs: 100
99    };
100    tabPaneBinders.initBinderData(threadStatesParam);
101    expect(threadBindersTbl.loading).toBe(true);
102  });
103});
104