Refactor multiline formatting, link definitions, and code consistency across components and tests

- Improved readability by updating multiline statements and object definitions.
- Applied consistent link and button wrapping in `DemoSection` and other components.
- Enhanced test assertions and helper functions with uniform formatting and parentheses usage.
This commit is contained in:
Felipe Cardoso
2025-11-18 07:25:23 +01:00
parent 55ae92c460
commit a73d3c7d3e
7 changed files with 71 additions and 42 deletions

View File

@@ -27,7 +27,8 @@ import { Separator } from '@/components/ui/separator';
export const metadata: Metadata = { export const metadata: Metadata = {
title: 'Demo Tour | FastNext Template', title: 'Demo Tour | FastNext Template',
description: 'Try all features with demo credentials - comprehensive guide to the FastNext template', description:
'Try all features with demo credentials - comprehensive guide to the FastNext template',
}; };
const demoCategories = [ const demoCategories = [
@@ -36,7 +37,12 @@ const demoCategories = [
title: 'Design System Hub', title: 'Design System Hub',
description: 'Browse components, layouts, spacing, and forms with live examples', description: 'Browse components, layouts, spacing, and forms with live examples',
href: '/dev', href: '/dev',
features: ['All UI components', 'Layout patterns', 'Spacing philosophy', 'Form implementations'], features: [
'All UI components',
'Layout patterns',
'Spacing philosophy',
'Form implementations',
],
credentials: null, credentials: null,
}, },
{ {
@@ -260,7 +266,8 @@ export default function DemoTourPage() {
{/* CTA */} {/* CTA */}
<Button asChild className="w-full gap-2"> <Button asChild className="w-full gap-2">
<Link href={category.href}> <Link href={category.href}>
{category.credentials ? 'Try Now' : 'Explore'} <ArrowRight className="h-4 w-4" /> {category.credentials ? 'Try Now' : 'Explore'}{' '}
<ArrowRight className="h-4 w-4" />
</Link> </Link>
</Button> </Button>
</CardContent> </CardContent>

View File

@@ -14,7 +14,8 @@ import { Separator } from '@/components/ui/separator';
export const metadata: Metadata = { export const metadata: Metadata = {
title: 'Design System Hub | FastNext Template', title: 'Design System Hub | FastNext Template',
description: 'Interactive design system demonstrations with live examples - explore components, layouts, spacing, and forms built with shadcn/ui and Tailwind CSS', description:
'Interactive design system demonstrations with live examples - explore components, layouts, spacing, and forms built with shadcn/ui and Tailwind CSS',
}; };
const demoPages = [ const demoPages = [

View File

@@ -10,7 +10,17 @@
import Link from 'next/link'; import Link from 'next/link';
import { usePathname } from 'next/navigation'; import { usePathname } from 'next/navigation';
import { Code2, Palette, LayoutDashboard, Box, FileText, BookOpen, Home, ArrowLeft, Rocket } from 'lucide-react'; import {
Code2,
Palette,
LayoutDashboard,
Box,
FileText,
BookOpen,
Home,
ArrowLeft,
Rocket,
} from 'lucide-react';
import { Button } from '@/components/ui/button'; import { Button } from '@/components/ui/button';
import { Badge } from '@/components/ui/badge'; import { Badge } from '@/components/ui/badge';
import { ThemeToggle } from '@/components/theme'; import { ThemeToggle } from '@/components/theme';

View File

@@ -120,9 +120,7 @@ export function DemoSection() {
transition={{ duration: 0.6, delay: 0.4 }} transition={{ duration: 0.6, delay: 0.4 }}
> >
<Button asChild variant="outline" size="lg" className="gap-2"> <Button asChild variant="outline" size="lg" className="gap-2">
<Link href="/demos"> <Link href="/demos">View Complete Demo Tour </Link>
View Complete Demo Tour
</Link>
</Button> </Button>
</motion.div> </motion.div>
</section> </section>

View File

@@ -30,7 +30,10 @@ describe('DemoTourPage', () => {
const header = screen.getByRole('banner'); const header = screen.getByRole('banner');
expect(within(header).getByText('Demo Tour')).toBeInTheDocument(); expect(within(header).getByText('Demo Tour')).toBeInTheDocument();
expect(within(header).getByRole('link', { name: /home/i })).toHaveAttribute('href', '/'); expect(within(header).getByRole('link', { name: /home/i })).toHaveAttribute('href', '/');
expect(within(header).getByRole('link', { name: /start exploring/i })).toHaveAttribute('href', '/login'); expect(within(header).getByRole('link', { name: /start exploring/i })).toHaveAttribute(
'href',
'/login'
);
}); });
}); });
@@ -38,7 +41,9 @@ describe('DemoTourPage', () => {
it('renders hero heading and description', () => { it('renders hero heading and description', () => {
render(<DemoTourPage />); render(<DemoTourPage />);
expect(screen.getByText('Explore All Features')).toBeInTheDocument(); expect(screen.getByText('Explore All Features')).toBeInTheDocument();
expect(screen.getByText(/Try everything with our pre-configured demo accounts/i)).toBeInTheDocument(); expect(
screen.getByText(/Try everything with our pre-configured demo accounts/i)
).toBeInTheDocument();
}); });
it('renders Interactive Demo badge', () => { it('renders Interactive Demo badge', () => {
@@ -63,7 +68,9 @@ describe('DemoTourPage', () => {
expect(screen.getByText(/Copy the demo credentials and login/i)).toBeInTheDocument(); expect(screen.getByText(/Copy the demo credentials and login/i)).toBeInTheDocument();
expect(screen.getByText('Explore Freely')).toBeInTheDocument(); expect(screen.getByText('Explore Freely')).toBeInTheDocument();
expect(screen.getByText(/Test all features - everything resets automatically/i)).toBeInTheDocument(); expect(
screen.getByText(/Test all features - everything resets automatically/i)
).toBeInTheDocument();
}); });
}); });
@@ -77,7 +84,9 @@ describe('DemoTourPage', () => {
it('renders Design System Hub category', () => { it('renders Design System Hub category', () => {
render(<DemoTourPage />); render(<DemoTourPage />);
expect(screen.getByText('Design System Hub')).toBeInTheDocument(); expect(screen.getByText('Design System Hub')).toBeInTheDocument();
expect(screen.getByText(/Browse components, layouts, spacing, and forms/i)).toBeInTheDocument(); expect(
screen.getByText(/Browse components, layouts, spacing, and forms/i)
).toBeInTheDocument();
expect(screen.getByText('All UI components')).toBeInTheDocument(); expect(screen.getByText('All UI components')).toBeInTheDocument();
expect(screen.getByText('Layout patterns')).toBeInTheDocument(); expect(screen.getByText('Layout patterns')).toBeInTheDocument();
expect(screen.getByText('Spacing philosophy')).toBeInTheDocument(); expect(screen.getByText('Spacing philosophy')).toBeInTheDocument();
@@ -136,14 +145,14 @@ describe('DemoTourPage', () => {
// Design System Hub // Design System Hub
const exploreLinks = screen.getAllByRole('link', { name: /explore/i }); const exploreLinks = screen.getAllByRole('link', { name: /explore/i });
expect(exploreLinks.some(link => link.getAttribute('href') === '/dev')).toBe(true); expect(exploreLinks.some((link) => link.getAttribute('href') === '/dev')).toBe(true);
// Authentication System // Authentication System
const tryNowLinks = screen.getAllByRole('link', { name: /try now/i }); const tryNowLinks = screen.getAllByRole('link', { name: /try now/i });
expect(tryNowLinks.length).toBeGreaterThan(0); expect(tryNowLinks.length).toBeGreaterThan(0);
expect(tryNowLinks.some(link => link.getAttribute('href') === '/login')).toBe(true); expect(tryNowLinks.some((link) => link.getAttribute('href') === '/login')).toBe(true);
expect(tryNowLinks.some(link => link.getAttribute('href') === '/settings')).toBe(true); expect(tryNowLinks.some((link) => link.getAttribute('href') === '/settings')).toBe(true);
expect(tryNowLinks.some(link => link.getAttribute('href') === '/admin')).toBe(true); expect(tryNowLinks.some((link) => link.getAttribute('href') === '/admin')).toBe(true);
}); });
}); });
@@ -178,13 +187,13 @@ describe('DemoTourPage', () => {
// Quick Tour links // Quick Tour links
const devLinks = screen.getAllByRole('link'); const devLinks = screen.getAllByRole('link');
const hasDevLink = devLinks.some(link => link.getAttribute('href') === '/dev'); const hasDevLink = devLinks.some((link) => link.getAttribute('href') === '/dev');
expect(hasDevLink).toBe(true); expect(hasDevLink).toBe(true);
const hasLoginLink = devLinks.some(link => link.getAttribute('href') === '/login'); const hasLoginLink = devLinks.some((link) => link.getAttribute('href') === '/login');
expect(hasLoginLink).toBe(true); expect(hasLoginLink).toBe(true);
const hasSettingsLink = devLinks.some(link => link.getAttribute('href') === '/settings'); const hasSettingsLink = devLinks.some((link) => link.getAttribute('href') === '/settings');
expect(hasSettingsLink).toBe(true); expect(hasSettingsLink).toBe(true);
}); });
}); });
@@ -199,7 +208,9 @@ describe('DemoTourPage', () => {
it('renders Feature Checklist card', () => { it('renders Feature Checklist card', () => {
render(<DemoTourPage />); render(<DemoTourPage />);
expect(screen.getByText('Feature Checklist')).toBeInTheDocument(); expect(screen.getByText('Feature Checklist')).toBeInTheDocument();
expect(screen.getByText(/Try these features to experience the full power/i)).toBeInTheDocument(); expect(
screen.getByText(/Try these features to experience the full power/i)
).toBeInTheDocument();
}); });
it('renders all checklist items', () => { it('renders all checklist items', () => {
@@ -224,17 +235,19 @@ describe('DemoTourPage', () => {
it('renders final CTA heading', () => { it('renders final CTA heading', () => {
render(<DemoTourPage />); render(<DemoTourPage />);
expect(screen.getByText('Ready to Start?')).toBeInTheDocument(); expect(screen.getByText('Ready to Start?')).toBeInTheDocument();
expect(screen.getByText(/Pick a demo category above or jump right into the action/i)).toBeInTheDocument(); expect(
screen.getByText(/Pick a demo category above or jump right into the action/i)
).toBeInTheDocument();
}); });
it('has CTA buttons', () => { it('has CTA buttons', () => {
render(<DemoTourPage />); render(<DemoTourPage />);
const tryAuthLinks = screen.getAllByRole('link', { name: /try authentication flow/i }); const tryAuthLinks = screen.getAllByRole('link', { name: /try authentication flow/i });
expect(tryAuthLinks.some(link => link.getAttribute('href') === '/login')).toBe(true); expect(tryAuthLinks.some((link) => link.getAttribute('href') === '/login')).toBe(true);
const browseDesignLinks = screen.getAllByRole('link', { name: /browse design system/i }); const browseDesignLinks = screen.getAllByRole('link', { name: /browse design system/i });
expect(browseDesignLinks.some(link => link.getAttribute('href') === '/dev')).toBe(true); expect(browseDesignLinks.some((link) => link.getAttribute('href') === '/dev')).toBe(true);
}); });
}); });
@@ -263,7 +276,7 @@ describe('DemoTourPage', () => {
expect(allLinks.length).toBeGreaterThan(10); expect(allLinks.length).toBeGreaterThan(10);
// Verify key destination paths exist // Verify key destination paths exist
const hrefs = allLinks.map(link => link.getAttribute('href')); const hrefs = allLinks.map((link) => link.getAttribute('href'));
expect(hrefs).toContain('/'); expect(hrefs).toContain('/');
expect(hrefs).toContain('/dev'); expect(hrefs).toContain('/dev');
expect(hrefs).toContain('/login'); expect(hrefs).toContain('/login');

View File

@@ -267,7 +267,7 @@ describe('HomePage', () => {
// Close the modal // Close the modal
const closeButtons = screen.getAllByRole('button', { name: /close/i }); const closeButtons = screen.getAllByRole('button', { name: /close/i });
const modalCloseButton = closeButtons.find(btn => btn.textContent === 'Close'); const modalCloseButton = closeButtons.find((btn) => btn.textContent === 'Close');
if (modalCloseButton) { if (modalCloseButton) {
fireEvent.click(modalCloseButton); fireEvent.click(modalCloseButton);
} }