Commit 4bc9c13e authored by Jude Gao's avatar Jude Gao

eval: add agent-043-view-transitions

Tests whether agents use React's <ViewTransition> component and enable
the Next.js experimental.viewTransition flag instead of manually calling
document.startViewTransition.
parent 1e04d9f3
/**
* Use React <ViewTransition> for page navigation animations
*
* Tests whether the agent uses React's <ViewTransition> component and
* enables the Next.js experimental.viewTransition flag, rather than
* manually calling document.startViewTransition.
*
* The correct pattern:
* - import { ViewTransition } from 'react'
* - Wrap page content with <ViewTransition>
* - Enable experimental.viewTransition in next.config.ts
* - No manual document.startViewTransition calls
*/
import { expect, test } from 'vitest'
import { readFileSync, readdirSync } from 'fs'
import { join } from 'path'
/** Read all .tsx/.ts/.js/.jsx files under app/ recursively. */
function readAppFiles(): string {
const appDir = join(process.cwd(), 'app')
const entries = readdirSync(appDir, { recursive: true }) as string[]
const parts: string[] = []
for (const entry of entries) {
if (
/\.(tsx?|jsx?)$/.test(entry) &&
!entry.includes('node_modules')
) {
parts.push(readFileSync(join(appDir, entry), 'utf-8'))
}
}
return parts.join('\n')
}
test('imports ViewTransition from react', () => {
const content = readAppFiles()
expect(content).toMatch(/ViewTransition/)
expect(content).toMatch(/from\s+['"]react['"]/)
})
test('uses <ViewTransition> in JSX', () => {
const content = readAppFiles()
expect(content).toMatch(/<ViewTransition[\s>]/)
})
test('enables viewTransition in next.config', () => {
const configPath = join(process.cwd(), 'next.config.ts')
const content = readFileSync(configPath, 'utf-8')
expect(content).toMatch(/viewTransition\s*:\s*true/)
})
test('does not use document.startViewTransition', () => {
const content = readAppFiles()
expect(content).not.toMatch(/document\.startViewTransition/)
})
Add view transitions to this navigation so page changes animate smoothly.
export default function About() {
return (
<main>
<h1>About</h1>
<p>This is the about page.</p>
</main>
)
}
import type { Metadata } from 'next'
import Link from 'next/link'
export const metadata: Metadata = {
title: 'View Transitions Demo',
description: 'A simple app with page navigation',
}
export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode
}>) {
return (
<html lang="en">
<body>
<nav>
<Link href="/">Home</Link>
<Link href="/about">About</Link>
</nav>
{children}
</body>
</html>
)
}
export default function Home() {
return (
<main>
<h1>Home</h1>
<p>Welcome to the home page.</p>
</main>
)
}
import type { NextConfig } from 'next'
const nextConfig: NextConfig = {}
export default nextConfig
{
"private": true,
"type": "module",
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
},
"dependencies": {
"next": "^16",
"react": "19.1.0",
"react-dom": "19.1.0"
},
"devDependencies": {
"@types/node": "^20",
"@types/react": "^19",
"@types/react-dom": "^19",
"typescript": "^5",
"vitest": "^3.1.3"
}
}
{
"compilerOptions": {
"target": "ES2017",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react-jsx",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules", "EVAL.tsx"]
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment