From 165b7d0fedb8decfe6c514b3156680dfc2ee7ee3 Mon Sep 17 00:00:00 2001 From: ishikawa999 <14245262+ishikawa999@users.noreply.github.com> Date: Tue, 14 Apr 2026 08:59:17 +0900 Subject: [PATCH 2/4] Add system test --- test/system/sticky_table_header_test.rb | 106 ++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 test/system/sticky_table_header_test.rb diff --git a/test/system/sticky_table_header_test.rb b/test/system/sticky_table_header_test.rb new file mode 100644 index 000000000..629dfafa4 --- /dev/null +++ b/test/system/sticky_table_header_test.rb @@ -0,0 +1,106 @@ +# frozen_string_literal: true + +# Redmine - project management software +# Copyright (C) 2006- Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +require_relative '../application_system_test_case' + +class StickyTableHeaderSystemTest < ApplicationSystemTestCase + def test_sticky_table_header_is_hidden_by_default + log_user('jsmith', 'jsmith') + page.current_window.resize_to(1600, 1200) + visit '/issues' + assert page.has_no_css?('table.list.sticky thead', visible: true) + end + + def test_sticky_table_header_appears_on_scroll + log_user('jsmith', 'jsmith') + page.current_window.resize_to(1600, 500) + + visit '/issues' + + scroll_issue_list_header_out_of_view + + assert page.has_css?('table.list.sticky thead', visible: true) + end + + def test_sticky_table_header_tracks_window_resize + log_user('jsmith', 'jsmith') + page.current_window.resize_to(1600, 500) + + visit '/issues' + scroll_issue_list_header_out_of_view + + initial_width = sticky_table_head_width + + page.current_window.resize_to(1300, 500) + + assert page.has_css?('table.list.sticky thead', visible: true) + assert_not_equal initial_width, sticky_table_head_width + assert_equal issue_table_head_width.round, sticky_table_head_width.round + end + + def test_sticky_table_header_is_hidden_when_issue_list_overflows_horizontally + log_user('jsmith', 'jsmith') + page.current_window.resize_to(700, 500) + + visit '/issues' + scroll_issue_list_header_out_of_view + + assert horizontal_overflow? + assert page.has_no_css?('table.list.sticky thead', visible: true) + end + + private + + def scroll_issue_list_header_out_of_view + page.execute_script(<<~JS) + (function() { + const head = document.querySelector('table.list.issues thead'); + const rect = head.getBoundingClientRect(); + window.scrollTo(0, window.scrollY + rect.top + rect.height + 20); + })(); + JS + end + + def sticky_table_head_width + page.evaluate_script(<<~JS) + (function() { + const stickyHead = document.querySelector('table.list.sticky thead'); + return stickyHead.getBoundingClientRect().width; + })(); + JS + end + + def issue_table_head_width + page.evaluate_script(<<~JS) + (function() { + const head = document.querySelector('table.list.issues thead'); + return head.getBoundingClientRect().width; + })(); + JS + end + + def horizontal_overflow? + page.evaluate_script(<<~JS) + (function() { + const autoscroll = document.querySelector('.autoscroll'); + return autoscroll.scrollWidth > autoscroll.clientWidth; + })(); + JS + end +end -- 2.50.1 (Apple Git-155)