Skip to content

Commit

Permalink
step3 - creates the SimpleForm component
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Junior committed Mar 19, 2020
1 parent 8d99afa commit ae58797
Show file tree
Hide file tree
Showing 5 changed files with 336 additions and 218 deletions.
14 changes: 12 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@
"name": "react",
"version": "1.0.0",
"description": "React example starter project",
"keywords": ["react", "starter"],
"keywords": [
"react",
"starter"
],
"main": "src/index.js",
"dependencies": {
"react": "16.12.0",
"react-dom": "16.12.0",
"react-scripts": "3.0.1"
},
"devDependencies": {
"@testing-library/jest-dom": "5.1.1",
"@testing-library/react": "10.0.1",
"typescript": "3.3.3"
},
"scripts": {
Expand All @@ -18,5 +23,10 @@
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"browserslist": [">0.2%", "not dead", "not ie <= 11", "not op_mini all"]
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
17 changes: 7 additions & 10 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import React from "react";
import "./styles.css";
import React from 'react';
import './styles.css';

export default function App() {
return (
<div className="App">
<h1>Hello CodeSandbox</h1>
<h2>Start editing to see some magic happen!</h2>
</div>
);
}
import SimpleForm from './components/SimpleForm';

const App = () => <SimpleForm />;

export default App;
24 changes: 24 additions & 0 deletions src/components/SimpleForm.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React, { useState } from 'react';

const SimpleForm = () => {
const [name, setName] = useState('');

const handleSubmit = e => e.preventDefault();

return (
<form onSubmit={handleSubmit}>
<div>
<label htmlFor="name">name</label>
<input
type="text"
name="name"
id="name"
value={name}
onChange={e => setName(e.target.value)}
/>
</div>
</form>
);
};

export default SimpleForm;
15 changes: 15 additions & 0 deletions src/components/SimpleForm.spec.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';
import { render } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';

import SimpleForm from './SimpleForm';

describe('<SimpleForm />', () => {
it('should render a name input', () => {
const { getByLabelText } = render(<SimpleForm />);

const nameInput = getByLabelText('name');

expect(nameInput).toBeInTheDocument();
});
});
Loading

0 comments on commit ae58797

Please sign in to comment.