Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion __tests__/components/__snapshots__/error.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exports[`ErrorComponet displays error cause and error message properly 1`] = `
/>
<a
className="flex items-center"
href="/classes"
href="/"
onClick={[Function]}
onMouseEnter={[Function]}
onTouchStart={[Function]}
Expand Down
2 changes: 1 addition & 1 deletion __tests__/components/__snapshots__/navbar.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ exports[`Navbar rendering correctly renders correctly 1`] = `
/>
<a
className="flex items-center"
href="/classes"
href="/"
onClick={[Function]}
onMouseEnter={[Function]}
onTouchStart={[Function]}
Expand Down
42 changes: 42 additions & 0 deletions __tests__/components/navbar.test.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Navbar from '../../components/navbar';
import React from 'react';
import { SessionProvider } from 'next-auth/react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import renderer from 'react-test-renderer';

describe('Navbar rendering correctly', () => {
Expand All @@ -15,3 +17,43 @@ describe('Navbar rendering correctly', () => {
expect(tree).toMatchSnapshot();
});
});

describe('Navbar Home button', () => {
const findHomeLink = () => screen.getByRole('link', { name: /freecodecamp logo/i });

it('points to the application home page when logged in as a teacher', () => {
render(
<SessionProvider session={{ user: { name: 'teacher', role: 'TEACHER' } }}>
<Navbar />
</SessionProvider>
);
expect(findHomeLink()).toHaveAttribute('href', '/');
});

it('points to the application home page when logged in as an admin', () => {
render(
<SessionProvider session={{ user: { name: 'admin', role: 'ADMIN' } }}>
<Navbar />
</SessionProvider>
);
expect(findHomeLink()).toHaveAttribute('href', '/');
});

it('points to the application home page when logged in as another role', () => {
render(
<SessionProvider session={{ user: { name: 'student', role: 'STUDENT' } }}>
<Navbar />
</SessionProvider>
);
expect(findHomeLink()).toHaveAttribute('href', '/');
});

it('points to the application home page when not logged in', () => {
render(
<SessionProvider session={null}>
<Navbar />
</SessionProvider>
);
expect(findHomeLink()).toHaveAttribute('href', '/');
});
});
2 changes: 1 addition & 1 deletion components/navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default function Navbar({ children, hideAuthButton = false }) {
<div className='h-[38px]'>
<div className='h-[38px] bg-fcc-gray-90 text-white flex items-center flex-wrap p-1'>
<div className='hidden lg:flex block flex-1 justify-end'></div>
<Link href='/classes' className='flex items-center'>
<Link href='/' className='flex items-center'>
<Image
className=''
priority
Expand Down