|
| 1 | +import React from 'react'; |
| 2 | +import { render } from '@testing-library/react'; |
| 3 | +import { HelmetProvider } from 'react-helmet-async'; |
| 4 | +import Community from './Community'; |
| 5 | + |
| 6 | +// Mock SharedLayout component |
| 7 | +jest.mock('../layout/SharedLayout', () => { |
| 8 | + // eslint-disable-next-line react/prop-types |
| 9 | + function MockSharedLayout({ children }) { |
| 10 | + return <div className="mock-shared-layout">{children}</div>; |
| 11 | + } |
| 12 | + return MockSharedLayout; |
| 13 | +}); |
| 14 | + |
| 15 | +// Mock all community section components |
| 16 | +jest.mock('../community/OurCommunitySection', () => { |
| 17 | + function MockOurCommunitySection() { |
| 18 | + return <div className="mock-our-community-section">Our Community Section</div>; |
| 19 | + } |
| 20 | + return MockOurCommunitySection; |
| 21 | +}); |
| 22 | + |
| 23 | +jest.mock('../community/AdviceSection', () => { |
| 24 | + function MockAdviceSection() { |
| 25 | + return <div className="mock-advice-section">Advice Section</div>; |
| 26 | + } |
| 27 | + return MockAdviceSection; |
| 28 | +}); |
| 29 | + |
| 30 | +jest.mock('../community/CodeofConductSection', () => { |
| 31 | + function MockCodeofConductSection() { |
| 32 | + return <div className="mock-code-of-conduct-section">Code of Conduct Section</div>; |
| 33 | + } |
| 34 | + return MockCodeofConductSection; |
| 35 | +}); |
| 36 | + |
| 37 | +jest.mock('../community/CFPWorkingGroupSection', () => { |
| 38 | + function MockCFPWorkingGroupSection() { |
| 39 | + return <div className="mock-cfp-working-group-section">CFP Working Group Section</div>; |
| 40 | + } |
| 41 | + return MockCFPWorkingGroupSection; |
| 42 | +}); |
| 43 | + |
| 44 | +jest.mock('../community/BookClubSection', () => { |
| 45 | + function MockBookClubSection() { |
| 46 | + return <div className="mock-book-club-section">Book Club Section</div>; |
| 47 | + } |
| 48 | + return MockBookClubSection; |
| 49 | +}); |
| 50 | + |
| 51 | +jest.mock('../community/In-PersonConferenceMeetupsSection', () => { |
| 52 | + function MockInPersonConferenceMeetupsSection() { |
| 53 | + return ( |
| 54 | + <div className="mock-in-person-conference-meetups-section"> |
| 55 | + In-Person Conference Meetups Section |
| 56 | + </div> |
| 57 | + ); |
| 58 | + } |
| 59 | + return MockInPersonConferenceMeetupsSection; |
| 60 | +}); |
| 61 | + |
| 62 | +jest.mock('../community/InterviewPrepSection', () => { |
| 63 | + function MockInterviewPrepSection() { |
| 64 | + return <div className="mock-interview-prep-section">Interview Prep Section</div>; |
| 65 | + } |
| 66 | + return MockInterviewPrepSection; |
| 67 | +}); |
| 68 | + |
| 69 | +describe('Community Component', () => { |
| 70 | + const renderWithHelmet = (component) => { |
| 71 | + return render(<HelmetProvider>{component}</HelmetProvider>); |
| 72 | + }; |
| 73 | + |
| 74 | + test('renders community page correctly', () => { |
| 75 | + const { container } = renderWithHelmet(<Community />); |
| 76 | + expect(container.firstChild).toMatchSnapshot(); |
| 77 | + }); |
| 78 | + |
| 79 | + test('applies correct CSS classes to main sections', () => { |
| 80 | + const { container } = renderWithHelmet(<Community />); |
| 81 | + |
| 82 | + const communitySection = container.querySelector('.community-section'); |
| 83 | + expect(communitySection).toBeInTheDocument(); |
| 84 | + |
| 85 | + const community = container.querySelector('.community'); |
| 86 | + expect(community).toBeInTheDocument(); |
| 87 | + |
| 88 | + const infoSection = container.querySelector('.info'); |
| 89 | + expect(infoSection).toBeInTheDocument(); |
| 90 | + |
| 91 | + const infoLayout = container.querySelector('.info-layout'); |
| 92 | + expect(infoLayout).toBeInTheDocument(); |
| 93 | + }); |
| 94 | + |
| 95 | + test('renders Our Community section with correct styling', () => { |
| 96 | + const { container, getByText } = renderWithHelmet(<Community />); |
| 97 | + |
| 98 | + expect(getByText('Our Community')).toBeInTheDocument(); |
| 99 | + expect(getByText('Our Community Section')).toBeInTheDocument(); |
| 100 | + |
| 101 | + const ourCommunityCard = container.querySelector('.bg-color-community'); |
| 102 | + expect(ourCommunityCard).toBeInTheDocument(); |
| 103 | + }); |
| 104 | + |
| 105 | + test('renders all info cards with correct titles', () => { |
| 106 | + const { getByText } = renderWithHelmet(<Community />); |
| 107 | + |
| 108 | + expect(getByText('Advice')).toBeInTheDocument(); |
| 109 | + expect(getByText('Book Club')).toBeInTheDocument(); |
| 110 | + expect(getByText('CFP Working Group')).toBeInTheDocument(); |
| 111 | + expect(getByText('In-Person Conference Meetups')).toBeInTheDocument(); |
| 112 | + expect(getByText('Code of Conduct')).toBeInTheDocument(); |
| 113 | + expect(getByText('Jobs & Interview Prep')).toBeInTheDocument(); |
| 114 | + }); |
| 115 | + |
| 116 | + test('applies correct background colors to info cards', () => { |
| 117 | + const { container } = renderWithHelmet(<Community />); |
| 118 | + |
| 119 | + const bgColor1Cards = container.querySelectorAll('.bg-color-1'); |
| 120 | + const bgColor2Cards = container.querySelectorAll('.bg-color-2'); |
| 121 | + const bgColor3Cards = container.querySelectorAll('.bg-color-3'); |
| 122 | + |
| 123 | + expect(bgColor1Cards.length).toBeGreaterThan(0); |
| 124 | + expect(bgColor2Cards.length).toBeGreaterThan(0); |
| 125 | + expect(bgColor3Cards.length).toBeGreaterThan(0); |
| 126 | + }); |
| 127 | + |
| 128 | + test('renders all mocked section components', () => { |
| 129 | + const { getByText } = renderWithHelmet(<Community />); |
| 130 | + |
| 131 | + expect(getByText('Our Community Section')).toBeInTheDocument(); |
| 132 | + expect(getByText('Advice Section')).toBeInTheDocument(); |
| 133 | + expect(getByText('Code of Conduct Section')).toBeInTheDocument(); |
| 134 | + expect(getByText('CFP Working Group Section')).toBeInTheDocument(); |
| 135 | + expect(getByText('Book Club Section')).toBeInTheDocument(); |
| 136 | + expect(getByText('In-Person Conference Meetups Section')).toBeInTheDocument(); |
| 137 | + expect(getByText('Interview Prep Section')).toBeInTheDocument(); |
| 138 | + }); |
| 139 | + |
| 140 | + test('applies correct typography classes to titles', () => { |
| 141 | + const { container } = renderWithHelmet(<Community />); |
| 142 | + |
| 143 | + const mainTitle = container.querySelector('.font-bold.font-syne'); |
| 144 | + expect(mainTitle).toBeInTheDocument(); |
| 145 | + |
| 146 | + const infoTitles = container.querySelectorAll('.text-xl.font-bold.font-syne'); |
| 147 | + expect(infoTitles.length).toBeGreaterThan(0); |
| 148 | + }); |
| 149 | + |
| 150 | + test('applies correct content typography', () => { |
| 151 | + const { container } = renderWithHelmet(<Community />); |
| 152 | + |
| 153 | + const contentDivs = container.querySelectorAll('.font-noto.text-base'); |
| 154 | + expect(contentDivs.length).toBeGreaterThan(0); |
| 155 | + }); |
| 156 | + |
| 157 | + test('renders within SharedLayout', () => { |
| 158 | + const { container } = renderWithHelmet(<Community />); |
| 159 | + |
| 160 | + const sharedLayout = container.querySelector('.mock-shared-layout'); |
| 161 | + expect(sharedLayout).toBeInTheDocument(); |
| 162 | + }); |
| 163 | +}); |
0 commit comments