Skip to content

Commit 94de2d0

Browse files
liviawanggLivia WangJessicaF
authored
568-feature-remove-linear-ratings (#569)
* removed linear ratings * fixed tests * removed unused imports --------- Co-authored-by: Livia Wang <z5417230@ad.unsw.edu.au> Co-authored-by: Jessica Feng <54833118+JessicaF@users.noreply.github.com>
1 parent 047de5e commit 94de2d0

File tree

7 files changed

+46
-104
lines changed

7 files changed

+46
-104
lines changed
+5-26
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,20 @@
11
import "@testing-library/jest-dom";
22

3-
import { Booking } from "@common/types";
43
import { render, screen } from "@testing-library/react";
5-
import { Provider } from "react-redux";
4+
import RoomRatingList from "components/Rooms/RoomRatingList";
65

7-
import BookingCalendar from "../components/BookingCalendar";
8-
import store from "../redux/store";
9-
10-
const start: Date = new Date();
11-
const end: Date = new Date();
12-
const roomID: string = "test";
13-
14-
const events: Booking[] = [
15-
{
16-
name: "MARK5827 TUT",
17-
bookingType: "(CLASS)",
18-
start: start,
19-
end: end,
20-
},
21-
];
22-
23-
describe("Booking calendar with circular rating", () => {
6+
describe("Rooms page with circular rating component", () => {
247
it("renders the CircularRating component", () => {
25-
render(
26-
<Provider store={store}>
27-
<BookingCalendar events={events} roomID={roomID} />
28-
</Provider>
29-
);
8+
const mockParams = "K-J17-101";
9+
10+
render(<RoomRatingList roomID={mockParams} />);
3011

3112
const cleanlinessRating = screen.getByText("Cleanliness");
3213
const quietnessRating = screen.getByText("Quietness");
3314
const locationRating = screen.getByText("Location");
34-
const overallRating = screen.getByText("Overall");
3515

3616
expect(cleanlinessRating).toBeInTheDocument();
3717
expect(quietnessRating).toBeInTheDocument();
3818
expect(locationRating).toBeInTheDocument();
39-
expect(overallRating).toBeInTheDocument();
4019
});
4120
});

frontend/__tests__/OverallRating.test.tsx

+4-26
Original file line numberDiff line numberDiff line change
@@ -10,40 +10,18 @@ jest.mock("react-redux", () => ({
1010
}));
1111

1212
describe("OverallRating", () => {
13-
it("renders overall rating title", () => {
13+
it("renders decimal rating", () => {
1414
render(<OverallRating />);
1515

16-
const heading = screen.getByText("Overall Rating");
16+
const decimalRating = screen.getByLabelText("decimal-rating");
1717

18-
expect(heading).toBeInTheDocument();
19-
});
20-
21-
it("renders linear ratings", () => {
22-
render(<OverallRating />);
23-
24-
const linearRatings = screen.getByRole("generic", {
25-
name: "Linear Ratings",
26-
});
27-
28-
expect(linearRatings).toBeInTheDocument();
29-
});
30-
31-
it("renders overall number and star rating", () => {
32-
render(<OverallRating />);
33-
34-
const numberStarRating = screen.getByRole("generic", {
35-
name: "Number Star Rating",
36-
});
37-
38-
expect(numberStarRating).toBeInTheDocument();
18+
expect(decimalRating).toBeInTheDocument();
3919
});
4020

4121
it("renders leave a review", () => {
4222
render(<OverallRating />);
4323

44-
const review = screen.getByRole("button", {
45-
name: "Leave A Review",
46-
});
24+
const review = screen.getByLabelText("leave-review-link");
4725

4826
expect(review).toBeInTheDocument();
4927
});

frontend/app/room/[room]/page.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import Link from "@mui/material/Link";
1717
import Rating from "@mui/material/Rating";
1818
import Stack from "@mui/material/Stack";
1919
import Typography from "@mui/material/Typography";
20-
import OverallRating from "components/OverallRating";
20+
import RoomRatingList from "components/Rooms/RoomRatingList";
2121
import Image from "next/image";
2222
import React, { useState } from "react";
2323

@@ -71,7 +71,7 @@ export default function Page({ params }: { params: { room: string } }) {
7171
<RoomPageHeader room={room} buildingName={building.name} />
7272
<RoomImage src={`/assets/building_photos/${campus}-${grid}.webp`} />
7373
<BookingCalendar events={adjustedBookings ?? []} roomID={room.id} />
74-
<OverallRating />
74+
<RoomRatingList roomID={room.id} />
7575
</Stack>
7676
) : (
7777
<LoadingCircle />

frontend/components/BookingCalendar.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,6 @@ const BookingCalendar: React.FC<{ events: Array<Booking>; roomID: string }> = ({
353353
}}
354354
/>
355355
</StyledCalendarContainer>
356-
<RoomRatingList roomID={roomID} />
357356
</Stack>
358357
</>
359358
);

frontend/components/DecimalStarRating.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const DecimalStarRating = () => {
88
component="legend"
99
variant="h3"
1010
sx={{
11-
marginBottom: "16px",
1211
fontSize: {
1312
xs: "2.5rem",
1413
md: "5rem",
@@ -24,7 +23,8 @@ const DecimalStarRating = () => {
2423
defaultValue={4.5}
2524
precision={0.1}
2625
readOnly
27-
size="large"
26+
size="medium"
27+
aria-label="decimal-rating"
2828
/>
2929
</>
3030
);

frontend/components/OverallRating.tsx

+13-38
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import Stack from "@mui/system/Stack";
33
import React, { useState } from "react";
44

55
import DecimalStarRating from "./DecimalStarRating";
6-
import LinearRatings from "./LinearRatings";
76
import ReviewModal from "./ReviewModal";
87

98
const OverallRating = () => {
@@ -13,44 +12,20 @@ const OverallRating = () => {
1312
const handleClose = () => setOpen(false);
1413

1514
return (
16-
<Stack
17-
direction="row"
18-
spacing={2}
19-
width="100%"
20-
alignItems="flex-start"
21-
marginTop={3}
22-
sx={{ flexGrow: 1 }}
23-
>
24-
<LinearRatings />
25-
<Stack
26-
spacing={2}
27-
alignItems={{ xs: "center", sm: "flex-start" }}
28-
width="40%"
29-
height="40%"
15+
<Stack direction="column" alignItems="center" justifyContent="center">
16+
<DecimalStarRating />
17+
<Button
18+
onClick={handleOpen}
19+
sx={{
20+
textAlign: "center",
21+
fontSize: "14px",
22+
color: "#1E90FF",
23+
}}
24+
aria-label="leave-review-link"
3025
>
31-
<Stack
32-
alignItems="center"
33-
justifyContent="flex-end"
34-
spacing={1}
35-
width="40%"
36-
height="150%"
37-
aria-label="Number Star Rating"
38-
>
39-
<DecimalStarRating />
40-
<Button
41-
onClick={handleOpen}
42-
sx={{
43-
textAlign: "center",
44-
fontSize: "14px",
45-
color: "#1E90FF",
46-
}}
47-
aria-label="Leave A Review"
48-
>
49-
Leave a Review
50-
</Button>
51-
<ReviewModal open={open} handleClose={handleClose} />
52-
</Stack>
53-
</Stack>
26+
Leave a Review
27+
</Button>
28+
<ReviewModal open={open} handleClose={handleClose} />
5429
</Stack>
5530
);
5631
};

frontend/components/Rooms/RoomRatingList.tsx

+20-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import Box from "@mui/material/Box";
2+
import Grid from "@mui/material/Grid2";
3+
import OverallRating from "components/OverallRating";
24
import useRoomRatings from "hooks/useRoomRatings";
35
import React from "react";
46

@@ -9,31 +11,40 @@ const RoomRatingList: React.FC<{
911
}> = ({ roomID }) => {
1012
const { ratings } = useRoomRatings(roomID);
1113

12-
let cleanlinesRating = 0;
14+
let cleanlinessRating = 0;
1315
let quietnessRating = 0;
1416
let locationRating = 0;
1517
let overallRating = 0;
1618

1719
if (ratings && ratings.length > 0) {
1820
ratings.forEach((rating) => {
19-
cleanlinesRating += rating.cleanliness;
21+
cleanlinessRating += rating.cleanliness;
2022
quietnessRating += rating.cleanliness;
2123
locationRating += rating.location;
2224
overallRating += rating.overall;
2325
});
2426

25-
cleanlinesRating = cleanlinesRating / ratings.length;
27+
cleanlinessRating = cleanlinessRating / ratings.length;
2628
quietnessRating = quietnessRating / ratings.length;
2729
locationRating = locationRating / ratings.length;
2830
overallRating = overallRating / ratings.length;
2931
}
30-
3132
return (
32-
<Box display="flex" justifyContent="flex-start" mt={2} gap={9}>
33-
<CircularRating category="Cleanliness" rating={cleanlinesRating} />
34-
<CircularRating category="Quietness" rating={quietnessRating} />
35-
<CircularRating category="Location" rating={locationRating} />
36-
<CircularRating category="Overall" rating={overallRating} />
33+
<Box display="flex" justifyContent="center" mt={2}>
34+
<Grid container spacing={{ xs: 1, sm: 2 }} columns={{ xs: 2, sm: 4 }}>
35+
<Grid size={1}>
36+
<OverallRating />
37+
</Grid>
38+
<Grid size={1}>
39+
<CircularRating category="Cleanliness" rating={cleanlinessRating} />
40+
</Grid>
41+
<Grid size={1}>
42+
<CircularRating category="Quietness" rating={quietnessRating} />
43+
</Grid>
44+
<Grid size={1}>
45+
<CircularRating category="Location" rating={locationRating} />
46+
</Grid>
47+
</Grid>
3748
</Box>
3849
);
3950
};

0 commit comments

Comments
 (0)