|
1 |
# frozen_string_literal: true
|
|
2 |
|
|
3 |
# Redmine - project management software
|
|
4 |
# Copyright (C) 2006- Jean-Philippe Lang
|
|
5 |
#
|
|
6 |
# This program is free software; you can redistribute it and/or
|
|
7 |
# modify it under the terms of the GNU General Public License
|
|
8 |
# as published by the Free Software Foundation; either version 2
|
|
9 |
# of the License, or (at your option) any later version.
|
|
10 |
#
|
|
11 |
# This program is distributed in the hope that it will be useful,
|
|
12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 |
# GNU General Public License for more details.
|
|
15 |
#
|
|
16 |
# You should have received a copy of the GNU General Public License
|
|
17 |
# along with this program; if not, write to the Free Software
|
|
18 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
19 |
|
|
20 |
require_relative '../application_system_test_case'
|
|
21 |
|
|
22 |
class StickyTableHeaderSystemTest < ApplicationSystemTestCase
|
|
23 |
def test_sticky_table_header_is_hidden_by_default
|
|
24 |
log_user('jsmith', 'jsmith')
|
|
25 |
page.current_window.resize_to(1600, 1200)
|
|
26 |
visit '/issues'
|
|
27 |
assert page.has_no_css?('table.list.sticky thead', visible: true)
|
|
28 |
end
|
|
29 |
|
|
30 |
def test_sticky_table_header_appears_on_scroll
|
|
31 |
log_user('jsmith', 'jsmith')
|
|
32 |
page.current_window.resize_to(1600, 500)
|
|
33 |
|
|
34 |
visit '/issues'
|
|
35 |
|
|
36 |
scroll_issue_list_header_out_of_view
|
|
37 |
|
|
38 |
assert page.has_css?('table.list.sticky thead', visible: true)
|
|
39 |
end
|
|
40 |
|
|
41 |
def test_sticky_table_header_tracks_window_resize
|
|
42 |
log_user('jsmith', 'jsmith')
|
|
43 |
page.current_window.resize_to(1600, 500)
|
|
44 |
|
|
45 |
visit '/issues'
|
|
46 |
scroll_issue_list_header_out_of_view
|
|
47 |
|
|
48 |
initial_width = sticky_table_head_width
|
|
49 |
|
|
50 |
page.current_window.resize_to(1300, 500)
|
|
51 |
|
|
52 |
assert page.has_css?('table.list.sticky thead', visible: true)
|
|
53 |
assert_not_equal initial_width, sticky_table_head_width
|
|
54 |
assert_equal issue_table_head_width.round, sticky_table_head_width.round
|
|
55 |
end
|
|
56 |
|
|
57 |
def test_sticky_table_header_is_hidden_when_issue_list_overflows_horizontally
|
|
58 |
log_user('jsmith', 'jsmith')
|
|
59 |
page.current_window.resize_to(700, 500)
|
|
60 |
|
|
61 |
visit '/issues'
|
|
62 |
scroll_issue_list_header_out_of_view
|
|
63 |
|
|
64 |
assert horizontal_overflow?
|
|
65 |
assert page.has_no_css?('table.list.sticky thead', visible: true)
|
|
66 |
end
|
|
67 |
|
|
68 |
private
|
|
69 |
|
|
70 |
def scroll_issue_list_header_out_of_view
|
|
71 |
page.execute_script(<<~JS)
|
|
72 |
(function() {
|
|
73 |
const head = document.querySelector('table.list.issues thead');
|
|
74 |
const rect = head.getBoundingClientRect();
|
|
75 |
window.scrollTo(0, window.scrollY + rect.top + rect.height + 20);
|
|
76 |
})();
|
|
77 |
JS
|
|
78 |
end
|
|
79 |
|
|
80 |
def sticky_table_head_width
|
|
81 |
page.evaluate_script(<<~JS)
|
|
82 |
(function() {
|
|
83 |
const stickyHead = document.querySelector('table.list.sticky thead');
|
|
84 |
return stickyHead.getBoundingClientRect().width;
|
|
85 |
})();
|
|
86 |
JS
|
|
87 |
end
|
|
88 |
|
|
89 |
def issue_table_head_width
|
|
90 |
page.evaluate_script(<<~JS)
|
|
91 |
(function() {
|
|
92 |
const head = document.querySelector('table.list.issues thead');
|
|
93 |
return head.getBoundingClientRect().width;
|
|
94 |
})();
|
|
95 |
JS
|
|
96 |
end
|
|
97 |
|
|
98 |
def horizontal_overflow?
|
|
99 |
page.evaluate_script(<<~JS)
|
|
100 |
(function() {
|
|
101 |
const autoscroll = document.querySelector('.autoscroll');
|
|
102 |
return autoscroll.scrollWidth > autoscroll.clientWidth;
|
|
103 |
})();
|
|
104 |
JS
|
|
105 |
end
|
|
106 |
end
|