This project is used in a presentation to show how we can use test-driven development to build user interfaces. It's not as hard as you may think!
yarn install
yarn start
build
: Builds the production appeject
: Ejects fromreact-scripts
format
: Formats the code using Prettierformat:watch
: Formats the code using Prettier in watch modestart
: Starts the app for running locally in development modetest
: Runs the unit tests with Jest and React Testing Library in watch modetest:coverage
: Runs the unit tests and generates a coverage report
Your task is to create a form that allows interested users to request a demo of our product. See the mocks for how this should look.
The basic requirements are:
- The form displays three inputs for first name, last name, and email address
- The form displays a submit button
- If any of the form inputs are left blank or filled out incorrectly, an error message should display
- When the form is successfully submitted, the form should disappear and be replaced with a confirmation message
Error messages appear on form submission if fields are left blank:
Confirmation text is shown after the form is successfully submitted:
- Create a
RequestForm.test.js
file - Write a test that renders the form (fails)
- Create a
RequestForm.js
file and have the component render an emptyform
element (passes) - Write a test that looks for a first name input (fails)
- Render a first name input and label (passes)
- Write a test that looks for a last name input (fails)
- Render a last name input and label (passes)
- Refactor your code to render the form inputs in a column (note that the tests continue to pass during our refactor!)
- Write a test that looks for the email address input (fails)
- Render an email input and label (passes)
- Refactor your code to line up the form inputs in nice columns (note that the tests continue to pass during our refactor!)
- Write a test that looks for a submit button (fails)
- Render a submit button (passes)
- Refactor your code to center the form on the page and place it in a bordered box (note that the tests continue to pass during our refactor!)
- Write a test that verifies error messages are shown if the user attempts to submit a blank form
- Change the
RequestForm
to use controlled components and state. WriteonChange
andonSubmit
methods to handle updating the form values and showing error messages when any of the form fields are empty and the form is submitted (passes) - Refactor the code to show the error messages in red and keep the form a consistent height (note that the tests continue to pass during our refactor!)
- Write a test that verifies the form can be successfully submitted (fails)
- Update the code to render the confirmation text when the form is submitted (passes)