Prevent table columns' width change on form toggle

This commit is contained in:
2026-11-05 18:00:34 +01:00
parent 4940e6de86
commit 3655a74b94
23 changed files with 150 additions and 90 deletions
+14 -7
View File
@@ -76,7 +76,7 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
# Override to count only data rows, to make it consistent with #match_row.
def match_row_count(size)
XPath.descendant(:tr).where(XPath.descendant(:td)).count.equals(size)
XPath.descendant(:tbody).descendant(:tr)[XPath.descendant(:td)].count.equals(size)
end
end
@@ -92,15 +92,22 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
# Based on Capybara :table and :table_row selectors.
Capybara.add_selector(:table_cell, locator_type: [String, Symbol]) do
xpath do |locator|
# TODO: make sure to only include visible column headers
column = XPath.string.n.is(locator.to_s)
header_xp = XPath.ancestor(:table)[1].descendant(:tr)[1].descendant(:th)[column]
position_xp = XPath.position.equals(header_xp.preceding_sibling.count.plus(1))
XPath.descendant(:td).where(header_xp.boolean & position_xp)
xpath = XPath.descendant(:td)
case locator
when String, Symbol
# TODO: make sure to only include visible column headers
column = XPath.string.n.is(locator.to_s)
header_xp = XPath.ancestor(:table)[1].descendant(:tr)[1].descendant(:th)[column]
position_xp = XPath.position.equals(header_xp.preceding_sibling.count.plus(1))
xpath.where(header_xp.boolean & position_xp)
else
xpath
end
end
expression_filter(:fillable) do |xpath, value|
value ? xpath.where(XPath.descendant(:input, :select, :textarea)) : xpath
value ? xpath[XPath.descendant(:input, :select, :textarea)
.where(!XPath.attr(:type).one_of('submit', 'hidden'))] : xpath
end
node_filter(:value) do |node, expected|
+18 -4
View File
@@ -79,7 +79,7 @@ class UnitsTest < ApplicationSystemTestCase
[name, value]
end
click_on t('helpers.submit.create')
click_on t(:save)
end
attributes = attributes.to_h
@@ -152,7 +152,7 @@ class UnitsTest < ApplicationSystemTestCase
click_on t('units.index.new_unit')
end
find(:table_cell, column(:symbol), fillable: true).fill_in with: unit.symbol
click_on t('helpers.submit.create')
click_on t(:save)
within :table_row, index+1 do
assert_selector :table_cell, column(:symbol), exact_text: symbol
@@ -190,7 +190,7 @@ class UnitsTest < ApplicationSystemTestCase
else
assert_matches_selector link, :link, disabled: true
end
click_on t(:cancel)
click_on t(:discard)
assert_no_selector '.flash.alert'
# TODO: change to assert_selector :table, rows: ...
@@ -258,13 +258,27 @@ class UnitsTest < ApplicationSystemTestCase
sign_in
click_on t('units.index.new_unit')
within 'tbody' do
find(:link_or_button, exact_text: t(:cancel)).click
find(:link_or_button, exact_text: t(:discard)).click
assert_no_selector :fillable_field
end
click_on t('units.index.new_unit')
assert_selector 'tbody > tr:has(input, textarea)'
end
test "new and edit forms open without changing table columns width" do
sign_in
width = if has_selector?(:table_row)
-> { all(:table_row).sample.all(:table_cell).map { |c| c.rect.width } }
else
link_labels.slice!(:new_unit)
-> { find(:table).rect.width }
end
assert_no_changes width do
all(:link, exact_text: link_labels.values.sample).sample.click
assert_selector :table_cell, fillable: true
end
end
test "rebase" do
# TODO
assert true