Files
gui/apps/kitchen-sink/tests/AnimatedByProp.animated.test.tsx
zeekayandHanzo Dev 69c6e860d7 transplant onto tamagui v2.6.0, brand as a re-runnable transform
This repo could never sync. There was NO merge-base with tamagui — 372 commits
here against 15,791 there, unrelated histories — because it began as a
copy-paste rebrand with a flattened layout. Every "sync" since was a hand
re-application that drifted, which is why the tree sat on 7.3.1 while upstream
shipped fixes we then rediscovered by hand.

This commit's PARENT IS TAMAGUI. A future sync is `git merge tama/main` then
`node scripts/rebrand.mjs` — a real merge, because the history is now shared.

174 packages: 166 upstream, our 8 restored (chrome, shell, telemetry, recipes,
get, font-geist-{sans,mono}, @hanzo/booker), bento-get gained. 170/170 build.

Our patches to files UPSTREAM ALSO OWNS are carried, which the package-level
delta missed and which was where the value actually was:
  - useMedia's server snapshot (`initState ?? getMedia()`). Upstream still
    returns undefined there, so every Tamagui Dialog kills a prerender — the
    exact crash hanzo.app spent a day on.
  - data-slot on web host nodes, absent upstream entirely.
Both applied ONTO upstream's newer files (it rewrote useMedia +150/-63 and
createComponent +160/-55), marked `PATCH (ours, carried across the transplant)`.

Seven traps are encoded in scripts/rebrand.mjs, each found by a gate:
skip itself and lockfiles; special-case the double-branded names in BOTH scoped
and bare form; map path strings, not just paths; drop a level for the flattened
group; check disk rather than a stale index.

Rust build artifacts are NOT committed. An earlier draft of this commit swept
apps/desktop/src-tauri/target/debug in via `git add -A` — 3,859 files including
a 272MB .a, over GitHub's 100MB cap, so the push could never have landed. They
are gitignored now.

Co-Authored-By: Hanzo Dev <[email protected]>
2026-07-30 18:25:06 -07:00

139 lines
5.0 KiB
TypeScript

import { expect, test } from '@playwright/test'
import { setupPage } from './test-utils'
/**
* Tests for the animatedBy prop.
*
* The key test: animatedBy="default" should work the same as not setting it,
* meaning the animation driver is properly looked up and applied.
*
* If the lookup is broken (returns null), the element with animatedBy="default"
* won't animate, while the one without animatedBy will still animate via context.
*/
const TOLERANCE = 0.05
test.describe('animatedBy prop', () => {
// Skip native driver - it doesn't work on web
test.beforeEach(async ({ page }, testInfo) => {
test.skip(
testInfo.project.name === 'animated-native',
'Native driver not supported on web'
)
await setupPage(page, {
name: 'AnimatedByProp',
type: 'useCase',
})
await page.waitForTimeout(500)
})
test('animatedBy="default" element animates properly', async ({ page }) => {
const START = 0.5,
END = 1
const explicitElement = page.getByTestId('explicit-default')
// Initial state
const initialOpacity = await explicitElement.evaluate((el) =>
Number(getComputedStyle(el).opacity)
)
expect(initialOpacity).toBeCloseTo(START, 1)
// Trigger animation and poll for intermediate values via rAF
// this avoids brittle single-point-in-time snapshots that miss on slow CI
const samples: number[] = await page.evaluate((testId) => {
return new Promise<number[]>((resolve) => {
const el = document.querySelector(`[data-testid="${testId}"]`)!
const vals: number[] = []
const start = performance.now()
function tick() {
vals.push(Number(getComputedStyle(el).opacity))
if (performance.now() - start < 600) requestAnimationFrame(tick)
else resolve(vals)
}
;(document.querySelector('[data-testid="toggle-trigger"]') as HTMLElement).click()
requestAnimationFrame(tick)
})
}, 'explicit-default')
const finalOpacity = samples[samples.length - 1]
expect(
finalOpacity,
`Should reach end state (${END}), got ${finalOpacity.toFixed(2)}`
).toBeCloseTo(END, 1)
// verify animation driver is working: must have intermediate values (not instant snap)
const intermediates = samples.filter(
(v) => Math.abs(v - START) > TOLERANCE && Math.abs(v - END) > TOLERANCE
)
expect(
intermediates.length,
`Should have multiple intermediate frames (got ${intermediates.length}). ` +
`Samples: [${samples
.slice(0, 8)
.map((s) => s.toFixed(2))
.join(', ')}...]`
).toBeGreaterThanOrEqual(2)
// verify first few samples haven't already jumped to end (animation has real duration)
const earlyEnd = samples.slice(0, 3).every((v) => Math.abs(v - END) < TOLERANCE)
expect(earlyEnd, 'Animation should not complete in first 3 frames').toBe(false)
})
test('context default (no animatedBy) also animates', async ({ page }) => {
const START = 0.5,
END = 1
const initialOpacity = await page
.getByTestId('context-driver')
.evaluate((el) => Number(getComputedStyle(el).opacity))
expect(initialOpacity).toBeCloseTo(START, 1)
// poll via rAF to capture intermediate values reliably
const samples: number[] = await page.evaluate((testId) => {
return new Promise<number[]>((resolve) => {
const el = document.querySelector(`[data-testid="${testId}"]`)!
const vals: number[] = []
const start = performance.now()
function tick() {
vals.push(Number(getComputedStyle(el).opacity))
if (performance.now() - start < 600) requestAnimationFrame(tick)
else resolve(vals)
}
;(document.querySelector('[data-testid="toggle-trigger"]') as HTMLElement).click()
requestAnimationFrame(tick)
})
}, 'context-driver')
const finalOpacity = samples[samples.length - 1]
expect(finalOpacity, 'End opacity').toBeCloseTo(END, 1)
// verify real animation duration: multiple intermediate frames, not instant
const intermediates = samples.filter(
(v) => Math.abs(v - START) > TOLERANCE && Math.abs(v - END) > TOLERANCE
)
expect(
intermediates.length,
`Context default should have multiple intermediate frames`
).toBeGreaterThanOrEqual(2)
})
test('both elements animate in sync', async ({ page }) => {
const explicitElement = page.getByTestId('explicit-default')
const contextElement = page.getByTestId('context-driver')
// Trigger animation
await page.getByTestId('toggle-trigger').click()
await page.waitForTimeout(500)
// Both should reach end state
const [explicitFinal, contextFinal] = await Promise.all([
explicitElement.evaluate((el) => Number(getComputedStyle(el).opacity)),
contextElement.evaluate((el) => Number(getComputedStyle(el).opacity)),
])
expect(explicitFinal, 'animatedBy="default" end state').toBeCloseTo(1, 1)
expect(contextFinal, 'context default end state').toBeCloseTo(1, 1)
})
})