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

NW6 | Fikret Ellek | React-Module-Project | Week-2 | orderType #46

Merged
merged 12 commits into from
Mar 9, 2024
Merged
17 changes: 17 additions & 0 deletions src/components/Order/Order.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import RestaurantButton from "../RestaurantButton/RestaurantButton";
import React, { useState } from "react";
import "./Order.scss";

export default function Order({ orderType }) {
const [orders, setOrders] = useState(0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We always create the SetState var to be camel case. So your setorder should be camel case. Can you change that please?

const handleAddOrder = () => {
setOrders(orders + 1);
};

return (
<li className="restaurant__item">
{orderType}: {orders}
<RestaurantButton handleAddOrder={handleAddOrder} />
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work

</li>
);
}
11 changes: 11 additions & 0 deletions src/components/Order/Order.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.restaurant__item {
width: 300px;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;

button {
margin-bottom: 5px;
}
}
16 changes: 4 additions & 12 deletions src/components/Restaurant/Restaurant.jsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
import React, { useState } from "react";
import Order from "../Order/Order";

const Restaurant = () => {
const [orders, setOrders] = useState(0);
const handleAddOrder = () => {
setOrders(orders + 1);
};

return (
<section className="restaurant">
<h3 className="restaurant__heading">Restaurant Orders</h3>
<ul className="restaurant__list">
<li className="restaurant__item">
Orders: {orders}
<button className="button restaurant__button" onClick={handleAddOrder}>
Add
</button>
</li>
<Order orderType="Pizzas" />
<Order orderType="Salads" />
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect work!

<Order orderType="Chocolate cake" />
</ul>
</section>
);
Expand Down
18 changes: 11 additions & 7 deletions src/components/Restaurant/Restaurant.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,23 @@ describe("Restaurant", () => {
describe("Restaurant Component", () => {
it("displays initial number of pizza 0", () => {
render(<Restaurant />);
const pizzaText = screen.getByText("Orders: 0");
expect(pizzaText).toBeInTheDocument();
const text1 = screen.getByText("Pizzas: 0");
const text2 = screen.getByText("Salads: 0");
const text3 = screen.getByText("Chocolate cake: 0");

expect(text1, text2, text3).toBeInTheDocument();
});

it("increase number of pizzas when 'Add' button is clicked", () => {
render(<Restaurant />);

const addButton = screen.getByText("Add");

fireEvent.click(addButton);
const addButtons = screen.getAllByTestId("addButton");
addButtons.map((addButton) => fireEvent.click(addButton));

const updatedPizzaText = screen.getByText("Orders: 1");
const updatedText1 = screen.getByText("Pizzas: 1");
const updatedText2 = screen.getByText("Salads: 1");
const updatedText3 = screen.getByText("Chocolate cake: 1");

expect(updatedPizzaText).toBeInTheDocument();
expect(updatedText1, updatedText2, updatedText3).toBeInTheDocument();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All looking good, tests are really good as well

});
});
7 changes: 7 additions & 0 deletions src/components/RestaurantButton/RestaurantButton.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function RestaurantButton({ handleAddOrder }) {
return (
<button data-testid="addButton" className="button restaurant__button" onClick={handleAddOrder}>
Add
</button>
);
}