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 { LitPageTable } from '../../../src/base-ui/table/LitPageTable';
17import { LitTableColumn } from '../../../src/base-ui/table/lit-table-column';
18import { TableRowObject } from '../../../src/base-ui/table/TableRowObject';
19import { LitProgressBar } from '../../../src/base-ui/progress-bar/LitProgressBar';
20import { LitIcon } from '../../../src/base-ui/icon/LitIcon';
21describe('LitTable Test', () => {
22  window.ResizeObserver =
23    window.ResizeObserver ||
24    jest.fn().mockImplementation(() => ({
25      disconnect: jest.fn(),
26      observe: jest.fn(),
27      unobserve: jest.fn(),
28    }));
29  let litTable = new LitPageTable();
30  litTable.selectable = true;
31  litTable.selectable = false;
32  litTable.scrollY = 'scrollY';
33
34  litTable.recycleDataSource = [];
35
36  litTable.recycleDataSource = [
37    {
38      id: 1,
39      name: 'name',
40    },
41    {
42      id: 2,
43      name: 'nameValue',
44    },
45  ];
46  const td = {
47    style: {
48      position: 'sticky',
49      left: '0px',
50      right: '0px',
51      boxShadow: '3px 0px 5px #33333333',
52    },
53  };
54  const placement = 'left';
55
56  const element = {
57    style: {
58      display: 'none',
59      transform: 'translateY',
60    },
61    childNodes: { forEach: true },
62    onclick: 1,
63  };
64  const rowObject = {
65    children: {
66      length: 1,
67    },
68    data: [{ isSelected: undefined }],
69    depth: 1,
70    top: 1,
71  };
72  const firstElement =
73    {
74      style: {
75        display: 'none',
76        paddingLeft: '',
77        transform: 'translateY',
78      },
79      innerHTML: '',
80      title: '',
81      firstChild: null,
82      onclick: 1,
83    } || undefined;
84
85  litTable.columns = litTable.columns || jest.fn(() => true);
86
87  litTable.tbodyElement = jest.fn(() => ({
88    innerHTML: '',
89  }));
90
91  litTable.tableColumns = jest.fn(() => []);
92
93  litTable.tableColumns.forEach = jest.fn(() => []);
94
95  it('LitTablePageTest01', () => {
96    expect(litTable.adoptedCallback()).toBeUndefined();
97  });
98
99  it('LitTablePageTest02', () => {
100    expect(litTable.disconnectedCallback()).toBeUndefined();
101  });
102
103  it('LitTablePageTest03', () => {
104    expect(litTable.attributeChangedCallback('name', 'a', 'b')).toBeUndefined();
105  });
106
107  it('LitTablePageTest04', () => {
108    litTable.hideDownload = true;
109    expect(litTable.hideDownload).toBeTruthy();
110  });
111
112  it('LitTablePageTest05', () => {
113    expect(litTable.hideDownload).not.toBeUndefined();
114  });
115
116  it('LitTablePageTest06', () => {
117    litTable.hideDownload = false;
118    expect(litTable.hideDownload).toBeFalsy();
119  });
120
121  it('LitTablePageTest07', () => {
122    expect(litTable.selectable).not.toBeUndefined();
123  });
124
125  it('LitTablePageTest08', () => {
126    litTable.selectable = true;
127    expect(litTable.selectable).toBeTruthy();
128  });
129
130  it('LitTablePageTest09', () => {
131    expect(litTable.scrollY).not.toBeUndefined();
132  });
133
134  it('LitTablePageTest10', () => {
135    litTable.scrollY = '';
136    expect(litTable.scrollY).not.toBeUndefined();
137  });
138
139  it('LitTablePageTest11', () => {
140    expect(litTable.recycleDataSource).not.toBeUndefined();
141  });
142
143  it('LitTablePageTest12', () => {
144    expect(litTable.measureReset()).toBeUndefined();
145  });
146
147  it('LitTablePageTest13', () => {
148    litTable.pagination = true;
149    expect(litTable.pagination).toBeTruthy();
150  });
151
152  it('LitTablePageTest14', () => {
153    litTable.setAttribute('pagination', '');
154    litTable.pagination = false;
155    expect(litTable.pagination).toBeFalsy();
156  });
157
158  it('LitTablePageTest15', () => {
159    expect(litTable.initElements()).toBeUndefined();
160  });
161
162  it('LitTablePageTest16', () => {
163    expect(litTable.initPageEventListener()).toBeUndefined();
164  });
165
166  it('LitTablePageTest17', () => {
167    litTable.rememberScrollTop = true;
168    expect(litTable.toTop()).toBeUndefined();
169  });
170
171  it('LitTablePageTest18', () => {
172    litTable.rememberScrollTop = true;
173    litTable.toTop();
174    expect(litTable.tableElement!.scrollTop).toEqual(0);
175    expect(litTable.tableElement!.scrollLeft).toEqual(0);
176  });
177
178  it('LitTablePageTest19', () => {
179    litTable.rememberScrollTop = false;
180    litTable.toTop();
181    expect(litTable.tableElement!.scrollTop).toEqual(0);
182    expect(litTable.tableElement!.scrollLeft).toEqual(0);
183  });
184
185  it('LitTablePageTest20', () => {
186    expect(typeof litTable.initHtml()).toEqual('string');
187  });
188
189  it('LitTablePageTest21', () => {
190    expect(litTable.connectedCallback()).toBeUndefined();
191  });
192
193  it('LitTablePageTest22', () => {
194    const rowData = {
195      data: [
196        {
197          isSelected: undefined,
198        },
199      ],
200    };
201    expect(litTable.meauseElementHeight(rowData)).toBe(27);
202  });
203
204  it('LitTablePageTest23', () => {
205    const rowData = {
206      data: [
207        {
208          isSelected: undefined,
209        },
210      ],
211    };
212    expect(litTable.meauseTreeElementHeight(rowData, 1)).toBe(27);
213  });
214
215  it('LitTablePageTest24', () => {
216    document.body.innerHTML = "<lit-table id='tab' tree></lit-table>";
217    let table = document.querySelector('#tab') as LitPageTable;
218    let htmlElement = document.createElement('lit-table-column') as LitTableColumn;
219    htmlElement.setAttribute('title', '1');
220    htmlElement.setAttribute('data-index', '1');
221    htmlElement.setAttribute('key', '1');
222    htmlElement.setAttribute('align', 'flex-start');
223    htmlElement.setAttribute('height', '32px');
224    table!.appendChild(htmlElement);
225    setTimeout(() => {
226      table.recycleDataSource = [
227        {
228          id: 1,
229          name: 'name',
230        },
231        {
232          id: 2,
233          name: 'nameValue',
234        },
235      ];
236      expect(table.meauseTreeElementHeight('1', 2)).toBe(27);
237    }, 20);
238  });
239
240  it('LitTablePageTest25', () => {
241    expect(litTable.createExpandBtn({ expanded: false, data: { status: true } })).not.toBeUndefined();
242  });
243
244  it('LitTablePageTest26', () => {
245    let newTableElement = document.createElement('div');
246    newTableElement.classList.add('tr');
247    newTableElement.style.cursor = 'pointer';
248    newTableElement.style.gridTemplateColumns = '1,2,3';
249    newTableElement.style.position = 'absolute';
250    newTableElement.style.top = '0px';
251    newTableElement.style.left = '0px';
252    litTable.currentRecycleList = [newTableElement];
253    litTable.recycleDs = [{ rowHidden: false, data: { isSearch: true } }];
254    litTable.tbodyElement = document.createElement('div');
255    litTable.treeElement = document.createElement('div');
256    litTable.tableElement = document.createElement('div');
257    litTable.theadElement = document.createElement('div');
258    expect(litTable.reMeauseHeight()).toBeUndefined();
259  });
260
261  it('LitTablePageTest27', () => {
262    const rowData = {
263      data: [
264        {
265          isSelected: undefined,
266        },
267      ],
268    };
269    litTable.columns.forEach = jest.fn(() => true);
270    expect(litTable.createNewTableElement(rowData)).not.toBeUndefined();
271  });
272
273  it('LitTablePageTest28', () => {
274    let element = document.createElement('div');
275    let ch = document.createElement('div');
276    element.appendChild(ch);
277    let rowObject = { rowHidden: false, data: { isSearch: true } };
278    let tableColmn = document.createElement('lit-table-column') as LitTableColumn;
279    tableColmn.setAttribute('data-index', '1');
280    tableColmn.setAttribute('title', '1');
281    tableColmn.setAttribute('data-index', '2');
282    tableColmn.setAttribute('align', 'flex-start');
283    tableColmn.setAttribute('height', '32px');
284    tableColmn.setAttribute('key', '2');
285    let tableColmn1 = document.createElement('lit-table-column') as LitTableColumn;
286    tableColmn1.setAttribute('align', 'flex-start');
287    tableColmn1.setAttribute('height', '32px');
288    tableColmn1.setAttribute('title', '2');
289    tableColmn1.setAttribute('data-index', '2');
290    tableColmn1.setAttribute('key', '2');
291    litTable.columns = [tableColmn, tableColmn1];
292    expect(litTable.freshCurrentLine(element, rowObject)).toBeUndefined();
293  });
294
295  it('LitTablePageTest29', () => {
296    litTable.recycleDs.length = 1;
297    litTable.setCurrentSelection = jest.fn(() => true);
298    expect(litTable.scrollToData(litTable.recycleDataSource)).toBeUndefined();
299  });
300
301  it('LitTablePageTest30', () => {
302    litTable.recycleDs = [{ rowHidden: false, data: { isSearch: true } }];
303    let dataSource = [
304      {
305        id: 11,
306        name: 'name',
307      },
308      {
309        id: 21,
310        name: 'value',
311      },
312    ];
313    expect(litTable.expandList(dataSource)).toBeUndefined();
314  });
315
316  it('LitTablePageTest31', () => {
317    expect(litTable.clearAllSelection()).toBeUndefined();
318  });
319
320  it('LitTablePageTest32', () => {
321    expect(litTable.dispatchRowClickEvent({ data: { isSelected: '' } }, [], { button: '' })).toBeUndefined();
322  });
323
324  it('LitTablePageTest33', () => {
325    litTable.treeElement = jest.fn(() => undefined);
326    litTable.treeElement.children = jest.fn(() => [1]);
327    litTable.columns.forEach = jest.fn(() => true);
328    litTable.treeElement.lastChild = jest.fn(() => true);
329    litTable.treeElement.lastChild.style = jest.fn(() => true);
330    expect(litTable.createNewTreeTableElement({ data: '' })).not.toBeUndefined();
331  });
332
333  it('LitTablePageTest34', () => {
334    let tableIcon = document.createElement('lit-icon') as LitIcon;
335    let mouseClickEvent: MouseEvent = new MouseEvent('click', <MouseEventInit>{ movementX: 1, movementY: 2 });
336    tableIcon.dispatchEvent(mouseClickEvent);
337  });
338
339  it('LitTablePageTest35', () => {
340    document.body.innerHTML = `<lit-table id="aaa"></lit-table>`;
341    let litTable = document.querySelector('#aaa') as LitTable;
342    litTable.formatName = true;
343    expect(litTable.formatName).toBeTruthy();
344  });
345
346  it('LitTablePageTest36', () => {
347    expect(litTable.formatExportData(litTable.recycleDataSource)).not.toBeUndefined();
348  });
349
350  it('LitTablePageTest37', () => {
351    expect(litTable.setSelectedRow(true, [])).toBeUndefined();
352  });
353
354  it('LitTablePageTest38', () => {
355    let tableColmn = document.createElement('lit-table-column') as LitTableColumn;
356    tableColmn.setAttribute('title', '21');
357    tableColmn.setAttribute('data-index', '13');
358    tableColmn.setAttribute('key', '4');
359    tableColmn.setAttribute('align', 'flex-start');
360    tableColmn.setAttribute('height', '32px');
361    let tableColmn1 = document.createElement('lit-table-column') as LitTableColumn;
362    tableColmn1.setAttribute('title', '52');
363    tableColmn1.setAttribute('data-index', '244');
364    tableColmn1.setAttribute('key', '25');
365    tableColmn1.setAttribute('align', 'flex-start');
366    tableColmn1.setAttribute('height', '24px');
367
368    let tableColmn2 = document.createElement('lit-table-column') as LitTableColumn;
369    tableColmn2.setAttribute('title', '53');
370    tableColmn2.setAttribute('data-index', '35');
371    tableColmn2.setAttribute('key', '35');
372    tableColmn2.setAttribute('align', 'flex-start');
373    tableColmn2.setAttribute('height', '325px');
374    litTable.columns = [tableColmn, tableColmn1, tableColmn2];
375    let dataSource = [
376      {
377        id: 22,
378        name: 'name',
379      },
380      {
381        id: 12,
382        name: 'nameValue',
383      },
384    ];
385    expect(litTable.formatExportData(dataSource)).toBeTruthy();
386  });
387
388  it('LitTablePageTest39', () => {
389    let element = document.createElement('div');
390    litTable.tableElement = document.createElement('div');
391    let firstElement = document.createElement('div');
392    let ch = document.createElement('div');
393    element.appendChild(ch);
394    let rowObject = { rowHidden: false, data: { isSearch: true } };
395    let tableColmn = document.createElement('lit-table-column') as LitTableColumn;
396    tableColmn.setAttribute('height', '32px');
397    tableColmn.setAttribute('title', '16');
398    tableColmn.setAttribute('data-index', '1');
399    tableColmn.setAttribute('align', 'flex-start');
400    tableColmn.setAttribute('height', '36px');
401    tableColmn.setAttribute('key', '1');
402    let tableColmn1 = document.createElement('lit-table-column') as LitTableColumn;
403    tableColmn1.setAttribute('key', '2');
404    tableColmn1.setAttribute('align', 'flex-start');
405    tableColmn1.setAttribute('height', '32px');
406    tableColmn1.setAttribute('title', '2');
407    tableColmn1.setAttribute('data-index', '2');
408    litTable.columns = [tableColmn, tableColmn1];
409    expect(litTable.freshCurrentLine(element, rowObject, firstElement)).toBeUndefined();
410  });
411  it('LitTablePageTest40', () => {
412    litTable.hideDownload = true;
413    expect(litTable.hideDownload).toBeTruthy();
414  });
415  it('LitTablePageTest41', () => {
416    litTable.hideDownload = false;
417    expect(litTable.hideDownload).not.toBeUndefined();
418  });
419  it('LitTablePageTest42', () => {
420    expect(litTable.createBtn({ expanded: false, data: { status: true } })).not.toBeUndefined();
421  });
422  it('LitTablePageTest43', () => {
423    expect(litTable.mouseOut()).toBeUndefined();
424  });
425  it('LitTablePageTest44', () => {
426    expect(litTable.setCurrentHover({})).toBeUndefined();
427  });
428  it('LitTablePageTest45', () => {
429    expect(litTable.clearAllHover({})).toBeUndefined();
430  });
431});
432