diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5e1b357..8abdd5c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,14 @@
# Changelog
+## 2.0.0.beta3
+
+### Added
+
+- `AttributesTable#row_keys`: the row keys in page order.
+- `AttributesTable#empty?(key)`, `#has_empty_row?(key)` and `#has_no_empty_row?(key)`: whether a row shows ActiveAdmin's empty marker for a blank value.
+- `Form#has_input?(name)` and `#has_no_input?(name)`: whether the field of `f.input :name` is on the page. A form that declares its fields takes only declared names.
+- `Form#has_submit?(label = nil)` and `#has_no_submit?`: the form's submit button, by label ignoring case.
+
## 2.0.0.beta2
### Added
diff --git a/README.md b/README.md
index 59bc4e0..4f09163 100644
--- a/README.md
+++ b/README.md
@@ -208,6 +208,24 @@ expect(table).to have_row(:name, exact_text: "Acme")
expect(table).to have_no_row(:secret)
table.row(:category) # the
table.value(:email) # => "acme@example.com"
+table.row_keys # => ["name", "email", ...], in page order
+expect(table).to have_empty_row(:category) # ActiveAdmin's empty marker; table.empty?(:category) does not wait
+```
+
+A page with several attributes tables or a `table_for` in a panel declares the table inside its panel's section:
+
+```ruby
+class AccountShow < ActiveAdminPageObjects::Page
+ section :details, ActiveAdminPageObjects::Panel, :active_admin_panel, "Details" do
+ section :attributes_table, ActiveAdminPageObjects::AttributesTable
+ end
+ section :users, ActiveAdminPageObjects::Panel, :active_admin_panel, "Users" do
+ section :table, ActiveAdminPageObjects::Table
+ end
+end
+
+show.details.attributes_table.value(:state)
+expect(show.users.table).to have_row_with(:email, "admin@example.com")
```
### Panel
@@ -373,6 +391,8 @@ form = form_page.form # section :form, ActiveAdminPageObjects::Form
form.field(:email).fill("acme@example.com")
form.fill(name: "Acme", category: "Retail", active: false) # in this order
form.submit
+expect(form).to have_submit("Create Customer") # the submit button, ignoring case
+expect(form).to have_no_input(:password) # the field of `f.input :password` is absent
```
`field(name)` returns the section typed by the formtastic input class. `fill(value)` sets the field the way its type needs. A Symbol name stays as it is, so `field(:_memo)` finds `#customer__memo_input`. The field ids and names start with the form's object name, which the gem reads from the first control named like `customer[name]`. When a form names its fields otherwise, set it on the form class: `object_name "batch_action_form_inputs"`.
diff --git a/lib/active_admin_page_objects/attributes_table.rb b/lib/active_admin_page_objects/attributes_table.rb
index 26ec518..6891c70 100644
--- a/lib/active_admin_page_objects/attributes_table.rb
+++ b/lib/active_admin_page_objects/attributes_table.rb
@@ -46,11 +46,49 @@ def value(key, visible: nil)
text_of(find(:css, cell_selector(key), **visibility), visibility).strip
end
+ # The row keys in page order, as `data-row` writes them: ["id", "uuid"].
+ # A row without a title has no key and is left out.
+ # @return [Array]
+ def row_keys(visible: nil)
+ page_element_keys(**given(visible: visible))
+ end
+
+ # True when row +key+ shows ActiveAdmin's empty marker for a blank value.
+ # Does not wait. A hidden row is found with `visible: :all`.
+ # @raise [Capybara::ElementNotFound] when there is no such row
+ def empty?(key, visible: nil)
+ visibility = visibility_of(key, visible)
+ empty_marker_in?(find(:css, cell_selector(key), wait: false, **visibility), visibility)
+ end
+
+ # True when row +key+ shows the empty marker. Takes `visible:` and `wait:`.
+ def has_empty_row?(key, visible: nil, **options)
+ visibility = visibility_of(key, visible)
+ eventually(**options) { empty_row?(key, visibility) }
+ end
+
+ # Waits until row +key+ shows no empty marker, or is gone.
+ def has_no_empty_row?(key, visible: nil, **options)
+ visibility = visibility_of(key, visible)
+ eventually(**options) { !empty_row?(key, visibility) }
+ end
+
# `has_declared_rows?`, `has_exact_rows?` and their `has_no_` forms.
Declarations.define_predicates(self, :rows)
private
+ def empty_row?(key, visibility)
+ cell = first(:css, cell_selector(key), minimum: 0, wait: false, **visibility)
+ !cell.nil? && empty_marker_in?(cell, visibility)
+ end
+
+ # Looks inside the cell, so a theme's marker selector with a comma stays
+ # scoped to the row.
+ def empty_marker_in?(cell, visibility)
+ cell.has_css?(sel(:attributes_table_empty_value), wait: false, **visibility)
+ end
+
def row_selector(key)
declaration_for(key)
sel(:attributes_table_row, slug(key))
diff --git a/lib/active_admin_page_objects/form.rb b/lib/active_admin_page_objects/form.rb
index f574f33..4f9f8ea 100644
--- a/lib/active_admin_page_objects/form.rb
+++ b/lib/active_admin_page_objects/form.rb
@@ -134,6 +134,30 @@ def submit
find(:active_admin, :form_submit, match: :first).click
end
+ # True when the field +name+ (`f.input :name`) is on the page. Not named
+ # has_field?, which is Capybara's lookup by label, id or name. A form that
+ # declares its fields takes only declared names, so declare a field that
+ # may be absent.
+ def has_input?(name, **options)
+ has_css?(field_selector(name), **visibility_of(name), **options)
+ end
+
+ # Waits until the field +name+ is not on the page.
+ def has_no_input?(name, **options)
+ has_no_css?(field_selector(name), **visibility_of(name), **options)
+ end
+
+ # True when the form has a submit button, or one labelled +label+
+ # (ignoring case): "Create Customer".
+ def has_submit?(label = nil, **options)
+ eventually(**options) { submit_labels.any? { |text| label.nil? || same_text?(text, label) } }
+ end
+
+ # Waits until the form has no submit button, or none labelled +label+.
+ def has_no_submit?(label = nil, **options)
+ eventually(**options) { submit_labels.none? { |text| label.nil? || same_text?(text, label) } }
+ end
+
# The `has_many` block of +association+, e.g. `has_many(:line_items)`. A form
# that declares has_many blocks takes the declared name. A hidden block is
# found with `visible: :all`.
@@ -207,6 +231,13 @@ def semantic_error_expectation(messages)
private
+ # An `` is labelled by its value, a `