Skip to content

Commit 2a8112d

Browse files
committed
Refactor testing setup and improve component structure; update test commands in package.json for consistency. Introduce Footer component for better layout management and replace BlogFooter references across routes. Enhance caching headers for blog and RSS routes, and streamline Navigation component styles.
1 parent f1e691f commit 2a8112d

File tree

16 files changed

+70
-67
lines changed

16 files changed

+70
-67
lines changed

.claude/settings.local.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919
"deny": []
2020
},
2121
"enableAllProjectMcpServers": false
22-
}
22+
}

app/__tests__/components/BlogFooter.test.tsx renamed to app/__tests__/components/Footer.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { render, screen } from '@testing-library/react'
22
import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest'
3-
import { BlogFooter } from '~/components/BlogFooter'
3+
import { Footer } from '~/components/Footer'
44

5-
describe('BlogFooter Component', () => {
5+
describe('Footer Component', () => {
66
beforeEach(() => {
77
vi.useFakeTimers()
88
vi.setSystemTime(new Date('2022-01-01'))
@@ -13,7 +13,7 @@ describe('BlogFooter Component', () => {
1313
})
1414

1515
it('should render with correct structure and default max-width', () => {
16-
render(<BlogFooter />)
16+
render(<Footer />)
1717

1818
// Check copyright text
1919
expect(screen.getByText(/© \d{4} mawburn\.com All rights reserved\./)).toBeInTheDocument()
@@ -30,7 +30,7 @@ describe('BlogFooter Component', () => {
3030
})
3131

3232
it('should use custom max-width when provided', () => {
33-
render(<BlogFooter maxWidth="max-w-3xl" />)
33+
render(<Footer maxWidth="max-w-3xl" />)
3434

3535
const container = document.querySelector('.container')
3636
expect(container).toHaveClass('max-w-3xl')

app/__tests__/routes/blog.post.test.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ vi.mock('~/utils/cache', () => ({
2828
},
2929
}))
3030

31-
vi.mock('~/components/BlogFooter', () => ({
32-
BlogFooter: ({ maxWidth }: { maxWidth?: string }) => (
31+
vi.mock('~/components/Footer', () => ({
32+
Footer: ({ maxWidth }: { maxWidth?: string }) => (
3333
<footer data-testid="blog-footer" data-max-width={maxWidth}>
3434
Blog Footer
3535
</footer>
@@ -96,9 +96,11 @@ describe('BlogPost Route', () => {
9696
})
9797

9898
describe('loader function', () => {
99-
it('should return post data for existing post', () => {
99+
it('should return post data for existing post', async () => {
100100
const result = loader({ params: { slug: 'test-post' } } as any)
101-
expect(result).toEqual({ post: mockPost })
101+
expect(result).toBeInstanceOf(Response)
102+
const data = await result.json()
103+
expect(data).toEqual({ post: mockPost })
102104
})
103105

104106
it('should throw 404 for non-existing post', () => {

app/__tests__/routes/blog.test.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ vi.mock('~/utils/cache', () => ({
3535
},
3636
}))
3737

38-
vi.mock('~/components/BlogFooter', () => ({
39-
BlogFooter: () => <footer data-testid="blog-footer">Blog Footer</footer>,
38+
vi.mock('~/components/Footer', () => ({
39+
Footer: () => <footer data-testid="blog-footer">Blog Footer</footer>,
4040
}))
4141

4242
vi.mock('react-router', () => ({
@@ -103,9 +103,11 @@ describe('Blog Route', () => {
103103
})
104104

105105
describe('loader function', () => {
106-
it('should return posts data with cache config', () => {
106+
it('should return posts data with cache config', async () => {
107107
const result = loader()
108-
expect(result).toEqual({
108+
expect(result).toBeInstanceOf(Response)
109+
const data = await result.json()
110+
expect(data).toEqual({
109111
posts: [
110112
{
111113
slug: 'test-post-1',

app/__tests__/routes/rss.xml.test.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ describe('RSS Feed Route', () => {
4040

4141
// Headers
4242
expect(response.headers.get('Content-Type')).toBe('application/rss+xml; charset=utf-8')
43-
expect(response.headers.get('Cache-Control')).toBe('public, max-age=3600')
43+
expect(response.headers.get('Cache-Control')).toBe(
44+
'public, max-age=3600, s-maxage=86400, stale-while-revalidate=86400'
45+
)
4446

4547
// XML structure
4648
expect(text).toContain('<?xml version="1.0" encoding="UTF-8"?>')

app/__tests__/routes/sitemap.xml.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ describe('Sitemap XML Route', () => {
7777
const response = await loader()
7878

7979
expect(response.headers.get('Content-Type')).toBe('application/xml')
80-
expect(response.headers.get('Cache-Control')).toBe('public, max-age=3600')
80+
expect(response.headers.get('Cache-Control')).toBe(
81+
'public, max-age=86400, s-maxage=604800, stale-while-revalidate=86400'
82+
)
8183
})
8284

8385
it('should use current date for static pages lastmod', async () => {

app/components/BlogFooter.tsx renamed to app/components/Footer.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
type BlogFooterProps = {
1+
type FooterProps = {
22
maxWidth?: 'max-w-3xl' | 'max-w-4xl'
33
}
44

5-
export function BlogFooter({ maxWidth = 'max-w-4xl' }: BlogFooterProps) {
5+
export function Footer({ maxWidth = 'max-w-4xl' }: FooterProps) {
66
return (
7-
<footer className="mt-auto">
7+
<footer className="mt-auto py-8">
88
<div className={`container mx-auto ${maxWidth} px-4 py-6`}>
99
<div className="text-center text-sm">
1010
<p className="text-black dark:text-white">

app/components/Navigation.tsx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,7 @@ export function Navigation() {
77
const isHomePage = location.pathname === '/'
88

99
return (
10-
<nav
11-
className="fixed top-0 left-0 right-0 z-50 bg-black bg-opacity-80 border-b border-cyan-500 border-opacity-30"
12-
style={{
13-
backgroundColor: 'rgba(0, 0, 0, 0.8)',
14-
borderBottom: '1px solid rgba(6, 182, 212, 0.3)',
15-
position: 'fixed',
16-
top: 0,
17-
left: 0,
18-
right: 0,
19-
zIndex: 50,
20-
}}
21-
>
10+
<nav className="fixed top-0 left-0 right-0 z-50 bg-black bg-opacity-80 backdrop-blur-md border-b border-cyan-500 border-opacity-30">
2211
<div className="container mx-auto px-4 py-3">
2312
<div className="flex items-center justify-between">
2413
<Link

app/root.tsx

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,23 @@ import type { Route } from './+types/root'
1212
import { Navigation } from './components/Navigation'
1313
import './app.css'
1414

15-
export const links: Route.LinksFunction = () => []
15+
export const links: Route.LinksFunction = () => [
16+
{
17+
rel: 'dns-prefetch',
18+
href: 'https://static.cloudflareinsights.com',
19+
},
20+
]
21+
22+
export function headers() {
23+
return {
24+
Link: [
25+
'</fonts/Lexend-Regular.woff2>; rel=preload; as=font; type=font/woff2; crossorigin=anonymous',
26+
'</fonts/Lexend-Bold.woff2>; rel=preload; as=font; type=font/woff2; crossorigin=anonymous',
27+
].join(', '),
28+
'X-Content-Type-Options': 'nosniff',
29+
'X-Frame-Options': 'DENY',
30+
}
31+
}
1632

1733
const fontPreloadLinks: Array<React.ComponentProps<'link'>> = [
1834
{
@@ -81,19 +97,6 @@ export function Layout({ children }: { children: React.ReactNode }) {
8197
`,
8298
}}
8399
/>
84-
<style
85-
dangerouslySetInnerHTML={{
86-
__html: `
87-
/* Critical CSS for initial render */
88-
body { margin: 0; font-family: sans-serif; }
89-
.container { max-width: 1200px; margin: 0 auto; padding: 0 1rem; }
90-
.dark { color-scheme: dark; }
91-
.dark body { background-color: #0f172a; color: #fdfdfd; }
92-
nav { position: fixed; top: 0; left: 0; right: 0; z-index: 50; background-color: rgba(0, 0, 0, 0.8); }
93-
.pt-16 { padding-top: 4rem; }
94-
`,
95-
}}
96-
/>
97100
{fontsToLoad.map(link => (
98101
<link key={link.href} {...link} />
99102
))}

app/routes/blog.post.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Route } from './+types/blog.post'
22
import { getPostBySlug } from '~/utils/blog'
33
import type { BlogPost } from '~/utils/blogTypes'
44
import { Link } from 'react-router'
5-
import { BlogFooter } from '~/components/BlogFooter'
5+
import { Footer } from '~/components/Footer'
66
import { MarkdownContent } from '~/components/MarkdownContent'
77
import { ShareButtons } from '~/components/ShareButtons'
88
import { RSSIcon } from '~/components/icons'
@@ -80,8 +80,8 @@ export function loader({ params }: Route.LoaderArgs) {
8080
'Cache-Control': 'public, max-age=7200, s-maxage=604800, stale-while-revalidate=86400',
8181
'CDN-Cache-Control': 'max-age=604800',
8282
'Cloudflare-CDN-Cache-Control': 'max-age=604800',
83-
'ETag': `"blog-post-${params.slug}-${post.date}"`,
84-
'Vary': 'Accept-Encoding',
83+
ETag: `"blog-post-${params.slug}-${post.date}"`,
84+
Vary: 'Accept-Encoding',
8585
},
8686
})
8787
}
@@ -142,7 +142,10 @@ export default function BlogPost({ loaderData }: Route.ComponentProps) {
142142
))}
143143
</div>
144144

145-
<ShareButtons title={post.title} url={`https://mawburn.com/blog/${post.slug}`} />
145+
<div className="flex items-center gap-3">
146+
<span className="text-gray-600 dark:text-gray-400 font-medium">Share:</span>
147+
<ShareButtons title={post.title} url={`https://mawburn.com/blog/${post.slug}`} />
148+
</div>
146149
</header>
147150

148151
<MarkdownContent html={post.content} />
@@ -152,7 +155,7 @@ export default function BlogPost({ loaderData }: Route.ComponentProps) {
152155
All posts are written by me, though AI helps with proofreading and editing.
153156
</p>
154157
</div>
155-
<BlogFooter maxWidth="max-w-3xl" />
158+
<Footer maxWidth="max-w-3xl" />
156159
</div>
157160
)
158161
}

0 commit comments

Comments
 (0)