From 6d49bc6ebbe1ca3ae9b416e3b01fa80eb448cbd2 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Thu, 12 Sep 2024 19:09:47 +0100 Subject: [PATCH 1/1] Make select all checkbox on users list work with turbo --- .rubocop_todo.yml | 1 + app/assets/javascripts/user.js | 10 ++++++---- test/system/users_test.rb | 28 ++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 test/system/users_test.rb diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index dc1092360..7384a8d95 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -26,6 +26,7 @@ FactoryBot/ExcessiveCreateList: - 'test/controllers/notes_controller_test.rb' - 'test/controllers/traces_controller_test.rb' - 'test/controllers/user_blocks_controller_test.rb' + - 'test/system/users_test.rb' # Offense count: 635 # This cop supports safe autocorrection (--autocorrect). diff --git a/app/assets/javascripts/user.js b/app/assets/javascripts/user.js index 495470f2f..681ec3ace 100644 --- a/app/assets/javascripts/user.js +++ b/app/assets/javascripts/user.js @@ -1,5 +1,11 @@ //= require leaflet.locatecontrol/src/L.Control.Locate +(function () { + $(document).on("change", "#user_all", function () { + $("#user_list input[type=checkbox]").prop("checked", $("#user_all").prop("checked")); + }); +}()); + $(document).ready(function () { var defaultHomeZoom = 12; var map, marker, deleted_lat, deleted_lon; @@ -200,10 +206,6 @@ $(document).ready(function () { enableAuth(); } - $("#user_all").change(function () { - $("#user_list input[type=checkbox]").prop("checked", $("#user_all").prop("checked")); - }); - $("#content.user_confirm").each(function () { $(this).hide(); $(this).find("#confirm").submit(); diff --git a/test/system/users_test.rb b/test/system/users_test.rb new file mode 100644 index 000000000..5d5bf56d7 --- /dev/null +++ b/test/system/users_test.rb @@ -0,0 +1,28 @@ +require "application_system_test_case" + +class UsersTest < ApplicationSystemTestCase + def setup + admin = create(:administrator_user) + sign_in_as(admin) + end + + test "all users can be selected" do + create_list(:user, 100) + + visit users_path + + assert_css "tbody input[type=checkbox]:checked", :count => 0 + assert_css "tbody input[type=checkbox]:not(:checked)", :count => 50 + check "user_all" + assert_css "tbody input[type=checkbox]:checked", :count => 50 + assert_css "tbody input[type=checkbox]:not(:checked)", :count => 0 + + click_on "Older Users", :match => :first + + assert_css "tbody input[type=checkbox]:checked", :count => 0 + assert_css "tbody input[type=checkbox]:not(:checked)", :count => 50 + check "user_all" + assert_css "tbody input[type=checkbox]:checked", :count => 50 + assert_css "tbody input[type=checkbox]:not(:checked)", :count => 0 + end +end -- 2.39.5