From 0e56cc6ec7017af0e5c03043a222314f3705169d Mon Sep 17 00:00:00 2001 From: Denis Talakevich Date: Tue, 1 Dec 2026 22:45:10 +0200 Subject: [PATCH 1/4] Add Table#footer, select search: and close the datepicker The datepicker's fade-out kept it over the Filter button after set returned, so the next click could land on the picker. Co-Authored-By: Clanker --- CHANGELOG.md | 7 ++++ Gemfile | 2 ++ README.md | 13 ++++--- .../filters/select_filter.rb | 7 ++-- .../form/select_field.rb | 7 ++-- lib/active_admin_page_objects/section.rb | 8 +++-- .../select_control.rb | 4 ++- lib/active_admin_page_objects/selectors.rb | 3 ++ lib/active_admin_page_objects/table.rb | 34 ++++++++++++------- .../extension_spec.rb | 12 ++++--- .../active_admin_page_objects/filters_spec.rb | 10 ++++-- .../rspec_matchers_spec.rb | 4 +-- spec/active_admin_page_objects/table_spec.rb | 11 ++++++ spec/dummy/app/admin/customers.rb | 6 ++-- spec/dummy/config/application.rb | 1 + 15 files changed, 93 insertions(+), 36 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bacb2a8..c84ab4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ ### Added +- `SelectFilter#select_option` and `Form::SelectField#fill` take `search:`, the text a select widget types when it differs from the option label. It reaches `SelectControl#choose_option` only when given, so a widget module that defines `choose_option(scope, label)` keeps working; the native `` for `SelectFilter` and `Form::Field`. For a widget on some selects, declare your own class: see [Hidden selects](#hidden-selects). A gem that renders a JavaScript select widget for every select prepends a module into `SelectControl` instead. It overrides the private methods `choose_option(scope, label)`, `option_offered?(scope, label)`, `control_disabled?(scope)` and `chosen_item?(scope, label)`, and `native_select_visibility` for the methods that still read the hidden `` for `SelectFilter` and `Form::Field`. For a widget on some selects, declare your own class: see [Hidden selects](#hidden-selects). A gem that renders a JavaScript select widget for every select prepends a module into `SelectControl` instead. It overrides the private methods `choose_option(scope, label, search: nil)`, `option_offered?(scope, label)`, `control_disabled?(scope)` and `chosen_item?(scope, label)`, and `native_select_visibility` for the methods that still read the hidden `` ignores it. + ## Themes and plugins A theme or plugin ships its own page objects in its own repository, with one entry point. The rule: diff --git a/lib/active_admin_page_objects/filters/select_filter.rb b/lib/active_admin_page_objects/filters/select_filter.rb index 9576823..dfe9a99 100644 --- a/lib/active_admin_page_objects/filters/select_filter.rb +++ b/lib/active_admin_page_objects/filters/select_filter.rb @@ -6,9 +6,10 @@ module ActiveAdminPageObjects class SelectFilter < Filter include SelectControl - # Chooses the option labelled +label+. - def select_option(label) - choose_option(root_element, label) + # Chooses the option labelled +label+. +search+ is the text a select + # widget types to find it; the native ignores it. + def fill(label, search: nil) + choose_option(root_element, label.to_s, **{ search: search }.compact) end # The option texts, without the blank option. diff --git a/lib/active_admin_page_objects/section.rb b/lib/active_admin_page_objects/section.rb index 645199c..f9155ef 100644 --- a/lib/active_admin_page_objects/section.rb +++ b/lib/active_admin_page_objects/section.rb @@ -49,10 +49,14 @@ def href_attribute(link) end # Types +text+ into a date input. jQuery UI opens the datepicker when the - # input gets focus, over the controls below; Escape closes it. + # input gets focus, over the controls below. Escape closes it, but its + # fade-out keeps it over them for a moment, so wait until it is hidden. def type_date(input, text) input.set(text) - input.send_keys(:escape) if class_names(input).include?("hasDatepicker") + return unless class_names(input).include?("hasDatepicker") + + input.send_keys(:escape) + input.session.document.assert_no_selector(:active_admin, :datepicker) end # Retries the block until it is truthy or the wait time runs out. diff --git a/lib/active_admin_page_objects/select_control.rb b/lib/active_admin_page_objects/select_control.rb index 420282f..91f21f6 100644 --- a/lib/active_admin_page_objects/select_control.rb +++ b/lib/active_admin_page_objects/select_control.rb @@ -37,7 +37,9 @@ def native_select(scope) scope.find("select", **native_select_lookup) { |select| native_select_shown?(select) } end - def choose_option(scope, label) + # Picks +label+. A widget module reads +search+, the text to type when it + # differs from the label; callers pass it only when a spec gives one. + def choose_option(scope, label, search: nil) # rubocop:disable Lint/UnusedMethodArgument native_select(scope).select(label, **native_select_lookup) end diff --git a/lib/active_admin_page_objects/selectors.rb b/lib/active_admin_page_objects/selectors.rb index b644103..4852041 100644 --- a/lib/active_admin_page_objects/selectors.rb +++ b/lib/active_admin_page_objects/selectors.rb @@ -51,6 +51,7 @@ module Selectors table_row_by_id: 'tbody > tr[id$="_%s"]', table_cell: "td.col-%s", table_row_checkbox: "input.collection_selection", + table_footer: "tfoot > tr", blank_slate: ".blank_slate_container", attributes_table: ".attributes_table", @@ -77,6 +78,8 @@ module Selectors filter_value: "input", filter_range_from: 'input[name*="_gteq"]', filter_range_to: 'input[name*="_lteq"]', + # jQuery UI renders one datepicker for the page, at the end of . + datepicker: "#ui-datepicker-div", filters_footer: "form.filter_form .buttons", filters_submit: "input[type=submit]", filters_clear: "a.clear_filters_btn", diff --git a/lib/active_admin_page_objects/table.rb b/lib/active_admin_page_objects/table.rb index 7e24afd..519b7e2 100644 --- a/lib/active_admin_page_objects/table.rb +++ b/lib/active_admin_page_objects/table.rb @@ -24,19 +24,13 @@ def column(key, label, visible: nil) SORT_DIRECTIONS = %i[asc desc].freeze - # One `` of the table body. `status_tag(:status)`, + # A `` whose cells are read by column key. `status_tag(:status)`, # `status_tags(:status)` and `has_status_tag?` read the cell of a column: # see StatusTag::Matchers. - class Row < Section + class BaseRow < Section include Declarations::Lookup include StatusTag::Matchers - # The record id from the row's `id="_"`. - # @return [String] - def record_id - root_element[:id].to_s.split("_").last - end - # The `` of column +key+ (`:external_id` or `"External ID"`). A # hidden cell is found with `visible: :all`. # @return [Capybara::Node::Element] @@ -54,11 +48,6 @@ def has_no_cell?(key, **options) has_no_css?(cell_selector(key), **visibility_of(key), **options) end - # Ticks the row's batch-action checkbox. - def select - find(:active_admin, :table_row_checkbox).check - end - private # The columns are declared on the table the row belongs to. @@ -72,7 +61,26 @@ def cell_selector(key) end end + # One `` of the table body. + class Row < BaseRow + # The record id from the row's `id="_"`. + # @return [String] + def record_id + root_element[:id].to_s.split("_").last + end + + # Ticks the row's batch-action checkbox. + def select + find(:active_admin, :table_row_checkbox).check + end + end + + # The `` row, such as the totals row of activeadmin_table_footer. + # Its cells are read by column key, as in a body row. + class Footer < BaseRow; end + sections :rows, Row, :active_admin, :table_row + section :footer, Footer, :active_admin, :table_footer # The row of the record with +record_id+. # @raise [ArgumentError] when +record_id+ is not an Integer or a non-empty String diff --git a/spec/active_admin_page_objects/extension_spec.rb b/spec/active_admin_page_objects/extension_spec.rb index 6a19647..7567f4b 100644 --- a/spec/active_admin_page_objects/extension_spec.rb +++ b/spec/active_admin_page_objects/extension_spec.rb @@ -11,8 +11,10 @@ def chosen end end - def choose_option(scope, label) - ChooseOptionSpy.chosen << label if ChooseOptionSpy.active + # Records the keywords too: none unless the spec gave a search, so a + # widget module written as `choose_option(scope, label)` keeps working. + def choose_option(scope, label, **options) + ChooseOptionSpy.chosen << [label, options] if ChooseOptionSpy.active super end @@ -77,13 +79,15 @@ def paragraphs index = Pages::CustomerIndex.new index.load index.filters.filter(:status).select_option("pending") - expect(ChooseOptionSpy.chosen).to eq(["pending"]) + expect(ChooseOptionSpy.chosen).to eq([["pending", {}]]) form_page = Pages::CustomerForm.new form_page.load(action: "new") form_page.form.field(:status).fill("closed") - expect(ChooseOptionSpy.chosen).to eq(%w[pending closed]) + form_page.form.field(:category).fill("Retail", search: "Ret") + expect(ChooseOptionSpy.chosen).to eq([["pending", {}], ["closed", {}], ["Retail", { search: "Ret" }]]) expect(form_page.form.field(:status)).to have_select(selected: "closed") + expect(form_page.form.field(:category)).to have_select(selected: "Retail") ensure ChooseOptionSpy.active = false ChooseOptionSpy.chosen.clear diff --git a/spec/active_admin_page_objects/filters_spec.rb b/spec/active_admin_page_objects/filters_spec.rb index 0c38577..5554d92 100644 --- a/spec/active_admin_page_objects/filters_spec.rb +++ b/spec/active_admin_page_objects/filters_spec.rb @@ -351,9 +351,9 @@ def declared_filters(&) expect(filters.filter(:status)).to have_no_item("active") end - it "filters by an association" do + it "filters by an association, and the native select ignores search:" do index.load - filters.filter(:category).select_option("Retail") + filters.filter(:category).select_option("Retail", search: "Ret") filters.submit expect(names).to eq(["Alpha"]) end @@ -503,6 +503,12 @@ def native_select_visibility = :all expect { range.set("yesterday") }.to raise_error(Date::Error) end + it "closes the datepicker before it returns" do + index.load + filters.filter(:created_at).set("2026-02-01", "2026-04-01") + expect(page).to have_no_css("#ui-datepicker-div", visible: true, wait: 0) + end + it "leaves an open end" do index.load filters.filter(:created_at).set("2026-02-01") diff --git a/spec/active_admin_page_objects/rspec_matchers_spec.rb b/spec/active_admin_page_objects/rspec_matchers_spec.rb index 19d69e1..a69d9ed 100644 --- a/spec/active_admin_page_objects/rspec_matchers_spec.rb +++ b/spec/active_admin_page_objects/rspec_matchers_spec.rb @@ -133,8 +133,8 @@ def have_flash_message(text, options = {}) it "is the predicate matcher for any object" do expect(index).to have_page_title(text: "Customers") expect(index.table.row(customer.id)).not_to have_status_tag(:status, "Active") - expect { expect(page).to have_footer } - .to raise_error(RSpec::Expectations::ExpectationNotMetError, /to respond to `has_footer\?`/) + expect { expect(page).to have_side_panel } + .to raise_error(RSpec::Expectations::ExpectationNotMetError, /to respond to `has_side_panel\?`/) end it "uses a matcher of the same name that Capybara or SitePrism defines" do diff --git a/spec/active_admin_page_objects/table_spec.rb b/spec/active_admin_page_objects/table_spec.rb index 227684f..39390fa 100644 --- a/spec/active_admin_page_objects/table_spec.rb +++ b/spec/active_admin_page_objects/table_spec.rb @@ -33,6 +33,17 @@ def declared_table(&) expect(table.exact_mismatches).to eq(missing: ["notes"], unexpected: [], labels: {}) end + it "reads the footer cells by column" do + expect(table).to have_no_footer + index.load(query: { with_totals: 1 }) + expect(table).to have_rows(count: 3) + expect(table.footer).to have_cell(:name, exact_text: "Total") + expect(table.footer).to have_cell("Balance", exact_text: "30.0") + expect(table.footer).to have_cell(:email, exact_text: "") + expect(table.footer).to have_no_cell(:balance, exact_text: "10.0") + expect(table.footer.cell(:balance).text).to eq("30.0") + end + it "has an optional column when the page shows it" do index.load(query: { with_notes: 1 }) expect(table).to have_exact_columns diff --git a/spec/dummy/app/admin/customers.rb b/spec/dummy/app/admin/customers.rb index 98e7420..a025af1 100644 --- a/spec/dummy/app/admin/customers.rb +++ b/spec/dummy/app/admin/customers.rb @@ -67,11 +67,13 @@ index do selectable_column id_column - column :name + # `?with_totals=1` adds the activeadmin_table_footer totals row. + totals = params[:with_totals].present? + column :name, **(totals ? { footer: "Total" } : {}) column :email column :external_id column(:status) { |customer| status_tag(customer.status) } - column :balance + column :balance, **(totals ? { footer: :sum } : {}) column :active column :category column "Created", :created_at diff --git a/spec/dummy/config/application.rb b/spec/dummy/config/application.rb index 8ea0a6e..d30a459 100644 --- a/spec/dummy/config/application.rb +++ b/spec/dummy/config/application.rb @@ -8,6 +8,7 @@ require "action_view/railtie" require "sprockets/railtie" require "activeadmin" +require "activeadmin_table_footer" module Dummy class Application < Rails::Application From 9949360ffb7c83e504f6c106993a5abbb291a3cf Mon Sep 17 00:00:00 2001 From: Denis Talakevich Date: Tue, 1 Dec 2026 22:45:10 +0200 Subject: [PATCH 2/4] Release 1.1.0 Co-Authored-By: Clanker --- CHANGELOG.md | 2 +- lib/active_admin_page_objects/version.rb | 2 +- spec/active_admin_page_objects/text_spec.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c84ab4c..2bf5da0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## Unreleased +## 1.1.0 (2026-12-01) ### Added diff --git a/lib/active_admin_page_objects/version.rb b/lib/active_admin_page_objects/version.rb index 2c18208..dfa328d 100644 --- a/lib/active_admin_page_objects/version.rb +++ b/lib/active_admin_page_objects/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module ActiveAdminPageObjects - VERSION = "1.0.0" + VERSION = "1.1.0" end diff --git a/spec/active_admin_page_objects/text_spec.rb b/spec/active_admin_page_objects/text_spec.rb index ea3896a..e0e55b9 100644 --- a/spec/active_admin_page_objects/text_spec.rb +++ b/spec/active_admin_page_objects/text_spec.rb @@ -59,6 +59,6 @@ end it "has a version" do - expect(ActiveAdminPageObjects::VERSION).to eq("1.0.0") + expect(ActiveAdminPageObjects::VERSION).to eq("1.1.0") end end From a175abe916620773a0a722486345f7a2469b3eab Mon Sep 17 00:00:00 2001 From: Denis Talakevich Date: Wed, 2 Dec 2026 10:46:10 +0200 Subject: [PATCH 3/4] Accept any flash type, open batch dialogs and match more selects Also close the datepicker through jQuery UI: an Escape sent after the picker closed would close an enclosing modal dialog. Co-Authored-By: Clanker --- CHANGELOG.md | 8 +++- README.md | 14 +++++-- .../batch_actions.rb | 38 +++++++++++++------ lib/active_admin_page_objects/flashes.rb | 11 ++++-- .../form/select_field.rb | 30 ++++++++++++++- lib/active_admin_page_objects/has_many.rb | 16 ++++++++ lib/active_admin_page_objects/modal_dialog.rb | 12 ++++-- lib/active_admin_page_objects/section.rb | 27 +++++++++++-- lib/active_admin_page_objects/selectors.rb | 1 + lib/active_admin_page_objects/table.rb | 9 ++++- .../batch_actions_spec.rb | 10 +++++ .../extension_spec.rb | 14 +++++++ .../active_admin_page_objects/flashes_spec.rb | 16 ++++++-- spec/active_admin_page_objects/form_spec.rb | 17 +++++++++ .../has_many_spec.rb | 3 ++ .../modal_dialog_spec.rb | 13 +++++++ spec/active_admin_page_objects/table_spec.rb | 3 ++ spec/dummy/app/admin/customers.rb | 12 +++++- 18 files changed, 220 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2bf5da0..ef974cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ ### Added - `SelectFilter#select_option` and `Form::SelectField#fill` take `search:`, the text a select widget types when it differs from the option label. It reaches `SelectControl#choose_option` only when given, so a widget module that defines `choose_option(scope, label)` keeps working; the native `