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 { LitSelect } from '../../../src/base-ui/select/LitSelect';
17
18describe('LitSelect Test', () => {
19  it('LitSelectTest01', function () {
20    let litSelect = new LitSelect();
21    expect(litSelect).not.toBeUndefined();
22  });
23
24  it('LitSelectTest02', function () {
25    document.body.innerHTML = `<lit-select id="litSelect"></lit-select>`;
26    let select = document.querySelector('#litSelect') as LitSelect;
27    expect(select).not.toBeUndefined();
28  });
29
30  it('LitSelectTest03', function () {
31    document.body.innerHTML = `<lit-select id="litSelect"></lit-select>`;
32    let select = document.querySelector('#litSelect') as LitSelect;
33    select.value = 'value';
34    expect(select.value).toBe('value');
35  });
36
37  it('LitSelectTest04', function () {
38    document.body.innerHTML = `<lit-select id="litSelect"></lit-select>`;
39    let select = document.querySelector('#litSelect') as LitSelect;
40    select.border = 'value';
41    expect(select.border).toBe('true');
42  });
43  it('LitSelectTest05', function () {
44    let lit = new LitSelect();
45    expect(lit.border).toBe('true');
46  });
47  it('LitSelectTest06', function () {
48    document.body.innerHTML = `<lit-select id="litSelect" allow-clear></lit-select>`;
49    let select = document.querySelector('#litSelect') as LitSelect;
50    select.listHeight = true;
51    expect(select.listHeight).toBe('true');
52  });
53
54  it('LitSelectTest07', function () {
55    document.body.innerHTML = `<lit-select id="litSelect" allow-clear></lit-select>`;
56    let select = document.querySelector('#litSelect') as LitSelect;
57    select.defaultValue = true;
58    expect(select.defaultValue).toBe('true');
59  });
60
61  it('LitSelectTest08', function () {
62    document.body.innerHTML = `<lit-select id="litSelect" allow-clear></lit-select>`;
63    let select = document.querySelector('#litSelect') as LitSelect;
64    select.loading = 1;
65    expect(select.loading).toBe(true);
66  });
67
68  it('LitSelectTest09', function () {
69    document.body.innerHTML = `<lit-select id="litSelect" allow-clear></lit-select>`;
70    let select = document.querySelector('#litSelect') as LitSelect;
71    expect(select.isMultiple()).toBe(false);
72  });
73
74  it('LitSelectTest10', function () {
75    document.body.innerHTML = `<lit-select id="litSelect" allow-clear></lit-select>`;
76    let select = document.querySelector('#litSelect') as LitSelect;
77    select.click();
78    expect(select.focused).toBe(true);
79  });
80
81  it('LitSelectTest11', function () {
82    document.body.innerHTML = `<lit-select allow-clear id="litSelect" ></lit-selectallow-clear>`;
83    let select = document.querySelector('#litSelect') as LitSelect;
84    select.clear();
85    expect(select.inputElement).toBeUndefined();
86  });
87
88  it('LitSelectTest12', function () {
89    document.body.innerHTML = `<lit-select id="litSelect" allow-clear></lit-select>`;
90    let select = document.querySelector('#litSelect') as LitSelect;
91    expect(select.reset()).toBeUndefined();
92  });
93
94  it('LitSelectTest13', function () {
95    document.body.innerHTML = `<lit-select id="litSelect" allow-clear></lit-select>`;
96    let select = document.querySelector('#litSelect') as LitSelect;
97    let newTag = select.newTag('111', '111');
98    expect(newTag.text).toBe('111');
99  });
100  it('LitSelectTest14', function () {
101    document.body.innerHTML = `<lit-select id="litSelect" mode="multiple" allow-clear></lit-select>`;
102    let select = document.querySelector('#litSelect') as LitSelect;
103    select.dataSource = [{ key: '111' }];
104    let cleart = select.clearElement as HTMLElement;
105    expect(select.inputElement).toBeUndefined();
106  });
107
108  it('LitSelectTest15', function () {
109    document.body.innerHTML = `<lit-select id="litSelect" mode="multiple" allow-clear></lit-select>`;
110    let select = document.querySelector('#litSelect') as LitSelect;
111    let input = select.inputElement as HTMLInputElement;
112    expect(select.inputElement).toBeUndefined();
113  });
114
115  it('LitSelectTest16', function () {
116    document.body.innerHTML = `<lit-select id="litSelect" mode="multiple" allow-clear></lit-select>`;
117    let select = document.querySelector('#litSelect') as LitSelect;
118    select.dataSource = [{ key: '111' }];
119    expect(select.inputElement).toBeUndefined();
120  });
121
122  it('LitSelectTest17', function () {
123    document.body.innerHTML = `<lit-select id="litSelect" allow-clear></lit-select>`;
124    let select = document.querySelector('#litSelect') as LitSelect;
125    select.placeholder = true;
126    expect(select.placeholder).toBe('true');
127  });
128  it('LitSelectTest20', function () {
129    document.body.innerHTML = `<lit-select id="litSelect" allow-clear></lit-select>`;
130    let select = document.querySelector('#litSelect') as LitSelect;
131    select.rounded = 1;
132    expect(select.rounded).toBe(true);
133  });
134
135  it('LitSelectTest21', function () {
136    document.body.innerHTML = `<lit-select id="litSelect" allow-clear></lit-select>`;
137    let select = document.querySelector('#litSelect') as LitSelect;
138    select.placement = 1;
139    expect(select.placement).toBe('1');
140  });
141
142  it('LitSelectTest23', function () {
143    document.body.innerHTML = `<lit-select id="litSelect" allow-clear></lit-select>`;
144    let select = document.querySelector('#litSelect') as LitSelect;
145    select.canInsert = true;
146    expect(select.canInsert).toBeTruthy();
147  });
148  it('LitSelectTest24', function () {
149    document.body.innerHTML = `<lit-select id="litSelect" allow-clear></lit-select>`;
150    let select = document.querySelector('#litSelect') as LitSelect;
151    select.rounded = false;
152    expect(select.rounded).toBeFalsy();
153  });
154  it('LitSelectTest25', function () {
155    document.body.innerHTML = `<lit-select id="litSelect" allow-clear></lit-select>`;
156    let select = document.querySelector('#litSelect') as LitSelect;
157    select.placement = false;
158    expect(select.placement).toBeFalsy();
159  });
160  it('LitSelectTest26', function () {
161    document.body.innerHTML = `<lit-select id="litSelect" allow-clear></lit-select>`;
162    let select = document.querySelector('#litSelect') as LitSelect;
163    select.border = true;
164    expect(select.border).toBeTruthy();
165  });
166  it('LitSelectTest27', function () {
167    document.body.innerHTML = `<lit-select id="litSelect" allow-clear></lit-select>`;
168    let select = document.querySelector('#litSelect') as LitSelect;
169    select.canInsert = false;
170    expect(select.canInsert).toBeFalsy();
171  });
172  it('LitSelectTest28', function () {
173    document.body.innerHTML = `<lit-select id="litSelect" allow-clear></lit-select>`;
174    let select = document.querySelector('#litSelect') as LitSelect;
175    select.loading = false;
176    expect(select.loading).toBeFalsy();
177  });
178
179  it('LitSelectTest29', function () {
180    let lit = new LitSelect();
181    lit.border = false;
182    expect(lit.border).toBe('false');
183  });
184
185  it('LitSelectTest30', function () {
186    let litSelect = (document.body.innerHTML = `<lit-select id="litSelect" allow-clear>
187            <lit-select-option id="litSelectOption1" selected></lit-select-option>
188            <lit-select-option id="litSelectOption2"></lit-select-option>
189        </lit-select>` as LitSelect);
190    let select = document.querySelector('#litSelect') as LitSelect;
191    expect(select.reset()).toBeUndefined();
192  });
193  it('LitSelectTest31', function () {
194    document.body.innerHTML = `<lit-select id="litSelect"  adaptive-expansion></lit-select>`;
195    let select = document.querySelector('#litSelect') as LitSelect;
196    let mouseClickEvent: MouseEvent = new MouseEvent('click', <MouseEventInit>{ movementX: 1, movementY: 2 });
197    select.isMultiple = jest.fn(() => true);
198    select.selectClearEl.dispatchEvent(mouseClickEvent);
199  });
200});
201