Skip to content

Commit

Permalink
Merge pull request #41 from RbAvci/feature/Restaurant
Browse files Browse the repository at this point in the history
  • Loading branch information
RbAvci authored Mar 5, 2024
2 parents 213b6a5 + 9274804 commit 584e113
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/components/App/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import "./App.scss";
import AppHeader from "../AppHeader/AppHeader.jsx";
import Card from "../Card/Card";
import Footer from "../Footer/Footer";


import Restaurant from "../Restaurant/Restaurant.jsx";

const App = () => (
<div className="app">
<AppHeader/>
<AppHeader />
<Card title="Welcome to CYF Hotel" url="https://cyf-hotel.com" image="https://cyf-hotel.com/images/banner.jpg" />
<Bookings />
<Restaurant />
<Footer />
</div>
);
Expand Down
14 changes: 11 additions & 3 deletions src/components/Restaurant/Restaurant.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import React, { useState } from "react";

const Restaurant = () => {
const pizzas = 0;
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">
Pizzas: {pizzas}{" "}
<button className="button restaurant__button">Add</button>
Orders: {orders}
<button className="button restaurant__button" onClick={handleAddOrder}>
Add
</button>
</li>
</ul>
</section>
Expand Down
22 changes: 21 additions & 1 deletion src/components/Restaurant/Restaurant.test.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Restaurant from "./Restaurant.jsx";
import { describe, it, expect } from "vitest";
import { render, screen } from "@testing-library/react";
import { render, screen, fireEvent } from "@testing-library/react";

describe("Restaurant", () => {
it("renders an Orders heading", () => {
Expand All @@ -11,3 +11,23 @@ describe("Restaurant", () => {
expect(titleElement).toBeInTheDocument();
});
});

describe("Restaurant Component", () => {
it("displays initial number of pizza 0", () => {
render(<Restaurant />);
const pizzaText = screen.getByText("Orders: 0");
expect(pizzaText).toBeInTheDocument();
});

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

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

fireEvent.click(addButton);

const updatedPizzaText = screen.getByText("Orders: 1");

expect(updatedPizzaText).toBeInTheDocument();
});
});

0 comments on commit 584e113

Please sign in to comment.