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| Rabia Avci | React Module Project | Feature Restaurant-State - Week2 #41

Merged
merged 2 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Comment on lines 3 to +6
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think nothing would change if you omit the const pizzas = 0; Since the pizzas variable is not used anywhere in the component, removing it would simplify the code without affecting its functionality.

};

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>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looking great :)

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();
});
});