forked from CodeYourFuture/React-Module-Project
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from RbAvci/Feature/Order
NW6 | Fikret Ellek | React-Module-Project | Week-2 | Order
- Loading branch information
Showing
4 changed files
with
48 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import RestaurantButton from "../RestaurantButton/RestaurantButton"; | ||
import React, { useState } from "react"; | ||
|
||
export default function Order() { | ||
const [orders, setOrders] = useState(0); | ||
const handleAddOrder = () => { | ||
setOrders(orders + 1); | ||
}; | ||
|
||
return ( | ||
<li className="restaurant__item"> | ||
Orders: {orders} | ||
<RestaurantButton handleAddOrder={handleAddOrder} /> | ||
</li> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { describe, expect, it } from "vitest"; | ||
import Order from "./Order"; | ||
import { render, screen, fireEvent } from "@testing-library/react"; | ||
|
||
describe("Order", () => { | ||
it("is still rendered on the page", () => { | ||
render(<Order />); | ||
|
||
const ordersText = screen.getByText("Orders: 0"); | ||
|
||
expect(ordersText).toBeInTheDocument(); | ||
}); | ||
|
||
it("button still increases the number of orders", () => { | ||
render(<Order />); | ||
|
||
const addButton = screen.getByText("Add"); | ||
fireEvent.click(addButton); | ||
const updatedPizzaText = screen.getByText("Orders: 1"); | ||
|
||
expect(updatedPizzaText).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function RestaurantButton({ handleAddOrder }) { | ||
return ( | ||
<button className="button restaurant__button" onClick={handleAddOrder}> | ||
Add | ||
</button> | ||
); | ||
} |