From 73e746e567d4baca87bf25808d89a342be1e14f1 Mon Sep 17 00:00:00 2001
From: Takashi Kato <tohosaku@users.osdn.me>
Date: Wed, 2 Aug 2023 22:44:11 +0000
Subject: [PATCH 2/2] Fix functional tests

---
 test/functional/calendars_controller_test.rb | 164 +++++++++----------
 test/functional/my_controller_test.rb        |  32 ++--
 2 files changed, 91 insertions(+), 105 deletions(-)

diff --git a/test/functional/calendars_controller_test.rb b/test/functional/calendars_controller_test.rb
index e5a4a6e94..a56831a38 100644
--- a/test/functional/calendars_controller_test.rb
+++ b/test/functional/calendars_controller_test.rb
@@ -65,19 +65,17 @@ class CalendarsControllerTest < Redmine::ControllerTest
     # Assert context menu on issues
     assert_select 'form[data-cm-url=?]', '/issues/context_menu'
 
-    assert_select 'table.cal' do
-      assert_select 'tr' do
-        assert_select 'td' do
-          assert_select(
-            'div.issue.hascontextmenu.tooltip.starting',
-            :text => /Add ingredients categories/
-          ) do
-            assert_select 'a.issue[href=?]', '/issues/2', :text => 'Feature request #2'
-            assert_select 'span.tip' do
-              assert_select 'img[class="gravatar"]'
-            end
-            assert_select 'input[name=?][type=?][value=?]', 'ids[]', 'checkbox', '2'
+    assert_select 'ul.cal' do
+      assert_select 'li' do
+        assert_select(
+          'div.issue.hascontextmenu.tooltip.starting',
+          :text => /Add ingredients categories/
+        ) do
+          assert_select 'a.issue[href=?]', '/issues/2', :text => 'Feature request #2'
+          assert_select 'span.tip' do
+            assert_select 'img[class="gravatar"]'
           end
+          assert_select 'input[name=?][type=?][value=?]', 'ids[]', 'checkbox', '2'
         end
       end
     end
@@ -89,16 +87,14 @@ class CalendarsControllerTest < Redmine::ControllerTest
     get(:show, :params => {:project_id => 1})
     assert_response :success
 
-    assert_select 'table.cal' do
-      assert_select 'tr' do
-        assert_select 'td' do
-          assert_select(
-            'div.issue.hascontextmenu.tooltip.ending',
-            :text => /Cannot print recipes/
-          ) do
-            assert_select 'a.issue[href=?]', '/issues/1', :text => 'Bug #1'
-            assert_select 'input[name=?][type=?][value=?]', 'ids[]', 'checkbox', '1'
-          end
+    assert_select 'ul.cal' do
+      assert_select 'li' do
+        assert_select(
+          'div.issue.hascontextmenu.tooltip.ending',
+          :text => /Cannot print recipes/
+        ) do
+          assert_select 'a.issue[href=?]', '/issues/1', :text => 'Bug #1'
+          assert_select 'input[name=?][type=?][value=?]', 'ids[]', 'checkbox', '1'
         end
       end
     end
@@ -120,24 +116,22 @@ class CalendarsControllerTest < Redmine::ControllerTest
     )
     assert_response :success
 
-    assert_select 'table.cal' do
-      assert_select 'tr' do
-        assert_select 'td' do
+    assert_select 'ul.cal' do
+      assert_select 'li' do
+        assert_select(
+          'div.issue.hascontextmenu.tooltip.starting.ending',
+          :text => /#{subject}/
+        ) do
           assert_select(
-            'div.issue.hascontextmenu.tooltip.starting.ending',
-            :text => /#{subject}/
-          ) do
-            assert_select(
-              'a.issue[href=?]', "/issues/#{issue.id}",
-              :text => "Bug ##{issue.id}"
-            )
-            assert_select(
-              'input[name=?][type=?][value=?]',
-              'ids[]',
-              'checkbox',
-              issue.id.to_s
-            )
-          end
+            'a.issue[href=?]', "/issues/#{issue.id}",
+            :text => "Bug ##{issue.id}"
+          )
+          assert_select(
+            'input[name=?][type=?][value=?]',
+            'ids[]',
+            'checkbox',
+            issue.id.to_s
+          )
         end
       end
     end
@@ -149,14 +143,12 @@ class CalendarsControllerTest < Redmine::ControllerTest
     get(:show, :params => {:project_id => 1})
     assert_response :success
 
-    assert_select 'table.cal' do
-      assert_select 'tr' do
-        assert_select 'td' do
-          assert_select(
-            'span.icon.icon-package'
-          ) do
-            assert_select 'a[href=?]', '/versions/2', :text => '1.0'
-          end
+    assert_select 'ul.cal' do
+      assert_select 'li' do
+        assert_select(
+          'span.icon.icon-package'
+        ) do
+          assert_select 'a[href=?]', '/versions/2', :text => '1.0'
         end
       end
     end
@@ -179,16 +171,14 @@ class CalendarsControllerTest < Redmine::ControllerTest
     get :show
     assert_response :success
 
-    assert_select 'table.cal' do
-      assert_select 'tr' do
-        assert_select 'td' do
-          assert_select(
-            'div.issue.hascontextmenu.tooltip.starting',
-            :text => /eCookbook.*Add ingredients categories/m
-          ) do
-            assert_select 'a.issue[href=?]', '/issues/2', :text => 'Feature request #2'
-            assert_select 'input[name=?][type=?][value=?]', 'ids[]', 'checkbox', '2'
-          end
+    assert_select 'ul.cal' do
+      assert_select 'li' do
+        assert_select(
+          'div.issue.hascontextmenu.tooltip.starting',
+          :text => /eCookbook.*Add ingredients categories/m
+        ) do
+          assert_select 'a.issue[href=?]', '/issues/2', :text => 'Feature request #2'
+          assert_select 'input[name=?][type=?][value=?]', 'ids[]', 'checkbox', '2'
         end
       end
     end
@@ -200,17 +190,15 @@ class CalendarsControllerTest < Redmine::ControllerTest
     get :show
     assert_response :success
 
-    assert_select 'table.cal' do
-      assert_select 'tr' do
-        assert_select 'td' do
+    assert_select 'ul.cal' do
+      assert_select 'li' do
+        assert_select(
+          'span.icon.icon-package'
+        ) do
           assert_select(
-            'span.icon.icon-package'
-          ) do
-            assert_select(
-              'a[href=?]', '/versions/2',
-              :text => 'eCookbook - 1.0'
-            )
-          end
+            'a[href=?]', '/versions/2',
+            :text => 'eCookbook - 1.0'
+          )
         end
       end
     end
@@ -228,16 +216,16 @@ class CalendarsControllerTest < Redmine::ControllerTest
       assert_response :success
     end
 
-    assert_select 'tr' do
-      assert_select 'td.week-number', :text => '53'
-      assert_select 'td.odd', :text => '27'
-      assert_select 'td.even', :text => '2'
+    assert_select 'ul' do
+      assert_select 'li.week-number:nth-of-type(2)', :text => /^53/
+      assert_select 'li.odd', :text => /^27/
+      assert_select 'li.even', :text => /^2/
     end
 
-    assert_select 'tr' do
-      assert_select 'td.week-number', :text => '1'
-      assert_select 'td.odd', :text => '3'
-      assert_select 'td.even', :text => '9'
+    assert_select 'ul' do
+      assert_select 'li.week-number', :text => /^1/
+      assert_select 'li.odd', :text => /^3/
+      assert_select 'li.even', :text => /^9/
     end
 
     with_settings :start_of_week => 1 do
@@ -251,16 +239,16 @@ class CalendarsControllerTest < Redmine::ControllerTest
       assert_response :success
     end
 
-    assert_select 'tr' do
-      assert_select 'td.week-number', :text => '53'
-      assert_select 'td.even', :text => '28'
-      assert_select 'td.even', :text => '3'
+    assert_select 'ul' do
+      assert_select 'li.week-number:nth-of-type(2)', :text => /^53/
+      assert_select 'li.even', :text => /^28/
+      assert_select 'li.even', :text => /^3/
     end
 
-    assert_select 'tr' do
-      assert_select 'td.week-number', :text => '1'
-      assert_select 'td.even', :text => '4'
-      assert_select 'td.even', :text => '10'
+    assert_select 'ul' do
+      assert_select 'li.week-number', :text => /^1/
+      assert_select 'li.even', :text => /^4/
+      assert_select 'li.even', :text => /^10/
     end
   end
 
@@ -296,12 +284,12 @@ class CalendarsControllerTest < Redmine::ControllerTest
     )
     assert_response :success
 
-    assert_select 'tr:nth-child(2)' do
-      assert_select 'td.week-number', :text => '49'
+    assert_select 'ul' do
+      assert_select 'li.week-number:nth-of-type(2)', :text => /^48/
       # non working days should have "nwday" CSS class
-      assert_select 'td.nwday', 2
-      assert_select 'td.nwday', :text => '4'
-      assert_select 'td.nwday', :text => '10'
+      assert_select 'li.nwday', 10
+      assert_select 'li.nwday', :text => /^4/
+      assert_select 'li.nwday', :text => /^10/
     end
   end
 end
diff --git a/test/functional/my_controller_test.rb b/test/functional/my_controller_test.rb
index c061f67ab..cb3014fda 100644
--- a/test/functional/my_controller_test.rb
+++ b/test/functional/my_controller_test.rb
@@ -444,24 +444,22 @@ class MyControllerTest < Redmine::ControllerTest
 
     assert_select 'form[data-cm-url=?]', '/issues/context_menu'
 
-    assert_select 'table.cal' do
-      assert_select 'tr' do
-        assert_select 'td' do
+    assert_select 'ul.cal' do
+      assert_select 'li' do
+        assert_select(
+          'div.issue.hascontextmenu.tooltip.starting.ending',
+          :text => /eCookbook.*#{subject}/m
+        ) do
+          assert_select(
+            'a.issue[href=?]', "/issues/#{issue.id}",
+            :text => "Bug ##{issue.id}"
+          )
           assert_select(
-            'div.issue.hascontextmenu.tooltip.starting.ending',
-            :text => /eCookbook.*#{subject}/m
-          ) do
-            assert_select(
-              'a.issue[href=?]', "/issues/#{issue.id}",
-              :text => "Bug ##{issue.id}"
-            )
-            assert_select(
-              'input[name=?][type=?][value=?]',
-              'ids[]',
-              'checkbox',
-              issue.id.to_s
-            )
-          end
+            'input[name=?][type=?][value=?]',
+            'ids[]',
+            'checkbox',
+            issue.id.to_s
+          )
         end
       end
     end
-- 
2.39.2

