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

Add test case for the permalink option of useFormState #56329

Merged
merged 2 commits into from
Oct 3, 2023
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
16 changes: 16 additions & 0 deletions test/e2e/app-dir/actions/app-action-form-state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,21 @@ createNextDescribe(
return browser.elementByCss('#hydrated').text()
}, 'hydrated')
})

it('should send the action to the provided permalink with form state when JS disabled', async () => {
const browser = await next.browser('/client/form-state/page-2', {
disableJavaScript: true,
})

// Simulate a progressively enhanced form request
await browser.eval(
`document.getElementById('name-input').value = 'test-permalink'`
)
await browser.eval(`document.getElementById('form-state-form').submit()`)

await check(() => {
return browser.elementByCss('#form-state').text()
}, 'initial-state:test-permalink')
})
}
)
31 changes: 31 additions & 0 deletions test/e2e/app-dir/actions/app/client/form-state/page-2/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use client'

import { experimental_useFormState } from 'react-dom'
import { appendName } from '../actions'
import { useEffect, useState } from 'react'

export default function Page() {
const [state, appendNameFormAction] = experimental_useFormState(
appendName,
'initial-state',
'/client/form-state'
)

const [hydrated, setHydrated] = useState(false)
useEffect(() => {
setHydrated(true)
}, [])

return (
<>
<form id="form-state-form" action={appendNameFormAction}>
<p id="form-state">{state}</p>
<input id="name-input" name="name" />
<button id="submit-form" type="submit">
log
</button>
</form>
{hydrated ? <p id="hydrated">hydrated</p> : null}
</>
)
}
3 changes: 2 additions & 1 deletion test/e2e/app-dir/actions/app/client/form-state/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { useEffect, useState } from 'react'
export default function Page() {
const [state, appendNameFormAction] = experimental_useFormState(
appendName,
'initial-state'
'initial-state',
'/client/form-state'
)

const [hydrated, setHydrated] = useState(false)
Expand Down
Loading