Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mm 005 header v2 #7

Merged
merged 18 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
18 changes: 16 additions & 2 deletions src/App.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
import { render, screen } from '@testing-library/react';
import React from 'react';
import { render, screen, fireEvent } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import App from './App';
import "@testing-library/jest-dom";
import Hamburger from './Hamburgerbutton';

// remove this test when real tests are added
test('renders header', () => {
render(<App />);
const header = screen.getAllByText(/MarsioKart/i);
expect(header[0]).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);
});

4 changes: 4 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ import React from 'react';
import {BrowserRouter as Router, Routes, Route} from 'react-router-dom';
import './App.scss';
import Home from './Home/Home';
import Header from './header';
import { Quiz } from './Quiz/Quiz';
import Footer from './Footer/Footer';



function App() {
return (
<div className="App">
<Router>
<h1>MarsioKart</h1>
<Header/>
<Routes>
<Route path='/'
element={<Home/>}/>
Expand Down
18 changes: 18 additions & 0 deletions src/Hamburgerbutton.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.hamburger {
display: flex;
flex-direction: column;
justify-content: space-around;
width: 30px;
height: 30px;
background: transparent;
border: none;
cursor: pointer;
}

.line {
width: 100%;
height: 3px;
background-color: black;
transition: all 0.3s ease;
}

27 changes: 27 additions & 0 deletions src/Hamburgerbutton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react';
import './Hamburgerbutton.scss'; // styling for the hmauburger button icon

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

}

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

const handleClick = () => {
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" />
</button>
);
};

export default Hamburger;
16 changes: 16 additions & 0 deletions src/header.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';
import Hamburger from './Hamburgerbutton';

const Header: React.FC = () => {
const handleHamburgerClick = () => {
console.log('Hamburger menu clicked!');
};

return (
<div className="App">
<Hamburger onClick={handleHamburgerClick} label={""}/>
</div>
);
};

export default Header;
Loading