-
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 #32 from neuefische/23-cache-restaurant-data-and-r…
…evalidate 23 cache restaurant data and revalidate
- Loading branch information
Showing
23 changed files
with
363 additions
and
194 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
2 changes: 1 addition & 1 deletion
2
...RestaurantsPage/RestaurantsPage.styled.ts → ...rc/components/AlertBox/AlertBox.styled.ts
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,10 @@ | ||
import { StyledErrorContainer } from "./AlertBox.styled.ts"; | ||
import { ReactNode } from "react"; | ||
|
||
type AlertBoxProps = { | ||
children: ReactNode; | ||
}; | ||
|
||
export default function AlertBox({ children }: Readonly<AlertBoxProps>) { | ||
return <StyledErrorContainer>{children}</StyledErrorContainer>; | ||
} |
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,23 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import "@testing-library/jest-dom"; | ||
import Button from "./Button.tsx"; | ||
|
||
test("Button component renders a button", () => { | ||
render( | ||
<Button buttonType="delete" handleOnClick={() => {}}> | ||
Delete | ||
</Button> | ||
); | ||
const button = screen.getByRole("button"); | ||
expect(button).toBeInTheDocument(); | ||
}); | ||
|
||
test("Button component renders children as text", () => { | ||
render( | ||
<Button buttonType="delete" handleOnClick={() => {}}> | ||
Delete | ||
</Button> | ||
); | ||
const text = screen.getByText(/delete/i); | ||
expect(text).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
34 changes: 34 additions & 0 deletions
34
frontend/src/components/ButtonLink/ButtonLink.component.test.tsx
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,34 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import "@testing-library/jest-dom"; | ||
import ButtonLink from "./ButtonLink.tsx"; | ||
import { MemoryRouter } from "react-router-dom"; | ||
|
||
test("ButtonLink component renders a link", () => { | ||
render( | ||
<MemoryRouter> | ||
<ButtonLink href="/my-url">Click here</ButtonLink> | ||
</MemoryRouter> | ||
); | ||
const button = screen.getByRole("link"); | ||
expect(button).toBeInTheDocument(); | ||
}); | ||
|
||
test("ButtonLink component links to the correct target", () => { | ||
render( | ||
<MemoryRouter> | ||
<ButtonLink href="/my-url">Click here</ButtonLink> | ||
</MemoryRouter> | ||
); | ||
const button = screen.getByRole("link"); | ||
expect(button).toHaveAttribute("href", "/my-url"); | ||
}); | ||
|
||
test("ButtonLink component renders children as text", () => { | ||
render( | ||
<MemoryRouter> | ||
<ButtonLink href="/my-url">Click here</ButtonLink> | ||
</MemoryRouter> | ||
); | ||
const text = screen.getByText(/click here/i); | ||
expect(text).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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import "@testing-library/jest-dom"; | ||
import Logo from "./Logo.tsx"; | ||
|
||
test("Button component renders a button", () => { | ||
render(<Logo />); | ||
const button = screen.getByText(/restaurantapp/i); | ||
expect(button).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
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,64 @@ | ||
import useSWR from "swr"; | ||
import { RestaurantType } from "../model/Restaurant.ts"; | ||
import axios from "axios"; | ||
import { logtail } from "../logger.ts"; | ||
|
||
export function useRestaurants() { | ||
const { data, error, isLoading } = useSWR<RestaurantType[]>( | ||
"/api/restaurants", | ||
(url: string) => { | ||
logtail.info(`Trying to receive all restaurants from ${url}`); | ||
|
||
return axios | ||
.get(url) | ||
.then((response) => { | ||
logtail.info("Received " + response.data.length + " restaurants"); | ||
return response.data; | ||
}) | ||
.catch((error) => { | ||
logtail.error(error.message, { | ||
error: error, | ||
}); | ||
throw error; | ||
}); | ||
} | ||
); | ||
|
||
return { | ||
restaurants: data, | ||
isLoading, | ||
isError: error, | ||
}; | ||
} | ||
|
||
export function useRestaurant(id: string) { | ||
if (!id) { | ||
throw new Error("Restaurant ID is required!"); | ||
} | ||
|
||
const { data, error, isLoading } = useSWR<RestaurantType>( | ||
`/api/restaurants/${id}`, | ||
(url: string) => { | ||
logtail.info(`Trying to receive restaurant from ${url}`); | ||
|
||
return axios | ||
.get(url) | ||
.then((response) => { | ||
logtail.info(`Received restaurant with ID ${response.data.id}`); | ||
return response.data; | ||
}) | ||
.catch((error) => { | ||
logtail.error(error.message, { | ||
error: error, | ||
}); | ||
throw error; | ||
}); | ||
} | ||
); | ||
|
||
return { | ||
restaurant: data, | ||
isLoading, | ||
isError: error, | ||
}; | ||
} |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.