-
Notifications
You must be signed in to change notification settings - Fork 1
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
Changes from all commits
d04d18b
f48ffeb
c344f15
2721af3
749f401
a382a93
90e5030
921fb86
10a654f
1c231cf
767ca95
d34c97e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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); | ||
const handleAddOrder = () => { | ||
setOrders(orders + 1); | ||
}; | ||
|
||
return ( | ||
<li className="restaurant__item"> | ||
{orderType}: {orders} | ||
<RestaurantButton handleAddOrder={handleAddOrder} /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice work |
||
</li> | ||
); | ||
} |
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; | ||
} | ||
} |
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" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perfect work! |
||
<Order orderType="Chocolate cake" /> | ||
</ul> | ||
</section> | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All looking good, tests are really good as well |
||
}); | ||
}); |
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> | ||
); | ||
} |
There was a problem hiding this comment.
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?