1fb726d48Sopenharmony_ci/*
2fb726d48Sopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd.
3fb726d48Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4fb726d48Sopenharmony_ci * you may not use this file except in compliance with the License.
5fb726d48Sopenharmony_ci * You may obtain a copy of the License at
6fb726d48Sopenharmony_ci *
7fb726d48Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8fb726d48Sopenharmony_ci *
9fb726d48Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10fb726d48Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11fb726d48Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12fb726d48Sopenharmony_ci * See the License for the specific language governing permissions and
13fb726d48Sopenharmony_ci * limitations under the License.
14fb726d48Sopenharmony_ci */
15fb726d48Sopenharmony_ci
16fb726d48Sopenharmony_ciimport { LitChartColumn } from '../../../../src/base-ui/chart/column/LitChartColumn';
17fb726d48Sopenharmony_ciimport '../../../../src/base-ui/chart/column/LitChartColumn';
18fb726d48Sopenharmony_ci
19fb726d48Sopenharmony_ciwindow.ResizeObserver =
20fb726d48Sopenharmony_ci  window.ResizeObserver ||
21fb726d48Sopenharmony_ci  jest.fn().mockImplementation(() => ({
22fb726d48Sopenharmony_ci    disconnect: jest.fn(),
23fb726d48Sopenharmony_ci    observe: jest.fn(),
24fb726d48Sopenharmony_ci    unobserve: jest.fn(),
25fb726d48Sopenharmony_ci  }));
26fb726d48Sopenharmony_ci
27fb726d48Sopenharmony_ciconst maybeHandler = jest.fn();
28fb726d48Sopenharmony_ci
29fb726d48Sopenharmony_cidescribe('litChartColumn Test', () => {
30fb726d48Sopenharmony_ci  it('litChartColumnTest01', function () {
31fb726d48Sopenharmony_ci    let litChartColumn = new LitChartColumn();
32fb726d48Sopenharmony_ci    expect(litChartColumn).not.toBeUndefined();
33fb726d48Sopenharmony_ci  });
34fb726d48Sopenharmony_ci
35fb726d48Sopenharmony_ci  it('litChartColumnTest03', function () {
36fb726d48Sopenharmony_ci    document.body.innerHTML = `
37fb726d48Sopenharmony_ci        <div>
38fb726d48Sopenharmony_ci            <lit-chart-column id='chart-cloumn'>小按钮</lit-chart-column>
39fb726d48Sopenharmony_ci        </div> `;
40fb726d48Sopenharmony_ci    let clo = document.getElementById('chart-cloumn') as LitChartColumn;
41fb726d48Sopenharmony_ci    clo.config = {
42fb726d48Sopenharmony_ci      data: [
43fb726d48Sopenharmony_ci        {
44fb726d48Sopenharmony_ci          pid: 11,
45fb726d48Sopenharmony_ci          pName: 'process01',
46fb726d48Sopenharmony_ci          tid: 332,
47fb726d48Sopenharmony_ci          tName: '11',
48fb726d48Sopenharmony_ci          total: 45,
49fb726d48Sopenharmony_ci          size: 'big core',
50fb726d48Sopenharmony_ci          timeStr: '91.11kb',
51fb726d48Sopenharmony_ci        },
52fb726d48Sopenharmony_ci        {
53fb726d48Sopenharmony_ci          pid: 21,
54fb726d48Sopenharmony_ci          pName: 'process02',
55fb726d48Sopenharmony_ci          tid: 21,
56fb726d48Sopenharmony_ci          tName: '222',
57fb726d48Sopenharmony_ci          total: 13,
58fb726d48Sopenharmony_ci          size: 'big core',
59fb726d48Sopenharmony_ci          timeStr: '211.00kb',
60fb726d48Sopenharmony_ci        },
61fb726d48Sopenharmony_ci      ],
62fb726d48Sopenharmony_ci      appendPadding: 10,
63fb726d48Sopenharmony_ci      xField: 'tid',
64fb726d48Sopenharmony_ci      yField: 'total',
65fb726d48Sopenharmony_ci      seriesField: 'total',
66fb726d48Sopenharmony_ci      color: (a: any) => {
67fb726d48Sopenharmony_ci        if (a.size === 'big core') {
68fb726d48Sopenharmony_ci          return '#2f72f8';
69fb726d48Sopenharmony_ci        } else {
70fb726d48Sopenharmony_ci          return '#0a59f7';
71fb726d48Sopenharmony_ci        }
72fb726d48Sopenharmony_ci      },
73fb726d48Sopenharmony_ci      tip: (a: any) => {
74fb726d48Sopenharmony_ci        if (a && a[0]) {
75fb726d48Sopenharmony_ci          let tip = '';
76fb726d48Sopenharmony_ci          let total = 0;
77fb726d48Sopenharmony_ci          for (let obj of a) {
78fb726d48Sopenharmony_ci            total += obj.obj.total;
79fb726d48Sopenharmony_ci            tip = `${tip}
80fb726d48Sopenharmony_ci                                <div style="display:flex;flex-direction: row;align-items: center;">
81fb726d48Sopenharmony_ci                                </div>
82fb726d48Sopenharmony_ci                            `;
83fb726d48Sopenharmony_ci          }
84fb726d48Sopenharmony_ci          tip = `<div>
85fb726d48Sopenharmony_ci                                        <div>tid:${a[0].obj.tid}</div>
86fb726d48Sopenharmony_ci                                    </div>`;
87fb726d48Sopenharmony_ci          return tip;
88fb726d48Sopenharmony_ci        } else {
89fb726d48Sopenharmony_ci          return '';
90fb726d48Sopenharmony_ci        }
91fb726d48Sopenharmony_ci      },
92fb726d48Sopenharmony_ci      label: null,
93fb726d48Sopenharmony_ci    };
94fb726d48Sopenharmony_ci    expect(clo.config).not.toBeUndefined();
95fb726d48Sopenharmony_ci    clo.dataSource = [
96fb726d48Sopenharmony_ci      {
97fb726d48Sopenharmony_ci        pid: 110,
98fb726d48Sopenharmony_ci        pName: 'process03',
99fb726d48Sopenharmony_ci        tid: 32,
100fb726d48Sopenharmony_ci        tName: '11',
101fb726d48Sopenharmony_ci        total: 121,
102fb726d48Sopenharmony_ci        size: 'big core',
103fb726d48Sopenharmony_ci        timeStr: '11.09kb',
104fb726d48Sopenharmony_ci      },
105fb726d48Sopenharmony_ci      {
106fb726d48Sopenharmony_ci        pid: 2,
107fb726d48Sopenharmony_ci        pName: 'process04',
108fb726d48Sopenharmony_ci        tid: 22,
109fb726d48Sopenharmony_ci        tName: 'thread',
110fb726d48Sopenharmony_ci        total: 131,
111fb726d48Sopenharmony_ci        size: 'big core',
112fb726d48Sopenharmony_ci        timeStr: '22.30kb',
113fb726d48Sopenharmony_ci      },
114fb726d48Sopenharmony_ci    ];
115fb726d48Sopenharmony_ci    expect(clo.data[0].obj.pid).toBe(2);
116fb726d48Sopenharmony_ci  });
117fb726d48Sopenharmony_ci  it('litChartColumnTest04', function () {
118fb726d48Sopenharmony_ci    let litChartColumn = new LitChartColumn();
119fb726d48Sopenharmony_ci    litChartColumn.litChartColumnTipEL = jest.fn(() => true);
120fb726d48Sopenharmony_ci    litChartColumn.litChartColumnTipEL.style = jest.fn(() => true);
121fb726d48Sopenharmony_ci    expect(litChartColumn.showTip(14, 5, 't')).toBeUndefined();
122fb726d48Sopenharmony_ci  });
123fb726d48Sopenharmony_ci  it('litChartColumnTest05', function () {
124fb726d48Sopenharmony_ci    let litChartColumn = new LitChartColumn();
125fb726d48Sopenharmony_ci    litChartColumn.litChartColumnTipEL = jest.fn(() => true);
126fb726d48Sopenharmony_ci    litChartColumn.litChartColumnTipEL.style = jest.fn(() => true);
127fb726d48Sopenharmony_ci    expect(litChartColumn.hideTip()).toBeUndefined();
128fb726d48Sopenharmony_ci  });
129fb726d48Sopenharmony_ci  it('litChartColumnTest06', function () {
130fb726d48Sopenharmony_ci    document.body.innerHTML = `
131fb726d48Sopenharmony_ci        <div>
132fb726d48Sopenharmony_ci            <lit-chart-column id='chart-cloumn'>小按钮</lit-chart-column>
133fb726d48Sopenharmony_ci        </div> `;
134fb726d48Sopenharmony_ci    let clo = document.getElementById('chart-cloumn') as LitChartColumn;
135fb726d48Sopenharmony_ci    let mouseOutEvent: MouseEvent = new MouseEvent('mouseout', <MouseEventInit>{ clientX: 1, clientY: 2 });
136fb726d48Sopenharmony_ci    clo.litChartColumnCanvas.dispatchEvent(mouseOutEvent);
137fb726d48Sopenharmony_ci  });
138fb726d48Sopenharmony_ci  it('litChartColumnTest07', function () {
139fb726d48Sopenharmony_ci    document.body.innerHTML = `
140fb726d48Sopenharmony_ci        <div>
141fb726d48Sopenharmony_ci            <lit-chart-column id='chart-cloumn'>小按钮</lit-chart-column>
142fb726d48Sopenharmony_ci        </div> `;
143fb726d48Sopenharmony_ci    let clo = document.getElementById('chart-cloumn') as LitChartColumn;
144fb726d48Sopenharmony_ci    let mouseOutEvent: MouseEvent = new MouseEvent('mousemove', <MouseEventInit>{ clientX: 1, clientY: 2 });
145fb726d48Sopenharmony_ci    clo.litChartColumnCanvas.dispatchEvent(mouseOutEvent);
146fb726d48Sopenharmony_ci  });
147fb726d48Sopenharmony_ci});
148