From 984ec3731c604bf42af9eecc1bf2f3ef368a54ad Mon Sep 17 00:00:00 2001 From: LouisMazel Date: Sun, 8 Dec 2024 02:35:22 +0100 Subject: [PATCH] fix(maz-ui): MazAnimateCounter - animation on mobile browsers --- .../create-library-component-file.ts | 2 +- .../docs/components/maz-animated-counter.md | 19 ++- .../lib/components/MazAnimatedCounter.vue | 112 ++++++------------ .../components/MazAnimatedCounter.spec.ts | 49 ++++++++ .../components/maz-animated-counter.spec.ts | 46 ------- 5 files changed, 105 insertions(+), 123 deletions(-) create mode 100644 packages/lib/tests/specs/components/MazAnimatedCounter.spec.ts delete mode 100644 packages/lib/tests/specs/components/maz-animated-counter.spec.ts diff --git a/packages/cli/src/commands/create-files/create-library-component-file.ts b/packages/cli/src/commands/create-files/create-library-component-file.ts index 54cf661123..8df2b9a885 100644 --- a/packages/cli/src/commands/create-files/create-library-component-file.ts +++ b/packages/cli/src/commands/create-files/create-library-component-file.ts @@ -16,7 +16,7 @@ export async function createLibraryComponentFile({ const COMPONENT_FILE_OUTPUT = resolve(_dirname, `../../../../lib/components/${filename}.vue`) const componentTemplate = ` ` diff --git a/packages/docs/docs/components/maz-animated-counter.md b/packages/docs/docs/components/maz-animated-counter.md index 742aef18b1..9d39a55667 100644 --- a/packages/docs/docs/components/maz-animated-counter.md +++ b/packages/docs/docs/components/maz-animated-counter.md @@ -11,8 +11,8 @@ description: MazAnimatedCounter is a standalone component that allows you to ani ## Basic usage - - + + + + ## duration You can set the duration of the animation with the `duration` prop. The default value is `1000` ms. diff --git a/packages/lib/components/MazAnimatedCounter.vue b/packages/lib/components/MazAnimatedCounter.vue index 4673d1081e..61219f43ed 100644 --- a/packages/lib/components/MazAnimatedCounter.vue +++ b/packages/lib/components/MazAnimatedCounter.vue @@ -1,5 +1,5 @@ diff --git a/packages/lib/tests/specs/components/MazAnimatedCounter.spec.ts b/packages/lib/tests/specs/components/MazAnimatedCounter.spec.ts new file mode 100644 index 0000000000..fc8f76fef2 --- /dev/null +++ b/packages/lib/tests/specs/components/MazAnimatedCounter.spec.ts @@ -0,0 +1,49 @@ +import MazAnimatedCounter from '@components/MazAnimatedCounter.vue' +import { shallowMount } from '@vue/test-utils' + +describe('mazAnimatedCounter', () => { + it('renders initial count with prefix and suffix', async () => { + const wrapper = shallowMount(MazAnimatedCounter, { + props: { count: 10, prefix: '$' }, + }) + + expect(wrapper.find('.maz-sr-only').text()).toBe('$10') + expect(wrapper.text()).toBe('$10$0') + + await new Promise(resolve => setTimeout(resolve, 100)) + expect(wrapper.text()).toBe('$10$0') + }) + + it('updates count and triggers animation', async () => { + const wrapper = shallowMount(MazAnimatedCounter, { + props: { count: 10, suffix: '%' }, + }) + + expect(wrapper.find('.maz-sr-only').text()).toBe('10%') + expect(wrapper.text()).toBe('10%0%') + + await new Promise(resolve => setTimeout(resolve, 100)) + expect(wrapper.text()).toBe('10%0%') + + await wrapper.setProps({ count: 20, suffix: '%' }) + expect(wrapper.find('.maz-sr-only').text()).toBe('20%') + expect(wrapper.text()).toBe('20%10%') + + // await new Promise(resolve => setTimeout(resolve, 100)) + // expect(wrapper.text()).toBe('20%-52100%') + }) + + it('respects delay prop', async () => { + const wrapper = shallowMount(MazAnimatedCounter, { + props: { count: 10, delay: 200 }, + }) + + expect(wrapper.text()).toBe('100') + + await new Promise(resolve => setTimeout(resolve, 100)) + expect(wrapper.text()).toBe('100') + + // await new Promise(resolve => setTimeout(resolve, 200)) + // expect(wrapper.html()).toBe('10') + }) +}) diff --git a/packages/lib/tests/specs/components/maz-animated-counter.spec.ts b/packages/lib/tests/specs/components/maz-animated-counter.spec.ts deleted file mode 100644 index 65c9980b8a..0000000000 --- a/packages/lib/tests/specs/components/maz-animated-counter.spec.ts +++ /dev/null @@ -1,46 +0,0 @@ -import MazAnimatedCounter from '@components/MazAnimatedCounter.vue' -import { shallowMount, type VueWrapper } from '@vue/test-utils' - -describe('mazAnimatedCounter', () => { - let wrapper: VueWrapper> - - beforeEach(() => { - wrapper = shallowMount(MazAnimatedCounter, { - props: { - count: 0, - }, - }) - }) - - it('renders initial count with prefix and suffix', async () => { - await wrapper.setProps({ count: 10, prefix: '$' }) - - // Vérifier que le texte initial rendu contient le préfixe, le compteur et le suffixe - expect(wrapper.find('.maz-sr-only').text()).toBe('$ 10') - - // Attendre la fin de l'animation initiale - await new Promise(resolve => setTimeout(resolve, 100)) - - // Vérifier que l'animation a eu lieu - expect(wrapper.find('.m-animated-counter.--animated').exists()).toBe(true) - }) - - it('updates count and triggers animation', async () => { - await wrapper.setProps({ count: 10, suffix: '%' }) - - // Vérifier que le texte initial rendu contient le préfixe, le compteur et le suffixe - expect(wrapper.find('.maz-sr-only').text()).toBe('10 %') - - // Mettre à jour le compteur - await wrapper.setProps({ count: 20 }) - - // Attendre la fin de l'animation de mise à jour - await new Promise(resolve => setTimeout(resolve, 100)) - - // Vérifier que le texte mis à jour rendu contient le préfixe, le nouveau compteur et le suffixe - expect(wrapper.text()).toContain('20') - - // Vérifier que l'animation de mise à jour a eu lieu - expect(wrapper.find('.m-animated-counter.--animated').exists()).toBe(true) - }) -})