-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into mm-107-startquizbutton
- Loading branch information
Showing
9 changed files
with
134 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,10 @@ | ||
import React from 'react'; | ||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { render, screen } from '@testing-library/react'; | ||
import App from './App'; | ||
import "@testing-library/jest-dom"; | ||
import Hamburger from './Hamburgerbutton/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); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
import "@testing-library/jest-dom"; | ||
import Hamburger from '../Hamburgerbutton/Hamburgerbutton'; | ||
|
||
test('should toggle hamburger menu on button click', () => { | ||
render(<Hamburger />); | ||
|
||
const button = screen.getByTestId('toggle-button'); | ||
const menu = screen.queryByTestId('data-testid'); | ||
|
||
// Initially, the menu should not be visible | ||
expect(menu).not.toBeInTheDocument(); | ||
|
||
// Click the button to open the menu | ||
fireEvent.click(button); | ||
expect(screen.getByTestId('menu')).toBeInTheDocument(); | ||
|
||
// Click the button again to close the menu | ||
fireEvent.click(button); | ||
expect(screen.queryByTestId('menu')).not.toBeInTheDocument(); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from 'react'; | ||
|
||
interface MenuItem { | ||
label: string; | ||
link: string; | ||
} | ||
|
||
interface MenuProps { | ||
items: MenuItem[]; | ||
} | ||
|
||
const Menu: React.FC<MenuProps> = ({ items }) => { | ||
return ( | ||
<div> | ||
<h1>Menu </h1> | ||
<nav> | ||
<ul> | ||
{items.map((item, index) => ( | ||
<li key={index}> | ||
<a href={item.link}>{item.label}</a> | ||
</li> | ||
))} | ||
</ul> | ||
</nav> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Menu; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
// list of the menu options that will be displayed when clicking on hamburger button | ||
export const menuItems = [ | ||
{ label: 'Home', link: '/' }, | ||
{ label: 'Quiz', link: '' }, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import { fetchAPI } from '../utils/fetchData'; | ||
|
||
interface ChosenPicture { | ||
date: string, | ||
explanation: string, | ||
hdurl: string, | ||
title: string, | ||
url: string | ||
} | ||
|
||
export const DisplayChosenPicture = ({date}: {date: string}) => { | ||
const [myPictureData, setMyPictureData] = useState<ChosenPicture | null>(null); | ||
const [isLoading, setIsLoading] = useState(false); | ||
const [error, setError] = useState<Error | null>(null); | ||
|
||
const FetchPicture = async () => { | ||
|
||
try { | ||
setIsLoading(true); | ||
|
||
const pictureData = await fetchAPI("https://api.nasa.gov/planetary/apod?api_key=", date); | ||
|
||
setMyPictureData(pictureData); | ||
setIsLoading(false); | ||
|
||
} catch (err: unknown) { | ||
if (err instanceof Error) { | ||
setError(err); // Set the actual Error object | ||
} else { | ||
setError(new Error('An unknown error occurred')); // Provide a default Error object | ||
} | ||
|
||
setIsLoading(false); | ||
} | ||
} | ||
useEffect(() => { | ||
FetchPicture(); | ||
}, []) | ||
|
||
if (isLoading) return (<div>Is Loading...</div>); | ||
if (error) return (<div>{error.message}</div>); | ||
if (!myPictureData) return (<div>EMPTY</div>); | ||
|
||
return myPictureData; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters