+ )
+ await typeLeagueInfo(result, true)
+
+ const submitButton = await result.findByText("Create")
+ act(() => {
+ Simulate.click(submitButton)
+ })
+
+ const error = await result.findByText('Please select a location for your league')
+ await waitFor(() => {
+ expect(error).toBeInTheDocument()
+ expect(mockedNavigate).not.toBeCalled()
+ })
+ })
+});
+
+async function typeLeagueInfo(result: RenderResult, omitLocation?: boolean) {
const name = faker.random.words(randomInt(3, 10))
const nameField = await result.findByPlaceholderText("name")
@@ -149,9 +200,11 @@ async function typeLeagueInfo(result: RenderResult) {
Simulate.change(slugField)
})
- const locationSelectValue = await result.findByPlaceholderText('test-location')
- slugField.setAttribute("value", faker.datatype.uuid())
- act(() => {
- Simulate.change(locationSelectValue)
- })
+ if (!omitLocation) {
+ const locationSelectValue = await result.findByPlaceholderText('test-location')
+ slugField.setAttribute("value", faker.datatype.uuid())
+ act(() => {
+ Simulate.change(locationSelectValue)
+ })
+ }
}
diff --git a/web/app/src/pages/Leagues/Form.tsx b/web/app/src/pages/Leagues/Form.tsx
index 110714d..ce9d850 100644
--- a/web/app/src/pages/Leagues/Form.tsx
+++ b/web/app/src/pages/Leagues/Form.tsx
@@ -41,7 +41,7 @@ export default function LeagueForm(props: LeagueFormProps) {
});
async function submitForm() {
- let locationId: string
+ let locationId: string | undefined
if (locationValue === undefined) {
setAlert({
status: "error",
@@ -60,8 +60,11 @@ export default function LeagueForm(props: LeagueFormProps) {
title: err.title,
detail: err.detail
})
- throw new Error(err.detail)
+ return undefined
})
+ if (locationId === undefined) {
+ return
+ }
} else {
locationId = locationValue.value
}
@@ -109,7 +112,8 @@ export default function LeagueForm(props: LeagueFormProps) {
if (validSlug !== e.target.value) {
setSlugError(
- Slug must be url-friendly. Try {validSlug}
instead, or clear the field to use the generated
+ Slug must be url-friendly. Try {validSlug}
instead, or clear the field to use the
+ generated
slug.
)