Skip to content

Commit

Permalink
create and delete task testing
Browse files Browse the repository at this point in the history
  • Loading branch information
dyooreen committed Jan 19, 2024
1 parent ce5f28c commit cdcea11
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function App() {
<CreateTask />
<TodoList />
</Container>
);
);
}

export default App;
3 changes: 2 additions & 1 deletion src/Components/CreateTask/CreateTask.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const CreateTask = () => {
onClick={addItem}
type="submit"
height="4.3rem"
name="add todo"
role="button"
name="createTask"
width="4.3rem"
>
<AddIcon />
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Task/Task.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AddIcon, CheckIcon, DeleteIcon, EditIcon } from "@chakra-ui/icons";
import { CheckIcon, DeleteIcon, EditIcon } from "@chakra-ui/icons";
import {
Button,
Card,
Expand Down Expand Up @@ -31,7 +31,7 @@ const Task: FC<Todo> = ({ id, text }) => {
>
<EditIcon boxSize={4} />
</Button>
<Button onClick={() => deleteTodo(id)}>
<Button data-testid="delete-element" onClick={() => deleteTodo(id)}>
<DeleteIcon color={"red"} boxSize={4} />
</Button>
</Flex>
Expand Down
25 changes: 23 additions & 2 deletions src/__test__/create_task.test.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
test("demo", () => {
expect(true).toBe(true);
import "@testing-library/jest-dom";

import { render, screen, fireEvent } from "@testing-library/react";
import { TodoProvider } from "../Context/TodoContext";
import App from "../App";

test("adds a new task to the list", () => {
render(
<TodoProvider>
<App />
</TodoProvider>
);

const inputElement = screen.getByPlaceholderText(/what need to do/i);

const addButton = screen.getByRole("button", { name: "" });

fireEvent.change(inputElement, { target: { value: "testTodo" } });

fireEvent.click(addButton);

const newTaskElement = screen.getByText("testTodo");
expect(newTaskElement).toBeInTheDocument();
});
25 changes: 25 additions & 0 deletions src/__test__/delete_task.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import "@testing-library/jest-dom";

import { fireEvent, render, screen } from "@testing-library/react";
import { TodoProvider } from "../Context/TodoContext";
import App from "../App";

test("delete a task from the list", async () => {
render(
<TodoProvider>
<App />
</TodoProvider>
);
const inputElement = screen.getByPlaceholderText(/what need to do/i);

const addButton = screen.getByRole("button", { name: "" });
fireEvent.change(inputElement, { target: { value: "testTodo" } });

fireEvent.click(addButton);
const deleteButton = screen.getByTestId("delete-element");

fireEvent.click(deleteButton);

const deletedTaskElement = screen.queryByText(/testTodo/i);
expect(deletedTaskElement).toBeNull();
});
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"compilerOptions": {
"types": ["@testing-library/jest-dom"],
"esModuleInterop":true,
"target": "ES2020",
"useDefineForClassFields": true,
Expand Down

0 comments on commit cdcea11

Please sign in to comment.