Skip to content

Commit

Permalink
Add another group test
Browse files Browse the repository at this point in the history
  • Loading branch information
barvian committed Nov 26, 2024
1 parent b182bd0 commit dcc7290
Show file tree
Hide file tree
Showing 8 changed files with 203 additions and 0 deletions.
50 changes: 50 additions & 0 deletions packages/react/test/apps/react-18/app/group-1-unchanged/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
'use client'

import * as React from 'react'
import NumberFlow, { NumberFlowElement, NumberFlowGroup } from '@number-flow/react'
import { flushSync } from 'react-dom'

export default function Page() {
const [value, setValue] = React.useState(42)
const ref1 = React.useRef<NumberFlowElement>(null)
const ref2 = React.useRef<NumberFlowElement>(null)
return (
<>
<div>
<NumberFlowGroup>
<NumberFlow ref={ref1} value={value} />
<NumberFlow ref={ref2} value={0} />
</NumberFlowGroup>
</div>
<button
onClick={() => {
flushSync(() => {
setValue(152000)
})
;[
...(ref1.current?.shadowRoot?.getAnimations() ?? []),
...(ref2.current?.shadowRoot?.getAnimations() ?? [])
].forEach((a) => {
a.pause()
a.currentTime = 300
})
}}
>
Change and pause
</button>
<br />
<button
onClick={() => {
;[
...(ref1.current?.shadowRoot?.getAnimations() ?? []),
...(ref2.current?.shadowRoot?.getAnimations() ?? [])
].forEach((a) => {
a.play()
})
}}
>
Resume
</button>
</>
)
}
50 changes: 50 additions & 0 deletions packages/react/test/apps/react-19/app/group-1-unchanged/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
'use client'

import * as React from 'react'
import NumberFlow, { NumberFlowElement, NumberFlowGroup } from '@number-flow/react'
import { flushSync } from 'react-dom'

export default function Page() {
const [value, setValue] = React.useState(42)
const ref1 = React.useRef<NumberFlowElement>(null)
const ref2 = React.useRef<NumberFlowElement>(null)
return (
<>
<div>
<NumberFlowGroup>
<NumberFlow ref={ref1} value={value} />
<NumberFlow ref={ref2} value={0} />
</NumberFlowGroup>
</div>
<button
onClick={() => {
flushSync(() => {
setValue(152000)
})
;[
...(ref1.current?.shadowRoot?.getAnimations() ?? []),
...(ref2.current?.shadowRoot?.getAnimations() ?? [])
].forEach((a) => {
a.pause()
a.currentTime = 300
})
}}
>
Change and pause
</button>
<br />
<button
onClick={() => {
;[
...(ref1.current?.shadowRoot?.getAnimations() ?? []),
...(ref2.current?.shadowRoot?.getAnimations() ?? [])
].forEach((a) => {
a.play()
})
}}
>
Resume
</button>
</>
)
}
43 changes: 43 additions & 0 deletions packages/svelte/src/routes/group-1-unchanged/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<script lang="ts">
import NumberFlow, { NumberFlowGroup, NumberFlowElement } from '$lib/index.js'
import { afterUpdate, tick } from 'svelte'
const initialValue = 42
let value = initialValue
let el1: NumberFlowElement | undefined
let el2: NumberFlowElement | undefined
afterUpdate(async () => {
await tick()
if (value !== initialValue) {
;[
...(el1?.shadowRoot?.getAnimations() ?? []),
...(el2?.shadowRoot?.getAnimations() ?? [])
].forEach((a) => {
a.pause()
a.currentTime = 300
})
}
})
</script>

<div>
<NumberFlowGroup>
<NumberFlow bind:el={el1} {value} /><NumberFlow bind:el={el2} value={0} />
</NumberFlowGroup>
</div>
<button on:click={() => (value = 152000)}>Change and pause</button>
<br />
<button
on:click={() => {
;[
...(el1?.shadowRoot?.getAnimations() ?? []),
...(el2?.shadowRoot?.getAnimations() ?? [])
].forEach((a) => {
a.play()
})
}}
>
Resume
</button>
45 changes: 45 additions & 0 deletions packages/vue/test/apps/nuxt3/src/pages/group-1-unchanged.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<script setup lang="ts">
import NumberFlow, { NumberFlowGroup } from '@number-flow/vue'
import { ref } from 'vue'
const flow1 = useTemplateRef('flow1')
const flow2 = useTemplateRef('flow2')
const value = ref(42)
watch(
value,
async () => {
await nextTick()
;[
...(flow1.value?.el?.shadowRoot?.getAnimations() ?? []),
...(flow2.value?.el?.shadowRoot?.getAnimations() ?? [])
].forEach((a) => {
a.pause()
a.currentTime = 300
})
},
{ flush: 'post' }
)
</script>
<template>
<div>
<NumberFlowGroup>
<NumberFlow ref="flow1" :value />
<NumberFlow ref="flow2" :value="0" />
</NumberFlowGroup>
</div>
<button @click="value = 152000">Change and pause</button><br />
<button
@click="
() => {
;[
...(flow1?.el?.shadowRoot?.getAnimations() ?? []),
...(flow2?.el?.shadowRoot?.getAnimations() ?? [])
].forEach((a) => {
a.play()
})
}
"
>
Resume
</button>
</template>
15 changes: 15 additions & 0 deletions test-suites/wrapper/group-1-unchanged.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { test, expect } from '@playwright/test'

test.skip(
({ javaScriptEnabled, contextOptions }) =>
!javaScriptEnabled || contextOptions.reducedMotion === 'reduce'
)

test('transitions correctly', async ({ page, contextOptions }) => {
// Not sure why this is necessary for Svelte Chromium/Safari but I couldn't get it to work without it:
// https://www.reddit.com/r/sveltejs/comments/15m9jch/how_do_you_wait_for_sveltekit_to_be_completely/
await page.goto('/group-1-unchanged', { waitUntil: 'networkidle' })

await page.getByRole('button', { name: 'Change and pause' }).click()
await expect(page).toHaveScreenshot({ animations: 'allow' })
})
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit dcc7290

Please sign in to comment.