Skip to content

Commit

Permalink
Merge pull request #13 from 392-f24/patrick-IT
Browse files Browse the repository at this point in the history
Working second test
  • Loading branch information
patrickchen8 authored Oct 29, 2024
2 parents 984e7be + 2e8ed9e commit 0d0be9b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/components/Navbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const Navbar = () => {
<p>Chat</p>
</NavLink> */}

<NavLink className="navbar-icon" to="/profile">
<NavLink data-testid="profile-icon" className="navbar-icon" to="/profile">
<i className="bi bi-person-circle" style={{ color: 'purple' }}></i>
<p><b>Profile</b></p>
</NavLink>
Expand Down
54 changes: 54 additions & 0 deletions src/tests/Navbar.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { describe, expect, it, vi } from 'vitest';
import { screen, render, fireEvent } from '@testing-library/react';
import Matches from '../pages/Matches'
import ProfilePage from '../pages/ProfilePage'
import { useAuthState, useDbData } from '../utilities/firebase'
import { MemoryRouter, Route, Routes } from 'react-router-dom';


const roommates = {"Chris Riesbeck": {
"bedTime": "Early",
"clean": "Clean",
"desc": "I'm an agile type of guy",
"fullName": "Chris Riesbeck",
"gender": "Male",
"guests": "No",
"location": "North",
"major": "Computer Science",
"noise": "Quiet",
"number": "1234567890",
"profilePhoto": "",
"roommateGender": [
"Any"
],
"size": [
"Double",
"Triple",
"Suite"
],
"wakeUpTime": "6-8 AM"}
}

vi.mock('../utilities/firebase')

describe('switching pages', () => {

it('clicking the profile icon goes to the Profile Page', async () => {
useAuthState.mockReturnValue([{id:'13213123'}, false])
useDbData.mockReturnValue([roommates, false])
render(
<MemoryRouter initialEntries={['/matches']}>
<Routes>
<Route path="/matches" element={<Matches roommates={roommates}/>} />
<Route path="profile" element={<ProfilePage />}/>
</Routes>
</MemoryRouter>)


const profileLink = await screen.findByTestId('profile-icon');
fireEvent.click(profileLink)
const profileElemts = await screen.findAllByText(/Profile/);
expect(profileElemts.length).toBeGreaterThan(0);

})
})

0 comments on commit 0d0be9b

Please sign in to comment.