Skip to content

Commit 8e353f4

Browse files
committed
add matchers #have_table_scopes #have_table_scope
1 parent 068a60c commit 8e353f4

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/capybara/active_admin/matchers/table.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,24 @@ def have_table_cell(options = {})
5353

5454
have_selector(selector, options)
5555
end
56+
57+
# @param options [Hash]
58+
# @option count [Integer] qty of nodes
59+
def have_table_scopes(options = {})
60+
have_selector("#{table_scopes_container_selector} > #{table_scope_selector}", options)
61+
end
62+
63+
# @param options [Hash]
64+
# @option exact_text [String] title of scope
65+
# @option counter [Integer,String,nil] counter value in brackets (nil if skipped)
66+
# @option selected [Boolean] is scope active (default false)
67+
def have_table_scope(options = {})
68+
active = options.delete(:active)
69+
selector = "#{table_scopes_container_selector} > #{table_scope_selector}"
70+
selector = active ? "#{selector}.selected" : "#{selector}:not(.selected)"
71+
72+
have_selector(selector, options)
73+
end
5674
end
5775
end
5876
end

lib/capybara/active_admin/selectors/table.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ def table_cell_selector(column = nil)
3535
column = column.to_s.gsub(' ', '_').downcase
3636
"td.col.col-#{column}"
3737
end
38+
39+
def table_scopes_container_selector
40+
'.scopes > ul.table_tools_segmented_control'
41+
end
42+
43+
def table_scope_selector
44+
'li.scope'
45+
end
3846
end
3947
end
4048
end

0 commit comments

Comments
 (0)