• 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
16// @ts-ignore
17import {TabPaneThreadStates} from "../../../../../../dist/trace/component/trace/sheet/process/TabPaneThreadStates.js"
18
19window.ResizeObserver = window.ResizeObserver ||
20    jest.fn().mockImplementation(() => ({
21        disconnect: jest.fn(),
22        observe: jest.fn(),
23        unobserve: jest.fn(),
24    }));
25
26const sqlit = require("../../../../../../dist/trace/database/SqlLite.js")
27jest.mock("../../../../../../dist/trace/database/SqlLite.js");
28describe('TabPaneThreadStates Test', () => {
29    let tabPaneThreadStates = new TabPaneThreadStates();
30
31    it('TabPaneThreadStatesTest01', function () {
32        expect(tabPaneThreadStates.sortByColumn({
33            key: 'name' ||  "thread" || "state",
34            sort: () => {
35            }
36        })).toBeUndefined();
37    });
38
39    it('TabPaneThreadStatesTest05', function () {
40        expect(tabPaneThreadStates.sortByColumn({
41            key: !'name' || ! "thread" || !"state",
42            sort: () => {
43            }
44        })).toBeUndefined();
45    });
46
47
48    it('TabPaneThreadStatesTest02', function () {
49        // @ts-ignore
50        let mockgetTabThreadStates = sqlit.getTabThreadStates
51        mockgetTabThreadStates.mockResolvedValue(
52            [{process: "11",
53                thread: "222",
54                wallDuration: 10,
55                occurrences: 10,
56                state: "sss",
57                stateJX: "mm"
58            },{process: "11",
59                thread: "222",
60                wallDuration: 10,
61                occurrences: 10,
62                state: "sss",
63                stateJX: "mm"
64            }]
65        )
66        let a = {rightNs: 1, leftNs: 0, threadIds: [11, 12, 13]}
67        expect(tabPaneThreadStates.data = a).toBeTruthy();
68    });
69
70    it('TabPaneThreadStatesTest03', function () {
71        // @ts-ignore
72        let mockgetTabThreadStates = sqlit.getTabThreadStates
73        mockgetTabThreadStates.mockResolvedValue([])
74        let a = {rightNs: 1, leftNs: 0, threadIds: [11, 12, 13]}
75        expect(tabPaneThreadStates.data = a).toBeTruthy();
76    });
77
78    it('TabPaneThreadStatesTest04', function () {
79        expect(tabPaneThreadStates.initHtml()).toMatchInlineSnapshot(`
80"
81        <style>
82        :host{
83            display: flex;
84            flex-direction: column;
85            padding: 10px 10px;
86        }
87        </style>
88        <div style=\\"display: flex;height: 20px;align-items: center;flex-direction: row;margin-bottom: 5px\\">
89            <stack-bar id=\\"stack-bar\\" style=\\"flex: 1\\"></stack-bar>
90            <label id=\\"time-range\\"  style=\\"width: auto;text-align: end;font-size: 10pt;\\">Selected range:0.0 ms</label>
91        </div>
92        <lit-table id=\\"tb-thread-states\\" style=\\"height: auto\\">
93            <lit-table-column width=\\"25%\\" title=\\"Process\\" data-index=\\"process\\" key=\\"process\\"  align=\\"flex-start\\" order>
94            </lit-table-column>
95            <lit-table-column width=\\"1fr\\" title=\\"PID\\" data-index=\\"pid\\" key=\\"pid\\"  align=\\"flex-start\\" order >
96            </lit-table-column>
97            <lit-table-column width=\\"20%\\" title=\\"Thread\\" data-index=\\"thread\\" key=\\"thread\\"  align=\\"flex-start\\" order >
98            </lit-table-column>
99            <lit-table-column width=\\"1fr\\" title=\\"TID\\" data-index=\\"tid\\" key=\\"tid\\"  align=\\"flex-start\\" order >
100            </lit-table-column>
101            <lit-table-column width=\\"1fr\\" title=\\"State\\" data-index=\\"state\\" key=\\"state\\"  align=\\"flex-start\\" order >
102            </lit-table-column>
103            <lit-table-column width=\\"1fr\\" title=\\"Wall duration(ms)\\" data-index=\\"wallDuration\\" key=\\"wallDuration\\"  align=\\"flex-start\\" order >
104            </lit-table-column>
105            <lit-table-column width=\\"1fr\\" title=\\"Avg Wall duration(ms)\\" data-index=\\"avgDuration\\" key=\\"avgDuration\\"  align=\\"flex-start\\" order >
106            </lit-table-column>
107            <lit-table-column width=\\"1fr\\" title=\\"Occurrences\\" data-index=\\"occurrences\\" key=\\"occurrences\\"  align=\\"flex-start\\" order >
108            </lit-table-column>
109        </lit-table>
110        "
111`);
112    });
113})
114