forked from CodeYourFuture/React-Module-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
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 #52 from HadikaMalik/PedroRicciardi/Component/Cust…
…omerProfile Pedro Ricciardi/Component/Customer Profile
- Loading branch information
Showing
8 changed files
with
173 additions
and
30 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
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
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,37 @@ | ||
import { useState, useEffect } from "react"; | ||
|
||
import "./CustomerProfile.scss"; | ||
|
||
const CustomerProfile = ({ id }) => { | ||
const [customerProfileData, setCustomerProfileData] = useState(null); | ||
|
||
useEffect(() => { | ||
fetch(`https://cyf-hotel-api.netlify.app/customers/${id}`) | ||
.then((response) => response.json()) | ||
.then((data) => setCustomerProfileData(data)) | ||
.catch((error) => | ||
console.error("Error fetching customer profile:", error) | ||
); | ||
}, [id]); | ||
|
||
if (!customerProfileData) { | ||
return ( | ||
<tr data-testid="customer-profile" className="customer-row"> | ||
<td colSpan={2}>Loading...</td> | ||
</tr> | ||
); | ||
} | ||
|
||
return ( | ||
<tr data-testid="customer-profile" className="customer-row"> | ||
<td colSpan={2}>Phone: {customerProfileData.phoneNumber}</td> | ||
<td colSpan={2} className={customerProfileData.vip ? `vip-customer` : ``}> | ||
{customerProfileData.vip ? `VIP Customer` : `Regular Customer`} | ||
</td> | ||
<td>ID: {customerProfileData.id}</td> | ||
<td colSpan={2}>More info</td> | ||
</tr> | ||
); | ||
}; | ||
|
||
export default CustomerProfile; |
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,42 @@ | ||
:root { | ||
--customer-row-light: 25%; | ||
--customer-row-saturation: 30%; | ||
} | ||
|
||
.hidden { | ||
display: none; | ||
} | ||
|
||
.customer-row:nth-child(even) { | ||
background-color: hsl( | ||
246, | ||
var(--customer-row-saturation), | ||
var(--customer-row-light) | ||
); | ||
} | ||
|
||
.customer-row:nth-child(odd) { | ||
background-color: hsl( | ||
236, | ||
var(--customer-row-saturation), | ||
var(--customer-row-light) | ||
); | ||
} | ||
|
||
td { | ||
text-align: center; | ||
} | ||
|
||
.vip-customer { | ||
background-color: hsl( | ||
176, | ||
var(--customer-row-saturation), | ||
var(--customer-row-light) | ||
); | ||
} | ||
|
||
@media (prefers-color-scheme: light) { | ||
:root { | ||
--customer-row-light: 80%; | ||
} | ||
} |
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,40 @@ | ||
import { describe, it, expect } from "vitest"; | ||
import { render, screen, fireEvent } from "@testing-library/react"; | ||
import Booking from "../Booking/Booking"; | ||
import FakeBookings from "../../data/fakeBookings.json"; | ||
|
||
describe("CustomerProfile Component", () => { | ||
it("renders a booking component", () => { | ||
const booking = FakeBookings[0]; | ||
render(<Booking booking={booking} />); | ||
const bookingComponent = screen.getByTestId("booking-component"); | ||
expect(bookingComponent).toBeInTheDocument(); | ||
}); | ||
|
||
it("first page load should not render the CustomerProfile component", () => { | ||
const booking = FakeBookings[0]; | ||
|
||
render(<Booking booking={booking} />); | ||
const bookingComponent = screen.getByTestId("booking-component"); | ||
const CustomerProfileComponent = screen.queryByTestId("customer-profile"); | ||
|
||
expect(bookingComponent).toBeInTheDocument(); | ||
|
||
expect(CustomerProfileComponent).toBeNull(); | ||
}); | ||
|
||
it("clicking on the 'Show Profile' button should render the CustomerProfile component", () => { | ||
const booking = FakeBookings[0]; | ||
render(<Booking booking={booking} />); | ||
|
||
const bookingComponent = screen.getByTestId("booking-component"); | ||
const showProfileButton = screen.getByTestId("show-profile-button"); | ||
|
||
fireEvent.click(showProfileButton); | ||
|
||
const CustomerProfileComponent = screen.getByTestId("customer-profile"); | ||
|
||
expect(bookingComponent).toBeInTheDocument(); | ||
expect(CustomerProfileComponent).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