Skip to content

Commit e6ec457

Browse files
committed
merged
2 parents 816401e + eb44fdc commit e6ec457

File tree

10 files changed

+173
-20
lines changed

10 files changed

+173
-20
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@
2121
npm-debug.log*
2222
yarn-debug.log*
2323
yarn-error.log*
24+
25+
.env

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"eslint-plugin-prettier": "^5.2.1",
5757
"globals": "^15.14.0",
5858
"jest": "^27.5.1",
59+
5960
"prettier": "3.4.2",
6061
"sass": "^1.85.0",
6162
"typescript-eslint": "^8.20.0"

src/App.test.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React from "react";
2-
import { render, screen } from "@testing-library/react";
3-
import App from "./App";
2+
import { render } from "@testing-library/react";
3+
import PhotoOfTheDay from "./Components/photoOfTheDay/photoOfTheDay";
44

5-
test("renders learn react link", () => {
6-
render(<App />);
7-
const linkElement = screen.getByText(/learn react/i);
8-
expect(linkElement).toBeInTheDocument();
5+
test("renders photo of the day", () => {
6+
render(<PhotoOfTheDay />);
7+
const imageElement = document.querySelector("img") as HTMLImageElement;
8+
expect(imageElement).toBeInTheDocument();
99
});

src/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React from "react";
22
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
33
import NavBar from "./Components/AddNavBar/NavBar";
4+
import "./App.scss";
5+
import PhotoOfTheDay from "./Components/photoOfTheDay/photoOfTheDay";
46

57
function App() {
68
return (

src/Components/AddNavBar/NavBar.scss

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,20 @@
2727

2828
#astroButton {
2929
width: 5vw;
30-
min-width: 40px;
30+
min-width: 50px;
3131

3232
}
3333

3434
#earthButton {
3535
width: 5vw;
36-
min-width: 40px;
36+
min-width: 50px;
37+
3738
}
3839

3940
a {
4041
margin: 15px 10px 10px 10px;
41-
// background: $greyBackground;
4242
color: $orangeBackground;
43-
// background-color: $greyBackground;
4443
padding: 2.5px 20px;
45-
// text-align: center;
46-
// text-decoration: none;
47-
// display: inline-block;
4844
border: solid 2px $orangeBackground;
4945
text-decoration: none;
5046
border-radius: 25px;

src/Components/AddNavBar/NavBar.spec.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import "@testing-library/jest-dom";
2-
import { fireEvent, render, screen } from "@testing-library/react";
2+
import { render, screen } from "@testing-library/react";
33
import userEvent from "@testing-library/user-event";
44
import React from "react";
55
import NavBar from "./NavBar";
6-
import {BrowserRouter} from "react-router-dom";
6+
import { BrowserRouter } from "react-router-dom";
77
import { createBrowserHistory } from "history";
88

99
describe(NavBar, () => {
1010
it("Should change current location to profile when link is clicked", () => {
11-
const history = createBrowserHistory({ window });
11+
//const history = createBrowserHistory({ window });
1212
render(
1313
<BrowserRouter>
1414
<NavBar />
15-
</BrowserRouter>,
15+
</BrowserRouter>
1616
);
1717
const linkProfile = screen.getByText("Profile");
1818
userEvent.click(linkProfile);
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
@import "../../Styles/GlobalStyles.scss";
2+
3+
4+
body {
5+
background-color: $blueBackground;
6+
font-family: $PublicSans;
7+
}
8+
9+
.photoOfTheDayContainer{
10+
display: flex;
11+
justify-content: center;
12+
background-color: $blueBackground;
13+
14+
}
15+
16+
.photo-of-the-day {
17+
display: flex;
18+
justify-content: center;
19+
width: auto;
20+
margin: auto;
21+
height: 50vh;
22+
object-fit: contain;
23+
margin: 2vw;
24+
25+
}
26+
27+
.explanation {
28+
width: 70%;
29+
margin: auto;
30+
color: $whiteFontColor;
31+
padding: 5px;
32+
text-align: center;
33+
display: none;
34+
}
35+
36+
.photoTitle {
37+
width: 70%;
38+
margin: auto;
39+
color: $whiteFontColor;
40+
padding: 5px;
41+
text-align: center;
42+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import "@testing-library/jest-dom";
2+
import PhotoOfTheDay from "./photoOfTheDay";
3+
import { render, waitFor } from "@testing-library/react";
4+
import React from "react";
5+
6+
describe(PhotoOfTheDay, () => {
7+
it("Should render today's image", async () => {
8+
global.fetch = jest.fn(() =>
9+
Promise.resolve(
10+
new Response(
11+
JSON.stringify({
12+
hdurl:
13+
"https://apod.nasa.gov/apod/image/2505/IssTransit_Sanz_2569.jpg",
14+
title: "Astronomy Picture of the Day",
15+
explanation:
16+
"An amazing view of the International Space Station transiting the Sun.",
17+
}),
18+
),
19+
),
20+
);
21+
render(<PhotoOfTheDay />);
22+
const testImage = document.querySelector("img") as HTMLImageElement;
23+
await waitFor(() => {
24+
expect(testImage).toHaveAttribute(
25+
"src",
26+
"https://apod.nasa.gov/apod/image/2505/IssTransit_Sanz_2569.jpg",
27+
);
28+
});
29+
});
30+
31+
it("Should render fallback image", async () => {
32+
global.fetch = jest.fn(() =>
33+
Promise.resolve(
34+
new Response(
35+
JSON.stringify({
36+
title: "Astronomy Picture of the Day",
37+
explanation:
38+
"An amazing view of the International Space Station transiting the Sun.",
39+
}),
40+
),
41+
),
42+
);
43+
render(<PhotoOfTheDay />);
44+
const testImage = document.querySelector("img") as HTMLImageElement;
45+
await waitFor(() => {
46+
expect(testImage).toBeInTheDocument();
47+
});
48+
});
49+
});
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import React, { useEffect, useState } from "react";
2+
import "./photoOfTheDay.scss";
3+
4+
export default function PhotoOfTheDay() {
5+
const [photo, setPhoto] = useState<string>();
6+
const [title, setTitle] = useState<string>();
7+
const [explanation, setExplanation] = useState<string>();
8+
9+
useEffect(() => {
10+
const photoAddress =
11+
"https://api.nasa.gov/planetary/apod?api_key=5s0C1UhCZLh3WVVN2kGzF1kEw76CImpsBBf3AvEy";
12+
const fallBackImageDates = [
13+
"2025-05-08",
14+
"2025-05-13",
15+
"2025-04-24",
16+
"2025-03-26",
17+
"2025-04-13",
18+
"2025-03-23",
19+
"2025-01-15",
20+
"2024-11-10",
21+
"2024-03-22",
22+
"2023-08-10",
23+
];
24+
25+
fetch(photoAddress)
26+
.then((response) => response.json())
27+
.then((data) => {
28+
if (data.hdurl) {
29+
setPhoto(data.hdurl);
30+
setTitle(data.title);
31+
setExplanation(data.explanation);
32+
} else {
33+
const randomFromZeroToNine = Math.floor(Math.random() * 10);
34+
const altPhotoAddress = `https://api.nasa.gov/planetary/apod?date=${fallBackImageDates[randomFromZeroToNine]}&api_key=5s0C1UhCZLh3WVVN2kGzF1kEw76CImpsBBf3AvEy`;
35+
36+
fetch(altPhotoAddress)
37+
.then((response) => response.json())
38+
.then((data) => {
39+
setPhoto(data.hdurl);
40+
setTitle(data.title);
41+
setExplanation(data.explanation);
42+
})
43+
.catch((error) => console.error("Error fetching api", error));
44+
}
45+
})
46+
.catch((error) => console.error("Error fetching api", error));
47+
}, []);
48+
49+
return (
50+
<div>
51+
<div className="photoOfTheDayContainer">
52+
<img
53+
src={photo}
54+
className="photo-of-the-day"
55+
width="100%"
56+
alt={title}
57+
/>
58+
</div>
59+
<div className="photoTitle">Astronomy Photo of the Day</div>
60+
<div className="explanation">{explanation}</div>
61+
</div>
62+
);
63+
}

src/index.scss

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
body {
22
margin: 0;
3-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
4-
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
5-
sans-serif;
3+
64
-webkit-font-smoothing: antialiased;
75
-moz-osx-font-smoothing: grayscale;
86
}

0 commit comments

Comments
 (0)