-
Notifications
You must be signed in to change notification settings - Fork 2
[Riccardo doubts about this] fix: Fix 404 on talk and article detail pages #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// src/app/articles/[slug]/page.test.tsx | ||
import { getArticle } from '../../lib/data'; | ||
|
||
describe('ArticlePage', () => { | ||
it('should return an article for a valid slug', async () => { | ||
const article = await getArticle('2020-12-31-the-art-of-slos'); | ||
expect(article).toBeDefined(); | ||
expect(article?.title).toBe('The Art of SLOs'); | ||
}); | ||
|
||
it('should return undefined for an invalid slug', async () => { | ||
const article = await getArticle('invalid-slug'); | ||
expect(article).toBeUndefined(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,15 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import TalkPage from './page'; | ||
import { getTalk } from '../../lib/data'; // Import getTalk directly | ||
import { notFound } from 'next/navigation'; | ||
import { vi } from 'vitest'; | ||
|
||
// Mock the next/navigation notFound function | ||
vi.mock('next/navigation', () => ({ | ||
notFound: vi.fn(() => { throw new Error('notFound called'); }), | ||
})); | ||
|
||
// Mock the getTalk function from src/app/lib/data.ts | ||
vi.mock('../../lib/data', () => ({ | ||
getTalk: vi.fn(), | ||
// Ensure other exports from data.ts are also mocked if used by getTalk | ||
getTalks: vi.fn(), | ||
getArticles: vi.fn(), | ||
getFutureTalks: vi.fn(), | ||
getHighlightedTalks: vi.fn(), | ||
getHighlightedArticles: vi.fn(), | ||
})); | ||
|
||
describe.skip('TalkPage', () => { | ||
const mockTalk = { | ||
id: 1, | ||
title: 'Test Talk Title', | ||
event: 'Test Event', | ||
date: '2025-01-01', | ||
location: 'Test Location', | ||
country_code: 'us', | ||
session_url: 'http://example.com/session', | ||
video_url: 'http://example.com/video', | ||
slides_url: 'http://example.com/slides', | ||
status: 'delivered', | ||
tags: 'tag1,tag2', | ||
image: '/images/placeholder-image.png', | ||
event_description: 'Event description.', | ||
talk_description: 'Talk description.', | ||
slug: '2025-01-01-test-talk-title', | ||
}; | ||
|
||
beforeEach(() => { | ||
// Reset mocks before each test | ||
(getTalk as vi.Mock).mockReset(); // Use getTalk directly | ||
(notFound as vi.Mock).mockReset(); | ||
}); | ||
|
||
it('renders talk details when talk is found', async () => { | ||
// Mock getTalk to return the mockTalk | ||
(getTalk as vi.Mock).mockResolvedValue(mockTalk); | ||
|
||
await render(<TalkPage params={{ slug: mockTalk.slug }} />); | ||
|
||
// Assert that the talk title is displayed | ||
expect(screen.getByText(mockTalk.title)).toBeInTheDocument(); | ||
expect(screen.getByText(`${mockTalk.event} - ${mockTalk.date}`)).toBeInTheDocument(); | ||
expect(screen.queryByText('404: This page could not be found.')).not.toBeInTheDocument(); | ||
expect(notFound).not.toHaveBeenCalled(); | ||
// src/app/talks/[slug]/page.test.tsx | ||
import { getTalk } from '../../lib/data'; | ||
|
||
describe('TalkPage', () => { | ||
it('should return a talk for a valid slug', async () => { | ||
const talk = await getTalk('2025-11-08-agenti-in-volo-unanalisi-approfondita-sulla-creazione-di-un-agente-di-viaggio-in-tempo-reale'); | ||
expect(talk).toBeDefined(); | ||
expect(talk?.title).toBe("Agenti in Volo: Un'Analisi Approfondita sulla Creazione di un Agente di Viaggio in Tempo Reale ✈️"); | ||
}); | ||
|
||
it('calls notFound when talk is not found', async () => { | ||
// Mock getTalk to return undefined (talk not found) | ||
(getTalk as vi.Mock).mockResolvedValue(undefined); // Simulate talk not found | ||
|
||
await render(<TalkPage params={{ slug: 'non-existent-slug' }} />); | ||
|
||
// Assert that notFound was called | ||
expect(notFound).toHaveBeenCalled(); | ||
it('should return undefined for an invalid slug', async () => { | ||
const talk = await getTalk('invalid-slug'); | ||
expect(talk).toBeUndefined(); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,10 @@ | ||||||||||||||
// src/lib/utils.ts | ||||||||||||||
|
||||||||||||||
export const formatDate = (date: Date): string => { | ||||||||||||||
if (!date) return ''; | ||||||||||||||
return new Date(date).toISOString().split('T')[0]; | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟢 Using
Suggested change
|
||||||||||||||
}; | ||||||||||||||
|
||||||||||||||
export const slugify = (str: string) => { | ||||||||||||||
if (!str) return ''; | ||||||||||||||
const a = 'àáâäæãåāăąçćčđďèéêëēėęěğǵḧîïíīįìłḿñńǹňôöòóœøōõőṕŕřßśšşșťțûüùúúūǘůűųẃẍÿýžźż·/_,:;' | ||||||||||||||
|
@@ -30,6 +36,4 @@ export function extractYouTubeVideoId(url: string) { | |||||||||||||
export function parseDateString(dateString: string): Date { | ||||||||||||||
const [year, month, day] = dateString.split('-').map(Number); | ||||||||||||||
return new Date(year, month - 1, day); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟢 For consistency and robustness, it's better to use the existing
parseDateString
utility to parse thepublish_date
string. Thenew Date(dateString)
constructor can have inconsistent behavior across different JavaScript environments, whereasparseDateString
is guaranteed to handle theYYYY-MM-DD
format correctly. You'll also need to importparseDateString
from../../lib/utils
.