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 { LitChartColumn } from '../../../../src/base-ui/chart/column/LitChartColumn'; 17import '../../../../src/base-ui/chart/column/LitChartColumn'; 18 19window.ResizeObserver = 20 window.ResizeObserver || 21 jest.fn().mockImplementation(() => ({ 22 disconnect: jest.fn(), 23 observe: jest.fn(), 24 unobserve: jest.fn(), 25 })); 26 27const maybeHandler = jest.fn(); 28 29describe('litChartColumn Test', () => { 30 it('litChartColumnTest01', function () { 31 let litChartColumn = new LitChartColumn(); 32 expect(litChartColumn).not.toBeUndefined(); 33 }); 34 35 it('litChartColumnTest03', function () { 36 document.body.innerHTML = ` 37 <div> 38 <lit-chart-column id='chart-cloumn'>小按钮</lit-chart-column> 39 </div> `; 40 let clo = document.getElementById('chart-cloumn') as LitChartColumn; 41 clo.config = { 42 data: [ 43 { 44 pid: 11, 45 pName: 'process01', 46 tid: 332, 47 tName: '11', 48 total: 45, 49 size: 'big core', 50 timeStr: '91.11kb', 51 }, 52 { 53 pid: 21, 54 pName: 'process02', 55 tid: 21, 56 tName: '222', 57 total: 13, 58 size: 'big core', 59 timeStr: '211.00kb', 60 }, 61 ], 62 appendPadding: 10, 63 xField: 'tid', 64 yField: 'total', 65 seriesField: 'total', 66 color: (a: any) => { 67 if (a.size === 'big core') { 68 return '#2f72f8'; 69 } else { 70 return '#0a59f7'; 71 } 72 }, 73 tip: (a: any) => { 74 if (a && a[0]) { 75 let tip = ''; 76 let total = 0; 77 for (let obj of a) { 78 total += obj.obj.total; 79 tip = `${tip} 80 <div style="display:flex;flex-direction: row;align-items: center;"> 81 </div> 82 `; 83 } 84 tip = `<div> 85 <div>tid:${a[0].obj.tid}</div> 86 </div>`; 87 return tip; 88 } else { 89 return ''; 90 } 91 }, 92 label: null, 93 }; 94 expect(clo.config).not.toBeUndefined(); 95 clo.dataSource = [ 96 { 97 pid: 110, 98 pName: 'process03', 99 tid: 32, 100 tName: '11', 101 total: 121, 102 size: 'big core', 103 timeStr: '11.09kb', 104 }, 105 { 106 pid: 2, 107 pName: 'process04', 108 tid: 22, 109 tName: 'thread', 110 total: 131, 111 size: 'big core', 112 timeStr: '22.30kb', 113 }, 114 ]; 115 expect(clo.data[0].obj.pid).toBe(2); 116 }); 117 it('litChartColumnTest04', function () { 118 let litChartColumn = new LitChartColumn(); 119 litChartColumn.litChartColumnTipEL = jest.fn(() => true); 120 litChartColumn.litChartColumnTipEL.style = jest.fn(() => true); 121 expect(litChartColumn.showTip(14, 5, 't')).toBeUndefined(); 122 }); 123 it('litChartColumnTest05', function () { 124 let litChartColumn = new LitChartColumn(); 125 litChartColumn.litChartColumnTipEL = jest.fn(() => true); 126 litChartColumn.litChartColumnTipEL.style = jest.fn(() => true); 127 expect(litChartColumn.hideTip()).toBeUndefined(); 128 }); 129 it('litChartColumnTest06', function () { 130 document.body.innerHTML = ` 131 <div> 132 <lit-chart-column id='chart-cloumn'>小按钮</lit-chart-column> 133 </div> `; 134 let clo = document.getElementById('chart-cloumn') as LitChartColumn; 135 let mouseOutEvent: MouseEvent = new MouseEvent('mouseout', <MouseEventInit>{ clientX: 1, clientY: 2 }); 136 clo.litChartColumnCanvas.dispatchEvent(mouseOutEvent); 137 }); 138 it('litChartColumnTest07', function () { 139 document.body.innerHTML = ` 140 <div> 141 <lit-chart-column id='chart-cloumn'>小按钮</lit-chart-column> 142 </div> `; 143 let clo = document.getElementById('chart-cloumn') as LitChartColumn; 144 let mouseOutEvent: MouseEvent = new MouseEvent('mousemove', <MouseEventInit>{ clientX: 1, clientY: 2 }); 145 clo.litChartColumnCanvas.dispatchEvent(mouseOutEvent); 146 }); 147}); 148