Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
kentcdodds committed Aug 21, 2024
1 parent 4844ec0 commit 5e0ffcc
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 5 deletions.
10 changes: 7 additions & 3 deletions exercises/03.forms/01.solution.form/form.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ const { screen } = dtl

import './index.tsx'

await testStep('Form is rendered', () =>
dtl.waitFor(() => document.querySelector('form')),
)
await testStep('Form is rendered', () => {
return dtl.waitFor(() => {
const form = document.querySelector('form')
expect(form).toBeInTheDocument()
return form
})
})

await testStep('Username input is rendered', async () => {
const usernameInput = await screen.findByLabelText(/username/i)
Expand Down
13 changes: 13 additions & 0 deletions exercises/03.forms/02.solution.action/action.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { expect, testStep, dtl } from '@epic-web/workshop-utils/test'

import './index.tsx'

const form = await dtl.waitFor(() => {
const form = document.querySelector('form')
expect(form).toBeInTheDocument()
return form
})

await testStep('Form has correct action', async () => {
expect(form).toHaveAttribute('action', 'api/onboarding')
})
21 changes: 21 additions & 0 deletions exercises/03.forms/02.solution.action/form.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { expect, testStep, dtl } from '@epic-web/workshop-utils/test'
const { screen } = dtl

import './index.tsx'

await testStep('Form is rendered', () => {
return dtl.waitFor(() => {
const form = document.querySelector('form')
expect(form).toBeInTheDocument()
return form
})
})

await testStep('Username input is rendered', async () => {
const usernameInput = await screen.findByLabelText(/username/i)
expect(usernameInput).toHaveAttribute('name', 'username')
})

await testStep('Submit button is rendered', () =>
screen.findByRole('button', { name: /submit/i }),
)
4 changes: 2 additions & 2 deletions exercises/03.forms/02.solution.action/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { createRoot } from 'react-dom/client'

function App() {
return (
<form action="api/onboarding">
<div>
<div>
<label htmlFor="usernameInput">Username:</label>
<input id="usernameInput" name="username" />
</div>
<button type="submit">Submit</button>
</form>
</div>
)
}

Expand Down
15 changes: 15 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"devDependencies": {
"@epic-web/config": "^1.5.3",
"@epic-web/workshop-utils": "^4.19.1",
"@testing-library/user-event": "^14.5.2",
"@types/react": "npm:types-react@19.0.0-alpha.5",
"@types/react-dom": "npm:types-react-dom@19.0.0-alpha.5",
"eslint": "^9.1.1",
Expand Down

0 comments on commit 5e0ffcc

Please sign in to comment.