Skip to content

Commit

Permalink
MM-005: Add test for hamburger button
Browse files Browse the repository at this point in the history
  • Loading branch information
Anum1608 committed Jul 30, 2024
1 parent cfef2ec commit 333fd03
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
20 changes: 17 additions & 3 deletions src/App.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { render, screen, fireEvent } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import App from './App';
import Hamburger from './Hamburgerbutton';

test('renders learn react link', () => {
/* test('renders learn react link', () => {
render(<App />);
const linkElement = screen.getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});
}); */



test('calls onClick when Hamburger button is clicked', () => {
const handleClick = jest.fn();
render(<Hamburger onClick={handleClick} label="Click Me" />);

const button = screen.getByText('Click Me');
fireEvent.click(button);

expect(handleClick).toHaveBeenCalledTimes(1);
});
5 changes: 4 additions & 1 deletion src/Hamburgerbutton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import './Hamburgerbutton.scss'; // styling for the hmauburger button icon

interface HamburgerProps {
onClick: () => void;
label: string;

}

const Hamburger: React.FC<HamburgerProps> = ({ onClick }) => {
const Hamburger: React.FC<HamburgerProps> = ({ onClick , label}) => {

const handleClick = () => {
onClick();
Expand All @@ -14,6 +16,7 @@ const Hamburger: React.FC<HamburgerProps> = ({ onClick }) => {
return (
<button onClick={handleClick} className="hamburger">
{/* draw the 3 lines which make up the hmburger */}
{label}
<div className="line" />
<div className="line" />
<div className="line" />
Expand Down

0 comments on commit 333fd03

Please sign in to comment.