From 5644afbb5a4c2d56bc86461918e676c820a57109 Mon Sep 17 00:00:00 2001 From: Erwin Mombay Date: Fri, 11 Aug 2023 13:44:55 -0700 Subject: [PATCH] add additional option to add initial state value for time based animations --- test/integration/test-boilerplates.js | 2 +- testing/helpers/service.js | 37 +++++++++++++++++++-------- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/test/integration/test-boilerplates.js b/test/integration/test-boilerplates.js index 7773a8a6cc3f3..f64289dcf952e 100644 --- a/test/integration/test-boilerplates.js +++ b/test/integration/test-boilerplates.js @@ -39,7 +39,7 @@ describes.sandboxed('New Visibility Boilerplate', {}, () => { expect(getStyle(fixture.win.document.body, 'visibility')).to.equal( 'visible' ); - expect(isAnimationNone(fixture.win.document.body)).to.be.true; + expect(isAnimationNone(fixture.win.document.body, true)).to.be.true; }); }); }); diff --git a/testing/helpers/service.js b/testing/helpers/service.js index 7102171a4f4c6..283cc828438fb 100644 --- a/testing/helpers/service.js +++ b/testing/helpers/service.js @@ -88,25 +88,40 @@ export function waitFor(callback, errorMessage) { ); } -const noneValues = { - 'animation-name': ['none', 'initial'], - 'animation-duration': ['0s', 'auto', 'initial'], - 'animation-timing-function': ['ease', 'initial'], - 'animation-delay': ['0s', 'initial'], - 'animation-iteration-count': ['1', 'initial'], - 'animation-direction': ['normal', 'initial'], - 'animation-fill-mode': ['none', 'initial'], - 'animation-play-state': ['running', 'initial', /* IE11 */ ''], -}; +/** + * Gets the initial values of an Element's animation state. + * The values for `animation-duration`; + * + * @param {!boolean} isTimeBasedAnimation + */ +function getInitialNoneValues(isTimeBasedAnimation) { + const initialValues = { + 'animation-name': ['none', 'initial'], + 'animation-duration': ['0s', 'auto', 'initial'], + 'animation-timing-function': ['ease', 'initial'], + 'animation-delay': ['0s', 'initial'], + 'animation-iteration-count': ['1', 'initial'], + 'animation-direction': ['normal', 'initial'], + 'animation-fill-mode': ['none', 'initial'], + 'animation-play-state': ['running', 'initial', /* IE11 */ ''], + }; + if (isTimeBasedAnimation) { + initialValues['animation-duration'].unshift('auto'); + } + return initialValues; +} /** * Browsers are inconsistent when accessing the value for 'animation: none'. * Some return 'none', some return the full shorthand, some give the full * shorthand in a different order. + * * @param {!Element} element + * @param {boolean=} opt_isTimeBasedAnimation * @return {boolean} */ -export function isAnimationNone(element) { +export function isAnimationNone(element, opt_isTimeBasedAnimation = true) { + const noneValues = getInitialNoneValues(opt_isTimeBasedAnimation); for (const property in noneValues) { const value = getStyle(element, property); const expectedValues = noneValues[property];