Skip to content

Commit c35e860

Browse files
hk-15preek0719Rachel Kelly
authored
Rover image component (#23)
Co-authored-by: preek0719 <preetha.krishnan@softwire.com> Co-authored-by: Rachel Kelly <rachel.kelly@softwire.com>
1 parent eb44fdc commit c35e860

File tree

6 files changed

+322
-8
lines changed

6 files changed

+322
-8
lines changed

package-lock.json

Lines changed: 118 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@
66
"@testing-library/dom": "^10.4.0",
77
"@types/jest": "^27.5.2",
88
"@types/node": "^16.18.126",
9-
"@types/react": "^19.1.4",
109
"@types/react-dom": "^19.1.5",
1110
"react": "^19.1.0",
1211
"react-dom": "^19.1.0",
12+
"react-responsive-carousel": "^3.2.23",
1313
"react-router": "^7.6.0",
1414
"react-router-dom": "^7.6.0",
1515
"react-scripts": "5.0.1",
16+
"react-slick": "^0.30.3",
17+
"react-spinners": "^0.17.0",
1618
"sass": "^1.88.0",
19+
"slick-carousel": "^1.8.1",
1720
"web-vitals": "^2.1.4"
1821
},
1922
"scripts": {
@@ -48,7 +51,8 @@
4851
"@testing-library/react": "^16.1.0",
4952
"@testing-library/user-event": "^14.6.1",
5053
"@types/jest": "^29.5.14",
51-
"@types/react": "^19.0.10",
54+
"@types/react": "^19.1.4",
55+
"@types/react-slick": "^0.23.13",
5256
"@types/sass": "^1.45.0",
5357
"eslint": "^8.57.1",
5458
"eslint-config-prettier": "^10.0.1",
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import React from "react";
2+
import { fireEvent, render, waitFor } from "@testing-library/react";
3+
import RoverImages from "./RoverImages";
4+
5+
const photo_mock_data = {
6+
photos: [
7+
{
8+
id: 1,
9+
img_src: "https://mars.nasa.gov/",
10+
},
11+
{
12+
id: 2,
13+
img_src: "https://mars.nasa.gov/1",
14+
},
15+
],
16+
};
17+
18+
const manifest_mock_data = {
19+
photo_manifest: {
20+
photos: [
21+
{
22+
cameras: ["HAZ"],
23+
},
24+
],
25+
},
26+
};
27+
28+
describe("Testing the rover image displayed on page load", () => {
29+
beforeEach(() => {
30+
global.fetch = jest
31+
.fn()
32+
.mockResolvedValueOnce({
33+
json: jest.fn().mockResolvedValue(manifest_mock_data),
34+
})
35+
.mockResolvedValueOnce({
36+
json: jest.fn().mockResolvedValue(photo_mock_data),
37+
});
38+
});
39+
test("Testing the rover image displayed on page load", async () => {
40+
render(<RoverImages name="curiosity" />);
41+
42+
await waitFor(() => {
43+
const testImage = document.querySelector("img") as HTMLImageElement;
44+
expect(testImage).toHaveAttribute(
45+
"src",
46+
photo_mock_data.photos[0].img_src,
47+
);
48+
});
49+
});
50+
51+
test("Testing the rover image is displayed when next is clicked", async () => {
52+
render(<RoverImages name="curiosity" />);
53+
await waitFor(() => {
54+
const firstTestImage = document.querySelector("img") as HTMLImageElement;
55+
const firstTestImageDiv = firstTestImage.parentElement?.parentElement;
56+
const nextButton = document.getElementsByClassName(
57+
"slick-arrow slick-next",
58+
);
59+
fireEvent.click(nextButton[0]);
60+
expect(firstTestImageDiv).toHaveAttribute("aria-hidden", "true");
61+
});
62+
});
63+
});
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
body {
2+
background: #062356;
3+
color: #fffff2;
4+
}
5+
6+
.sliderContainer {
7+
max-width: 30%;
8+
margin: auto;
9+
padding: 40px;
10+
}
11+
12+
.error {
13+
text-align: center;
14+
font-size: 50px;
15+
}
16+
17+
18+
@media screen and (max-width: 1000px) {
19+
.sliderContainer {
20+
max-width: 60%;
21+
}
22+
}
23+
24+
@media screen and (max-width: 600px) {
25+
.sliderContainer {
26+
max-width: 80%;
27+
}
28+
}

0 commit comments

Comments
 (0)