|
1 | 1 | import { expect } from '@vaadin/chai-plugins'; |
2 | | -import { fixtureSync, nextFrame, nextResize } from '@vaadin/testing-helpers'; |
| 2 | +import { fixtureSync, isChrome, nextFrame, nextResize } from '@vaadin/testing-helpers'; |
3 | 3 | import '../src/vaadin-icon.js'; |
| 4 | +import { needsFontIconSizingFallback, supportsCQUnitsForPseudoElements } from '../src/vaadin-icon-helpers.js'; |
4 | 5 | import { iconFontCss } from './test-icon-font.js'; |
5 | 6 |
|
6 | 7 | describe('vaadin-icon - icon fonts', () => { |
@@ -267,4 +268,84 @@ describe('vaadin-icon - icon fonts', () => { |
267 | 268 | expect(['"My icons 6"', 'My icons 6']).to.include(fontIconStyle.fontFamily); |
268 | 269 | }); |
269 | 270 | }); |
| 271 | + |
| 272 | + // These tests make sure that the heavy container query fallback is only used |
| 273 | + // when font icons are used. |
| 274 | + describe('container query fallback', () => { |
| 275 | + // Tests for browsers that require the fallback |
| 276 | + const fallBackIt = needsFontIconSizingFallback() ? it : it.skip; |
| 277 | + // Tests for browsers that we know for sure not to require the fallback |
| 278 | + const supportedIt = isChrome ? it : it.skip; |
| 279 | + |
| 280 | + let icon; |
| 281 | + |
| 282 | + supportedIt('should support CQ width units on pseudo elements', () => { |
| 283 | + expect(supportsCQUnitsForPseudoElements()).to.be.true; |
| 284 | + }); |
| 285 | + |
| 286 | + supportedIt('should not need the fallback', () => { |
| 287 | + expect(needsFontIconSizingFallback()).to.be.false; |
| 288 | + }); |
| 289 | + |
| 290 | + fallBackIt('should not support CQ width units on pseudo elements', () => { |
| 291 | + expect(supportsCQUnitsForPseudoElements()).to.be.false; |
| 292 | + }); |
| 293 | + |
| 294 | + fallBackIt('should have the custom property (iconClass)', async () => { |
| 295 | + icon = fixtureSync('<vaadin-icon icon-class="foo" style="--vaadin-icon-size: 24px"></vaadin-icon>'); |
| 296 | + await nextFrame(); |
| 297 | + expect(icon.style.getPropertyValue('--_vaadin-font-icon-size')).to.equal('24px'); |
| 298 | + }); |
| 299 | + |
| 300 | + fallBackIt('should have the custom property (char)', async () => { |
| 301 | + icon = fixtureSync('<vaadin-icon char="foo" style="--vaadin-icon-size: 24px"></vaadin-icon>'); |
| 302 | + await nextFrame(); |
| 303 | + expect(icon.style.getPropertyValue('--_vaadin-font-icon-size')).to.equal('24px'); |
| 304 | + }); |
| 305 | + |
| 306 | + fallBackIt('should not have the custom property', async () => { |
| 307 | + icon = fixtureSync('<vaadin-icon></vaadin-icon>'); |
| 308 | + await nextFrame(); |
| 309 | + expect(icon.style.getPropertyValue('--_vaadin-font-icon-size')).to.equal(''); |
| 310 | + }); |
| 311 | + |
| 312 | + fallBackIt('should set the custom property', async () => { |
| 313 | + icon = fixtureSync('<vaadin-icon style="--vaadin-icon-size: 24px"></vaadin-icon>'); |
| 314 | + await nextFrame(); |
| 315 | + icon.iconClass = 'foo'; |
| 316 | + expect(icon.style.getPropertyValue('--_vaadin-font-icon-size')).to.equal('24px'); |
| 317 | + }); |
| 318 | + |
| 319 | + fallBackIt('should update the custom property', async () => { |
| 320 | + icon = fixtureSync('<vaadin-icon icon-class="foo"></vaadin-icon>'); |
| 321 | + await nextFrame(); |
| 322 | + icon.style.width = '100px'; |
| 323 | + icon.style.height = '100px'; |
| 324 | + await nextResize(icon); |
| 325 | + expect(icon.style.getPropertyValue('--_vaadin-font-icon-size')).to.equal('100px'); |
| 326 | + }); |
| 327 | + |
| 328 | + fallBackIt('should not update the custom property', async () => { |
| 329 | + icon = fixtureSync('<vaadin-icon></vaadin-icon>'); |
| 330 | + await nextFrame(); |
| 331 | + icon.style.width = '100px'; |
| 332 | + icon.style.height = '100px'; |
| 333 | + await nextFrame(icon); |
| 334 | + await nextFrame(icon); |
| 335 | + expect(icon.style.getPropertyValue('--_vaadin-font-icon-size')).to.equal(''); |
| 336 | + }); |
| 337 | + |
| 338 | + fallBackIt('should have the same height as the host with shadow root', async () => { |
| 339 | + icon = fixtureSync('<vaadin-icon char="foo" style="--vaadin-icon-size: 24px"></vaadin-icon>'); |
| 340 | + const parent = fixtureSync('<div></div>'); |
| 341 | + parent.attachShadow({ mode: 'open' }); |
| 342 | + parent.shadowRoot.innerHTML = '<slot></slot>'; |
| 343 | + |
| 344 | + parent.append(icon); |
| 345 | + await nextResize(icon); |
| 346 | + |
| 347 | + const fontIconStyle = getComputedStyle(icon, ':before'); |
| 348 | + expect(parseInt(fontIconStyle.height)).to.be.closeTo(24, 1); |
| 349 | + }); |
| 350 | + }); |
270 | 351 | }); |
0 commit comments