Skip to content

Commit

Permalink
MSW Works
Browse files Browse the repository at this point in the history
  • Loading branch information
Gloria Giannascoli committed Jul 29, 2024
1 parent 5c4b0b9 commit 63bb655
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 18 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/Routing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const Routing = () => {
<Route path="/menu" element={<Menu />} />
<Route path="/order" element={<Order />} />
<Route path="/reserved-area" element={<ReservedArea />} />
<Route path="/checkout-wizard*" element={<Wizard />} />
<Route path="/checkout-wizard/*" element={<Wizard />} />
</Routes>
)
}
Expand Down
3 changes: 3 additions & 0 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import MockWrapper from "./mocks/MockWrapper.tsx"
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"
import { Auth0Wrapper } from "./auth/Auth0Wrapper/Auth0Wrapper.tsx"
import { ThemeProvider, createTheme } from "@mui/material/styles"
import axios from "axios"

const queryClient = new QueryClient()
const root = ReactDOM.createRoot(document.getElementById("root") as HTMLElement)
Expand Down Expand Up @@ -38,6 +39,8 @@ export const theme = createTheme({
}
})

axios.defaults.baseURL = import.meta.env.VITE_PUBLIC_PATH || "/"

root.render(
<React.StrictMode>
<Auth0Wrapper>
Expand Down
7 changes: 6 additions & 1 deletion src/mocks/MockWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ const MockWrapper: React.FC<{ children: React.ReactNode }> = ({ children }) => {
return
}*/
const { worker } = await import("./browser")
await worker.start()
await worker.start({
waitUntilReady: true,
serviceWorker: {
url: import.meta.env.BASE_URL + "/mockServiceWorker.js"
}
})
setStarted(true)
}

Expand Down
32 changes: 17 additions & 15 deletions src/mocks/handlers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { HttpResponse, delay, http } from "msw"

const base = import.meta.env.BASE_URL

export const handlers = [
http.get("/districts", async () => {
http.get(base + "/districts", async () => {
return Response.json([
{ district: "Bologna", code: "BO" },
{ district: "Firenze", code: "FI" },
Expand All @@ -18,10 +20,10 @@ export const handlers = [
])
}),

http.post("/address", async () => {
http.post(base + "/address", async () => {
return Response.json({})
}),
http.get("/dishes", async ({ request }) => {
http.get(base + "/dishes", async ({ request }) => {
delay(7000)
let dishes = [
{
Expand All @@ -31,7 +33,7 @@ export const handlers = [
categories: ["lunches", "dinners"],
price: 25.99,
rating: 1,
imgUrl: "/menu-1.jpg"
imgUrl: base + "/menu-1.jpg"
},
{
id: 2,
Expand All @@ -40,7 +42,7 @@ export const handlers = [
description: "A classic breakfast staple, a fried egg cooked to golden perfection, with a runny yolk that adds a rich and satisfying touch to any meal.",
price: 12.99,
rating: 4,
imgUrl: "/menu-2.jpg"
imgUrl: base + "/menu-2.jpg"
},
{
id: 3,
Expand All @@ -49,7 +51,7 @@ export const handlers = [
category: ["lunches", "dinners"],
price: 23.99,
rating: 3,
imgUrl: "/menu-3.jpg"
imgUrl: base + "/menu-3.jpg"
},
{
id: 4,
Expand All @@ -59,7 +61,7 @@ export const handlers = [
category: ["breakfasts", "desserts"],
price: 6.99,
rating: 4,
imgUrl: "/menu-4.jpg"
imgUrl: base + "/menu-4.jpg"
},
{
id: 5,
Expand All @@ -68,7 +70,7 @@ export const handlers = [
category: ["breakfasts"],
price: 10.99,
rating: 5,
imgUrl: "/menu-5.jpg"
imgUrl: base + "/menu-5.jpg"
},
{
id: 6,
Expand All @@ -78,7 +80,7 @@ export const handlers = [
category: ["breakfasts"],
price: 17.99,
rating: 5,
imgUrl: "/menu-6.jpg"
imgUrl: base + "/menu-6.jpg"
},
{
id: 7,
Expand All @@ -87,7 +89,7 @@ export const handlers = [
category: ["lunches", "dinners"],
price: 21.6,
rating: 4,
imgUrl: "/menu-7.jpg"
imgUrl: base + "/menu-7.jpg"
},
{
id: 8,
Expand All @@ -96,7 +98,7 @@ export const handlers = [
category: ["lunches", "dinners"],
price: 31.5,
rating: 4,
imgUrl: "/menu-8.jpg"
imgUrl: base + "/menu-8.jpg"
},
{
id: 9,
Expand All @@ -105,7 +107,7 @@ export const handlers = [
category: ["lunches", "dinners", "fastfoods"],
price: 5.78,
rating: 5,
imgUrl: "/menu-9.jpg"
imgUrl: base + "/menu-9.jpg"
},
{
id: 10,
Expand All @@ -114,7 +116,7 @@ export const handlers = [
category: ["breakfasts", "lunches", "dinners"],
price: 13.67,
rating: 4,
imgUrl: "/menu-10.jpg"
imgUrl: base + "/menu-10.jpg"
},
{
id: 11,
Expand All @@ -123,7 +125,7 @@ export const handlers = [
category: ["lunches", "dinners"],
price: 9.21,
rating: 3,
imgUrl: "/menu-11.jpg"
imgUrl: base + "/menu-11.jpg"
},
{
id: 12,
Expand All @@ -132,7 +134,7 @@ export const handlers = [
category: ["breakfasts", "fastfoods"],
price: 11.89,
rating: 2,
imgUrl: "/menu-12.jpg"
imgUrl: base + "/menu-12.jpg"
}
]

Expand Down
2 changes: 1 addition & 1 deletion src/pages/Menu/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export interface DishComplete {
}

export const Menu = () => {
const [categoryId, setCategoryId] = useState<string>("")
const [categoryId, setCategoryId] = useState<string>()
const { favouriteIds, toggleFavouriteDish } = useDishStore()
const { addToOrder, removeFromOrder, order } = useOrderStore()
const fetchDishes = async (): Promise<DishComplete[]> => {
Expand Down

0 comments on commit 63bb655

Please sign in to comment.