Skip to content

Commit bbd15c2

Browse files
committed
created unit tests for NavBar
1 parent c6bbbc4 commit bbd15c2

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

www/__tests__/NavBar.test.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import {screen, render, fireEvent} from '@testing-library/react';
2+
import '@testing-library/jest-dom/extend-expect';
3+
import NavBar from '../src/pages/components/NavBar';
4+
5+
describe('Navbar Component Test ', () => {
6+
beforeEach(() => {
7+
render(<NavBar />)
8+
});
9+
10+
it ('navbar should have two buttons(anchor tags)', () => {
11+
const buttons = screen.getAllByRole('link');
12+
expect(buttons).toHaveLength(2)
13+
});
14+
15+
it ('clicking a post link navigates to the correct URL', () => {
16+
expect(screen.getAllByRole('link')[0]).toHaveAttribute('href', 'http://github.com/open-source-labs/reactime');
17+
expect(screen.getAllByRole('link')[1]).toHaveAttribute('href', 'https://chrome.google.com/webstore/detail/reactime/cgibknllccemdnfhfpmjhffpjfeidjga?hl=en-US');
18+
})
19+
})

www/__tests__/TeamSection.test.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {screen, render} from '@testing-library/react';
2+
import '@testing-library/jest-dom/extend-expect';
3+
import { Profile } from '../src/pages/components/TeamSection';
4+
5+
// http://localhost/_next/image?url=https%3A%2F%2Fgithub.com%2Fwiltonlee948.png&w=256&q=75
6+
7+
test('sets src to /profileFallback.png if src causes an error', async () => {
8+
render(<Profile key='' profile='qcvber' name='' />);
9+
const src = screen.getByTestId('image').getAttribute('src');
10+
console.debug(src)
11+
});

www/src/pages/components/TeamSection.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ function replace(e: React.SyntheticEvent<HTMLImageElement>): void{
112112
profile: string | undefined,
113113
name: string | undefined,
114114
}
115-
function Profile({profile, name}: profileType) {
115+
export function Profile({profile, name}: profileType) {
116116
const [imageError, setImageError] = useState(false);
117117
return (
118118
<div className="space-y-4">
@@ -123,6 +123,7 @@ function replace(e: React.SyntheticEvent<HTMLImageElement>): void{
123123
className="mx-auto h-20 w-20 rounded-full lg:h-24 lg:w-24"
124124
onError={(e) => setImageError(true)}
125125
alt="missing-profile-image"
126+
data-testid="image"
126127
/>
127128
<div className="space-y-2">
128129
<div className="text-xs font-medium lg:text-sm">

0 commit comments

Comments
 (0)