|
| 1 | +export default { |
| 2 | + props: { |
| 3 | + visible: true |
| 4 | + }, |
| 5 | + intro: true, |
| 6 | + async test({ assert, component, window, waitUntil, target }) { |
| 7 | + /** @type {HTMLElement} */ |
| 8 | + const elAnimatedOnMount = target.querySelector('#animated-on-mount'); |
| 9 | + /** @type {HTMLElement} */ |
| 10 | + const elAnimatedOnInit = target.querySelector('#animated-on-init'); |
| 11 | + |
| 12 | + assert.equal(elAnimatedOnInit.getAnimations().length, 1); |
| 13 | + assert.equal(elAnimatedOnMount.getAnimations().length, 1); |
| 14 | + const elAnimatedOnInitAnimation = elAnimatedOnInit.getAnimations().at(0); |
| 15 | + const elAnimatedOnMountAnimation = elAnimatedOnMount.getAnimations().at(0); |
| 16 | + |
| 17 | + assert.equal(elAnimatedOnInitAnimation.playState, 'running'); |
| 18 | + assert.equal(elAnimatedOnMountAnimation.playState, 'running'); |
| 19 | + assert.equal(!!elAnimatedOnInit.style.animation, true); |
| 20 | + assert.equal(!!elAnimatedOnMount.style.animation, true); |
| 21 | + assert.equal(window.document.head.querySelector('style')?.sheet.rules.length, 2); |
| 22 | + |
| 23 | + await elAnimatedOnInitAnimation.finished.catch((e) => { |
| 24 | + if (e.name === 'AbortError') { |
| 25 | + throw new Error( |
| 26 | + 'The animation was aborted, keyframes have been removed before the animation execution end.' |
| 27 | + ); |
| 28 | + } |
| 29 | + throw e; |
| 30 | + }); |
| 31 | + assert.equal(elAnimatedOnInitAnimation.playState, 'finished'); |
| 32 | + assert.equal(elAnimatedOnMountAnimation.playState, 'running'); |
| 33 | + assert.equal(!!elAnimatedOnInit.style.animation, true); |
| 34 | + assert.equal(!!elAnimatedOnMount.style.animation, true); |
| 35 | + assert.equal(window.document.head.querySelector('style')?.sheet.rules.length, 2); |
| 36 | + assert.equal(elAnimatedOnInit.getAnimations().length, 1); |
| 37 | + assert.equal(elAnimatedOnMount.getAnimations().length, 1); |
| 38 | + |
| 39 | + await waitUntil(() => elAnimatedOnInit.getAnimations().length === 0); |
| 40 | + assert.equal(elAnimatedOnInitAnimation.playState, 'idle'); |
| 41 | + assert.equal(elAnimatedOnMountAnimation.playState, 'running'); |
| 42 | + assert.equal(!!elAnimatedOnInit.style.animation, false); |
| 43 | + assert.equal(!!elAnimatedOnMount.style.animation, true); |
| 44 | + assert.equal(window.document.head.querySelector('style')?.sheet.rules.length, 2); |
| 45 | + assert.equal(elAnimatedOnInit.getAnimations().length, 0); |
| 46 | + assert.equal(elAnimatedOnMount.getAnimations().length, 1); |
| 47 | + |
| 48 | + await elAnimatedOnMountAnimation.finished.catch((e) => { |
| 49 | + if (e.name === 'AbortError') { |
| 50 | + throw new Error( |
| 51 | + 'The animation was aborted, keyframes have been removed before the animation execution end.' |
| 52 | + ); |
| 53 | + } |
| 54 | + throw e; |
| 55 | + }); |
| 56 | + assert.equal(elAnimatedOnInitAnimation.playState, 'idle'); |
| 57 | + assert.equal(elAnimatedOnMountAnimation.playState, 'finished'); |
| 58 | + assert.equal(!!elAnimatedOnInit.style.animation, false); |
| 59 | + assert.equal(!!elAnimatedOnMount.style.animation, true); |
| 60 | + assert.equal(window.document.head.querySelector('style')?.sheet.rules.length, 2); |
| 61 | + assert.equal(elAnimatedOnInit.getAnimations().length, 0); |
| 62 | + assert.equal(elAnimatedOnMount.getAnimations().length, 1); |
| 63 | + |
| 64 | + await waitUntil(() => window.document.head.querySelector('style') === null); |
| 65 | + assert.equal(elAnimatedOnInitAnimation.playState, 'idle'); |
| 66 | + assert.equal(elAnimatedOnMountAnimation.playState, 'idle'); |
| 67 | + assert.equal(!!elAnimatedOnInit.style.animation, false); |
| 68 | + assert.equal(!!elAnimatedOnMount.style.animation, false); |
| 69 | + assert.equal(window.document.head.querySelector('style'), null); |
| 70 | + assert.equal(elAnimatedOnInit.getAnimations().length, 0); |
| 71 | + assert.equal(elAnimatedOnMount.getAnimations().length, 0); |
| 72 | + |
| 73 | + /** @type {NodeListOf<HTMLElement>} */ |
| 74 | + let divs = target.querySelectorAll('.fading-div'); |
| 75 | + /** @type {Animation[]} */ |
| 76 | + let animations; |
| 77 | + assert.equal(divs.length, 1); |
| 78 | + divs.forEach((div) => assert.equal(div.getAnimations().length, 0)); |
| 79 | + |
| 80 | + component.visible = false; |
| 81 | + divs = target.querySelectorAll('.fading-div'); |
| 82 | + assert.equal(divs.length, 1); |
| 83 | + divs.forEach((div) => assert.equal(div.getAnimations().length, 1)); |
| 84 | + animations = Array.from(divs).map((div) => div.getAnimations().at(0)); |
| 85 | + animations.forEach((animation) => assert.equal(animation.playState, 'running')); |
| 86 | + assert.equal(window.document.head.querySelector('style')?.sheet.rules.length, 1); |
| 87 | + assert.equal(elAnimatedOnInit.getAnimations().length, 0); |
| 88 | + assert.equal(elAnimatedOnMount.getAnimations().length, 0); |
| 89 | + |
| 90 | + await animations[0].finished.catch((e) => { |
| 91 | + if (e.name === 'AbortError') { |
| 92 | + throw new Error( |
| 93 | + 'The animation was aborted, keyframes have been removed before the animation execution end.' |
| 94 | + ); |
| 95 | + } |
| 96 | + throw e; |
| 97 | + }); |
| 98 | + divs = target.querySelectorAll('.fading-div'); |
| 99 | + assert.equal(divs.length, 1); |
| 100 | + divs.forEach((div) => assert.equal(div.getAnimations().length, 1)); |
| 101 | + animations.forEach((animation) => assert.equal(animation.playState, 'finished')); |
| 102 | + assert.equal(window.document.head.querySelector('style')?.sheet.rules.length, 1); |
| 103 | + assert.equal(elAnimatedOnInit.getAnimations().length, 0); |
| 104 | + assert.equal(elAnimatedOnMount.getAnimations().length, 0); |
| 105 | + |
| 106 | + await waitUntil(() => window.document.head.querySelector('style') === null); |
| 107 | + divs = target.querySelectorAll('.fading-div'); |
| 108 | + assert.equal(divs.length, 1); |
| 109 | + divs.forEach((div) => assert.equal(div.getAnimations().length, 0)); |
| 110 | + animations.forEach((animation) => assert.equal(animation.playState, 'idle')); |
| 111 | + assert.equal(window.document.head.querySelector('style'), null); |
| 112 | + assert.equal(elAnimatedOnInit.getAnimations().length, 0); |
| 113 | + assert.equal(elAnimatedOnMount.getAnimations().length, 0); |
| 114 | + |
| 115 | + component.visible = true; |
| 116 | + divs = target.querySelectorAll('.fading-div'); |
| 117 | + assert.equal(divs.length, 1); |
| 118 | + divs.forEach((div) => assert.equal(div.getAnimations().length, 1)); |
| 119 | + animations = Array.from(divs).map((div) => div.getAnimations().at(0)); |
| 120 | + animations.forEach((animation) => assert.equal(animation.playState, 'running')); |
| 121 | + assert.equal(window.document.head.querySelector('style')?.sheet.rules.length, 1); |
| 122 | + assert.equal(elAnimatedOnInit.getAnimations().length, 0); |
| 123 | + assert.equal(elAnimatedOnMount.getAnimations().length, 0); |
| 124 | + |
| 125 | + await animations[0].finished.catch((e) => { |
| 126 | + if (e.name === 'AbortError') { |
| 127 | + throw new Error( |
| 128 | + 'The animation was aborted, keyframes have been removed before the animation execution end.' |
| 129 | + ); |
| 130 | + } |
| 131 | + throw e; |
| 132 | + }); |
| 133 | + divs = target.querySelectorAll('.fading-div'); |
| 134 | + assert.equal(divs.length, 1); |
| 135 | + divs.forEach((div) => assert.equal(div.getAnimations().length, 1)); |
| 136 | + animations.forEach((animation) => assert.equal(animation.playState, 'finished')); |
| 137 | + assert.equal(window.document.head.querySelector('style')?.sheet.rules.length, 1); |
| 138 | + assert.equal(elAnimatedOnInit.getAnimations().length, 0); |
| 139 | + assert.equal(elAnimatedOnMount.getAnimations().length, 0); |
| 140 | + |
| 141 | + await waitUntil(() => window.document.head.querySelector('style') === null); |
| 142 | + divs = target.querySelectorAll('.fading-div'); |
| 143 | + assert.equal(divs.length, 1); |
| 144 | + divs.forEach((div) => assert.equal(div.getAnimations().length, 0)); |
| 145 | + animations.forEach((animation) => assert.equal(animation.playState, 'idle')); |
| 146 | + assert.equal(window.document.head.querySelector('style'), null); |
| 147 | + assert.equal(elAnimatedOnInit.getAnimations().length, 0); |
| 148 | + assert.equal(elAnimatedOnMount.getAnimations().length, 0); |
| 149 | + } |
| 150 | +}; |
0 commit comments