Skip to content

Commit

Permalink
TEST: add test for Footer, Navbar and ProfileIcon
Browse files Browse the repository at this point in the history
  • Loading branch information
sahsisunny committed Sep 25, 2023
1 parent 90145d0 commit be6c16e
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

# testing
/coverage
/__tests__/__snapshots__
./__tests__/__snapshots__

# next.js
/.next/
Expand Down
19 changes: 19 additions & 0 deletions __tests__/components/Footer.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Footer } from '@/components/Footer/Footer';
import { render } from '@testing-library/react';

describe('Footer', () => {
it('should render', () => {
const { container } = render(<Footer />);
expect(container).toHaveTextContent('The contents of this website are deployed from this open sourced repo');
});

it('should have a link to the repo', () => {
const { container } = render(<Footer />);
expect(container.querySelector('a')).toHaveAttribute('href', '#');
});

it('should have a link to the repo', () => {
const { container } = render(<Footer />);
expect(container.querySelector('a')).toHaveAttribute('target', '_blank');
});
});
27 changes: 27 additions & 0 deletions __tests__/components/Navbar.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react';
import { Navbar } from '@/components/Navbar/Navbar';
import { render } from '@testing-library/react';
import '@testing-library/jest-dom';

describe('Navbar', () => {
it('should render', () => {
const { container } = render(<Navbar />);
expect(container).toHaveTextContent('URL Shortener');
expect(container.querySelector('a')).toHaveAttribute('href', '#');
});

it('should have dropdown menu', () => {
const { container } = render(<Navbar />);
expect(container.querySelector('ul')).toHaveTextContent('Profile');
expect(container.querySelector('ul')).toHaveTextContent('Dashboard');
expect(container.querySelector('ul')).toHaveTextContent('Settings');
});

it('should toggle menu', () => {
const { container } = render(<Navbar />);
const button = container.querySelector('button');
expect(button).toHaveTextContent('Sunny');
button?.click();
expect(container.querySelector('ul')).toHaveClass('lg:flex space-x-4');
});
});
15 changes: 15 additions & 0 deletions __tests__/components/ProfileIcon.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';
import { render } from '@testing-library/react';
import ProfileIcon from '@/components/ProfileIcon/ProfileIcon';

describe('ProfileIcon', () => {
it('should render', () => {
const { container } = render(<ProfileIcon firstName="Sunny" lastName="Sahsi" size={50} />);
expect(container).toMatchSnapshot();
});

it('should have the correct initials', () => {
const { container } = render(<ProfileIcon firstName="Sunny" lastName="Sahsi" size={50} />);
expect(container).toHaveTextContent('SS');
});
});
1 change: 0 additions & 1 deletion src/components/ProfileIcon/ProfileIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// components/ProfileIcon.tsx
import React from 'react';

interface ProfileIconProps {
Expand Down

0 comments on commit be6c16e

Please sign in to comment.