|
1 | 1 | import { expect } from '@esm-bundle/chai'; |
2 | | -import { aTimeout, fixtureSync, nextFrame } from '@vaadin/testing-helpers'; |
| 2 | +import { aTimeout, fixtureSync } from '@vaadin/testing-helpers'; |
3 | 3 | import sinon from 'sinon'; |
4 | 4 | import '../src/vaadin-text-field.js'; |
5 | 5 |
|
@@ -128,94 +128,11 @@ describe('text-field', () => { |
128 | 128 | expect(textField.value).to.be.equal('foo'); |
129 | 129 | }); |
130 | 130 |
|
131 | | - it('setting input value updates has-value attribute', () => { |
132 | | - textField.value = 'foo'; |
133 | | - expect(textField.hasAttribute('has-value')).to.be.true; |
134 | | - }); |
135 | | - |
136 | | - it('setting value to undefined should not update has-value attribute', () => { |
137 | | - textField.value = undefined; |
138 | | - expect(textField.hasAttribute('has-value')).to.be.false; |
139 | | - }); |
140 | | - |
141 | 131 | it('setting value to undefined should clear the native input value', () => { |
142 | 132 | textField.value = 'foo'; |
143 | 133 | textField.value = undefined; |
144 | 134 | expect(input.value).to.equal(''); |
145 | 135 | }); |
146 | | - |
147 | | - it('setting empty value does not update has-value attribute', () => { |
148 | | - textField.value = ''; |
149 | | - expect(textField.hasAttribute('has-value')).to.be.false; |
150 | | - }); |
151 | | - |
152 | | - // User could accidentally set a 0 or false value |
153 | | - it('setting number value updates has-value attribute', () => { |
154 | | - textField.value = 0; |
155 | | - expect(textField.hasAttribute('has-value')).to.be.true; |
156 | | - }); |
157 | | - |
158 | | - it('setting boolean value updates has-value attribute', () => { |
159 | | - textField.value = false; |
160 | | - expect(textField.hasAttribute('has-value')).to.be.true; |
161 | | - }); |
162 | | - |
163 | | - it('setting label updates has-label attribute', () => { |
164 | | - textField.label = 'foo'; |
165 | | - expect(textField.hasAttribute('has-label')).to.be.true; |
166 | | - }); |
167 | | - |
168 | | - it('setting label to empty string does not update has-label attribute', () => { |
169 | | - textField.label = ''; |
170 | | - expect(textField.hasAttribute('has-label')).to.be.false; |
171 | | - }); |
172 | | - |
173 | | - it('setting label to null does not update has-label attribute', () => { |
174 | | - textField.label = null; |
175 | | - expect(textField.hasAttribute('has-label')).to.be.false; |
176 | | - }); |
177 | | - |
178 | | - it('setting helper updates has-helper attribute', () => { |
179 | | - textField.helperText = 'foo'; |
180 | | - expect(textField.hasAttribute('has-helper')).to.be.true; |
181 | | - }); |
182 | | - |
183 | | - it('setting helper to empty string does not update has-helper attribute', () => { |
184 | | - textField.helperText = ''; |
185 | | - expect(textField.hasAttribute('has-helper')).to.be.false; |
186 | | - }); |
187 | | - |
188 | | - it('setting helper to null does not update has-helper attribute', () => { |
189 | | - textField.helperText = null; |
190 | | - expect(textField.hasAttribute('has-helper')).to.be.false; |
191 | | - }); |
192 | | - |
193 | | - it('setting helper with slot updates has-helper attribute', async () => { |
194 | | - const helper = document.createElement('div'); |
195 | | - helper.setAttribute('slot', 'helper'); |
196 | | - helper.textContent = 'foo'; |
197 | | - textField.appendChild(helper); |
198 | | - await nextFrame(); |
199 | | - expect(textField.hasAttribute('has-helper')).to.be.true; |
200 | | - }); |
201 | | - |
202 | | - it('setting errorMessage updates has-error-message attribute', () => { |
203 | | - textField.invalid = true; |
204 | | - textField.errorMessage = 'foo'; |
205 | | - expect(textField.hasAttribute('has-error-message')).to.be.true; |
206 | | - }); |
207 | | - |
208 | | - it('setting errorMessage to empty string does not update has-error-message attribute', () => { |
209 | | - textField.invalid = true; |
210 | | - textField.errorMessage = ''; |
211 | | - expect(textField.hasAttribute('has-error-message')).to.be.false; |
212 | | - }); |
213 | | - |
214 | | - it('setting errorMessage to null does not update has-error-message attribute', () => { |
215 | | - textField.invalid = true; |
216 | | - textField.errorMessage = null; |
217 | | - expect(textField.hasAttribute('has-error-message')).to.be.false; |
218 | | - }); |
219 | 136 | }); |
220 | 137 |
|
221 | 138 | describe('required', () => { |
@@ -348,6 +265,31 @@ describe('text-field', () => { |
348 | 265 | }); |
349 | 266 | }); |
350 | 267 |
|
| 268 | + describe('has-value attribute', () => { |
| 269 | + it('should toggle the attribute on value change', () => { |
| 270 | + textField.value = 'foo'; |
| 271 | + expect(textField.hasAttribute('has-value')).to.be.true; |
| 272 | + textField.value = undefined; |
| 273 | + expect(textField.hasAttribute('has-value')).to.be.false; |
| 274 | + }); |
| 275 | + |
| 276 | + it('should not add the attribute when the value is an empty string', () => { |
| 277 | + textField.value = ''; |
| 278 | + expect(textField.hasAttribute('has-value')).to.be.false; |
| 279 | + }); |
| 280 | + |
| 281 | + // User could accidentally set a 0 or false value |
| 282 | + it('should add the attribute when the value is a number', () => { |
| 283 | + textField.value = 0; |
| 284 | + expect(textField.hasAttribute('has-value')).to.be.true; |
| 285 | + }); |
| 286 | + |
| 287 | + it('should add the attribute when the value is a boolean', () => { |
| 288 | + textField.value = false; |
| 289 | + expect(textField.hasAttribute('has-value')).to.be.true; |
| 290 | + }); |
| 291 | + }); |
| 292 | + |
351 | 293 | describe('value property', () => { |
352 | 294 | it('should not consider updating the value as user input if the value is not changed', () => { |
353 | 295 | const event = new Event('input', { |
@@ -387,12 +329,4 @@ describe('text-field', () => { |
387 | 329 | expect(input.value).to.equal(''); |
388 | 330 | }); |
389 | 331 | }); |
390 | | - |
391 | | - describe('theme attribute', () => { |
392 | | - it('should propagate theme attribute to input container', () => { |
393 | | - const container = textField.shadowRoot.querySelector('[part="input-field"]'); |
394 | | - textField.setAttribute('theme', 'align-center'); |
395 | | - expect(container.getAttribute('theme')).to.equal('align-center'); |
396 | | - }); |
397 | | - }); |
398 | 332 | }); |
0 commit comments