-
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.
created Task.test.js, 100% coverge for Task.js
- Loading branch information
Showing
18 changed files
with
25,588 additions
and
20,458 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = 'test-file-stub'; |
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 @@ | ||
module.exports = {}; |
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,7 @@ | ||
const path = require('path'); | ||
|
||
module.exports = { | ||
process(src, filename, config, options) { | ||
return 'module.exports = ' + JSON.stringify(path.basename(filename)) + ';'; | ||
}, | ||
}; |
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import React, { useState } from "react"; | ||
|
||
function Form(props) { | ||
const [person, setPerson] = useState({ | ||
name: "", | ||
job: "" | ||
}); | ||
|
||
return ( | ||
<form> | ||
<label htmlFor="name">Name</label> | ||
<input type="text" name="name" id="name" | ||
value={person.name} onChange={handleChange} | ||
/> | ||
<label htmlFor="job">Job</label> | ||
<input type="text" name="job" id="job" | ||
value={person.job} onChange={handleChange} | ||
/> | ||
<input type="button" value="Submit" | ||
onClick={submitForm} | ||
/> | ||
</form> | ||
); | ||
|
||
function handleChange(event) { | ||
const { name, value } = event.target; | ||
if (name === "job") | ||
setPerson({ | ||
name: person["name"], | ||
job: value | ||
}); | ||
else setPerson({ | ||
name: value, | ||
job: person["job"] }); | ||
} | ||
function submitForm() { | ||
props.handleSubmit(person); | ||
setPerson({ name: "", job: "" }); | ||
} | ||
} | ||
export default Form; |
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,44 @@ | ||
import { render, screen, fireEvent } from "@testing-library/react"; | ||
import '@testing-library/jest-dom' | ||
import React from "react"; | ||
import Form from "./Form"; | ||
|
||
|
||
|
||
test("renders the empty form correctly", () => { | ||
render(<Form />); | ||
expect(screen.getByLabelText("Name")).toBeInTheDocument(); | ||
expect(screen.getByLabelText("Job")).toBeInTheDocument(); | ||
expect(screen.getByText("Submit")).toBeInTheDocument(); | ||
}); | ||
|
||
const testUser = { name: "Ken Kubiak", job: "Educator" }; | ||
test("accepts name input", () => { | ||
render(<Form />); | ||
const input = screen.getByLabelText("Name"); | ||
fireEvent.change(input, { target: { value: testUser.name } }); | ||
expect(input).toHaveValue(testUser.name); | ||
}); | ||
|
||
test("accepts job input", () => { | ||
render(<Form />); | ||
const input = screen.getByLabelText("Job"); | ||
fireEvent.change(input, { target: { value: testUser.job } }); | ||
expect(input).toHaveValue(testUser.job); | ||
}); | ||
|
||
test("handles form submission", () => { | ||
let formData = {}; | ||
const mockUpdate = (data) => { | ||
formData = data; | ||
}; | ||
render(<Form handleSubmit={mockUpdate} />); | ||
let input = screen.getByLabelText("Name"); | ||
fireEvent.change(input, { target: { value: testUser.name } }); | ||
input = screen.getByLabelText("Job"); | ||
fireEvent.change(input, { target: { value: testUser.job } }); | ||
const button = screen.getByRole("button", { type: "submit" }); | ||
fireEvent.click(button); | ||
expect(formData).toHaveProperty("name", testUser.name); | ||
expect(formData).toHaveProperty("job", testUser.job); | ||
}); |
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
50 changes: 50 additions & 0 deletions
50
packages/studywell-frontend/src/components/taskbar/Task.test.js
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,50 @@ | ||
import { render, screen, fireEvent } from "@testing-library/react"; | ||
import '@testing-library/jest-dom' | ||
import React from "react"; | ||
import Task from "./Task"; | ||
|
||
test("renders the pomodoro counter correctly", () => { | ||
const {getAllByPlaceholderText } = render(<Task />); | ||
|
||
const pomInputs = getAllByPlaceholderText('# of pomodoros'); | ||
const pomInput = pomInputs[0]; | ||
expect(pomInput).toBeInTheDocument(); | ||
}); | ||
|
||
test('renders "type here..." initially with placeholder style', () => { | ||
const taskInput = document.querySelector('input[task="task"]'); | ||
Check failure on line 15 in packages/studywell-frontend/src/components/taskbar/Task.test.js GitHub Actions / build
|
||
|
||
expect(taskInput).toHaveStyle({ | ||
fontStyle: 'italic' | ||
}); | ||
}); | ||
|
||
|
||
test('handles task submission', () => { | ||
const testTask = { task: 'write essay', pomodoros: 2 }; // Define the test task data | ||
|
||
let formData = {}; | ||
const mockUpdate = (data) => { | ||
formData = data; | ||
}; | ||
|
||
render(<Task handleSubmit={mockUpdate} />); | ||
|
||
const taskInput = document.querySelector('input[task="task"]'); | ||
Check failure on line 33 in packages/studywell-frontend/src/components/taskbar/Task.test.js GitHub Actions / build
|
||
fireEvent.change(taskInput, { target: { value: testTask.task } }); | ||
fireEvent.click(taskInput); // simulate click | ||
|
||
const pomodorosInput = screen.getByPlaceholderText('# of pomodoros'); | ||
fireEvent.change(pomodorosInput, { target: { value: testTask.pomodoros } }); | ||
|
||
const submitButton = screen.getByRole('button', { name: '+' }); | ||
fireEvent.click(submitButton); | ||
|
||
expect(formData).toHaveProperty('task', testTask.task); | ||
expect(formData).toHaveProperty('pomodoros', Number(testTask.pomodoros)); | ||
|
||
// retrieve input value after click event | ||
const inputValueAfterClick = taskInput.value; | ||
|
||
expect(inputValueAfterClick).toBe(''); | ||
}); |
43 changes: 43 additions & 0 deletions
43
packages/studywell-frontend/src/components/taskbar/TaskCard.js
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, { useState } from "react"; | ||
|
||
function TaskCard(props) { | ||
const [task, setTask] = useState({ | ||
task: "", | ||
}); | ||
|
||
const [showModal, setShowModal] = useState(false); | ||
|
||
function submitTask() { | ||
props.handleSubmit(task); | ||
setTask({ task: "" }); | ||
} | ||
|
||
function handleChange(event) { | ||
const { value } = event.target; | ||
setTask({ task: value }); | ||
} | ||
|
||
function handleShowModal() { | ||
setShowModal((prev) => !prev); | ||
} | ||
|
||
return ( | ||
<div> | ||
<form> | ||
<input | ||
type="text" | ||
task="task" | ||
value={task.task} | ||
onChange={handleChange} | ||
/> | ||
<input | ||
type="button" | ||
class="submit_task" | ||
value="Submit" | ||
onClick={submitTask} | ||
/> | ||
</form> | ||
</div> | ||
); | ||
} | ||
export default TaskCard; |
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
40 changes: 0 additions & 40 deletions
40
packages/studywell-frontend/src/components/taskbar/TotalTask.test.js
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.