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