generated from chiffre-io/template-library
-
-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add native HTML form test (#829)
- Loading branch information
Showing
22 changed files
with
198 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { testForm } from 'e2e-shared/specs/form.cy' | ||
|
||
testForm({ | ||
path: '/app/form/useQueryState', | ||
hook: 'useQueryState', | ||
nextJsRouter: 'app' | ||
}) | ||
|
||
testForm({ | ||
path: '/app/form/useQueryStates', | ||
hook: 'useQueryStates', | ||
nextJsRouter: 'app' | ||
}) | ||
|
||
testForm({ | ||
path: '/pages/form/useQueryState', | ||
hook: 'useQueryState', | ||
nextJsRouter: 'pages' | ||
}) | ||
|
||
testForm({ | ||
path: '/pages/form/useQueryStates', | ||
hook: 'useQueryStates', | ||
nextJsRouter: 'pages' | ||
}) |
10 changes: 10 additions & 0 deletions
10
packages/e2e/next/src/app/app/(shared)/form/useQueryState/page.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,10 @@ | ||
import { TestFormUseQueryState } from 'e2e-shared/specs/form' | ||
import { Suspense } from 'react' | ||
|
||
export default function Page() { | ||
return ( | ||
<Suspense> | ||
<TestFormUseQueryState /> | ||
</Suspense> | ||
) | ||
} |
10 changes: 10 additions & 0 deletions
10
packages/e2e/next/src/app/app/(shared)/form/useQueryStates/page.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,10 @@ | ||
import { TestFormUseQueryStates } from 'e2e-shared/specs/form' | ||
import { Suspense } from 'react' | ||
|
||
export default function Page() { | ||
return ( | ||
<Suspense> | ||
<TestFormUseQueryStates /> | ||
</Suspense> | ||
) | ||
} |
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,3 @@ | ||
import { TestFormUseQueryState } from 'e2e-shared/specs/form' | ||
|
||
export default TestFormUseQueryState |
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,3 @@ | ||
import { TestFormUseQueryStates } from 'e2e-shared/specs/form' | ||
|
||
export default TestFormUseQueryStates |
11 changes: 11 additions & 0 deletions
11
packages/e2e/react-router/v6/cypress/e2e/shared/form.cy.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { testForm } from 'e2e-shared/specs/form.cy' | ||
|
||
testForm({ | ||
path: '/form/useQueryState', | ||
hook: 'useQueryState' | ||
}) | ||
|
||
testForm({ | ||
path: '/form/useQueryStates', | ||
hook: 'useQueryStates' | ||
}) |
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
3 changes: 3 additions & 0 deletions
3
packages/e2e/react-router/v6/src/routes/form.useQueryState.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,3 @@ | ||
import { TestFormUseQueryState } from 'e2e-shared/specs/form' | ||
|
||
export default TestFormUseQueryState |
3 changes: 3 additions & 0 deletions
3
packages/e2e/react-router/v6/src/routes/form.useQueryStates.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,3 @@ | ||
import { TestFormUseQueryStates } from 'e2e-shared/specs/form' | ||
|
||
export default TestFormUseQueryStates |
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
3 changes: 3 additions & 0 deletions
3
packages/e2e/react-router/v7/app/routes/form.useQueryState.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,3 @@ | ||
import { TestFormUseQueryState } from 'e2e-shared/specs/form' | ||
|
||
export default TestFormUseQueryState |
3 changes: 3 additions & 0 deletions
3
packages/e2e/react-router/v7/app/routes/form.useQueryStates.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,3 @@ | ||
import { TestFormUseQueryStates } from 'e2e-shared/specs/form' | ||
|
||
export default TestFormUseQueryStates |
11 changes: 11 additions & 0 deletions
11
packages/e2e/react-router/v7/cypress/e2e/shared/form.cy.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { testForm } from 'e2e-shared/specs/form.cy' | ||
|
||
testForm({ | ||
path: '/form/useQueryState', | ||
hook: 'useQueryState' | ||
}) | ||
|
||
testForm({ | ||
path: '/form/useQueryStates', | ||
hook: 'useQueryStates' | ||
}) |
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,11 @@ | ||
import { testForm } from 'e2e-shared/specs/form.cy' | ||
|
||
testForm({ | ||
path: '/form/useQueryState', | ||
hook: 'useQueryState' | ||
}) | ||
|
||
testForm({ | ||
path: '/form/useQueryStates', | ||
hook: 'useQueryStates' | ||
}) |
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,3 @@ | ||
import { TestFormUseQueryState } from 'e2e-shared/specs/form' | ||
|
||
export default TestFormUseQueryState |
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,3 @@ | ||
import { TestFormUseQueryStates } from 'e2e-shared/specs/form' | ||
|
||
export default TestFormUseQueryStates |
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,3 @@ | ||
import { TestFormUseQueryState } from 'e2e-shared/specs/form' | ||
|
||
export default TestFormUseQueryState |
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,3 @@ | ||
import { TestFormUseQueryStates } from 'e2e-shared/specs/form' | ||
|
||
export default TestFormUseQueryStates |
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,11 @@ | ||
import { testForm } from 'e2e-shared/specs/form.cy' | ||
|
||
testForm({ | ||
path: '/form/useQueryState', | ||
hook: 'useQueryState' | ||
}) | ||
|
||
testForm({ | ||
path: '/form/useQueryStates', | ||
hook: 'useQueryStates' | ||
}) |
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,25 @@ | ||
import { createTest } from '../create-test' | ||
|
||
export const testForm = createTest('Form', ({ path }) => { | ||
it('supports native HTML forms to update search params', () => { | ||
cy.visit(path) | ||
cy.contains('#hydration-marker', 'hydrated').should('be.hidden') | ||
cy.get('input').type('pass') | ||
cy.get('form').submit() | ||
cy.get('#state').should('have.text', 'pass') | ||
cy.go('back') | ||
cy.get('#state').should('have.text', '') | ||
}) | ||
|
||
it('supports loading initial form state from the URL', () => { | ||
cy.visit(path + '?test=init') | ||
cy.contains('#hydration-marker', 'hydrated').should('be.hidden') | ||
cy.get('input').should('have.value', 'init') | ||
cy.get('#state').should('have.text', 'init') | ||
cy.get('input').clear().type('pass') | ||
cy.get('form').submit() | ||
cy.get('#state').should('have.text', 'pass') | ||
cy.go('back') | ||
cy.get('#state').should('have.text', 'init') | ||
}) | ||
}) |
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,47 @@ | ||
'use client' | ||
|
||
import { parseAsString, useQueryState, useQueryStates } from 'nuqs' | ||
|
||
type FormProps = { | ||
defaultValue: string | ||
} | ||
|
||
const testParser = parseAsString.withDefault('') | ||
|
||
function Form({ defaultValue }: FormProps) { | ||
return ( | ||
<form> | ||
<input type="text" id="test" name="test" defaultValue={defaultValue} /> | ||
<button type="submit">Submit</button> | ||
</form> | ||
) | ||
} | ||
|
||
export function TestFormUseQueryState() { | ||
const [state] = useQueryState('test', testParser) | ||
return ( | ||
<> | ||
<pre id="state">{state}</pre> | ||
<Form defaultValue={state} /> | ||
</> | ||
) | ||
} | ||
|
||
export function TestFormUseQueryStates() { | ||
const [{ state }] = useQueryStates( | ||
{ | ||
state: testParser | ||
}, | ||
{ | ||
urlKeys: { | ||
state: 'test' | ||
} | ||
} | ||
) | ||
return ( | ||
<> | ||
<pre id="state">{state}</pre> | ||
<Form defaultValue={state} /> | ||
</> | ||
) | ||
} |