From 4dcb191c676db6aafffc169711c8d52a01915533 Mon Sep 17 00:00:00 2001 From: Junichi Ito Date: Wed, 20 Nov 2024 20:40:36 +0900 Subject: [PATCH 1/2] Add system test --- test/system/tasks_test.rb | 46 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 test/system/tasks_test.rb diff --git a/test/system/tasks_test.rb b/test/system/tasks_test.rb new file mode 100644 index 0000000..235addc --- /dev/null +++ b/test/system/tasks_test.rb @@ -0,0 +1,46 @@ +require "application_system_test_case" + +class TasksTest < ApplicationSystemTestCase + test "CRUD tasks" do + visit tasks_url + + assert_selector "h1", text: "Tasks" + + fill_in "Title", with: "ミルクを買う" + click_on "Create Task" + assert_text "Task was successfully created." + within '#tasks' do + assert_text "ミルクを買う" + end + assert_field "Title", with: "" + assert_text "Remains: 1 / Total: 1" + + fill_in "Title", with: "ネギを買う" + click_on "Create Task" + assert_text "Task was successfully created." + within '#tasks' do + assert_text "ネギを買う" + end + assert_field "Title", with: "" + assert_text "Remains: 2 / Total: 2" + + rows = all('#tasks tbody tr') + assert_equal 2, rows.size + within rows[0] do + assert_text "ミルクを買う" + assert_text "not yet" + click_on "DONE" + assert_text "done" + end + assert_text "Task was successfully updated." + assert_text "Remains: 1 / Total: 2" + + within rows[1] do + assert_text "ネギを買う" + click_on "DELETE" + end + assert_text "Task was successfully deleted." + refute_text "ネギを買う" + assert_text "Remains: 0 / Total: 1" + end +end From 6e742e4025c5b1767179e55d00c25b79e1bdd86b Mon Sep 17 00:00:00 2001 From: Junichi Ito Date: Wed, 20 Nov 2024 20:46:19 +0900 Subject: [PATCH 2/2] Fix for RuboCop --- test/system/tasks_test.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/system/tasks_test.rb b/test/system/tasks_test.rb index 235addc..b260580 100644 --- a/test/system/tasks_test.rb +++ b/test/system/tasks_test.rb @@ -9,7 +9,7 @@ class TasksTest < ApplicationSystemTestCase fill_in "Title", with: "ミルクを買う" click_on "Create Task" assert_text "Task was successfully created." - within '#tasks' do + within "#tasks" do assert_text "ミルクを買う" end assert_field "Title", with: "" @@ -18,13 +18,13 @@ class TasksTest < ApplicationSystemTestCase fill_in "Title", with: "ネギを買う" click_on "Create Task" assert_text "Task was successfully created." - within '#tasks' do + within "#tasks" do assert_text "ネギを買う" end - assert_field "Title", with: "" + assert_field "Title", with: "" assert_text "Remains: 2 / Total: 2" - rows = all('#tasks tbody tr') + rows = all("#tasks tbody tr") assert_equal 2, rows.size within rows[0] do assert_text "ミルクを買う"