-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
2,152 additions
and
858 deletions.
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
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 @@ | ||
module.exports = { | ||
testEnvironment: 'jsdom', | ||
moduleFileExtensions: ['js', 'jsx', 'json', 'node'], | ||
transform: { | ||
'^.+\\.(js|jsx)?$': 'babel-jest', | ||
}, | ||
moduleNameMapper: { | ||
'\\.(css|less|scss|sass)$': 'identity-obj-proxy', | ||
}, | ||
setupFilesAfterEnv: ['@testing-library/jest-dom/extend-expect'], | ||
}; |
Large diffs are not rendered by default.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,8 +1,28 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import App from './App'; | ||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
import React from 'react'; | ||
import TodoList from './features/todos/TodoList'; | ||
|
||
test('renders learn react link', () => { | ||
render(<App />); | ||
const linkElement = screen.getByText(/learn react/i); | ||
expect(linkElement).toBeInTheDocument(); | ||
test('renders todo list', () => { | ||
render(<TodoList />); | ||
|
||
render(<TodoList />); | ||
|
||
const headingElement = screen.getAllByRole('heading', { name: /todo list/i })[0]; | ||
expect(headingElement).toBeInTheDocument(); | ||
|
||
const inputElement = screen.getByLabelText(/Add to list/i); | ||
expect(inputElement).toBeInTheDocument(); | ||
|
||
// eslint-disable-next-line testing-library/no-node-access | ||
const submitButton = document.getElementsByClassName('submit')[0]; | ||
expect(submitButton).toBeInTheDocument(); | ||
}); | ||
|
||
|
||
test('allows user to type in a new todo', () => { | ||
render(<TodoList />); | ||
|
||
const inputElement = screen.getByLabelText(/Add to list/i); | ||
fireEvent.change(inputElement, { target: { value: 'New Todo Item' } }); | ||
expect(inputElement.value).toBe('New Todo Item'); | ||
}); |
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,43 @@ | ||
import React from 'react' | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' | ||
import { faTrash, faUpload } from '@fortawesome/free-solid-svg-icons' | ||
import { useState } from 'react' | ||
|
||
const TodoList = () => { | ||
const [ newTodo, setNewTodo ] = useState('') | ||
|
||
const handleSubmit = (e)=> { | ||
e.preventDefault() | ||
//addTodo | ||
setNewTodo('') | ||
} | ||
|
||
const newItemSection = | ||
<form onSubmit={handleSubmit}> | ||
<label htmlFor="new-todo">Add to list</label> | ||
<div className="new-todo"> | ||
<input | ||
type="text" | ||
id="new-todo" | ||
value={newTodo} | ||
onChange={(e)=> setNewTodo(e.target.value)} | ||
placeholder="Add New Todo" | ||
/> | ||
</div> | ||
<button className="submit"> | ||
<FontAwesomeIcon icon={faUpload} /> | ||
</button> | ||
</form> | ||
|
||
let content; | ||
|
||
return ( | ||
<main> | ||
<h1>Todo List</h1> | ||
{newItemSection} | ||
{content} | ||
</main> | ||
) | ||
} | ||
|
||
export default TodoList |
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