• 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 {LitTable} from "../../../dist/base-ui/table/lit-table.js";
18import {LitTableColumn} from "../../../src/base-ui/table/lit-table-column.js";
19
20describe('LitTable Test', () => {
21    window.ResizeObserver = window.ResizeObserver ||
22    jest.fn().mockImplementation(() => ({
23        disconnect: jest.fn(),
24        observe: jest.fn(),
25        unobserve: jest.fn(),
26    }));
27    let litTable = new LitTable();
28    litTable.selectable = true
29    litTable.selectable = false
30    litTable.scrollY = 'scrollY'
31
32    litTable.dataSource = []
33
34    litTable.dataSource = [{
35        id: 1,
36        name: 'name'
37    }, {
38        id: 2,
39        name: 'nameValue'
40    }]
41    const td = {
42        style: {
43            position: 'sticky',
44            left: '0px',
45            right: '0px',
46            boxShadow: '3px 0px 5px #33333333'
47        }
48    }
49    const placement = "left"
50
51    const element = {
52        style: {
53            display: 'none',
54            transform: 'translateY'
55        },
56        childNodes:{forEach:true},
57        onclick: 1
58    }
59    const rowObject = {
60        children: {
61            length: 1,
62        },
63        data: [{isSelected:undefined}],
64        depth: 1,
65        top: 1
66    }
67    const firstElement = {
68        style: {
69            display: 'none',
70            paddingLeft: "",
71            transform: 'translateY'
72
73        },
74        innerHTML: "",
75        title: "",
76        firstChild: null,
77        onclick: 1
78
79    }||undefined
80
81    JSON.parse = jest.fn(() => [['children', 'father'], ['children', 'father']])
82
83    litTable.columns = litTable.columns || jest.fn(() => true)
84    litTable.ds = jest.fn(() => [{
85        id: 1,
86        name: 'name'
87    }, {
88        id: 2,
89        name: 'nameValue'
90    }])
91
92    litTable.tbodyElement = jest.fn(() => ({
93        innerHTML: ''
94    }))
95
96    litTable.tableColumns = jest.fn(() => [])
97
98    litTable.tableColumns.forEach = jest.fn(() => [])
99
100
101    it('LitTableTest01', () => {
102        expect(litTable.adoptedCallback()).toBeUndefined();
103    })
104
105    it('LitTableTest02', () => {
106        litTable.ds.forEach = jest.fn(() => true)
107        expect(litTable.renderTable()).toBeUndefined();
108    })
109
110    it('LitTableTest04', () => {
111        litTable.switch = document.querySelector("#switch") as HTMLInputElement;
112        expect(litTable.connectedCallback()).toBeUndefined()
113    })
114
115    it('LitTableTest05', () => {
116        let rowLength = litTable.getCheckRows().length == 0;
117        expect(rowLength).toBeTruthy()
118    })
119
120    it('LitTableTest06', () => {
121        expect(litTable.deleteRowsCondition(() => {
122            return true
123        })).toBeUndefined()
124    })
125
126    it('LitTableTest07', () => {
127        expect(litTable.selectable).not.toBeUndefined()
128    })
129
130    it('LitTableTest08', () => {
131        litTable.selectable = true
132        expect(litTable.selectable).toBeTruthy()
133    })
134
135    it('LitTableTest09', () => {
136        expect(litTable.scrollY).not.toBeUndefined()
137    })
138
139    it('LitTableTest10', () => {
140        expect(litTable.dataSource).not.toBeUndefined()
141    })
142
143    it('LitTableTest11', () => {
144        expect(litTable.recycleDataSource).not.toBeUndefined()
145    })
146
147    it('LitTableTest12', () => {
148        expect(litTable.fixed(td, placement)).toBeUndefined()
149    })
150
151    it('LitTableTest13', () => {
152        expect(litTable.fixed(td, "right")).toBe(undefined)
153    })
154
155    it('LitTableTest14', () => {
156        expect(litTable.meauseElementHeight()).toBe(27)
157    })
158
159    it('LitTableTest15', () => {
160        expect(litTable.meauseTreeElementHeight()).toBe(27)
161    })
162
163    it('LitTableTest16', () => {
164        document.body.innerHTML = "<lit-table id='tab' tree></lit-table>"
165       let table = document.querySelector("#tab") as LitTable;
166        let htmlElement = document.createElement('lit-table-column') as LitTableColumn;
167        htmlElement.setAttribute('title', "1");
168        htmlElement.setAttribute('data-index', "1");
169        htmlElement.setAttribute('key', "1");
170        htmlElement.setAttribute('align', 'flex-start');
171        htmlElement.setAttribute('height', '32px');
172        table!.appendChild(htmlElement);
173        setTimeout(() => {
174            table.recycleDataSource = [{
175                id: 1,
176                name: 'name'
177            }, {
178                id: 2,
179                name: 'nameValue'
180            }]
181            expect(table.meauseTreeElementHeight()).toBe(27)
182        }, 20)
183    })
184
185    it('LitTableTest17', () => {
186         expect(litTable.shadowRoot.innerHTML).toMatchInlineSnapshot(`
187"
188        <style>
189        :host{
190            display: grid;
191            grid-template-columns: repeat(1,1fr);
192            width: 100%;
193            flex:1;
194        }
195        .tr{
196            display: grid;
197            grid-column-gap: 5px;
198            min-width:100%;
199        }
200        .tr:nth-of-type(even){
201        }
202
203        .tr{
204            background-color: var(--dark-background,#FFFFFF);
205        }
206        .tr:hover{
207            background-color: var(--dark-background6,#DEEDFF);
208        }
209        .td{
210            box-sizing: border-box;
211            padding: 3px;
212            display: flex;
213            justify-content: flex-start;
214            align-items: center;
215            width: 100%;
216            height: auto;
217            cursor: pointer;
218        }
219        .td text{
220            overflow: hidden;
221            text-overflow: ellipsis;
222            white-space: nowrap;
223        }
224        .tr[selected]{
225            background-color: var(--dark-background6,#DEEDFF);
226        }
227        .td-order{
228        }
229        .td-order:before{
230
231        }
232        :host([grid-line]) .td{
233            border-left: 1px solid #f0f0f0;
234        }
235        :host([grid-line]) .td:last-of-type{
236            border-right: 1px solid #f0f0f0;
237        }
238        .table{
239            width: 100%;
240             color: var(--dark-color2,#262626);
241        }
242        .thead{
243            display: grid;
244            position: sticky;
245            top: 0;
246            font-weight: bold;
247            font-size: .9rem;
248            color: var(--dark-color1,#000);
249            background-color: var(--dark-background,#FFFFFF);
250            z-index: 1;
251        }
252        .tbody{
253            width: 100%;
254            top: 0;
255            left: 0;
256            right:0;
257            bottom:0;
258            display: flex;
259            flex-direction: row
260            row-gap: 1px;
261            column-gap: 1px;
262        }
263        .tree{
264            overflow-x:hidden;
265            overflow-y:hidden;
266            display: grid;
267            grid-template-columns: 1fr;
268            row-gap: 1px;
269            column-gap: 1px;
270            position:relative;
271        }
272        .tree:hover{
273            overflow-x: overlay;
274        }
275        .tree-first-body{
276            min-width: 100%;
277            box-sizing: border-box;
278            display:flex;
279            align-items:center;
280            white-space: nowrap;
281            cursor: pointer;
282        }
283        .tree-first-body:hover{
284            background-color: var(--dark-background6,#DEEDFF); /*antd #fafafa 42b983*/
285        }
286        .body{
287            display: grid;
288            grid-template-columns: 1fr;
289            row-gap: 1px;
290            column-gap: 1px;
291            flex:1;
292            position: relative;
293        }
294        :host([grid-line])  .tbody{
295            border-bottom: 1px solid #f0f0f0;
296            background-color: #f0f0f0;
297        }
298        .th{
299            grid-column-gap: 5px;
300            display: grid;
301            background-color: var(--dark-background,#FFFFFF);
302        }
303
304        .tree-icon{
305            font-size: 1.2rem;
306            width: 20px;
307            height: 20px;
308            padding-right: 5px;
309            padding-left: 5px;
310            cursor: pointer;
311        }
312        .tree-icon:hover{
313            color: #42b983;
314        }
315        .row-checkbox,row-checkbox-all{
316
317        }
318        :host([no-head]) .thead{
319            display: none;
320        }
321        .up-svg{
322            position: absolute;
323            right: 5px;
324            top: 8px;
325            bottom: 8px;
326            width: 15px;
327            height: 15px;
328        }
329        .down-svg{
330            position: absolute;
331            top: 8px;
332            right: 5px;
333            bottom: 8px;
334            width: 15px;
335            height: 15px;
336        }
337        .mouse-select{
338            background-color: var(--dark-background6,#DEEDFF);
339        }
340        .mouse-in{
341            background-color: var(--dark-background6,#DEEDFF);
342        }
343        .export{
344            width:30px;
345            height:30px;
346            cursor:pointer;
347            color:var(--dark-background6,#262626);
348            box-sizing: border-box;
349            position:fixed;
350            right:30px;
351            bottom:15px;
352        }
353        </style>
354
355        <slot id=\\"slot\\" style=\\"display: none\\"></slot>
356        <slot name=\\"head\\"></slot>
357        <div class=\\"table\\" style=\\"overflow-x:auto;\\">
358            <div class=\\"thead\\"></div>
359            <div class=\\"tbody\\">
360                <div class=\\"tree\\"></div>
361                <div class=\\"body\\"></div>
362        </div>
363        </div>
364        "
365`);
366    })
367
368    it('LitTableTest18', () => {
369        expect(litTable.createExpandBtn({expanded:false})).not.toBeUndefined()
370    })
371
372    it('LitTableTest19', () => {
373        expect(litTable.reMeauseHeight()).toBeUndefined();
374    })
375
376    it('LitTableTest20', () => {
377        const rowData= {
378            data:[{
379                isSelected:undefined
380            }],
381        }
382        litTable.columns.forEach = jest.fn(()=>true)
383        expect(litTable.createNewTableElement(rowData)).not.toBeUndefined();
384    })
385
386    it('LitTableTest21', () => {
387        expect(litTable.freshCurrentLine(element)).toBeUndefined();
388    })
389
390    it('LitTableTest22', () => {
391        litTable.recycleDs.length = 1
392        litTable.setCurrentSelection = jest.fn(()=>true)
393        expect(litTable.scrollToData()).toBeUndefined();
394    })
395
396    it('LitTableTest23', () => {
397        expect(litTable.expandList()).toBeUndefined();
398    })
399
400    it('LitTableTest24', () => {
401        expect(litTable.clearAllSelection()).toBeUndefined();
402    })
403
404    it('LitTableTest25', () => {
405        expect(litTable.dispatchRowClickEvent({data:{isSelected:""}})).toBeUndefined();
406    })
407
408    it('LitTableTest26', () => {
409        litTable.treeElement = jest.fn(()=>undefined)
410        litTable.treeElement.children = jest.fn(()=>[1])
411        litTable.columns.forEach = jest.fn(()=>true)
412        litTable.treeElement.lastChild= jest.fn(()=>true)
413        litTable.treeElement.lastChild.style= jest.fn(()=>true)
414        expect(litTable.createNewTreeTableElement({data:""})).not.toBeUndefined();
415    });
416
417    it('LitTableTest27', () => {
418        litTable.tableElement = jest.fn(()=>undefined)
419        litTable.tableElement.scrollTop = jest.fn(()=>1)
420        expect(litTable.move1px()).toBeUndefined();
421    })
422
423    it('LitTableTest28', () => {
424        document.body.innerHTML = `<lit-table id="aaa"></lit-table>`
425        let litTable = document.querySelector('#aaa') as LitTable
426        expect(litTable.renderTreeTable()).toBeUndefined();
427    })
428
429    it('LitTableTest29', () => {
430        document.body.innerHTML = `<lit-table id="aaa"></lit-table>`
431        let litTable = document.querySelector('#aaa') as LitTable
432        expect(litTable.setMouseIn(true,[])).toBeUndefined();
433    })
434
435    it('LitTableTest30', () => {
436        document.body.innerHTML = `<lit-table id="aaa"></lit-table>`
437        let litTable = document.querySelector('#aaa') as LitTable
438        const data = {
439            isSelected:true
440        }
441        expect(litTable.setCurrentSelection(data)).toBeUndefined();
442    })
443
444    it("LitTableTest31",() => {
445        document.body.innerHTML = `<lit-table id="aaa"></lit-table>`;
446        let litTable = document.querySelector('#aaa') as LitTable;
447        litTable.formatName =true;
448        expect(litTable.formatName).toBeTruthy();
449    })
450    it("LitTableTest32",() => {
451        let litTable =new LitTable();
452        expect(litTable.formatName()).toBe("");
453    })
454
455    it("LitTableTest33",() => {
456        let litTable =new LitTable();
457        expect(litTable.dataExportInit()).toBeUndefined();
458    })
459    it("LitTableTest34",() => {
460        let litTable =new LitTable();
461        expect(litTable.exportData()).toBeUndefined();
462    })
463
464    it('LitTableTest35', () => {
465        expect(litTable.formatExportData()).not.toBeUndefined();
466    })
467
468    it('LitTableTest36', () => {
469        expect(litTable.setSelectedRow(true,[])).toBeUndefined();
470
471    })
472
473    it('LitTableTest37', () => {
474        document.body.innerHTML = `<lit-table id="aaa"></lit-table>`;
475        let litTable = document.querySelector('#aaa') as LitTable;
476        litTable.setAttribute('tree',true);
477        expect(litTable.dataSource).toStrictEqual([]);
478    });
479
480    it('LitTableTest38', () => {
481        document.body.innerHTML = `<lit-table id="aaa"></lit-table>`;
482        let litTable = document.querySelector('#aaa') as LitTable;
483        litTable.rememberScrollTop = true;
484        expect(litTable.recycleDataSource).toStrictEqual([]);
485    });
486
487    it("LitTableTest39",() => {
488        let litTable =new LitTable();
489        expect(litTable.dataExportInit()).toBeUndefined();
490    });
491
492    it('LitTableTest40', () => {
493        litTable.columns = undefined;
494        expect(litTable.formatExportData()).toStrictEqual([]);
495    });
496
497})
498
499