In this episode, we're diving into adding edit functionality for our tasks. We kick things off by updating our task item component to include an "Edit" button. When you click this button, it toggles the state to show an input field instead of just the task text, allowing you to modify the task title.
We set up a reactive state (editing
) to track whether we're editing or not. When the user clicks "Edit", we switch on an input form pre-filled with the current task title, using a model bound to a form object. There are some little hiccups around making sure the value is actually displayed in the input, but we sort those out along the way.
Once that's set up visually, we turn our attention to writing a test for this feature. We use Laravel Dusk to automate a browser test: log in as a user, visit the task list, create a sample task, and simulate clicking the "Edit" button for a task. The key thing we're learning here is, when testing for input values, you can't use the regular assertSee
method—you have to use assertValue
because the input's value isn't plain text on the page, it's tucked inside the element's value property.
By the end of this episode, you've got a task list where you can switch into edit mode for a task and verify via testing that the correct value is in the input. Up next, we'll look at updating the task title after editing and making sure those changes stick!