From 910607eb1d6c9a593c9577ad6eb0e074a9b762d8 Mon Sep 17 00:00:00 2001 From: jonniebigodes Date: Fri, 3 Nov 2023 13:04:26 +0000 Subject: [PATCH] Added the ability to delete a task --- src/InboxScreen.jsx | 4 ++++ src/InboxScreen.stories.jsx | 19 +++++++++++++++++++ src/components/Task.jsx | 11 ++++++++++- src/components/Task.stories.jsx | 1 + src/components/TaskList.jsx | 3 +++ 5 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/InboxScreen.jsx b/src/InboxScreen.jsx index 19726d4..8cf1b0f 100644 --- a/src/InboxScreen.jsx +++ b/src/InboxScreen.jsx @@ -8,6 +8,9 @@ export default function InboxScreen({ error }) { const archiveTask = (archive, id) => { dispatch({ type: archive ? "ARCHIVE_TASK" : "INBOX_TASK", id }); }; + const deleteTask = (id) => { + dispatch({ type: "DELETE_TASK", id }); + }; const togglePinTask = (state, id) => { dispatch({ @@ -41,6 +44,7 @@ export default function InboxScreen({ error }) { onArchiveTask={archiveTask} onTogglePinTask={togglePinTask} onEditTitle={editTitle} + onDeleteTask={deleteTask} /> ); diff --git a/src/InboxScreen.stories.jsx b/src/InboxScreen.stories.jsx index a86d46a..2c04962 100644 --- a/src/InboxScreen.stories.jsx +++ b/src/InboxScreen.stories.jsx @@ -92,3 +92,22 @@ export const EditTask = { ); }, }; + +export const DeleteTask = { + parameters: { + ...Default.parameters, + }, + play: async ({ canvasElement }) => { + const canvas = within(canvasElement); + const getTask = (id) => canvas.findByRole("listitem", { name: id }); + + const itemToDelete = await getTask("task-1"); + const deleteButton = await findByRole(itemToDelete, "button", { + name: "delete", + }); + + // Click the pin button + await userEvent.click(deleteButton); + await expect(canvas.getAllByRole("listitem").length).toBe(5); + }, +}; diff --git a/src/components/Task.jsx b/src/components/Task.jsx index 0391018..461411a 100644 --- a/src/components/Task.jsx +++ b/src/components/Task.jsx @@ -4,6 +4,7 @@ export default function Task({ onArchiveTask, onTogglePinTask, onEditTitle, + onDeleteTask, }) { return (
onEditTitle(e.target.value, id)} /> - + {state !== "TASK_ARCHIVED" && (