Exercise 1: A Real End-to-End UI Test for Adding a Task — Possible Solution ================================================================================== // In NewTaskView's toolbar: .toolbar { Button("Save") { // existing save() call save() } .accessibilityIdentifier("saveButton") } // Also assumed already present, per Chapter 7's own established pattern: // TextField("Title", text: $title).accessibilityIdentifier("newTaskTitleField") // Button("Add") { isShowingNewTask = true }.accessibilityIdentifier("addTaskButton") // The UI test: func testAddingATaskShowsItInTheList() { let app = XCUIApplication() app.launch() app.buttons["addTaskButton"].tap() app.textFields["newTaskTitleField"].typeText("Call the dentist") app.buttons["saveButton"].tap() XCTAssertTrue(app.staticTexts["Call the dentist"].exists) } HOW IT WORKS: The real .accessibilityIdentifier("saveButton") modifier is added to NewTaskView's own Save button, giving the test a real, stable way to find and tap it - exactly following the identical pattern already used for "addTaskButton" earlier in this course. The test itself launches a real, fresh instance of the app, taps "Add" to open NewTaskView as a modal sheet (Fundamentals Chapter 8's own real navigation mechanism), types a real title into the identified text field, and taps "Save." Because save() (the capstone's own real method) both inserts the new Task into the shared SwiftData ModelContext and dismisses the sheet, tapping "saveButton" triggers the full real chain: a new Task is persisted, TaskListView's own @Query automatically picks up the change (Chapter 4's own real live-update behavior), and the sheet closes, revealing the updated list underneath - all real, observable through one single real assertion checking that "Call the dentist" now appears somewhere in the app's own real UI. ANSWER: Adding a real .accessibilityIdentifier("saveButton") to NewTaskView's own Save button, then writing a UI test that taps "addTaskButton," types into "newTaskTitleField," taps "saveButton," and asserts the new task's title appears via app.staticTexts["Call the dentist"].exists correctly verifies the entire real add-task flow end to end, exactly as the chapter's own established XCUITest pattern demonstrates. WHY THIS WORKS AS AN ANSWER ------------------------------ This correctly adds the missing real accessibility identifier and writes a genuine end-to-end UI test exercising the capstone's own real add-task flow, confirming the SwiftData-backed list actually updates as a result.