Skip to content

Commit

Permalink
Merge pull request #45 from RbAvci/Feature/Order
Browse files Browse the repository at this point in the history
NW6 | Fikret Ellek | React-Module-Project | Week-2 | Order
  • Loading branch information
RbAvci authored Mar 9, 2024
2 parents 5ad953e + 90e5030 commit b65e37c
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 12 deletions.
16 changes: 16 additions & 0 deletions src/components/Order/Order.jsx
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>
);
}
23 changes: 23 additions & 0 deletions src/components/Order/Order.test.jsx
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();
});
});
14 changes: 2 additions & 12 deletions src/components/Restaurant/Restaurant.jsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
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 />
</ul>
</section>
);
Expand Down
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 className="button restaurant__button" onClick={handleAddOrder}>
Add
</button>
);
}

0 comments on commit b65e37c

Please sign in to comment.