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 { Top20ThreadCpuUsage } from '../../../../src/trace/component/schedulingAnalysis/Top20ThreadCpuUsage';
16// @ts-ignore
17window.ResizeObserver =
18  window.ResizeObserver ||
19  jest.fn().mockImplementation(() => ({
20    disconnect: jest.fn(),
21    observe: jest.fn(),
22    unobserve: jest.fn(),
23  }));
24
25describe('Top20ThreadCpuUsage Test', () => {
26  it('Top20ThreadCpuUsageTest01', () => {
27    let top20ThreadCpuUsage = new Top20ThreadCpuUsage();
28    expect(top20ThreadCpuUsage).not.toBeUndefined();
29  });
30  it('Top20ThreadCpuUsageTest02', () => {
31    let top20ThreadCpuUsage = new Top20ThreadCpuUsage();
32    let data = [
33      {
34        pid: 101,
35        pName: 4,
36        tid: 311,
37        tName: '',
38        total: 112,
39        size: 'middle core',
40        no: '',
41        timeStr: '120.00kb',
42      },
43    ];
44    expect(top20ThreadCpuUsage.sortByColumn({ key: 'bigTimeStr' }, {}, data)).toBeUndefined();
45  });
46  it('Top20ThreadCpuUsageTest03', () => {
47    let top20ThreadCpuUsage = new Top20ThreadCpuUsage();
48    top20ThreadCpuUsage.queryLogicWorker = jest.fn();
49    expect(top20ThreadCpuUsage.queryData()).toBeUndefined();
50  });
51  it('Top20ThreadCpuUsageTest04', () => {
52    let top20ThreadCpuUsage = new Top20ThreadCpuUsage();
53    let data = [
54      {
55        pid: 32,
56        pName: 21,
57        tid: 224,
58        tName: 'thread1',
59        total: 1,
60        size: 'middle core',
61        no: '',
62        timeStr: '19.00kb',
63      },
64    ];
65    expect(top20ThreadCpuUsage.getArrayDataBySize('total', data)).toStrictEqual(
66        [
67          {"no": "", "pName": 21, "pid": 32, "size": "big core", "tName": "thread1", "tid": 224, "timeStr": undefined, "total": undefined},
68          {"no": "", "pName": 21, "pid": 32, "size": "middle core", "tName": "thread1", "tid": 224, "timeStr": undefined, "total": undefined},
69          {"no": "", "pName": 21, "pid": 32, "size": "small core", "tName": "thread1", "tid": 224, "timeStr": undefined, "total": undefined}
70          ]
71    );
72  });
73  it('Top20ThreadCpuUsageTest05', () => {
74    let top20ThreadCpuUsage = new Top20ThreadCpuUsage();
75    let data = [
76      {
77        pid: 35,
78        pName: 651,
79        tid: 43,
80        tName: 'thread3',
81        total: 65,
82        size: 'middle core',
83        no: '',
84        timeStr: '123.0kb',
85      },
86    ];
87    expect(top20ThreadCpuUsage.sortByColumn({ key: 'midTimeStr' }, {}, data)).toBeUndefined();
88  });
89  it('Top20ThreadCpuUsageTest06', () => {
90    let top20ThreadCpuUsage = new Top20ThreadCpuUsage();
91    let data = [
92      {
93        pid: 32,
94        pName: 2342,
95        tid: 543,
96        tName: 'thread6',
97        total: 120,
98        size: 'middle core',
99        no: '',
100        timeStr: '133.320kb',
101      },
102    ];
103    expect(top20ThreadCpuUsage.sortByColumn({ key: 'smallTimeStr' }, {}, data)).toBeUndefined();
104  });
105  it('Top20ThreadCpuUsageTest07', () => {
106    let top20ThreadCpuUsage = new Top20ThreadCpuUsage();
107    let data = [
108      {
109        pid: 67,
110        pName: 161,
111        tid: 87,
112        tName: 'thread90',
113        total: 322,
114        size: 'middle core',
115        no: '',
116        timeStr: '190.32kb',
117      },
118    ];
119    expect(top20ThreadCpuUsage.sortByColumn({ key: 'bigPercent' }, {}, data)).toBeUndefined();
120  });
121  it('Top20ThreadCpuUsageTest08', () => {
122    let top20ThreadCpuUsage = new Top20ThreadCpuUsage();
123    top20ThreadCpuUsage.queryLogicWorker = jest.fn();
124    expect(top20ThreadCpuUsage.queryLogicWorker('', '', {})).toBeUndefined();
125  });
126});
127