From 0a413efa2f7784f176d1ee533d9b404b423713a4 Mon Sep 17 00:00:00 2001 From: Anjana Vakil Date: Wed, 27 Aug 2025 08:49:51 -0500 Subject: exercise --- frontend/test/components/Events.test.js | 144 ++++++++++++++++++++++++++++++++ frontend/test/components/Header.test.js | 73 ++++++++++++++++ 2 files changed, 217 insertions(+) create mode 100644 frontend/test/components/Events.test.js create mode 100644 frontend/test/components/Header.test.js (limited to 'frontend/test/components') diff --git a/frontend/test/components/Events.test.js b/frontend/test/components/Events.test.js new file mode 100644 index 0000000..326c328 --- /dev/null +++ b/frontend/test/components/Events.test.js @@ -0,0 +1,144 @@ +import { describe, it, expect, beforeEach, vi } from 'vitest' +import { EventCard, EventModal, EventsSection } from '../../src/components/Events.js' + +describe('Events', () => { + beforeEach(() => { + vi.clearAllMocks() + }) + + describe('EventCard', () => { + it('should render event card with basic information', () => { + const event = { + id: 1, + host_id: 2, + title: 'Test Event', + date: '2024-12-25', + host: { name: 'John Doe' }, + description: 'A test event', + rsvps: [], + image_url: 'https://example.com/image.jpg' + } + + const result = EventCard(event) + + expect(result).toContain('Test Event') + expect(result).toContain('John Doe') + expect(result).toContain('A test event') + expect(result).toContain('https://example.com/image.jpg') + expect(result).toContain('0 went') + }) + + it('should handle missing optional fields', () => { + const event = { + id: 1, + title: 'Test Event', + date: '2024-12-25T10:00:00Z', + host_id: 123, + rsvps: [], + image_url: 'http://image.web' + } + + const result = EventCard(event) + + expect(result).toContain('Test Event') + expect(result).toContain('User 123') + expect(result).not.toContain('undefined') + }) + + it('should show past events correctly', () => { + + const event = { + id: 1, + host_id: 4, + title: 'Past Event', + date: '1995-01-01', + host: { name: 'John Doe' }, + image_url: 'http://image.web', + rsvps: [{}, {}] // 2 RSVPs + } + + const result = EventCard(event); + + expect(result).toContain('2 went'); + expect(result).not.toContain('