diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3e9edfc..6d3ee14 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,7 +2,7 @@ name: CI on: push: - branches: [main, 1-x-stable] + branches: [main] pull_request: jobs: @@ -21,6 +21,15 @@ jobs: with: ruby-version: ${{ matrix.ruby }} bundler-cache: true + - uses: actions/setup-node@v4 + with: + node-version: 22 + cache: npm + cache-dependency-path: spec/dummy/package-lock.json + - run: npm ci --no-audit --no-fund + working-directory: spec/dummy + - run: npm run build + working-directory: spec/dummy - run: bundle exec rspec rubocop: diff --git a/.gitignore b/.gitignore index 1cbc8cd..e14aeac 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,7 @@ /gemfiles/*.lock /tmp/ /.bundle/ +/spec/dummy/node_modules/ +/spec/dummy/app/assets/builds/ /spec/dummy/tmp/ /spec/dummy/log/ diff --git a/CHANGELOG.md b/CHANGELOG.md index bacb2a8..9c1b8e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,57 +1,53 @@ # Changelog -## Unreleased +## 2.0.0.beta1 ### Added +- `Table::Row#cell`, `has_cell?` and `Table#row_with` find the cells of the `actions` and `selectable` columns. ActiveAdmin 4 writes no `data-column` on them, so these lookups used to fail. +- `BatchActions#apply` leaves an open menu open; clicking the toggle again closed it. +- A String `text:` together with a String `exact_text:` checks both, also in the case-insensitive cell and row matchers. +- `Flashes#flash_types`, a private method that a theme overrides to add the flash types it renders. +- `Comments` section for resource comments: `count`, `bodies`, `authors`, `has_comment?`, `add` and `delete`. The `form` selector leaves the comment form out. +- has_many support: `Form.has_many`, `Form#has_many` and the `HasMany` section with fieldsets, `add`, `remove` and `marked_for_destroy?`. `have_exact_fields` counts a has_many block as one declared element, so a form with an undeclared has_many block reports it as unexpected. +- Status tags: `Table::Row` and `AttributesTable` get `status_tag(key)`, `status_tags(key)`, `has_status_tag?(key, label = nil, status:)` and `has_no_status_tag?`. `type:` is an alias of `status:`. +- Sorting: `Table#sort_by(key, direction = nil)`, `#sort_direction`, `#has_sort?` (alias `sorted_by?`), `#has_no_sort?`, `#has_sortable_column?` and `#has_no_sortable_column?`. +- A panel nested in another panel is found by its own title; before, the outer panel matched too and Capybara raised `Ambiguous`. + +- `Table::Row#has_cell?`, `Table#has_row?`, `AttributesTable#has_row?` and their `has_no_` forms ignore case for a String `text:` or `exact_text:`. Chrome reports text as CSS shows it, so a theme that uppercases a value no longer breaks the match. - `StringFilter` and `NumericFilter` drive a filter whose key holds its predicate, such as `filter :uuid_eq`: ActiveAdmin renders a bare input without a predicate select. - `Form::Field#required?`, `#input` (the field's first control) and `#force_fill(text)`, which sets a text control's value with JavaScript past its `maxlength`. - `Table#row_with(key, text)`, `#has_row_with?` and `#has_no_row_with?` find a row by a cell's text, for tables without record ids. - `MainMenu#href(*labels)`, and `has_item?` and `has_no_item?` take `href:`: a path, a full URL or a Regexp. - `have_semantic_errors` and `have_no_semantic_errors` take a Regexp, which matches part of a message. - `ActiveAdminPageObjects.register_field_class(wrapper_class, field_class)` and `.register_filter_class(wrapper_class, filter_class)`: a theme or plugin maps the formtastic class of its own input to its section class, and `form.field` and `filters.filter` return that class without a declaration. A registered class wins over the gem's class. - -## 1.0.0 (2026-11-24) - -### Added - - Arguments that would make a matcher pass on any page raise `ArgumentError`: a record id that is not an Integer or a non-empty String in `Table#row`, `#has_row?` and `#has_no_row?`, an `only:` or `except:` scope that leaves no declared name, and a flash type of `nil`. - `MainMenu#has_item?` and `#has_no_item?` wait, and take `wait:`. - `DateRangeFilter#set` clears an end for `""` as for `nil`. - `have_table` from `ActiveAdminPageObjects::RSpec::Matchers` calls the page object only when it defines `has_table?` itself, as `section :table` does; Capybara's own `has_table?` does not count. -- `Form::FileField` for formtastic's `file` input: `fill(path)` attaches the file, and `form.fill(attachment: path)` works. `Form#field` and `HasMany::Fieldset#field` return it by the input class. -- Disabled fields: `Form::Field#disabled?` and `#enabled?` on every field type, and `have_disabled_field(name)` and `have_enabled_field(name)` with their `have_no_` forms on a form and on a has_many fieldset. -- `have_status_tag` and `have_no_status_tag` look at every status tag of the cell, not only the first. `status_tags(key)` on an index row and on the attributes table returns all of them. +- `Form::FileField` for formtastic's `file` input: `fill(path)` attaches the file, and `form.fill(attachment: path)` works. `Form#field` returns it by the input class. +- Disabled fields: `Form::Field#disabled?` and `#enabled?` on every field type, and `have_disabled_field(name)` and `have_enabled_field(name)` with their `have_no_` forms on a form. - `Table#has_row?(record_id)` and `#has_no_row?(record_id)`: `expect(table).to have_row(customer.id)`. -- Regexp titles: `Tabs#switch`, `have_tab`, `page.panel`, `page.sidebar` and the `:active_admin_panel` and `:active_admin_sidebar` selectors take a Regexp for a title with a changing part, such as "Possible Routes (2)". A String still compares the whole title. +- Regexp titles: `page.panel` and the `:active_admin_panel` selector take a Regexp for a title with a changing part, such as "Possible Routes (2)". A String still compares the whole title. - `DownloadLinks`, declared with `section :download_links, ActiveAdminPageObjects::DownloadLinks`: `formats`, `have_format(format)`, `href(format)` and `click(format)` for the "Download: CSV XML JSON" links of an index page. - Declared elements: `AttributesTable.row(key, label)`, `Table.column(key, label)`, `Filters.filter(name, label, type)` and `Form.field(name, label, type)` declare a section's elements with their labels, also inside a `section ... do` block. A filter or a field also needs its section class. - `have_declared_rows`, `have_declared_columns`, `have_declared_filters` and `have_declared_fields` compare the declared labels with the page exactly. `have_exact_rows`, `have_exact_columns`, `have_exact_filters` and `have_exact_fields` also fail when the page has an element that is not declared. All take `only:` and `except:`. `declared_label_mismatches` and `exact_mismatches` return what differs. - Lookups and matchers see only visible elements, as Capybara does by default. `visible: :all` on a call takes hidden elements too: `form.field(:notes, visible: :all)`, `have_exact_fields(visible: :all)`, `exact_mismatches(visible: :all)`. `visible: :all` on a declaration makes it the default for that element: `field :notes, "Notes", ActiveAdminPageObjects::Form::StringField, visible: :all`. - Failure messages: with `ActiveAdminPageObjects::RSpec::Matchers` included, the `have_declared_*` and `have_exact_*` matchers and their `have_no_` forms list the missing elements, the unexpected elements and the labels that differ. `have_exact_field_errors` and `have_exact_semantic_errors` list the missing and the unexpected messages. `last_mismatches`, `last_field_errors` and `last_semantic_errors` return what the last of these matchers found. +- The untitled selection and actions columns of an index table are the columns `selectable` and `actions`, declared with the label `""`. ActiveAdmin 4 gives them no `data-column`. - `Filters#filter` and `Form#field` return an instance of the declared class, and raise `ActiveAdminPageObjects::DeclaredClassMismatch`, a `Capybara::ExpectationNotMet`, unless it is the detected class or a subclass of it. `have_disabled_field` and `have_enabled_field` raise it too. To use your own field or filter class, declare it. A declaration defines no method on the section: reach it with `form.field(:name)` or `filters.filter(:name)`, and write your own methods in the section block for shortcuts. -- `Form.has_many(name, heading, &block)` declares a has_many block with the fields of its fieldsets, reached with `form.has_many(:name)`. - A section with declarations raises `ArgumentError` for an undeclared name before it queries the page. -- Typed form fields: `Form#field` and `HasMany::Fieldset#field` return `Form::StringField`, `SelectField`, `BooleanField`, `RadioField`, `CheckBoxesField` or `DatePickerField` by the formtastic input class. Each has a `fill(value)` for its type. `form.fill(name: "Acme", active: false)` fills several fields in the given order, on a form and on a has_many fieldset. -- Form errors: `have_field_error`, `have_field_errors`, `have_exact_field_errors`, `have_semantic_errors` and `have_exact_semantic_errors(*messages, strict_order: false)`, each with its `have_no_` form. Has_many fieldsets have the field error matchers too. -- `have_status_tag(key, label, type: nil)` and `have_no_status_tag` on index rows and on the attributes table. -- `Panel#links` and `Sidebar#links` list the links of the body as `{ text:, href: }`, with the href as a path. +- Typed form fields: `Form#field` returns `Form::StringField`, `SelectField`, `BooleanField`, `RadioField`, `CheckBoxesField` or `DatePickerField` by the formtastic input class. Each has a `fill(value)` for its type. `DatePickerField` is the `date_picker` input, a native ``. `form.fill(name: "Acme", active: false)` fills several fields in the given order. +- Form errors: `have_field_error`, `have_field_errors`, `have_exact_field_errors`, `have_semantic_errors` and `have_exact_semantic_errors(*messages, strict_order: false)`, each with its `have_no_` form. +- `Panel#links` lists the links of the body as `{ text:, href: }`, with the `href` attribute as the page wrote it. - `ActiveAdminPageObjects::RSpec::Matchers`, loaded with `require "active_admin_page_objects/rspec"`: the matcher names of capybara_active_admin 1.0.0, which call the predicate of a page object and that gem's matcher for anything else. -- `MainMenu#labels(*parents)` lists the item labels at a menu level. `MainMenu#click(*labels)` hovers each parent and clicks the item's link, as a user does; it sees visible items only, so a hidden submenu raises `Capybara::ElementNotFound`. `go` still visits the link's URL. -- Version 1.0.0: page objects for vanilla ActiveAdmin 3 only. The gem depends on `activeadmin` (>= 3.0, < 4.0.0.a). Vanilla ActiveAdmin 4 is the 2.x line on `main`. -- SitePrism page and sections for vanilla ActiveAdmin 3: layout, breadcrumbs, action items, flashes, main menu, index table, attributes table, panel, filters (string, numeric, select, boolean, date range), scopes, pagination, batch actions and formtastic forms. -- `HasMany`, reached with `form.has_many(:orders)`: count, add and remove fieldsets, and fill their fields. -- `StatusTag`, reached with `row.status_tag(:status)` and `attributes_table.status_tag(:status)`. -- `Sidebar`, reached with `page.sidebar("Help")`. `page.panel` skips sidebar sections and the comments panel. -- `ModalDialog`, reached with `page.modal_dialog`. `BatchActions#apply(label, inputs = {})` fills the dialog of an action with `confirm:` or `form:`. -- `Comments`, declared with `section :comments, ActiveAdminPageObjects::Comments`: read, add and delete comments. -- Table sorting: `Table#sort_by`, `#sorted_by` and `#has_sortable_column?`. -- `Tabs`, `UtilityNavigation` and `DropdownMenu` (`action_items.dropdown("More")`). -- `ActiveAdminPageObjects.register_selectors(**map)` takes only the selector map. +- `MainMenu#labels(*parents)` lists the item labels at a menu level. `MainMenu#click(*labels)` opens each collapsed parent with its toggle button and clicks the item's link, as a user does; it sees visible items only, so a hidden submenu raises `Capybara::ElementNotFound`. `go` still visits the link's URL. +- Version 2.x: page objects for vanilla ActiveAdmin 4 only. The gem now depends on `activeadmin` (>= 4.0.0.beta23, < 5.0.0.a): the comments section needs the `active-admin-comments-form` id of beta20, and beta23 is the version the suite runs on. Vanilla ActiveAdmin 3 moves to the 1.x line. +- SitePrism page and sections for vanilla ActiveAdmin 4: layout, breadcrumbs, action items, flashes, main menu, index table, attributes table, panel, filters (string, numeric, select, boolean, date range), scopes, pagination, batch actions and formtastic forms. +- `ActiveAdminPageObjects.register_selectors(**map)` takes only the selector map. It can also replace a key ActiveAdmin 4 removed, such as `tabs`. - `ActiveAdminPageObjects::Layout.add_section` and `Layout.add_element` add a section or an element to every page that includes `Layout`, including page classes defined earlier. - `ActiveAdminPageObjects::SelectControl` drives a visible native `` that is hidden or marked `aria-hidden="true"`, as a JavaScript select widget leaves it, raises `Capybara::ElementNotFound` when it is picked from or read. A section class for a widget overrides the private `native_select_visibility` to return `:all` and read the hidden select, and overrides `select_option` or `fill` to drive the widget. A gem with a widget on every select prepends a module into `SelectControl`. -- `ActiveAdminPageObjects.check_version!` for theme and plugin page objects. -- `dark_mode_toggle` and `user_menu_button` raise `NotInActiveAdmin3`: ActiveAdmin 3 has neither. +- `ActiveAdminPageObjects.check_version!` for theme and plugin page objects. Features ActiveAdmin 4 removed raise `RemovedInActiveAdmin4`. ### Removed diff --git a/Gemfile b/Gemfile index f0f17e2..5cdfe5d 100644 --- a/Gemfile +++ b/Gemfile @@ -8,12 +8,12 @@ gem "rake" gem "rspec", "~> 3.13" gem "rubocop", "~> 1.80", require: false -# Dummy ActiveAdmin 3 app (spec/dummy): sprockets, jQuery from jquery-rails, -# Sass for active_admin.scss. -gem "activeadmin", "3.5.2" +# Dummy ActiveAdmin 4 app (spec/dummy): importmap + propshaft, Tailwind CSS +# built with the npm CLI. +gem "activeadmin", "4.0.0.beta23" gem "cuprite" -gem "dartsass-sprockets" +gem "importmap-rails" +gem "propshaft" gem "puma" gem "rails", "~> 8.0" -gem "sprockets-rails" gem "sqlite3" diff --git a/README.md b/README.md index b943b88..60f0f90 100644 --- a/README.md +++ b/README.md @@ -2,14 +2,12 @@ A Page Object Model DSL for Capybara of ActiveAdmin, built on [SitePrism](https://github.com/site-prism/site_prism). -System specs call semantic methods, such as `table.row(id).cell(:name)`, `filters.filter(:status).select_option("Active")` or `main_menu.go("Catalog", "Orders")`, instead of CSS selectors. The selectors for vanilla ActiveAdmin 3 live in this gem. +System specs call semantic methods, such as `table.row(id).cell(:name)`, `filters.filter(:status).select_option("Active")` or `main_menu.go("Catalog", "Orders")`, instead of CSS selectors. The selectors for vanilla ActiveAdmin 4 live in this gem. ## Versions -- 1.x supports vanilla ActiveAdmin 3 (tested on 3.5.2). This is the `1-x-stable` branch. -- 2.x supports vanilla ActiveAdmin 4. This is the `main` branch. Its sections and methods have the same names as 1.x where the component exists in both versions. - -To upgrade ActiveAdmin from 3 to 4, bump this gem to 2.x. Only specs that use a feature ActiveAdmin 4 removed need a change: `Tabs`, the action-item dropdown and `UtilityNavigation` raise `RemovedInActiveAdmin4` in 2.x. +- 2.x supports vanilla ActiveAdmin 4 (tested on 4.0.0.beta23). This is the `main` line. +- 1.x is planned for vanilla ActiveAdmin 3, on the `1-x-stable` branch, with the same names where the component exists. ## Installation @@ -18,7 +16,7 @@ Until the first release, install it from git: ```ruby # Gemfile group :test do - gem "active_admin_page_objects", github: "activeadmin-plugins/active_admin_page_objects", branch: "1-x-stable" + gem "active_admin_page_objects", github: "activeadmin-plugins/active_admin_page_objects" end ``` @@ -27,7 +25,7 @@ end require "active_admin_page_objects" ``` -Runtime dependencies: `activeadmin` (>= 3.0, < 4.0.0.a), `site_prism` (>= 5.0, < 7) and `capybara` (>= 3.37), on Ruby 3.3 or later. CI runs Ruby 3.3 and 3.4 with activeadmin 3.5.2, capybara 3.40 and site_prism 5.2 and 6.0; older versions inside these ranges are not tested. +Runtime dependencies: `activeadmin` (>= 4.0.0.beta23, < 5.0.0.a), `site_prism` (>= 5.0, < 7) and `capybara` (>= 3.37), on Ruby 3.3 or later. ### Rails 8 setup @@ -76,25 +74,10 @@ Use the `has_no_*` matchers (`have_no_row`), not `not_to have_*`. They wait for ```ruby expect(page_object).to have_site_title(text: "My Admin") expect(page_object).to have_page_title(text: "Customers") +expect(page_object).to have_dark_mode_toggle # alias: have_theme_switcher +expect(page_object).to have_user_menu_button expect(page_object).to have_blank_slate(text: "There are no Customers yet.") page_object.panel("Notes").body # the panel titled "Notes" -page_object.sidebar("Help").body # the sidebar section titled "Help" -page_object.modal_dialog # see Batch actions -``` - -ActiveAdmin 3 has no dark mode toggle and no user menu button. `dark_mode_toggle` (alias `theme_switcher`) and `user_menu_button` raise `ActiveAdminPageObjects::NotInActiveAdmin3`. - -`panel` skips sidebar sections and the comments panel, which ActiveAdmin 3 renders as panels too. Use `sidebar` and `Comments` for them. - -### Utility navigation - -The current user and the logout link in the header. - -```ruby -navigation = page_object.utility_navigation -navigation.current_user # => "admin@example.com" -navigation.labels # => ["admin@example.com", "Logout"] -navigation.logout ``` ### Breadcrumbs @@ -106,32 +89,19 @@ page_object.breadcrumbs.labels # => ["Admin", "Customers"] page_object.breadcrumbs.links # => Capybara elements ``` -`labels` returns the text the driver reports. ActiveAdmin 3's CSS uppercases the trail, so a JavaScript driver gives `["ADMIN", "CUSTOMERS"]`. The matchers ignore case. - ### Action items ```ruby -page_object.action_items.labels # => ["New Customer", "More"] +page_object.action_items.labels # => ["New Customer", "Report"] page_object.action_items.click("New Customer") -expect(page_object.action_items).to have_item("More") +expect(page_object.action_items).to have_item("Report") ``` -ActiveAdmin 3 always renders the container, so assert on its items, not on the section. - -A `dropdown_menu` is an item too. `dropdown(label)` returns a `DropdownMenu` (the only one when called without a label): - -```ruby -more = page_object.action_items.dropdown("More") -more.label # => "More" -more.labels # => ["Report", "Customers"], also from a closed menu -more.open -more.click("Customers") # opens the menu first -expect(more).to have_item("Report") -``` +`dropdown` raises `ActiveAdminPageObjects::RemovedInActiveAdmin4`: ActiveAdmin 4 has no action-item dropdown. ### Flashes -ActiveAdmin 3 renders the `notice`, `alert`, `error` and `warning` types. It renders the container on every page, so assert on the content: `have_no_flash` works without flashes. +ActiveAdmin 4 renders the `notice`, `alert` and `error` types. ```ruby expect(page_object.flashes).to have_flash(:notice, "Customer was successfully created.") @@ -142,7 +112,7 @@ page_object.flashes.messages(:alert) # one type ### Main menu -Items are found by their label path, case-insensitively. `href` returns the link's URL as the driver reports it, which is the absolute URL in a browser. `have_item(..., href:)` takes a path, a full URL or a Regexp, and compares a path to the URL's path and query. `go` reads the link's URL and visits it, so it works with closed submenus and under `rack_test`. `click` drives the menu as a user does: it hovers each parent, then clicks the item's link. It sees visible items only, so a hidden or unreachable submenu raises `Capybara::ElementNotFound`. Under `rack_test`, which cannot hover, it skips the hovering. +Items are found by their label path, case-insensitively. `href` returns the link's URL as the driver reports it, which is the absolute URL in a browser. `have_item(..., href:)` takes a path, a full URL or a Regexp, and compares a path to the URL's path and query. `go` reads the link's URL and visits it, so it works with closed submenus and under `rack_test`. `click` drives the menu as a user does: it opens each collapsed parent with its toggle button, then clicks the item's link. It sees visible items only, so a submenu that stays hidden raises `Capybara::ElementNotFound`. Under `rack_test`, which has no JavaScript, the submenus are never collapsed, so `click` just clicks the link. ```ruby page_object.main_menu.go("Customers") @@ -157,7 +127,7 @@ page_object.main_menu.labels("Catalog") # => ["Categories", "Orders"] ### Table -Cells are keyed by column: `:external_id` or `"External ID"` both match the `col-external_id` class. `have_header_names` takes every header in order and compares case-insensitively, so `"Id"` and `"ID"` match. To check the exact labels, declare the columns: see [Declared labels](#declared-labels). +Cells are keyed by column: `:external_id` or `"External ID"` both match `data-column="external_id"`. `have_header_names` takes every header in order and compares case-insensitively, because ActiveAdmin 4 uppercases `th` in CSS and Chrome reports the uppercased text. To check the exact labels, declare the columns: see [Declared labels](#declared-labels). ```ruby table = index.table @@ -172,7 +142,6 @@ expect(row).to have_cell(:name, exact_text: "Acme") expect(row).to have_no_cell(:email, text: "old@example.com") row.cell(:email) # the row.select # ticks the batch-action checkbox -row.status_tag(:status) # see Status tags table.rows.map(&:record_id) expect(table).to have_row(customer.id) # by record id expect(table).to have_no_row(deleted.id) @@ -180,24 +149,39 @@ table.row_with(:server, "10.0.0.1:7080") # by a cell's whole text; a Regexp matc expect(table).to have_row_with(:status, "Failed") ``` +`have_cell`, `have_row` and their `have_no_` forms ignore case when `text:` or `exact_text:` is a String, so a value the theme uppercases in CSS still matches. A Regexp is passed to Capybara unchanged. + `row_with`, `have_row_with` and `have_no_row_with` find rows that have no record id, such as a `table_for` of plain values. `row`, `have_row` and `have_no_row` take the record id: an Integer or a non-empty String. Anything else, such as the record itself or `nil`, raises `ArgumentError`. -Sorting reads and clicks the header links: +The section defaults to `table.data-table`. Pass a locator for another table, such as a `table_for` inside a panel: `section :orders, ActiveAdminPageObjects::Table, "#orders_panel table"`. + +Sortable columns: ActiveAdmin 4 marks a sortable header with `data-sortable` and the sorted one with `data-sort-direction`. ```ruby -table.sort_by(:name) # one click -table.sort_by(:name, :asc) # clicks until the column is sorted that way -table.sorted_by # => ["name", :asc], or nil expect(table).to have_sortable_column(:name) +table.sort_by(:name) # clicks the header; an unsorted column sorts :desc first +table.sort_by(:name, :asc) # clicks until the column shows :asc +expect(table).to have_sort(:name, :asc) # also sorted_by?(:name, :asc) +expect(table).to have_no_sort(:email) +table.sort_direction(:id) # => :desc, without waiting ``` -The first click on an unsorted column sorts descending. +#### Status tags + +A row of an index table or an attributes table finds the `status_tag` in a cell. `status:` compares the tag's `data-status`, and `type:` is an alias of it; passing both raises `ArgumentError`. A String label is the whole text, ignoring case; a Regexp matches part of it. -The section defaults to `table.index_table`. Pass a locator for another table, such as a `table_for` inside a panel: `section :orders, ActiveAdminPageObjects::Table, "#orders_panel table"`. +```ruby +row = index.table.row(customer.id) +expect(row).to have_status_tag(:status, "Pending", status: :pending) +expect(row).to have_no_status_tag(:status, status: :failed) +row.status_tag(:status).status # => "pending" +row.status_tags(:flags).map(&:label) +expect(show.attributes_table).to have_status_tag(:active, status: true) # true is "yes", false is "no" +``` ### Attributes table -Rows are keyed by the `row :foo` symbol, or by the label parameterized with `_`. +Rows are keyed by the `row :foo` symbol, or by the label parameterized with `_`. As in the index table, a String `text:` or `exact_text:` ignores case. ```ruby table = show.attributes_table @@ -205,36 +189,6 @@ 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.status_tag(:status) # see Status tags -``` - -### Status tags - -An index row and the attributes table of a show page match the status tag of a cell by its label and, with `type:`, its CSS classes: - -```ruby -expect(index.table.row(customer.id)).to have_status_tag(:status, "Pending") -expect(show.attributes_table).to have_status_tag(:status, "Pending", type: "pending") -expect(show.attributes_table).to have_no_status_tag(:status, "Active") -``` - -`status_tag(key)` returns the `StatusTag`: - -```ruby -tag = show.attributes_table.status_tag(:status) -tag.label # => "Pending" -tag.type # => "pending", or "ok warning" for several classes -expect(tag).to have_type("pending") -expect(tag).to have_label("pending") -``` - -`label` returns the DOM text. ActiveAdmin 3's CSS uppercases it on screen. The matchers ignore the case of the label. - -A cell may hold several status tags. `have_status_tag` passes when any of them matches, and `have_no_status_tag` when none does. `status_tag(key)` raises `Capybara::Ambiguous` for such a cell: use `status_tags(key)`. - -```ruby -expect(row).to have_status_tag(:flags, "Archived", type: "warning") -row.status_tags(:flags).map(&:label) # => ["Draft", "Archived"] ``` ### Panel @@ -252,37 +206,35 @@ expect(show.notes.body).to have_text("Pays late") show.notes.links # => [{ text: "Invoices", href: "/admin/invoices?customer=1" }] ``` -A sidebar section works the same way, with `ActiveAdminPageObjects::Sidebar` and the `:active_admin_sidebar` selector: `section :help, ActiveAdminPageObjects::Sidebar, :active_admin_sidebar, "Help"`. - `links` lists the links of the body, each with its text and its `href` attribute as the page wrote it, on every driver. -A String title is the whole title, ignoring case. For a title with a changing part, such as "Possible Routes (2)", pass a Regexp, which is case-sensitive unless it has `/i`. It works for `page.panel`, `page.sidebar` and both selectors: +A String title is the whole title, ignoring case. For a title with a changing part, such as "Possible Routes (2)", pass a Regexp, which is case-sensitive unless it has `/i`. It works for `page.panel` and the `:active_admin_panel` selector: ```ruby section :routes, ActiveAdminPageObjects::Panel, :active_admin_panel, /\APossible Routes \(\d+\)\z/ show.panel(/\APossible Routes/).title # => "Possible Routes (2)" -show.sidebar(/\AVersions/) ``` +A panel nested in another panel's body is found by its own title, and the outer panel's `title` and `body` are its own. + ### Comments -```ruby -class CustomerShow < ActiveAdminPageObjects::Page - set_url "/admin/customers/{id}" +Declare the comments of a show page; ActiveAdmin renders them when the resource has `config.comments = true`. A custom `show` block must call `active_admin_comments_for(resource)`. - section :comments, ActiveAdminPageObjects::Comments -end +```ruby +section :comments, ActiveAdminPageObjects::Comments -comments = show.comments -comments.add("Called back") -expect(comments).to have_comment("Called back") -comments.count # => 1, from the "Comments (1)" title -comments.bodies # => ["Called back"] -comments.authors # => ["admin@example.com"] -comments.delete("Called back") # accepts the browser confirmation +show.comments.count # from the "All Comments (N)" title +show.comments.bodies +show.comments.authors +expect(show.comments).to have_comment("Called the customer") +show.comments.add("Called the customer") +show.comments.delete("Called the customer") # accepts the browser confirm ``` +The base `form` selector leaves the comment form out. + ### Filters `filter(key)` returns the section typed by the filter input: `StringFilter`, `NumericFilter`, `SelectFilter`, `BooleanFilter` or `DateRangeFilter`. The key is the one given to `filter :key`; the section wraps `#q__input`. Filters that [declare their filters](#declared-labels) take the declared name. A filter whose key holds its predicate, such as `filter :uuid_eq`, has a bare input and no predicate select: `fill_in(with:)` and `have_value` work, and a `predicate:` raises. @@ -295,7 +247,7 @@ filters.filter(:status).select_option("Active") filters.filter(:active).set(true) # false, or nil for "Any" filters.filter(:created_at).set("2026-01-01", Date.new(2026, 1, 31)) filters.submit -filters.clear # needs a JavaScript driver +filters.clear expect(filters.filter(:name)).to have_value("Acme", predicate: "Equals") expect(filters.filter(:status)).to have_selected("Active") @@ -303,7 +255,7 @@ expect(filters.filter(:active)).to have_value(true) expect(filters.filter(:created_at)).to have_range("2026-01-01", "2026-01-31") ``` -`DateRangeFilter` types the dates into the two inputs. It does not use the jQuery UI datepicker. `set` takes Date objects or ISO strings; `nil` or `""` clears that end. +`DateRangeFilter#set` takes Date objects or ISO strings; `nil` or `""` clears that end. Declare one filter directly when a page uses it often: @@ -362,29 +314,15 @@ Under `rack_test`, `click` loads the file: read it from `page.body`. A JavaScrip ### Batch actions -Actions are found by label (`"Delete Selected"`) or by name (`:destroy`). `apply(label, inputs = {})` opens the menu and clicks the action. An action with `confirm:` or `form:` opens ActiveAdmin's modal dialog: `apply` sets each of `inputs` by field name and clicks OK. +Actions are found by label (`"Delete Selected"`) or by name (`:destroy`). `apply` opens the menu, clicks the action, and accepts its confirmation. ```ruby index.table.row(customer.id).select index.batch_actions.select_all index.batch_actions.apply(:destroy) -index.batch_actions.apply("Set Status Selected", status: "pending") expect(index.batch_actions).to have_action("Flag Selected") ``` -### Modal dialog - -`page.modal_dialog` is the dialog ActiveAdmin opens for batch actions. Use it to drive the dialog yourself, for example to cancel: - -```ruby -dialog = index.modal_dialog -dialog.title # => "Are you sure you want to do this?" -dialog.fill("status", with: "pending") # input or select, by field name -expect(dialog).to have_field("status") -dialog.confirm # or dialog.cancel -expect(index).to have_no_modal_dialog -``` - ### Form Fields are named by attribute, as in `f.input :email`. A form that [declares its fields](#declared-labels) takes the declared names. @@ -403,7 +341,7 @@ form.submit - `Form::BooleanField` for `boolean`: `fill(true)` ticks the checkbox and `fill(false)` unticks it. `checked?`. - `Form::RadioField` for `radio`: `fill` picks the radio button with that label. `options` and `selected`. - `Form::CheckBoxesField` for `check_boxes`: `fill` takes an array of labels, ticks them and unticks the others. `check(*labels)`, `uncheck(*labels)` and `checked`. -- `Form::DatePickerField` for `datepicker`: `fill` takes a Date or a string and types it in. It does not use the jQuery UI datepicker. +- `Form::DatePickerField` for `date_picker`, a native ``: `fill` takes a Date or a string such as `"2026-01-31"`. - `Form::FileField` for `file`: `fill` takes the path of the file and attaches it. A JavaScript driver needs an absolute path. - `Form::Field` for any other class: `fill` types text, picks a select option or ticks a checkbox, by what the wrapper holds. @@ -431,7 +369,31 @@ form.field(:code).disabled? # => true, without waiting - A field is disabled when every control in it is: the input, the select, or each radio button or checkbox of a field with choices. It is enabled when a control is not disabled. Hidden inputs do not count. - `have_no_disabled_field` and `have_no_enabled_field` also pass when the form has no such field. -- The matchers wait, and take `visible:` like `field`. A has_many fieldset has them too. +- The matchers wait, and take `visible:` like `field`. + +#### has_many + +Declare a has_many block with its heading and the fields of one fieldset, then reach it with `form.has_many`: + +```ruby +section :form, ActiveAdminPageObjects::Form do + field :reference, "Reference", ActiveAdminPageObjects::Form::StringField + has_many :line_items, "Line Items" do + field :sku, "Sku", ActiveAdminPageObjects::Form::StringField + end +end + +items = form_page.form.has_many(:line_items) +items.heading # => "Line Items" +items.count # number of fieldsets +items.add.fill(sku: "SKU-1") # clicks the add link +items.fieldset(0).field(:sku).value +items.remove(0) # the remove link of a new fieldset, the delete checkbox of a saved one +items.fieldset(0).marked_for_destroy? +expect(items).to have_fieldsets(count: 2) +``` + +A fieldset has the form's field API. `have_exact_fields` counts a has_many block once, as its declared element, and skips its inner inputs; ask each fieldset for its own. The destroy checkbox is not a field, and asking for a has_many name as a field raises `ArgumentError`. #### Form errors @@ -450,47 +412,14 @@ expect(form).to have_exact_semantic_errors("Name is reserved", "Balance is negat form.semantic_errors # => ["Name is reserved", "Balance is negative"] ``` -- `have_field_errors` and `have_no_field_errors` look at the whole form, has_many fieldsets included. -- `have_exact_field_errors` takes each field with its message, or an array of messages. Every one of these fields shows exactly these messages, and no other field shows an error. Without arguments it passes when no field shows an error. It leaves out the fields of has_many fieldsets: ask each fieldset. Its keywords are field names, so it takes no Capybara options and no `visible:`. See [Hidden elements](#hidden-elements). +- `have_field_errors` and `have_no_field_errors` look at the whole form. +- `have_exact_field_errors` takes each field with its message, or an array of messages. Every one of these fields shows exactly these messages, and no other field shows an error. Without arguments it passes when no field shows an error. Its keywords are field names, so it takes no Capybara options and no `visible:`. See [Hidden elements](#hidden-elements). - `have_exact_semantic_errors` compares the base errors exactly and case-sensitively: the same messages, in any order. `strict_order: true` compares the order too. Without messages it passes when the form shows no base error. - `have_no_exact_field_errors` and `have_no_exact_semantic_errors` wait until the errors differ. -### Has many - -`form.has_many(association)` returns a `HasMany` for a `has_many` block. Fieldsets are 0-based. A fieldset has the field methods of the form: `field`, `fill` and the field error matchers. - -```ruby -orders = form.has_many(:orders) -orders.heading # => "Orders" -orders.count # => 2 -expect(orders).to have_fieldsets(count: 2) - -fieldset = orders.add # clicks the add link, returns the new fieldset -fieldset.fill(reference: "REF-NEW", state: "shipped") -orders.fieldset(0).field(:quantity).value # => "2" -expect(orders.fieldset(0)).to have_exact_field_errors(quantity: "must be greater than 0") -orders.remove(2) # a new fieldset: its remove link -orders.remove(0) # a saved one: ticks its delete checkbox -expect(orders.fieldset(0)).to be_marked_for_destroy -``` - -Declare the block on the form to declare the fields of its fieldsets: see [Declared has_many blocks](#declared-has_many-blocks). - ### Tabs -```ruby -class CustomerShow < ActiveAdminPageObjects::Page - section :tabs, ActiveAdminPageObjects::Tabs -end - -show.tabs.labels # => ["Overview", "Orders"] -show.tabs.switch("Orders") -show.tabs.current # => "Orders", or nil before jQuery UI sets the tabs up -expect(show.tabs.body).to have_text("Order list") -expect(show.tabs).to have_tab("Orders") -``` - -A String is the whole label, ignoring case. `switch`, `have_tab` and `have_no_tab` also take a Regexp, case-sensitive unless it has `/i`, for a label with a changing part: `show.tabs.switch(/\AOrders \(\d+\)\z/)`. +ActiveAdmin 4 removed the `tabs` component. `ActiveAdminPageObjects::Tabs` raises `RemovedInActiveAdmin4`. A theme that brings tabs back registers a `tabs` selector and patches the section. ## Declared labels @@ -544,14 +473,14 @@ SitePrism 5 and 6 turn the block into a subclass of the section class. A named s ### Declarations define no methods -A declaration defines no method on the section, so any name is valid, including `name` and `title`. Reach an element with `filter(name)`, `field(name)` or `has_many(name)`: +A declaration defines no method on the section, so any name is valid, including `name` and `title`. Reach an element with `filter(name)` or `field(name)`: ```ruby index.filters.filter(:balance).fill_in(with: 100, predicate: :gt) form_page.form.field(:status).fill("pending") ``` -The name is the formtastic attribute or the ActiveAdmin filter key, and the only key: `field :id, "Gateway", ActiveAdminPageObjects::Form::SelectField` is reached with `field(:id)`, `has_field_error?(:id)` and `fill(id: ...)`. A subclass can declare an inherited name again. +The name is the formtastic attribute or the ActiveAdmin filter key, and the only key: `field :name, "Name", ActiveAdminPageObjects::Form::StringField` is reached with `field(:name)`, `has_field_error?(:name)` and `fill(name: ...)`. A subclass can declare an inherited name again. For shortcuts, write your own methods in the section block. @@ -560,12 +489,12 @@ For shortcuts, write your own methods in the section block. `filters.filter(name)` and `form.field(name)` return an instance of the declared class. To use your own field or filter class, declare it. It is a subclass of the gem's class for that input: ```ruby -class Select2Field < ActiveAdminPageObjects::Form::SelectField +class MySelectField < ActiveAdminPageObjects::Form::SelectField # drives the widget: see Hidden selects below end section :form, ActiveAdminPageObjects::Form do - field :id, "Gateway", Select2Field + field :status, "Status", MySelectField end ``` @@ -577,16 +506,16 @@ The gem detects its classes by the formtastic class of the wrapper, and returns ### Hidden selects -`SelectFilter`, `BooleanFilter`, `Form::SelectField`, `Form::Field` and the predicate select of `StringFilter` and `NumericFilter` find the native `` as Capybara finds elements by default, and leave out a select marked `aria-hidden="true"`. When it is hidden or marked so, as a JavaScript select widget leaves it, picking and reading raise `Capybara::ElementNotFound`: `select_option`, `fill`, `selected`, `options`, `have_selected`, `have_option`, `have_item`, `have_disabled` and their `have_no_` forms. A page object that declares `SelectFilter` on a widget fails, and does not drive the select behind the widget. For a widget, declare your own class. Override the method that picks, to drive the widget, and the private `native_select_visibility`, to read the select the widget hides: ```ruby -class Select2Filter < ActiveAdminPageObjects::SelectFilter +class MySelectFilter < ActiveAdminPageObjects::SelectFilter def select_option(label) - find(".select2-selection").click - # select2 appends the dropdown to , outside the filter. - root_element.session.find(".select2-results__option", exact_text: label).click + find(".my-widget-toggle").click + # the widget may append its dropdown to , outside the filter + root_element.session.find(".my-widget-option", exact_text: label).click end private @@ -597,7 +526,7 @@ class Select2Filter < ActiveAdminPageObjects::SelectFilter end section :filters, ActiveAdminPageObjects::Filters do - filter :customer, "Customer", Select2Filter + filter :customer, "Customer", MySelectFilter end filters.filter(:customer).select_option("Acme") # clicks the widget @@ -605,43 +534,16 @@ expect(filters.filter(:customer)).to have_selected("Acme") # reads the hidden `: `:all`, `:hidden`, `:visible`, `true` or `false`. The default is `nil`: no `visible:`, so `Capybara.ignore_hidden_elements` decides. -- A lookup of visible elements also leaves out a select marked `aria-hidden="true"`, on every driver. select2 clips its select to one pixel, which Cuprite reports as visible, and marks it `aria-hidden`. `:all` takes that select too. +- A lookup of visible elements also leaves out a select marked `aria-hidden="true"`, on every driver. A widget may clip its select to one pixel, which Cuprite reports as visible, and mark it `aria-hidden`. `:all` takes that select too. - With `:all` the inherited methods pick from the hidden select and read it. Override the ones that have to go through the widget. - A `Form::SelectField` subclass overrides `fill` the same way. -### Declared has_many blocks - -`has_many(name, heading, &block)` declares a `has_many` block of a form. `form.has_many(:gateways)` returns the `HasMany`. The block declares the fields of a fieldset, by the same rules. - -```ruby -section :form, ActiveAdminPageObjects::Form do - field :email, "Email", ActiveAdminPageObjects::Form::StringField - has_many :gateways, "Gateways" do - field :id, "Gateway", ActiveAdminPageObjects::Form::SelectField - end - - def add_gateway(name) = has_many(:gateways).add.field(:id).fill(name) -end - -form.has_many(:gateways).add.field(:id) # the SelectField of the new fieldset -form.has_many(:gateways).fieldset(0).field(:id).selected -expect(form.has_many(:gateways)).to have_fieldsets(count: 2) -expect(form.has_many(:gateways).fieldsets).to all(have_exact_fields) -``` - -`fieldsets` reads the page once, and `all` passes on an empty list, so check the count first. - -- `heading` is the text of the block's `h3`. The form's label matchers compare it. Pass `nil` when the form uses `heading: false`. -- `name` is the association. -- A form that declares has_many blocks raises `ArgumentError` from `has_many(association)` for any other association. - ### Label matchers `have_declared_columns`, `have_declared_filters`, `have_declared_rows` and `have_declared_fields` pass when every declared element is on the page with exactly its label. The comparison is exact and case-sensitive, so `"External id"` does not match `"External ID"`. Only whitespace is normalized. -- CSS `text-transform` does not change the result, on any driver. +- CSS `text-transform` does not change the result, on any driver. ActiveAdmin 4 uppercases the `th` of both tables in CSS; declare the label as the DOM has it, such as `"External ID"`. - In filter and form labels, the text of links, buttons and `abbr` elements is not part of the label. That drops the required marker (`*`) and controls that plugins append, such as the date range preset's "Set range" link. -- `have_declared_fields` on a form also compares the headings of the declared has_many blocks. The fields of a fieldset are compared on the fieldset. - The order is not checked. Elements that are on the page but not declared are ignored: the exact matchers catch those. - They wait like the other matchers. `have_no_declared_columns` and the other three wait until a label differs. - They raise `ArgumentError` on a section that declares nothing. @@ -650,11 +552,12 @@ expect(form.has_many(:gateways).fieldsets).to all(have_exact_fields) `have_exact_columns`, `have_exact_filters`, `have_exact_rows` and `have_exact_fields` pass when the label matcher passes and the page has no other element of that kind: -- Rows: the `tr.row-*` of the attributes table. -- Columns: the `th.col-*` of the table, the untitled selection and actions columns included. +- Rows: the `tr[data-row]` of the attributes table. +- Columns: the `th[data-column]` of the table, and the untitled selection and actions columns. - Filters: the filter wrappers of the filter form. -- Form fields: the input wrappers outside the has_many blocks, and each has_many block. `as: :hidden` inputs are not fields. -- Fieldset fields: the input wrappers of the fieldset. The delete checkbox and a has_many block nested in the fieldset are left out. +- Form fields: the input wrappers of the form. `as: :hidden` inputs are not fields. + +ActiveAdmin 4 writes no `data-column` on an untitled column. The selection column is the one whose header holds the toggle-all checkbox, and the actions column is the one whose cells hold the row actions. Any other untitled column has no key, so the matchers leave it out. Only visible elements count: see [Hidden elements](#hidden-elements). @@ -675,13 +578,12 @@ expect(form_page.form).to have_declared_fields(only: %i[email status]) ### Hidden elements -Lookups and matchers see only visible elements, as Capybara does by default. A hidden field, filter, row, column or has_many block is not found. The label matchers report it as missing, and the exact matchers do not count it as unexpected. +Lookups and matchers see only visible elements, as Capybara does by default. A hidden field, filter, row or column is not found. The label matchers report it as missing, and the exact matchers do not count it as unexpected. Pass `visible: :all` to a call to take hidden elements too: ```ruby form.field(:notes, visible: :all) -form.has_many(:orders, visible: :all) filters.filter(:email, visible: :all) show.attributes_table.row(:email, visible: :all) show.attributes_table.value(:email, visible: :all) @@ -703,7 +605,7 @@ form.field(:notes) # found when it is hidden too expect(form).to have_exact_fields # passes with the notes field hidden or shown ``` -- `row`, `column`, `filter`, `field` and `has_many` take `visible:`. Every lookup and matcher then finds that element with it. +- `row`, `column`, `filter` and `field` take `visible:`. Every lookup and matcher then finds that element with it. - `visible:` on a call overrides the declaration: `form.field(:notes, visible: :visible)`. It takes Capybara's values: `:all`, `:hidden`, `:visible`, `true` and `false`. - On a matcher, `visible:` applies to every element: the declared ones and the ones that are not declared. - `have_exact_field_errors` has no `visible:` option, because its keywords are field names. It counts the errors of the visible fields and of the fields declared with `visible:`. @@ -741,7 +643,7 @@ expected exactly the declared rows (except: notes), but: - `not_to have_exact_rows` calls `has_no_exact_rows?`, so it waits for the page to differ. - On an object that declares nothing, each one is RSpec's predicate matcher. -The module also defines `have_exact_field_errors`, `have_exact_semantic_errors` and their `have_no_` forms, for a form and for a has_many fieldset: +The module also defines `have_exact_field_errors`, `have_exact_semantic_errors` and their `have_no_` forms, for a form: ```ruby expect(form).to have_exact_field_errors(name: "is reserved", notes: "is too long") @@ -783,20 +685,20 @@ index.table.exact_mismatches ### Strict names -A section that declares anything raises `ArgumentError` for every other name, before it queries the page. `Form#has_many` is the exception: it checks the name only when the form declares has_many blocks. The message gives the name and lists the declared ones. A section without declarations takes any key, as before. +A section that declares anything raises `ArgumentError` for every other name, before it queries the page. The message gives the name and lists the declared ones. A section without declarations takes any key, as before. -- `AttributesTable`: `has_row?`, `has_no_row?`, `row`, `value`, `status_tag`, `status_tags`, `has_status_tag?` and `has_no_status_tag?`. -- `Table`: `sort_by` and `has_sortable_column?`. Its rows: `cell`, `has_cell?`, `has_no_cell?`, `status_tag`, `status_tags`, `has_status_tag?` and `has_no_status_tag?`. +- `AttributesTable`: `has_row?`, `has_no_row?`, `row` and `value`. +- `Table`: its rows' `cell`, `has_cell?` and `has_no_cell?`. - `Filters`: `filter`. -- `Form` and the fieldsets of a declared has_many: `field`, `fill`, `has_field_error?`, `has_no_field_error?`, `has_exact_field_errors?`, `has_no_exact_field_errors?`, `has_disabled_field?`, `has_enabled_field?` and their `has_no_` forms. +- `Form`: `field`, `fill`, `has_field_error?`, `has_no_field_error?`, `has_exact_field_errors?`, `has_no_exact_field_errors?`, `has_disabled_field?`, `has_enabled_field?` and their `has_no_` forms. -Filters and fields take the declared name: `form.field(:id)` and `have_field_error(:id)`. +Filters and fields take the declared name: `form.field(:name)` and `have_field_error(:name)`. Names compare as everywhere else: `:external_id`, `"external_id"` and `"External ID"` are the same name. ## Matchers shared with capybara_active_admin -[capybara_active_admin](https://github.com/activeadmin-plugins/capybara_active_admin) defines RSpec matchers for Capybara's `page`, such as `have_page_title`, `have_table` and `have_status_tag`. In an example group that includes them, they replace the predicate matchers of the page objects: `expect(index).to have_page_title(text: "Customers")` calls the matcher of that gem. +[capybara_active_admin](https://github.com/activeadmin-plugins/capybara_active_admin) defines RSpec matchers for Capybara's `page`, such as `have_page_title`, `have_table` and `have_semantic_errors`. In an example group that includes them, they replace the predicate matchers of the page objects: `expect(index).to have_page_title(text: "Customers")` calls the matcher of that gem. `ActiveAdminPageObjects::RSpec::Matchers` defines the same names for both. Include it after capybara_active_admin's matchers, so it takes precedence. The module also gives the label and exact matchers their [failure messages](#failure-messages). @@ -819,16 +721,13 @@ It covers the matchers of capybara_active_admin 1.0.0: `have_action_item`, `have These need a JavaScript driver such as Cuprite or Selenium: -- `BatchActions#apply` and `ModalDialog`: ActiveAdmin's JavaScript opens the menu and the dialog and submits the form. -- `Filters#clear` and `FiltersFooter#clear`: the "Clear Filters" link is `href="#"`. -- `Tabs#switch` and `Tabs#current`: jQuery UI switches the tabs. Without JavaScript every tab body is shown. -- `DropdownMenu#open` and `#click`: the button toggles the menu. Without JavaScript the list is always shown. -- `HasMany#add` and `#remove`: the JavaScript adds and removes the fieldsets. -- `Comments#delete`: the link asks the browser to confirm. +- `BatchActions#apply`: ActiveAdmin's JavaScript opens the menu and submits the form. - `StringFilter#fill_in` and `NumericFilter#fill_in` with a predicate other than the selected one: the JavaScript renames the input when the predicate changes. - `Form::Field#force_fill`: it sets the value with a script. +- `HasMany#add` and `#remove` on a new fieldset: ActiveAdmin's JavaScript adds and removes the fieldset. +- `Comments#delete`: it accepts the browser confirm. -Everything else works with `rack_test` too, including `MainMenu#go` and `MainMenu#click` (without hovering), filters with the current predicate, plain selects, date ranges, scopes, pagination, sorting and forms. +Everything else works with `rack_test` too, including `MainMenu#go` and `MainMenu#click`, filters with the current predicate, plain selects, date ranges, scopes, pagination and forms. ## Selectors @@ -861,7 +760,7 @@ class AuditPanel < ActiveAdminPageObjects::Section end ``` -`register_selectors` also replaces a key of the gem, for example a theme's own `main_menu`. +`register_selectors` can also replace a key that ActiveAdmin 4 removed, such as `tabs`. Add a section or an element to every page that includes `Layout`, including page classes defined earlier: @@ -870,7 +769,7 @@ ActiveAdminPageObjects::Layout.add_section(:audit_panel, AuditPanel) ActiveAdminPageObjects::Layout.add_element(:banner, ".banner") ``` -To use your own field or filter class, declare it on the section: `field :id, "Gateway", Select2Field`. It is a subclass of the gem's class for that input, or of `ActiveAdminPageObjects::Form::Field` or `ActiveAdminPageObjects::Filter` for an input class the gem has no class for. See [Declared types](#declared-types). +To use your own field or filter class, declare it on the section: `field :status, "Status", MySelectField`. It is a subclass of the gem's class for that input, or of `ActiveAdminPageObjects::Form::Field` or `ActiveAdminPageObjects::Filter` for an input class the gem has no class for. See [Declared types](#declared-types). ### Registered input classes @@ -914,7 +813,7 @@ A theme or plugin ships its own page objects in its own repository, with one ent ```ruby # lib/my_plugin/page_objects.rb require "active_admin_page_objects" -ActiveAdminPageObjects.check_version!(">= 1.0.0.a", "< 2.0.0.a", plugin: "my_plugin") +ActiveAdminPageObjects.check_version!(">= 2.0.0.a", "< 3.0.0.a", plugin: "my_plugin") module MyPlugin class Widget < ActiveAdminPageObjects::Section @@ -931,12 +830,11 @@ Apps load it with `require "my_plugin/page_objects"`. ```sh bundle install -bundle exec rspec +bundle exec rake # builds the dummy app's CSS (npm), runs rubocop and rspec BUNDLE_GEMFILE=gemfiles/site_prism_5.gemfile bundle exec rspec -bundle exec rubocop ``` -The specs drive a Rails 8 dummy app with ActiveAdmin 3.5.2 (`spec/dummy`) through headless Chrome with Cuprite. The dummy app uses sprockets and dartsass-sprockets, so it needs no Node. +The specs drive a Rails 8 dummy app with ActiveAdmin 4 (`spec/dummy`) through headless Chrome with Cuprite. ## License diff --git a/Rakefile b/Rakefile index 971d985..0a4f859 100644 --- a/Rakefile +++ b/Rakefile @@ -7,4 +7,13 @@ require "rubocop/rake_task" RSpec::Core::RakeTask.new(:spec) RuboCop::RakeTask.new +desc "Build the dummy app's Tailwind CSS with the npm CLI" +task :assets do + Dir.chdir("spec/dummy") do + sh "npm #{ENV['CI'] ? 'ci' : 'install'} --no-audit --no-fund" unless Dir.exist?("node_modules") + sh "npm run build" + end +end + +task spec: :assets task default: %i[rubocop spec] diff --git a/active_admin_page_objects.gemspec b/active_admin_page_objects.gemspec index d53590e..254b1df 100644 --- a/active_admin_page_objects.gemspec +++ b/active_admin_page_objects.gemspec @@ -9,7 +9,7 @@ Gem::Specification.new do |spec| spec.email = ["senid231@gmail.com"] spec.summary = "A Page Object Model DSL for Capybara of ActiveAdmin, built on SitePrism." - spec.description = "SitePrism pages and sections for vanilla ActiveAdmin 3's layout, index tables, filters, " \ + spec.description = "SitePrism pages and sections for vanilla ActiveAdmin 4's layout, index tables, filters, " \ "scopes, batch actions, show pages and forms, so system specs call semantic methods " \ "instead of CSS selectors." spec.homepage = "https://github.com/activeadmin-plugins/active_admin_page_objects" @@ -18,15 +18,13 @@ Gem::Specification.new do |spec| spec.metadata["homepage_uri"] = spec.homepage spec.metadata["source_code_uri"] = spec.homepage - spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/1-x-stable/CHANGELOG.md" + spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/main/CHANGELOG.md" spec.metadata["rubygems_mfa_required"] = "true" spec.files = Dir["lib/**/*.rb", "README.md", "CHANGELOG.md", "LICENSE"] spec.require_paths = ["lib"] - # CI resolves activeadmin 3.5.2, capybara 3.40 and site_prism 5.2 and 6.0. - # Lower versions inside these ranges are not tested. - spec.add_dependency "activeadmin", ">= 3.0", "< 4.0.0.a" + spec.add_dependency "activeadmin", ">= 4.0.0.beta23", "< 5.0.0.a" spec.add_dependency "capybara", ">= 3.37" spec.add_dependency "site_prism", ">= 5.0", "< 7" end diff --git a/lib/active_admin_page_objects.rb b/lib/active_admin_page_objects.rb index be57837..95f4ecb 100644 --- a/lib/active_admin_page_objects.rb +++ b/lib/active_admin_page_objects.rb @@ -14,37 +14,13 @@ module ActiveAdminPageObjects extend Text # Raises unless the loaded gem satisfies +requirements+. Plugins call it when - # their page objects load, e.g. `check_version!(">= 1.0.0.a", "< 2.0.0.a", plugin: "my_plugin")`. + # their page objects load, e.g. `check_version!(">= 2.0.0.a", "< 3.0.0.a", plugin: "my_plugin")`. def self.check_version!(*requirements, plugin:) return if Gem::Requirement.new(*requirements).satisfied_by?(Gem::Version.new(VERSION)) raise IncompatibleVersion, "#{plugin} page objects need active_admin_page_objects #{requirements.join(', ')}, but #{VERSION} is loaded" end - - # Adds the Capybara selector +name+ for the containers of +container_key+ - # whose heading, found with +title_key+, matches the locator. - def self.add_titled_selector(name, container_key, title_key) - Capybara.add_selector(name) do - css { |_title| ActiveAdminPageObjects.selector(container_key) } - locator_filter do |node, title| - next true if title.nil? - - # The first heading is the container's own; later ones belong to its body. - heading = node.first(:css, ActiveAdminPageObjects.selector(title_key), visible: :all, minimum: 0, wait: false) - !heading.nil? && ActiveAdminPageObjects.text_match?(heading.text(:all), title) - end - end - end - private_class_method :add_titled_selector - - # `find(:active_admin_panel, "Notes")` finds the panel whose title is - # "Notes", ignoring case and surrounding whitespace. A Regexp title matches - # the title text instead: `find(:active_admin_panel, /\ARoutes \(\d+\)\z/)`. - # `:active_admin_sidebar` does the same for sidebar sections, which - # `:active_admin_panel` leaves out. - add_titled_selector(:active_admin_panel, :panel, :panel_title) - add_titled_selector(:active_admin_sidebar, :sidebar_section, :sidebar_title) end # `find(:active_admin, :table)` resolves the CSS when the query runs, so @@ -53,18 +29,23 @@ def self.add_titled_selector(name, container_key, title_key) css { |key| ActiveAdminPageObjects.selector(key) } end +# `find(:active_admin_panel, "Notes")` finds the panel whose title is "Notes", +# ignoring case and surrounding whitespace. A Regexp title matches the title +# text instead: `find(:active_admin_panel, /\ARoutes \(\d+\)\z/)`. +Capybara.add_selector(:active_admin_panel) do + css { |_title| ActiveAdminPageObjects.selector(:panel) } + locator_filter do |node, title| + next true if title.nil? + + # The panel's own title comes before the titles of panels nested in its body. + own = node.first(:css, ActiveAdminPageObjects.selector(:panel_title), visible: :all, minimum: 0, wait: false) + own && ActiveAdminPageObjects.text_match?(own.text(:all), title) + end +end + require_relative "active_admin_page_objects/section" require_relative "active_admin_page_objects/declarations" require_relative "active_admin_page_objects/select_control" -require_relative "active_admin_page_objects/status_tag" -require_relative "active_admin_page_objects/panel" -require_relative "active_admin_page_objects/sidebar" -require_relative "active_admin_page_objects/modal_dialog" -require_relative "active_admin_page_objects/fields" -require_relative "active_admin_page_objects/has_many" -require_relative "active_admin_page_objects/comments" -require_relative "active_admin_page_objects/utility_navigation" -require_relative "active_admin_page_objects/dropdown_menu" require_relative "active_admin_page_objects/breadcrumbs" require_relative "active_admin_page_objects/action_items" require_relative "active_admin_page_objects/flashes" @@ -74,11 +55,16 @@ def self.add_titled_selector(name, container_key, title_key) require_relative "active_admin_page_objects/table/rows_by_cell" require_relative "active_admin_page_objects/table" require_relative "active_admin_page_objects/attributes_table" +require_relative "active_admin_page_objects/status_tag" +require_relative "active_admin_page_objects/panel" +require_relative "active_admin_page_objects/comments" require_relative "active_admin_page_objects/filters" require_relative "active_admin_page_objects/filters_footer" require_relative "active_admin_page_objects/scopes" require_relative "active_admin_page_objects/pagination" require_relative "active_admin_page_objects/download_links" require_relative "active_admin_page_objects/batch_actions" +require_relative "active_admin_page_objects/fields" require_relative "active_admin_page_objects/form" +require_relative "active_admin_page_objects/has_many" require_relative "active_admin_page_objects/tabs" diff --git a/lib/active_admin_page_objects/action_items.rb b/lib/active_admin_page_objects/action_items.rb index 99fa87c..26a2530 100644 --- a/lib/active_admin_page_objects/action_items.rb +++ b/lib/active_admin_page_objects/action_items.rb @@ -1,8 +1,7 @@ # frozen_string_literal: true module ActiveAdminPageObjects - # The action items (buttons and links) right of the page title. The button - # of a `dropdown_menu` is an item too; #dropdown reaches the menu's own items. + # The action items (buttons and links) right of the page title. class ActionItems < Section selector_key :action_items @@ -29,23 +28,14 @@ def has_no_item?(label, **options) eventually(**options) { find_item(label).nil? } end - # The dropdown menu whose button is labelled +label+ (case-insensitive), - # or the only one when +label+ is nil. - # @return [DropdownMenu] - def dropdown(label = nil) - DropdownMenu.new(self, label.nil? ? find(:active_admin, :action_item_dropdown) : dropdown_node(label)) + # The action-item dropdown of ActiveAdmin 3. + # @raise [RemovedInActiveAdmin4] on ActiveAdmin 4 + def dropdown(*) + find(:active_admin, :action_item_dropdown) end private - def dropdown_node(label) - root_element.synchronize do - all(:active_admin, :action_item_dropdown, wait: false).find do |menu| - same_text?(menu.find(:active_admin, :dropdown_menu_button, wait: false).text, label) - end || raise(Capybara::ElementNotFound, "no action item dropdown #{label.inspect}") - end - end - def item(label) find_item(label) || raise(Capybara::ElementNotFound, "no action item #{label.inspect} in #{labels.inspect}") end diff --git a/lib/active_admin_page_objects/attributes_table.rb b/lib/active_admin_page_objects/attributes_table.rb index 5dc4f7d..26ec518 100644 --- a/lib/active_admin_page_objects/attributes_table.rb +++ b/lib/active_admin_page_objects/attributes_table.rb @@ -9,12 +9,8 @@ module ActiveAdminPageObjects # row :name, "Name" # row :external_id, "External ID" # end - # - # `status_tag(:status)`, `status_tags(:status)` and `has_status_tag?` read - # the value cell of a row: see StatusTag::Matchers. class AttributesTable < Section include Declarations - include StatusTag::Matchers selector_key :attributes_table @@ -26,14 +22,15 @@ def row(key, label, visible: nil) end end - # True when row +key+ has a value cell matching the Capybara options. + # True when row +key+ has a value cell matching the Capybara options. A + # String `text:` or `exact_text:` ignores case. def has_row?(key, **options) - has_css?(cell_selector(key), **visibility_of(key), **options) + has_css?(cell_selector(key), **visibility_of(key), **case_insensitive_text(options)) end # Waits until row +key+ has no value cell matching the Capybara options. def has_no_row?(key, **options) - has_no_css?(cell_selector(key), **visibility_of(key), **options) + has_no_css?(cell_selector(key), **visibility_of(key), **case_insensitive_text(options)) end # The `` of row +key+. A hidden row is found with `visible: :all`. @@ -67,8 +64,9 @@ def declared_label_text(key, _declaration, **visibility) label_text("#{sel(:attributes_table_row, key)} > th", **visibility) end + # A row without a title has no `data-row` and no key. def page_element_keys(**visibility) - all(:css, sel(:attributes_table_rows), wait: false, **visibility).filter_map { |row| class_key(row, "row-") } + all(:css, sel(:attributes_table_rows), wait: false, **visibility).map { |row| row[:"data-row"].to_s } end end end diff --git a/lib/active_admin_page_objects/batch_actions.rb b/lib/active_admin_page_objects/batch_actions.rb index 0f938b8..3814b05 100644 --- a/lib/active_admin_page_objects/batch_actions.rb +++ b/lib/active_admin_page_objects/batch_actions.rb @@ -2,8 +2,7 @@ module ActiveAdminPageObjects # The batch-action form around the index table. Needs a JavaScript driver: - # ActiveAdmin's JavaScript enables the menu once a row is selected, and - # submits the form. + # ActiveAdmin's JavaScript enables the menu and submits the form. class BatchActions < Section selector_key :batch_actions @@ -13,20 +12,17 @@ def select_all end # Opens the batch-action menu and runs the action labelled +label+ - # ("Delete Selected"), or with the batch-action name (`:destroy`). - # - # An action with a `confirm:` or a `form:` opens ActiveAdmin's modal - # dialog instead of submitting. #apply then sets each of +inputs+ in the - # dialog by field name (`status: "pending"` picks the option of a select, - # or types into an input) and clicks OK. - def apply(label, inputs = {}) - button = find(:active_admin, :batch_actions_button) + # ("Delete Selected"), or with the batch-action name (`:destroy`). Accepts + # the browser confirmation when the action has one. + def apply(label) # The button toggles the menu, so leave an open menu open. - button.click unless has_css?(sel(:batch_actions_menu), wait: false) + find(:active_admin, :batch_actions_button).click unless find_action_item(label)&.visible? item = action_item(label) - opens_dialog = !item[:"data-confirm"].to_s.empty? - item.click - confirm_dialog(inputs) if opens_dialog + if item[:"data-confirm"].to_s.empty? + item.click + else + accept_confirm(item[:"data-confirm"]) { item.click } + end end # True when the menu has an action labelled +label+ or named +label+. @@ -41,13 +37,6 @@ def has_no_action?(label, **options) private - # The dialog is appended to , outside this section. - def confirm_dialog(inputs) - dialog = ModalDialog.new(self, capybara_session.find(:active_admin, :modal_dialog)) - inputs.each { |name, value| dialog.fill(name, with: value) } - dialog.confirm - end - def action_items all(:active_admin, :batch_action_item, visible: :all, wait: false) end diff --git a/lib/active_admin_page_objects/comments.rb b/lib/active_admin_page_objects/comments.rb index 7c5eafd..8449f38 100644 --- a/lib/active_admin_page_objects/comments.rb +++ b/lib/active_admin_page_objects/comments.rb @@ -1,13 +1,15 @@ # frozen_string_literal: true module ActiveAdminPageObjects - # The comments panel of a show page. Declare it on the page: + # The comments of a show page. Declare it on the page; the page must render + # them, which the default show page does and a custom `show` block does not + # until it calls `active_admin_comments_for(resource)`: # # section :comments, ActiveAdminPageObjects::Comments class Comments < Section selector_key :comments - # The number in the "Comments (N)" title, 0 without one. + # The number in the "All Comments (N)" title. # @return [Integer] def count find(:active_admin, :comments_title).text[/\((\d+)\)/, 1].to_i diff --git a/lib/active_admin_page_objects/declarations.rb b/lib/active_admin_page_objects/declarations.rb index 1f58713..a68b70b 100644 --- a/lib/active_admin_page_objects/declarations.rb +++ b/lib/active_admin_page_objects/declarations.rb @@ -5,8 +5,7 @@ module ActiveAdminPageObjects # Names and labels declared on a section class. AttributesTable, Table, - # Filters, Form and HasMany::Fieldset include it and add their own class - # method: + # Filters and Form include it and add their own class method: # # section :attributes_table, ActiveAdminPageObjects::AttributesTable do # row :external_id, "External ID" @@ -76,8 +75,8 @@ module ClassMethods # The declarations of this class and its superclasses, in declaration # order. A subclass adds to its own copy. # @return [Hash{String => Hash}] name => `{ label: }`, with `type:` for - # filters, fields and has_many blocks, `kind:` for fields and has_many - # blocks, and `visible:` when the declaration gives it + # filters and fields, `kind:` for fields, and `visible:` when the + # declaration gives it def declarations inherited = superclass.respond_to?(:declarations) ? superclass.declarations : {} inherited.merge(own_declarations).freeze diff --git a/lib/active_admin_page_objects/dropdown_menu.rb b/lib/active_admin_page_objects/dropdown_menu.rb deleted file mode 100644 index 9d38762..0000000 --- a/lib/active_admin_page_objects/dropdown_menu.rb +++ /dev/null @@ -1,63 +0,0 @@ -# frozen_string_literal: true - -module ActiveAdminPageObjects - # A `dropdown_menu` among the action items. Reached with - # `page.action_items.dropdown("More")`. - class DropdownMenu < Section - selector_key :action_item_dropdown - - # The button text. - # @return [String] - def label - find(:active_admin, :dropdown_menu_button).text.strip - end - - # Opens the menu unless it is open. The button toggles the menu, so the - # list's visibility is checked first; without JavaScript the list is - # always shown. - def open - button = find(:active_admin, :dropdown_menu_button) - unless has_css?(sel(:dropdown_menu_list), wait: false) - button.click - find(:active_admin, :dropdown_menu_list) - end - self - end - - # The item labels in document order, read from a closed menu too. - # @return [Array] - def labels - items.map { |item| item.text(:all).strip } - end - - # Opens the menu and clicks the item labelled +label+ (case-insensitive). - def click(label) - open - item(label).click - end - - # True when the menu has an item labelled +label+. - def has_item?(label, **options) - eventually(**options) { find_item(label) } - end - - # Waits until the menu has no item labelled +label+. - def has_no_item?(label, **options) - eventually(**options) { find_item(label).nil? } - end - - private - - def items - all(:active_admin, :dropdown_menu_item, visible: :all, wait: false) - end - - def item(label) - find_item(label) || raise(Capybara::ElementNotFound, "no dropdown item #{label.inspect} in #{labels.inspect}") - end - - def find_item(label) - items.find { |el| same_text?(el.text(:all), label) } - end - end -end diff --git a/lib/active_admin_page_objects/errors.rb b/lib/active_admin_page_objects/errors.rb index 01e766d..ba44904 100644 --- a/lib/active_admin_page_objects/errors.rb +++ b/lib/active_admin_page_objects/errors.rb @@ -4,12 +4,8 @@ module ActiveAdminPageObjects class Error < StandardError; end # The page object drives a feature that ActiveAdmin 4 no longer renders. - # Raised by 2.x only; defined here so code that rescues it loads on 1.x. class RemovedInActiveAdmin4 < Error; end - # The page object drives a feature that ActiveAdmin 3 does not have. - class NotInActiveAdmin3 < Error; end - # The page has an element of another class than the declared one. Field # and filter lookups raise it. class DeclaredClassMismatch < Capybara::ExpectationNotMet; end diff --git a/lib/active_admin_page_objects/fields.rb b/lib/active_admin_page_objects/fields.rb index 6335386..969b116 100644 --- a/lib/active_admin_page_objects/fields.rb +++ b/lib/active_admin_page_objects/fields.rb @@ -26,7 +26,7 @@ module Fields "boolean" => :BooleanField, "radio" => :RadioField, "check_boxes" => :CheckBoxesField, - "datepicker" => :DatePickerField, + "date_picker" => :DatePickerField, "file" => :FileField }.freeze private_constant :FIELD_CLASSES diff --git a/lib/active_admin_page_objects/filters.rb b/lib/active_admin_page_objects/filters.rb index e159729..6be60d4 100644 --- a/lib/active_admin_page_objects/filters.rb +++ b/lib/active_admin_page_objects/filters.rb @@ -17,8 +17,7 @@ def submit find(:active_admin, :filters_submit).click end - # Clicks "Clear Filters". ActiveAdmin 3 clears in JavaScript, so this - # needs a JavaScript driver. + # Clicks "Clear Filters". def clear find(:active_admin, :filters_clear).click end diff --git a/lib/active_admin_page_objects/filters/date_range_filter.rb b/lib/active_admin_page_objects/filters/date_range_filter.rb index 2303e98..4ca8b3e 100644 --- a/lib/active_admin_page_objects/filters/date_range_filter.rb +++ b/lib/active_admin_page_objects/filters/date_range_filter.rb @@ -3,8 +3,7 @@ require "date" module ActiveAdminPageObjects - # A date range filter: "from" and "to" text inputs with a jQuery UI - # datepicker. The dates are typed in, not picked. + # A date range filter: "from" and "to" date inputs. class DateRangeFilter < Filter # Sets the range. Takes Date objects or ISO strings ("2026-01-31"); nil # or "" clears that end. @@ -39,8 +38,8 @@ def iso(value) end def fill_date(input, value) - value = Date.iso8601(value) if value.is_a?(String) && !value.empty? - type_date(input, iso(value)) + value = nil if value == "" + input.set(value.nil? || value.respond_to?(:strftime) ? value : Date.iso8601(value.to_s)) end def range_matches?(from, to) diff --git a/lib/active_admin_page_objects/flashes.rb b/lib/active_admin_page_objects/flashes.rb index 9d5108e..3e7d5dc 100644 --- a/lib/active_admin_page_objects/flashes.rb +++ b/lib/active_admin_page_objects/flashes.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true module ActiveAdminPageObjects - # The flash messages under the title bar. ActiveAdmin 3 renders the - # container on every page, so `has_no_flash?` also works without flashes. + # The flash messages under the page header. ActiveAdmin 4 renders the + # `notice`, `alert` and `error` types only. class Flashes < Section selector_key :flashes - TYPES = %i[notice alert error warning].freeze + TYPES = %i[notice alert error].freeze # True when a flash of +type+ contains +text+. # @raise [ArgumentError] when +type+ is not one of TYPES @@ -29,11 +29,16 @@ def messages(type = nil) private def flash_selector(type) - unless type.respond_to?(:to_sym) && TYPES.include?(type.to_sym) - raise ArgumentError, "flash type must be one of #{TYPES.inspect}, got #{type.inspect}" + unless type.respond_to?(:to_sym) && flash_types.include?(type.to_sym) + raise ArgumentError, "flash type must be one of #{flash_types.inspect}, got #{type.inspect}" end sel(:"flash_#{type}") end + + # The types this layout renders. A theme that renders more overrides it. + def flash_types + TYPES + end end end diff --git a/lib/active_admin_page_objects/form.rb b/lib/active_admin_page_objects/form.rb index 5af1f87..8935c64 100644 --- a/lib/active_admin_page_objects/form.rb +++ b/lib/active_admin_page_objects/form.rb @@ -9,8 +9,8 @@ module ActiveAdminPageObjects # section :form, ActiveAdminPageObjects::Form do # field :email, "Email", ActiveAdminPageObjects::Form::StringField # field :status, "Status", ActiveAdminPageObjects::Form::SelectField - # has_many :orders, "Orders" do - # field :reference, "Reference", ActiveAdminPageObjects::Form::StringField + # has_many :line_items, "Line Items" do + # field :sku, "Sku", ActiveAdminPageObjects::Form::StringField # end # end class Form < Section @@ -122,7 +122,7 @@ def submit find(:active_admin, :form_submit, match: :first).click end - # The `has_many` block of +association+, e.g. `has_many(:orders)`. A form + # 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`. # @raise [ArgumentError] when has_many blocks are declared and +association+ is not one of them @@ -206,7 +206,7 @@ def declared_label_text(name, declaration, **visibility) container = sel(:has_many, name) return unless first(:css, container, minimum: 0, wait: false, **visibility) - label_text("#{container} > h3", **visibility).to_s + label_text("#{container} > #{sel(:has_many_heading)}", **visibility).to_s end # The fields outside the has_many blocks, and one entry per has_many block. @@ -220,12 +220,7 @@ def has_many_keys(**visibility) every = all(:active_admin, :has_many_container, visible: :all, wait: false) nested = every.flat_map { |node| node.all(:active_admin, :has_many_container, visible: :all, wait: false).to_a } containers = all(:active_admin, :has_many_container, wait: false, **visibility) - [containers, nested].map { |nodes| nodes.map { |node| has_many_key(node) } }.reduce(:-).uniq - end - - # The association is the container's other class: `has_many_container orders`. - def has_many_key(container) - (class_names(container) - ["has_many_container"]).first + [containers, nested].map { |nodes| nodes.map { |node| node["data-has-many-association"] } }.reduce(:-).uniq end end end diff --git a/lib/active_admin_page_objects/form/date_picker_field.rb b/lib/active_admin_page_objects/form/date_picker_field.rb index a9c6362..99d3db0 100644 --- a/lib/active_admin_page_objects/form/date_picker_field.rb +++ b/lib/active_admin_page_objects/form/date_picker_field.rb @@ -4,12 +4,11 @@ module ActiveAdminPageObjects class Form - # An `as: :datepicker` field: a text input with a jQuery UI datepicker. - # The date is typed in, not picked. + # An `as: :date_picker` field: a native ``. class DatePickerField < StringField - # Types the date: a Date, or a string such as "2026-01-31". + # Sets the date: a Date, or a string such as "2026-01-31". def fill(value) - type_date(input, iso_date(value)) + input.set(iso_date(value)) end end end diff --git a/lib/active_admin_page_objects/has_many.rb b/lib/active_admin_page_objects/has_many.rb index b9c16f2..5b0ba2a 100644 --- a/lib/active_admin_page_objects/has_many.rb +++ b/lib/active_admin_page_objects/has_many.rb @@ -2,7 +2,7 @@ module ActiveAdminPageObjects # A `has_many` block of a resource form, with the fieldsets of its nested - # records. Reached with `form.has_many(:orders)`. + # records. Reached with `form.has_many(:line_items)`. class HasMany < Section selector_key :has_many @@ -45,7 +45,7 @@ def marked_for_destroy? private # Formtastic ids a field ``, so the prefix of - # `customer[orders_attributes][0][reference]` is `customer_orders_attributes_0`. + # `order[line_items_attributes][0][sku]` is `order_line_items_attributes_0`. # A check_boxes or multiple select name ends in `[]` after the attribute. def field_prefix first_control_name.delete_suffix("[]").sub(/\[[^\]]*\]\z/, "").tr("[", "_").delete("]") diff --git a/lib/active_admin_page_objects/layout.rb b/lib/active_admin_page_objects/layout.rb index 997e9f3..7ef988a 100644 --- a/lib/active_admin_page_objects/layout.rb +++ b/lib/active_admin_page_objects/layout.rb @@ -5,8 +5,7 @@ module ActiveAdminPageObjects # layout. Each element and section also gets SitePrism's `has_?` and # `has_no_?` predicates. module Layout - # Element name => selector-map key. ActiveAdmin 3 has no dark mode toggle - # and no user menu button: using those elements raises NotInActiveAdmin3. + # Element name => selector-map key. ELEMENTS = { site_title: :site_title, dark_mode_toggle: :dark_mode_toggle, @@ -30,8 +29,7 @@ def sections breadcrumbs: [Breadcrumbs], action_items: [ActionItems], flashes: [Flashes], - main_menu: [MainMenu], - modal_dialog: [ModalDialog] + main_menu: [MainMenu] } end @@ -66,23 +64,15 @@ def add_section(name, klass, *find_args) end # The panel titled +title+: a String (case-insensitive) or a Regexp. - # Sidebar sections and the comments panel are not panels here: use - # #sidebar and Comments. # @return [Panel] def panel(title) Panel.new(self, find(:active_admin_panel, title)) end - # The sidebar section titled +title+: a String (case-insensitive) or a Regexp. - # @return [Sidebar] - def sidebar(title) - Sidebar.new(self, find(:active_admin_sidebar, title)) - end - - # The utility navigation in the header: the current user and the logout link. - # @return [UtilityNavigation] + # The utility navigation of ActiveAdmin 3. + # @raise [RemovedInActiveAdmin4] on ActiveAdmin 4 def utility_navigation - UtilityNavigation.new(self, find(:active_admin, :utility_navigation)) + find(:active_admin, :utility_navigation) end end end diff --git a/lib/active_admin_page_objects/main_menu.rb b/lib/active_admin_page_objects/main_menu.rb index 2c9583e..7aa8a68 100644 --- a/lib/active_admin_page_objects/main_menu.rb +++ b/lib/active_admin_page_objects/main_menu.rb @@ -10,10 +10,11 @@ module ActiveAdminPageObjects class MainMenu < Section selector_key :main_menu - # The root is the `ul` itself; a nested item holds its submenu in a `ul`. - ITEM_XPATH = "./li | ./ul/li" - LABEL_XPATH = "./a | ./span" - LINK_XPATH = "./a" + ITEM_XPATH = "./ul/li" + LABEL_XPATH = "./a | ./button | ./div/a" + LINK_XPATH = "./a | ./div/a" + TOGGLE_XPATH = "./button | ./div/button" + SUBMENU_XPATH = "./ul" # Visits the menu item at the label path +labels+. def go(*labels) @@ -31,15 +32,15 @@ def href(*labels) end # Navigates to the menu item at the label path +labels+ as a user does: - # hovers each parent, then clicks the item's link. It sees visible items - # only, so a submenu that stays hidden raises Capybara::ElementNotFound. - # A driver without hover support skips the hovering. + # opens each collapsed parent with its toggle button, then clicks the item's + # link. It sees visible items only, so a submenu that stays hidden raises + # Capybara::ElementNotFound. def click(*labels) raise ArgumentError, "give at least one label" if labels.empty? root_element.synchronize do *parents, last = labels - scope = parents.reduce(root_element) { |current, label| hover(visible_item(current, label, labels)) } + scope = parents.reduce(root_element) { |current, label| expand(visible_item(current, label, labels)) } visible_item(scope, last, labels).find(:xpath, LINK_XPATH, wait: false).click end end @@ -70,7 +71,8 @@ def labels(*parents) # The label path of the current item, e.g. `["Catalog", "Orders"]`. # @return [Array] def current_labels - current_path_in(root_element).map { |li| label_of(li) } + path = current_path_in(root_element) + path ? path.map { |li| label_of(li) } : [] end private @@ -84,8 +86,7 @@ def item_with_href?(labels, expected) def link_href(item) href = item.first(:xpath, LINK_XPATH, visible: :all, minimum: 0, wait: false)&.[](:href).to_s - # A parent item links to "#", which a browser reports as the page URL plus "#". - href unless href.empty? || href.end_with?("#") + href unless href.empty? || href == "#" end # A browser driver reports the absolute URL, so a path is compared to the @@ -114,10 +115,8 @@ def visible_item(scope, label, path) raise(Capybara::ElementNotFound, "no visible menu item #{label.inspect} in #{path.inspect}") end - def hover(item) - item.find(:xpath, LABEL_XPATH, wait: false).hover - item - rescue Capybara::NotSupportedByDriverError + def expand(item) + item.first(:xpath, TOGGLE_XPATH, minimum: 0, wait: false)&.click unless item.has_xpath?(SUBMENU_XPATH, wait: false) item end @@ -129,10 +128,15 @@ def label_of(item) item.first(:xpath, LABEL_XPATH, visible: :all, minimum: 0)&.text(:all).to_s.strip end - # ActiveAdmin marks the current item and each of its parents. def current_path_in(scope) - current = children(scope).find { |li| li.matches_css?(sel(:main_menu_selected), visible: :all, wait: false) } - current ? [current, *current_path_in(current)] : [] + children(scope).each do |li| + return [li] if li.has_xpath?(LINK_XPATH, visible: :all, wait: false) && + li.first(:xpath, LINK_XPATH, visible: :all).matches_css?(sel(:main_menu_selected), wait: false) + + nested = current_path_in(li) + return [li, *nested] if nested + end + nil end end end diff --git a/lib/active_admin_page_objects/modal_dialog.rb b/lib/active_admin_page_objects/modal_dialog.rb deleted file mode 100644 index 64f3a4e..0000000 --- a/lib/active_admin_page_objects/modal_dialog.rb +++ /dev/null @@ -1,59 +0,0 @@ -# frozen_string_literal: true - -module ActiveAdminPageObjects - # The modal dialog ActiveAdmin opens for batch actions that ask to confirm or - # for input. Needs a JavaScript driver. Reached with `page.modal_dialog`. - class ModalDialog < Section - selector_key :modal_dialog - - # The dialog title text. - # @return [String] - def title - find(:active_admin, :modal_dialog_title).text.strip - end - - # Sets the field named +name+: types into an input, or picks the option - # labelled +with+ in a select. - def fill(name, with:) - field = find(:active_admin, :modal_dialog_form).find(:css, field_selector(name)) - if field.tag_name == "select" - field.select(with.to_s) - else - field.set(with) - end - end - - # Clicks OK and waits until the dialog is gone. - def confirm - find(:active_admin, :modal_dialog_ok).click - wait_until_gone - end - - # Clicks Cancel and waits until the dialog is gone. - def cancel - find(:active_admin, :modal_dialog_cancel).click - wait_until_gone - end - - # True when the dialog form has a field named +name+. - def has_field?(name, **options) - has_css?("#{sel(:modal_dialog_form)} #{field_selector(name)}", **options) - end - - # Waits until the dialog form has no field named +name+. - def has_no_field?(name, **options) - has_no_css?("#{sel(:modal_dialog_form)} #{field_selector(name)}", **options) - end - - private - - def field_selector(name) - format('[name="%s"]', name) - end - - # The root element is stale once the dialog closes, so ask the session. - def wait_until_gone - root_element.session.assert_no_selector(:css, sel(:modal_dialog)) - end - end -end diff --git a/lib/active_admin_page_objects/panel.rb b/lib/active_admin_page_objects/panel.rb index 11a98b3..b250d64 100644 --- a/lib/active_admin_page_objects/panel.rb +++ b/lib/active_admin_page_objects/panel.rb @@ -7,11 +7,11 @@ module ActiveAdminPageObjects # # The title is a String, compared whole and ignoring case, or a Regexp for a # title with a changing part: `page.panel(/\ARoutes \(\d+\)\z/)`. - # Sidebar sections and the comments panel are left out: see Sidebar and Comments. class Panel < Section selector_key :panel - # The panel title text. + # The panel title text. The panel's own title and body come before those + # of a panel nested in its body. # @return [String] def title find(:active_admin, :panel_title, match: :first).text.strip diff --git a/lib/active_admin_page_objects/scopes.rb b/lib/active_admin_page_objects/scopes.rb index f00a9c4..6696689 100644 --- a/lib/active_admin_page_objects/scopes.rb +++ b/lib/active_admin_page_objects/scopes.rb @@ -31,7 +31,7 @@ def has_no_selected?(label, **options) # @return [Integer, nil] def count(label) badge = scope_link(label).first(:active_admin, :scope_count, minimum: 0) - badge && Integer(badge.text[/\d+/]) + badge && Integer(badge.text.strip) end private diff --git a/lib/active_admin_page_objects/section.rb b/lib/active_admin_page_objects/section.rb index 645199c..94b5d2a 100644 --- a/lib/active_admin_page_objects/section.rb +++ b/lib/active_admin_page_objects/section.rb @@ -31,11 +31,6 @@ def class_names(node) node[:class].to_s.split end - # The key in the node's `` class: "name" for `col col-name` and "col-". - def class_key(node, prefix) - class_names(node).filter_map { |name| name.delete_prefix(prefix) if name.start_with?(prefix) && name != prefix }.first - end - # True when +actual+ holds the +expected+ texts, in order, ignoring case. def texts_match?(actual, expected) actual.size == expected.size && actual.zip(expected).all? { |a, e| same_text?(a, e) } @@ -48,13 +43,6 @@ def href_attribute(link) link[:href].to_s end - # Types +text+ into a date input. jQuery UI opens the datepicker when the - # input gets focus, over the controls below; Escape closes it. - def type_date(input, text) - input.set(text) - input.send_keys(:escape) if class_names(input).include?("hasDatepicker") - end - # Retries the block until it is truthy or the wait time runs out. # Capybara's synchronize takes `false` as a number, so it becomes 0 here. def eventually(wait: Capybara.default_max_wait_time) diff --git a/lib/active_admin_page_objects/selectors.rb b/lib/active_admin_page_objects/selectors.rb index b644103..3622404 100644 --- a/lib/active_admin_page_objects/selectors.rb +++ b/lib/active_admin_page_objects/selectors.rb @@ -1,145 +1,119 @@ # frozen_string_literal: true module ActiveAdminPageObjects - # Marks a selector-map entry for a feature that ActiveAdmin 3 does not have. - NOT_IN_ACTIVE_ADMIN_3 = Object.new.freeze + # Marks a selector-map entry for a feature that ActiveAdmin 4 removed. + REMOVED = Object.new.freeze - # The CSS selector map for vanilla ActiveAdmin 3. A `%s` in a selector is + # The CSS selector map for vanilla ActiveAdmin 4. A `%s` in a selector is # filled from the arguments of ActiveAdminPageObjects.selector. module Selectors DEFAULTS = { - site_title: "#site_title", - dark_mode_toggle: NOT_IN_ACTIVE_ADMIN_3, - user_menu_button: NOT_IN_ACTIVE_ADMIN_3, - page_title: "#page_title", - - utility_navigation: "#utility_nav", - utility_navigation_item: "li", - utility_navigation_current_user: "#current_user", - utility_navigation_logout: "#logout a", - - breadcrumbs: "#titlebar_left .breadcrumb", - breadcrumb_link: "a", - - # Rendered on every page, also without items. - action_items: "#titlebar_right .action_items", - action_item: ".action_item > a, .action_item > button, .action_item > .dropdown_menu > .dropdown_menu_button", - action_item_dropdown: ".action_item .dropdown_menu", - - dropdown_menu_button: "a.dropdown_menu_button", - dropdown_menu_list: ".dropdown_menu_list_wrapper", - dropdown_menu_item: ".dropdown_menu_list a", - - # Rendered on every page, also without flashes. - flashes: ".flashes", - flash: ".flash", - flash_notice: ".flash.flash_notice", - flash_alert: ".flash.flash_alert", - flash_error: ".flash.flash_error", - flash_warning: ".flash.flash_warning", - - main_menu: "#header #tabs", - main_menu_selected: "li.current", - - table: "table.index_table", - table_header: "thead th.col", - table_column_header: "thead th.col-%s", - table_sortable_header: "thead th.sortable.col-%s", - table_sorted_header: "thead th.sorted-asc, thead th.sorted-desc", - table_sort_link: "a", + site_title: "h1[data-test-site-title]", + dark_mode_toggle: "button.dark-mode-toggle", + user_menu_button: "#user-menu-button", + page_title: "[data-test-page-header] h2", + utility_navigation: REMOVED, + + breadcrumbs: 'nav[aria-label="breadcrumb"]', + breadcrumb_link: "ol > li > a", + + action_items: "[data-test-action-items]", + action_item: "a, button", + action_item_dropdown: REMOVED, + + flashes: "[data-test-page-header] + div:not([data-test-page-content])", + flash: "div", + flash_notice: "div.bg-green-50", + flash_alert: "div.bg-yellow-50", + flash_error: "div.bg-red-50", + + main_menu: "#main-menu", + main_menu_selected: "a.selected", + + table: "table.data-table", + table_header: "thead th", + table_column_header: 'thead th[data-column="%s"]', table_row: "tbody > tr", table_row_by_id: 'tbody > tr[id$="_%s"]', - table_cell: "td.col-%s", - table_row_checkbox: "input.collection_selection", - blank_slate: ".blank_slate_container", - - attributes_table: ".attributes_table", - attributes_table_row: "tr.row-%s", - attributes_table_rows: "tr[class*='row-']", - - status_tag: ".status_tag", + table_cell: 'td[data-column="%s"]', + table_row_checkbox: "input.batch-actions-resource-selection", + # The cells of the actions column at a 1-based column position. + table_actions_cell: "tbody > tr > td:nth-child(%s) .data-table-resource-actions", + table_row_actions_cell: "td:has(.data-table-resource-actions)", + table_row_selection_cell: "td:has(input.batch-actions-resource-selection)", + table_sortable_header: 'thead th[data-column="%s"][data-sortable]', + table_sorted_header: 'thead th[data-column="%s"][data-sort-direction]', + table_sorted_header_in: 'thead th[data-column="%s"][data-sort-direction="%s"]', + table_sort_link: "a", + status_tag: ".status-tag", + status_tag_with_status: '[data-status="%s"]', + blank_slate: ".main-content-container .border-dashed", - # Sidebar sections and the comments panel are panels too in ActiveAdmin 3; - # they have their own sections, so `panel` leaves them out. - panel: ".panel:not(.sidebar_section):not(.comments)", - panel_title: "h3", - panel_body: ".panel_contents", + attributes_table: ".attributes-table", + attributes_table_row: 'tr[data-row="%s"]', + attributes_table_rows: "tr[data-row]", - sidebar: "#sidebar", - sidebar_section: "#sidebar .sidebar_section", - sidebar_title: "h3", - sidebar_body: ".panel_contents", + panel: ".panel", + panel_title: ".panel-title", + panel_body: ".panel-body", - filters: "#filters_sidebar_section form.filter_form", + filters: "form.filters-form", filter: "#q_%s_input", - filter_wrappers: ".filter_form_field", - filter_predicate: "select", - filter_value: "input", - filter_range_from: 'input[name*="_gteq"]', - filter_range_to: 'input[name*="_lteq"]', - filters_footer: "form.filter_form .buttons", - filters_submit: "input[type=submit]", - filters_clear: "a.clear_filters_btn", + filter_wrappers: ".filters-form-field", + filter_predicate: "select[data-search-methods]", + filter_value: ".filters-form-input-group > input", + filter_range_from: 'input[name$="_gteq]"]', + filter_range_to: 'input[name$="_lteq]"]', + filters_footer: ".filters-form-buttons", + filters_submit: ".filters-form-submit", + filters_clear: ".filters-form-clear", scopes: ".scopes", - scope: ".table_tools_segmented_control li.scope > a", - scope_selected: ".table_tools_segmented_control li.scope.selected > a", - scope_count: "span.count", + scope: "a.index-button", + scope_selected: "a.index-button-selected", + scope_count: ".scopes-count", - pagination: "#index_footer .pagination", - pagination_current: ".page.current", - pagination_next: ".next a", - pagination_previous: ".prev a", + pagination: "nav[data-test-pagination]", + pagination_current: "a.bg-blue-500", + pagination_next: 'a[rel="next"]:has(.sr-only)', + pagination_previous: 'a[rel="prev"]:has(.sr-only)', - download_links: "#index_footer .download_links", + download_links: ".paginated-collection-footer > div:has(> a)", download_link: "a", batch_actions: "form#collection_selection", - batch_actions_toggle_all: "#collection_selection_toggle_all", - batch_actions_button: ".batch_actions_selector a.dropdown_menu_button", - batch_actions_menu: ".batch_actions_selector .dropdown_menu_list_wrapper", - batch_action_item: ".batch_actions_selector a.batch_action[data-action]", - - modal_dialog: ".active_admin_dialog", - modal_dialog_title: ".ui-dialog-title", - modal_dialog_form: "form#dialog_confirm", - modal_dialog_ok: ".ui-dialog-buttonset button:nth-child(1)", - modal_dialog_cancel: ".ui-dialog-buttonset button:nth-child(2)", + batch_actions_toggle_all: "input.batch-actions-toggle-all", + batch_actions_button: ".batch-actions-dropdown-toggle", + batch_action_item: "[data-batch-action-item]", form: "form.formtastic:not(.active_admin_comment)", - # Hidden inputs and the delete checkbox of a has_many fieldset are not fields. - form_input_wrapper: "li.input:not(.hidden):not(.has_many_delete)", + # Hidden inputs are not fields. + form_input_wrapper: "li.input:not(.hidden):not(.has-many-delete)", + has_many_container: ".has-many-container", + has_many: '.has-many-container[data-has-many-association="%s"]', + has_many_heading: "h3.has-many-fields-title", + has_many_fieldset: "fieldset.has-many-fields", + has_many_add: "a.has-many-add", + has_many_remove: "a.has-many-remove", + has_many_delete: "li.has-many-delete input[type=checkbox]", form_input: "li#%s_%s_input", form_choice: "li.choice label", # The hidden input of a boolean or check_boxes wrapper is not a control. form_control: "input:not([type=hidden]), select, textarea", - form_inline_error: "p.inline-errors", + form_inline_error: ".inline-errors", form_semantic_error: "ul.errors > li", form_submit: "fieldset.actions input[type=submit], fieldset.actions button[type=submit]", - - has_many_container: ".has_many_container", - has_many: ".has_many_container.%s", - has_many_heading: "h3", - has_many_fieldset: "fieldset.has_many_fields", - has_many_add: "a.has_many_add", - has_many_remove: "a.has_many_remove", - has_many_delete: "li.has_many_delete input[type=checkbox]", - - # `ul#tabs` (the main menu) and `ul#utility_nav` carry the `tabs` class too. - tabs: "#active_admin_content .tabs", - tab_link: ".nav-tabs > li > a", - tab_current_link: ".nav-tabs > li.ui-tabs-active > a", - tab_panel: ".tab-content > div", - - comments: '[id^="active_admin_comments_for_"]', - comments_title: "h3", - # The comment form carries the `active_admin_comment` class too. - comment: "div.active_admin_comment", - comment_body: ".active_admin_comment_body", - comment_author: ".active_admin_comment_author", - comment_delete: '.active_admin_comment_meta a[data-method="delete"]', - comment_input: "#active_admin_comment_body", - comment_submit: "form.active_admin_comment input[type=submit]" + comments: "#active-admin-comments-form", + # The comments block has two bold titles: "Comments", then "All Comments (N)". + comments_title: "div.font-bold:not(:first-child)", + comment: "[data-test-comment-container]", + comment_body: "[data-test-comment-container] > div:nth-child(2)", + comment_author: "[data-test-comment-container] > div:first-child > span:first-child", + comment_delete: '[data-test-comment-container] > a[data-method="delete"]', + comment_input: 'textarea[name="comment[body]"]', + comment_submit: "form fieldset.actions input[type=submit], form fieldset.actions button[type=submit]", + + tabs: REMOVED }.freeze # The map in use: DEFAULTS plus ActiveAdminPageObjects.register_selectors. @@ -148,12 +122,12 @@ module Selectors class << self # The CSS selector for +key+. - # @raise [NotInActiveAdmin3] when ActiveAdmin 3 does not have the feature + # @raise [RemovedInActiveAdmin4] when ActiveAdmin 4 removed the feature # @raise [KeyError] when no selector is registered for +key+ # @return [String] def selector(key, *args) css = Selectors::MAP.fetch(key) { raise KeyError, "no selector for #{key.inspect}" } - raise NotInActiveAdmin3, "#{key.to_s.tr('_', ' ')} is not in ActiveAdmin 3" if css.equal?(NOT_IN_ACTIVE_ADMIN_3) + raise RemovedInActiveAdmin4, "#{key.to_s.tr('_', ' ')} was removed in ActiveAdmin 4" if css.equal?(REMOVED) args.empty? ? css : format(css, *args) end diff --git a/lib/active_admin_page_objects/sidebar.rb b/lib/active_admin_page_objects/sidebar.rb deleted file mode 100644 index e46aef1..0000000 --- a/lib/active_admin_page_objects/sidebar.rb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: true - -module ActiveAdminPageObjects - # A sidebar section. Find one by title with `page.sidebar("Help")`, or with a - # Regexp: `page.sidebar(/\AVersions/)`. - class Sidebar < Panel - selector_key :sidebar_section - - # The section title text. - # @return [String] - def title - find(:active_admin, :sidebar_title).text.strip - end - - # The section body node, for content assertions. - # @return [Capybara::Node::Element] - def body - find(:active_admin, :sidebar_body) - end - end -end diff --git a/lib/active_admin_page_objects/status_tag.rb b/lib/active_admin_page_objects/status_tag.rb index 6655e2a..91ecc21 100644 --- a/lib/active_admin_page_objects/status_tag.rb +++ b/lib/active_admin_page_objects/status_tag.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true module ActiveAdminPageObjects - # A `status_tag`. Reached with `row.status_tag(:status)` on an index row or + # A `status_tag`: `Pending`. + # Reached with `row.status_tag(:status)` on an index row or # `attributes_table.status_tag(:status)` on a show page. A cell with several # tags gives them with `status_tags(:status)`. class StatusTag < Section @@ -16,73 +17,105 @@ module Matchers # @return [StatusTag] def status_tag(key, visible: nil) visibility = visibility_of(key, visible) - StatusTag.new(self, find(:css, cell_selector(key), **visibility).find(:active_admin, :status_tag, **visibility)) + StatusTag.new(self, find(:css, status_tag_selector(key), **visibility)) end # Every status tag in the cell of +key+, in page order. # @return [Array] def status_tags(key, visible: nil) - status_tags_in(cell_selector(key), **visibility_of(key, visible)) + all(:css, status_tag_selector(key), **visibility_of(key, visible)).map { |node| StatusTag.new(self, node) } end - # True when a status tag in the cell of +key+ has +label+, ignoring - # case, and every class of +type+. - def has_status_tag?(key, label, type: nil, **options) - status_tag_match?(true, key, label, type, **options) + # True when the cell of +key+ has a status tag with the Capybara options. + # +label+ is the whole text of the tag, ignoring case: a Regexp matches + # part of it. +status+ is the tag's `data-status`, e.g. :pending, or + # true for "yes" and false for "no". `type:` is another name for `status:`. + # @raise [ArgumentError] when both `status:` and `type:` are given, or one + # is not a String, a Symbol, true or false + def has_status_tag?(key, label = nil, status: nil, type: nil, **options) + css, query = status_tag_query(key, label, status, type, options) + has_css?(css, **query) end - # Waits until no status tag in the cell of +key+ is such a tag. - def has_no_status_tag?(key, label, type: nil, **options) - status_tag_match?(false, key, label, type, **options) + # Waits until the cell of +key+ has no such status tag. + # @raise [ArgumentError] as #has_status_tag? does + def has_no_status_tag?(key, label = nil, status: nil, type: nil, **options) + css, query = status_tag_query(key, label, status, type, options) + has_no_css?(css, **query) end private - # Waits until a status tag of the cell has +label+ and +type+ (+expected+ - # true), or none has. `visible:` is Capybara's option. - def status_tag_match?(expected, key, label, type, **options) - cell_css = cell_selector(key) - visibility = visibility_of(key, options.delete(:visible)) - eventually(**options) do - tags = status_tags_in(cell_css, **visibility) - tags.any? { |tag| tag.match?(label, type: type) } == expected - end + def status_tag_selector(key, status = nil) + base = "#{cell_selector(key)} #{sel(:status_tag)}" + status.nil? ? base : "#{base}#{sel(:status_tag_with_status, Capybara::Selector::CSS.escape(status))}" + end + + # The CSS and the Capybara options of a status tag lookup. A status + # that is not one of the accepted kinds would match no tag, so + # `has_no_status_tag?` would pass. + def status_tag_query(key, label, status, type, options) + raise ArgumentError, "give status: or type:, not both" unless status.nil? || type.nil? + + status = StatusTag.status_value(status.nil? ? type : status) + css = status_tag_selector(key, status) + [css, { **visibility_of(key), **case_insensitive_text(status_tag_label(label, options)) }] end - # The status tags of the cell +cell_css+, in page order, without waiting. - def status_tags_in(cell_css, **visibility) - all(:css, "#{cell_css} #{sel(:status_tag)}", wait: false, **visibility).map { |node| StatusTag.new(self, node) } + def status_tag_label(label, options) + return options if label.nil? + + label.is_a?(Regexp) ? options.except(:exact_text).merge(text: label) : options.except(:text).merge(exact_text: label) end end - # The tag text as rendered in the DOM, e.g. "Pending". ActiveAdmin 3's - # CSS uppercases it on screen, so this reads the text before that. + class << self + # The `data-status` value of +status+: nil for none, "yes" for true and + # "no" for false, as ActiveAdmin writes them. + # @api private + # @raise [ArgumentError] when +status+ is not nil, a String, a Symbol, true or false + # @return [String, nil] + def status_value(status) + case status + when nil then nil + when true then "yes" + when false then "no" + when String, Symbol then status.to_s + else raise ArgumentError, "status must be a String, a Symbol, true or false, got #{status.inspect}" + end + end + end + + # The tag text as rendered in the DOM, e.g. "Pending", before any CSS + # `text-transform`. # @return [String] def label - root_element.text(:all).strip + squish(root_element.text(:all)) end - # The CSS classes other than `status_tag`, joined by a space, or nil. + # The tag's `data-status`, e.g. "pending", or nil when it has none. # @return [String, nil] - def type - classes = types - classes.empty? ? nil : classes.join(" ") + def status + value = root_element[:"data-status"].to_s + value.empty? ? nil : value end - # True when the tag has every class of +type+ ("pending", or "ok warning"). - def has_type?(type, **options) - eventually(**options) { type_match?(type) } - end + # True when the tag's `data-status` is +status+ (see Matchers#has_status_tag?). + # @raise [ArgumentError] when +status+ is not a String, a Symbol, true or false + def has_status?(status, **options) + wanted = self.class.status_value(status) + raise ArgumentError, "status must be given" if wanted.nil? - # Waits until the tag lacks the class +type+. - def has_no_type?(type, **options) - eventually(**options) { !type_match?(type) } + eventually(**options) { self.status == wanted } end - # True when the label equals +label+, ignoring case, and the tag has - # every class of +type+. Does not wait. - def match?(label, type: nil) - same_text?(self.label, label) && (type.nil? || type_match?(type)) + # Waits until the tag's `data-status` is not +status+. + # @raise [ArgumentError] as #has_status? does + def has_no_status?(status, **options) + wanted = self.class.status_value(status) + raise ArgumentError, "status must be given" if wanted.nil? + + eventually(**options) { self.status != wanted } end # True when the label equals +text+, ignoring case. @@ -94,16 +127,15 @@ def has_label?(text, **options) def has_no_label?(text, **options) eventually(**options) { !same_text?(label, text) } end + end - private - - def types - class_names(root_element) - ["status_tag"] + class Table < Section + class Row < Section + include StatusTag::Matchers end + end - def type_match?(type) - expected = type.to_s.split - expected.any? && (expected - types).empty? - end + class AttributesTable < Section + include StatusTag::Matchers end end diff --git a/lib/active_admin_page_objects/table.rb b/lib/active_admin_page_objects/table.rb index 7e24afd..8cdad26 100644 --- a/lib/active_admin_page_objects/table.rb +++ b/lib/active_admin_page_objects/table.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true module ActiveAdminPageObjects - # An index table. Declare the columns and their header labels on the section: + # An index table (`table_for`). Declare the columns and their header labels + # on the section: # # section :table, ActiveAdminPageObjects::Table do # column :id, "Id" @@ -22,14 +23,26 @@ def column(key, label, visible: nil) end end - SORT_DIRECTIONS = %i[asc desc].freeze + # ActiveAdmin 4 writes no `data-column` on the selection and actions + # columns: their headers have no title. These are their keys. + SELECTION_COLUMN = "selectable" + ACTIONS_COLUMN = "actions" + private_constant :SELECTION_COLUMN, :ACTIONS_COLUMN + + # The CSS of the body cells of column +column+, a #slug. The selection + # and actions cells are found by their content. + # @api private + def self.cell_css(column) + case column + when SELECTION_COLUMN then ActiveAdminPageObjects.selector(:table_row_selection_cell) + when ACTIONS_COLUMN then ActiveAdminPageObjects.selector(:table_row_actions_cell) + else ActiveAdminPageObjects.selector(:table_cell, column) + end + end - # One `` of the table body. `status_tag(:status)`, - # `status_tags(:status)` and `has_status_tag?` read the cell of a column: - # see StatusTag::Matchers. + # One `` of the table body. class Row < Section include Declarations::Lookup - include StatusTag::Matchers # The record id from the row's `id="_"`. # @return [String] @@ -44,14 +57,15 @@ def cell(key, visible: nil) find(:css, cell_selector(key), **visibility_of(key, visible)) end - # True when column +key+ has a cell matching the Capybara options. + # True when column +key+ has a cell matching the Capybara options. A + # String `text:` or `exact_text:` ignores case. def has_cell?(key, **options) - has_css?(cell_selector(key), **visibility_of(key), **options) + has_css?(cell_selector(key), **visibility_of(key), **case_insensitive_text(options)) end # Waits until column +key+ has no cell matching the Capybara options. def has_no_cell?(key, **options) - has_no_css?(cell_selector(key), **visibility_of(key), **options) + has_no_css?(cell_selector(key), **visibility_of(key), **case_insensitive_text(options)) end # Ticks the row's batch-action checkbox. @@ -68,7 +82,7 @@ def declaring_class def cell_selector(key) declaration_for(key) - sel(:table_cell, slug(key)) + Table.cell_css(slug(key)) end end @@ -84,26 +98,26 @@ def row(record_id) # True when the body has the row of the record with +record_id+. # @raise [ArgumentError] when +record_id+ is not an Integer or a non-empty String def has_row?(record_id, **options) - has_css?(row_selector(record_id), **options) + has_css?(row_selector(record_id), **case_insensitive_text(options)) end # Waits until the body has no row of the record with +record_id+. # @raise [ArgumentError] when +record_id+ is not an Integer or a non-empty String def has_no_row?(record_id, **options) - has_no_css?(row_selector(record_id), **options) + has_no_css?(row_selector(record_id), **case_insensitive_text(options)) end - # The non-empty header texts, as the driver reports them. + # The non-empty header texts, as the driver reports them (Chrome reports + # CSS-uppercased text). # @return [Array] def header_names all(:active_admin, :table_header).map { |th| th.text.strip }.reject(&:empty?) end - # The keys of the titled columns, from each header's `col-` class. - # The selection and actions columns have no title and are left out. + # The `data-column` keys of the headers. # @return [Array] def column_keys - all(:active_admin, :table_header).filter_map { |th| class_key(th, "col-") unless th.text.strip.empty? } + all(:active_admin, :table_header).filter_map { |th| th[:"data-column"] } end # True when the headers equal +names+, in order, ignoring case. @@ -133,39 +147,6 @@ def has_no_rows?(count: nil, **options) has_no_css?(sel(:table_row), **given(count: count), **options) end - # Clicks the header link of column +key+. With +direction+ (`:asc` or - # `:desc`) it clicks until the column is sorted that way: the first click - # on an unsorted column sorts descending. - # @raise [Capybara::ElementNotFound] when the column is not sortable - def sort_by(key, direction = nil) - declaration_for(key) - return click_sort_link(key) if direction.nil? - - direction = checked_direction(direction) - 2.times do - current = sort_direction(key) - break if current == direction - - click_sort_link(key) - # The click reloads the page; wait for the header to show the new order. - eventually { sort_direction(key) != current } || - raise(Capybara::ExpectationNotMet, "column #{key.inspect} kept its sort order after a click") - end - end - - # The sorted column and its direction, e.g. `["name", :desc]`, or nil - # when no column is sorted. - # @return [Array(String, Symbol), nil] - def sorted_by - th = first(:active_admin, :table_sorted_header, minimum: 0, wait: false) - th && [class_key(th, "col-"), direction_of(th)] - end - - # True when column +key+ has a sort link. - def has_sortable_column?(key) - has_css?(sel(:table_sortable_header, slug(key)), **visibility_of(key)) - end - private # A record or nil in the selector would match no row, so `has_no_row?` would pass. @@ -183,34 +164,147 @@ def header_names_match?(expected, names, **options) eventually(**options) { texts_match?(header_names, names) == expected } end - def sortable_header(key) - find(:css, sel(:table_sortable_header, slug(key))) + def declared_label_text(key, _declaration, **visibility) + label_text(sel(:table_column_header, key), **visibility) || untitled_header_label(key, **visibility) end - def click_sort_link(key) - sortable_header(key).find(:active_admin, :table_sort_link).click + def page_element_keys(**visibility) + keyed_headers(**visibility).map(&:first) end - def sort_direction(key) - direction_of(sortable_header(key)) + # Each header with its key: its `data-column`, or the key of the selection + # or actions column. Any other untitled column has no key and is left out. + def keyed_headers(**visibility) + all(:active_admin, :table_header, wait: false, **visibility).filter_map do |header| + key = header[:"data-column"].to_s + key = untitled_column_key(header) if key.empty? + [key, header] if key + end end - def checked_direction(direction) - return direction.to_sym if SORT_DIRECTIONS.include?(direction.to_sym) + # The selection header holds the toggle-all checkbox. The actions header + # is empty, so the column is known by the actions in its body cells. The + # checkbox and the actions tell the columns apart, so they are found + # hidden too. + def untitled_column_key(header) + return SELECTION_COLUMN if header.has_css?(sel(:batch_actions_toggle_all), visible: :all, wait: false) - raise ArgumentError, "direction must be one of #{SORT_DIRECTIONS.inspect}, got #{direction.inspect}" + ACTIONS_COLUMN if has_css?(sel(:table_actions_cell, column_position(header)), visible: :all, wait: false) end - def direction_of(header) - SORT_DIRECTIONS.find { |direction| class_names(header).include?("sorted-#{direction}") } + # The 1-based position of +header+ among every header, the hidden ones included. + def column_position(header) + header.all(:xpath, "preceding-sibling::*", visible: :all, wait: false).size + 1 end - def declared_label_text(key, _declaration, **visibility) - label_text(sel(:table_column_header, key), **visibility) + def untitled_header_label(key, **visibility) + return unless [SELECTION_COLUMN, ACTIONS_COLUMN].include?(key) + + header = keyed_headers(**visibility).assoc(key)&.last + header && squish(header.text(:all)) end - def page_element_keys(**visibility) - all(:active_admin, :table_header, wait: false, **visibility).filter_map { |header| class_key(header, "col-") } + # Sorting by the header links. Included below the class body. + module Sorting + # True when the header of column +key+ is sortable. + def has_sortable_column?(key, **options) + has_css?(sortable_header_selector(key), **visibility_of(key), **options) + end + + # Waits until the header of column +key+ is not sortable. + def has_no_sortable_column?(key, **options) + has_no_css?(sortable_header_selector(key), **visibility_of(key), **options) + end + + # The direction the table is sorted by column +key+ in, or nil when it is + # not sorted by it. Does not wait. + # @return [Symbol, nil] :asc, :desc or nil + def sort_direction(key) + header = first(:css, sel(:table_column_header, slug(key)), minimum: 0, wait: false, **visibility_of(key)) + direction = header && header[:"data-sort-direction"].to_s + direction.to_sym unless direction.nil? || direction.empty? + end + + # True when the table is sorted by column +key+, in +direction+ (:asc or + # :desc) when given. + # @raise [ArgumentError] when +direction+ is neither :asc nor :desc + def has_sort?(key, direction = nil, **options) + has_css?(sorted_header_selector(key, direction), **visibility_of(key), **options) + end + + # Waits until the table is not sorted by column +key+, in +direction+ when given. + # @raise [ArgumentError] when +direction+ is neither :asc nor :desc + def has_no_sort?(key, direction = nil, **options) + has_no_css?(sorted_header_selector(key, direction), **visibility_of(key), **options) + end + alias sorted_by? has_sort? + alias not_sorted_by? has_no_sort? + + # Clicks the header link of column +key+ and waits for the page to show the + # new order. The link flips the direction, and an unsorted column sorts + # :desc first. With +direction+ it clicks until the column shows it, at + # most twice, and not at all when it already does. + # @raise [ArgumentError] when +direction+ is neither :asc nor :desc, or the column is not sortable + # @raise [Capybara::ExpectationNotMet] when the page does not show the direction in time + # @return [Symbol] the direction the column is sorted in + def sort_by(key, direction = nil) + wanted = sort_direction_name(direction) + (wanted ? 2 : 1).times do + header = sortable_header(key) + break if wanted && header[:"data-sort-direction"].to_s == wanted + + click_sort_link(key, header) + end + shown = sort_direction(key) + raise Capybara::ExpectationNotMet, "#{key.inspect} is not sorted #{wanted}" if wanted && shown.to_s != wanted + + shown + end + + private + + def sort_direction_name(direction) + return if direction.nil? + return direction.to_s if %w[asc desc].include?(direction.to_s) + + raise ArgumentError, "sort direction must be :asc or :desc, got #{direction.inspect}" + end + + def sortable_header_selector(key) + declaration_for(key) + sel(:table_sortable_header, slug(key)) + end + + def sorted_header_selector(key, direction) + declaration_for(key) + name = sort_direction_name(direction) + name ? sel(:table_sorted_header_in, slug(key), name) : sel(:table_sorted_header, slug(key)) + end + + # The header of column +key+, found with a wait. + def sortable_header(key) + header = find(:css, sel(:table_column_header, slug(key)), **visibility_of(key)) + return header if has_css?(sortable_header_selector(key), wait: false, **visibility_of(key)) + + raise ArgumentError, "#{key.inspect} is not a sortable column" + end + + def click_sort_link(key, header) + link = header.find(:css, sel(:table_sort_link)) + direction = link_direction(link) + raise ArgumentError, "the header link of #{key.inspect} has no order param" unless direction + + link.click + raise Capybara::ExpectationNotMet, "#{key.inspect} is not sorted #{direction}" unless has_sort?(key, direction) + end + + # The link's `order` param ends in the direction the click sorts by. + def link_direction(link) + query = href_attribute(link).partition("?").last + URI.decode_www_form(query).to_h["order"].to_s[/_(asc|desc)\z/, 1] + end end + + include Sorting end end diff --git a/lib/active_admin_page_objects/table/rows_by_cell.rb b/lib/active_admin_page_objects/table/rows_by_cell.rb index cc078d3..9e9f54d 100644 --- a/lib/active_admin_page_objects/table/rows_by_cell.rb +++ b/lib/active_admin_page_objects/table/rows_by_cell.rb @@ -32,7 +32,7 @@ def eventually_row(key, text, **options) def find_row_with(key, text) declaration_for(key) - cell_css = sel(:table_cell, slug(key)) + cell_css = Table.cell_css(slug(key)) rows.find do |row| cell = row.first(:css, cell_css, minimum: 0, wait: false, **visibility_of(key)) cell && text_match?(cell.text, text) diff --git a/lib/active_admin_page_objects/tabs.rb b/lib/active_admin_page_objects/tabs.rb index 33f72c0..60915a9 100644 --- a/lib/active_admin_page_objects/tabs.rb +++ b/lib/active_admin_page_objects/tabs.rb @@ -1,60 +1,9 @@ # frozen_string_literal: true module ActiveAdminPageObjects - # The `tabs` component. jQuery UI switches the tabs, so #current and #switch - # need a JavaScript driver; without one every tab body is shown. A tab is - # named by its whole label, ignoring case, or by a Regexp for a label with a - # changing part: `switch(/\AOrders \(\d+\)\z/)`. + # The `tabs` component. ActiveAdmin 4 removed it, so finding this section + # raises RemovedInActiveAdmin4 on stock ActiveAdmin 4. class Tabs < Section selector_key :tabs - - # The tab labels in document order. - # @return [Array] - def labels - links.map { |link| link.text.strip } - end - - # The label of the open tab, or nil before jQuery UI has set the tabs up. - # @return [String, nil] - def current - current_link&.text&.strip - end - - # Opens the tab labelled +label+: a String (case-insensitive) or a Regexp. - def switch(label) - link = find_link(label) || raise(Capybara::ElementNotFound, "no tab #{label.inspect} in #{labels.inspect}") - link.click - end - - # The body of the open tab, or of the first tab when none is marked open. - # @return [Capybara::Node::Element] - def body - fragment = current_link && current_link[:href].to_s[/#(.+)\z/, 1] - fragment ? find(:id, fragment) : find(:active_admin, :tab_panel, match: :first) - end - - # True when there is a tab labelled +label+. - def has_tab?(label, **options) - eventually(**options) { find_link(label) } - end - - # Waits until there is no tab labelled +label+. - def has_no_tab?(label, **options) - eventually(**options) { find_link(label).nil? } - end - - private - - def links - all(:active_admin, :tab_link) - end - - def current_link - first(:active_admin, :tab_current_link, minimum: 0, wait: false) - end - - def find_link(label) - links.find { |link| text_match?(link.text, label) } - end end end diff --git a/lib/active_admin_page_objects/text.rb b/lib/active_admin_page_objects/text.rb index efc52f8..5e99cb4 100644 --- a/lib/active_admin_page_objects/text.rb +++ b/lib/active_admin_page_objects/text.rb @@ -26,6 +26,41 @@ def text_match?(actual, expected) expected.is_a?(Regexp) ? expected.match?(squish(actual)) : same_text?(actual, expected) end + # Capybara options with a String `text:` or `exact_text:` turned into a + # case-insensitive Regexp in `text:`; when both are set, the Regexp keeps + # both. Chrome reports CSS-transformed text, so a tag uppercased by the + # theme still matches "verified". + # @return [Hash] + def case_insensitive_text(options) + text = options[:text] + exact = options[:exact_text] + return options if text.is_a?(Regexp) || !(text.is_a?(String) || exact.is_a?(String)) + + pattern = if exact.is_a?(String) + text_pattern(exact, exact: true, containing: text) + else + text_pattern(text, exact: exact == true) + end + options.except(:exact_text).merge(text: pattern) + end + + # A Regexp matching +text+ with any whitespace between its words, ignoring + # case. With +containing+, the match must also contain that text. + # @return [Regexp] + def text_pattern(text, exact: false, containing: nil) + words = word_pattern(text) + words = "\\A\\s*#{words}\\s*\\z" if exact + return Regexp.new(words, Regexp::IGNORECASE) unless containing + + Regexp.new("(?=.*?#{word_pattern(containing)})#{words}", Regexp::IGNORECASE | Regexp::MULTILINE) + end + + # The words of +text+, escaped and joined by `\\s+`. + # @return [String] + def word_pattern(text) + text.to_s.split.map { |word| Regexp.escape(word) }.join("\\s+") + end + # A date as the date inputs take it: "2026-01-31" for a Date or a Time, # and the text of anything else. # @return [String] @@ -33,7 +68,7 @@ def iso_date(value) value.respond_to?(:strftime) ? value.strftime("%Y-%m-%d") : value.to_s end - # The key ActiveAdmin writes into the `col-` and `row-` classes: + # The key ActiveAdmin writes into `data-column` and `data-row`: # `"EXTERNAL ID"` and `:external_id` both become `"external_id"`. # @return [String] def slug(key) diff --git a/lib/active_admin_page_objects/utility_navigation.rb b/lib/active_admin_page_objects/utility_navigation.rb deleted file mode 100644 index c89f1b6..0000000 --- a/lib/active_admin_page_objects/utility_navigation.rb +++ /dev/null @@ -1,26 +0,0 @@ -# frozen_string_literal: true - -module ActiveAdminPageObjects - # The utility navigation in the header: the current user and the logout - # link. Reached with `page.utility_navigation`. - class UtilityNavigation < Section - selector_key :utility_navigation - - # The item texts in document order. - # @return [Array] - def labels - all(:active_admin, :utility_navigation_item).map { |item| item.text.strip } - end - - # The current user's display name. - # @return [String] - def current_user - find(:active_admin, :utility_navigation_current_user).text.strip - end - - # Clicks the logout link. - def logout - find(:active_admin, :utility_navigation_logout).click - end - end -end diff --git a/lib/active_admin_page_objects/version.rb b/lib/active_admin_page_objects/version.rb index 2c18208..cce6ac5 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 = "2.0.0.beta1" end diff --git a/spec/active_admin_page_objects/action_items_spec.rb b/spec/active_admin_page_objects/action_items_spec.rb index 90c7d99..4660846 100644 --- a/spec/active_admin_page_objects/action_items_spec.rb +++ b/spec/active_admin_page_objects/action_items_spec.rb @@ -2,66 +2,25 @@ RSpec.describe ActiveAdminPageObjects::ActionItems do let(:index) { Pages::CustomerIndex.new } - let(:show) { Pages::CustomerShow.new } - describe "on an index page" do - before { index.load } + before { index.load } - it "lists the labels" do - expect(index.action_items.labels).to eq(["New Customer", "Report"]) - end - - it "checks for an item, ignoring case" do - expect(index.action_items).to have_item("new customer") - expect(index.action_items).to have_no_item("Delete Customer") - end - - it "clicks an item" do - index.action_items.click("New Customer") - expect(Pages::CustomerForm.new).to have_page_title(text: "New Customer") - end + it "lists the labels" do + expect(index.action_items.labels).to eq(["New Customer", "Report"]) end - shared_examples "action item dropdown" do - before { show.load(id: create_customer.id) } - - it "lists the dropdown button among the items" do - expect(show.action_items.labels).to eq(["Edit Customer", "Delete Customer", "More"]) - end - - it "reads the items of a closed dropdown" do - dropdown = show.action_items.dropdown("more") - expect(dropdown).to be_a(ActiveAdminPageObjects::DropdownMenu) - expect(dropdown.label).to eq("More") - expect(dropdown.labels).to eq(%w[Report Customers]) - expect(dropdown).to have_item("report") - expect(dropdown).to have_no_item("Export") - expect(show.action_items.dropdown.labels).to eq(%w[Report Customers]) - end - - it "opens the dropdown and clicks an item" do - show.action_items.dropdown("More").click("Customers") - expect(page).to have_current_path("/admin/customers") - end - - it "clicks an item of an open dropdown" do - dropdown = show.action_items.dropdown("More") - dropdown.open - dropdown.open - dropdown.click("report") - expect(index.flashes).to have_flash(:alert, "Report is not ready") - end + it "checks for an item, ignoring case" do + expect(index.action_items).to have_item("new customer") + expect(index.action_items).to have_no_item("Delete Customer") end - it_behaves_like "action item dropdown" - - context "with rack_test", driver: :rack_test do - it_behaves_like "action item dropdown" + it "clicks an item" do + index.action_items.click("New Customer") + expect(Pages::CustomerForm.new).to have_page_title(text: "New Customer") + end - it "raises for a missing dropdown or item" do - show.load(id: create_customer.id) - expect { show.action_items.dropdown("Nope") }.to raise_error(Capybara::ElementNotFound, /Nope/) - expect { show.action_items.dropdown("More").click("Nope") }.to raise_error(Capybara::ElementNotFound, /Nope/) - end + it "raises for the dropdown removed in ActiveAdmin 4" do + expect { index.action_items.dropdown("More") } + .to raise_error(ActiveAdminPageObjects::RemovedInActiveAdmin4, /action item dropdown/) end end diff --git a/spec/active_admin_page_objects/attributes_table_spec.rb b/spec/active_admin_page_objects/attributes_table_spec.rb index 4ac9d4f..e8adede 100644 --- a/spec/active_admin_page_objects/attributes_table_spec.rb +++ b/spec/active_admin_page_objects/attributes_table_spec.rb @@ -16,6 +16,10 @@ def declared_table(&) expect(show.attributes_table).to have_row(:name, exact_text: "Acme") expect(show.attributes_table).to have_row("Signed up") expect(show.attributes_table).to have_no_row(:name, exact_text: "Other") + expect(show.attributes_table).to have_row(:name, exact_text: "ACME") + expect(show.attributes_table).to have_row(:category, text: "wholesale") + expect(show.attributes_table).to have_no_row(:name, exact_text: "acm") + expect(show.attributes_table.has_no_row?(:name, exact_text: "acme", wait: 0)).to be(false) end it "reads a row and its value" do @@ -52,26 +56,17 @@ def declared_table(&) expect { partial.has_declared_rows?(except: :email) }.to raise_error(ArgumentError, /:email is not declared/) end - it "matches the status tag of a row" do - table = show.attributes_table - expect(table).to have_status_tag(:status, "Active") - expect(table).to have_status_tag(:status, "ACTIVE", type: "active") - expect(table).to have_no_status_tag(:status, "Pending") - expect(table).to have_no_status_tag(:status, "Active", type: "pending") - expect(table).to have_no_status_tag(:name, "Active") - expect(table.has_status_tag?(:status, "Pending", wait: 0)).to be(false) - expect(table.has_no_status_tag?(:status, "Active", wait: 0)).to be(false) - end - it "compares a declared label exactly" do wrong_case = declared_table do row :name, "Name" row :external_id, "External id" + row :signed_up, "Signed Up" row :notes, "Notes" end expect(wrong_case).to have_no_declared_rows expect(wrong_case.has_declared_rows?(wait: 0)).to be(false) - expect(wrong_case.declared_label_mismatches).to eq("external_id" => "External ID", "notes" => nil) + expect(wrong_case.declared_label_mismatches) + .to eq("external_id" => "External ID", "signed_up" => "Signed up", "notes" => nil) expect(declared_table { row :external_id, "External ID" }).to have_declared_rows end @@ -94,7 +89,7 @@ def declared_table(&) before do show.load(id: customer.id) - hide("tr.row-email") + hide('tr[data-row="email"]') end it "leaves a hidden row out by default" do @@ -116,7 +111,7 @@ def declared_table(&) end it "takes a hidden row when the query has visible: :all" do - expect(table.row(:email, visible: :all)[:class]).to include("row-email") + expect(table.row(:email, visible: :all)[:"data-row"]).to eq("email") expect(table.value(:email, visible: :all)).to eq(customer.email) expect(table).to have_row(:email, visible: :all, exact_text: customer.email) expect(table).to have_exact_rows(visible: :all) @@ -129,25 +124,23 @@ def declared_table(&) end it "takes a hidden row declared with visible: :all" do - hide("tr.row-status") + hide('tr[data-row="status"]') declared = declared_table do row :name, "Name" row :email, "Email", visible: :all row :status, "Status", visible: :all end expect(declared.class.declarations).to include("name" => { label: "Name" }, "email" => { label: "Email", visible: :all }) - expect(declared.row(:email)[:class]).to include("row-email") + expect(declared.row(:email)[:"data-row"]).to eq("email") expect(declared.value(:email)).to eq(customer.email) + expect(declared.value(:status)).to eq("Active") expect(declared).to have_row(:email, exact_text: customer.email) - expect(declared.status_tag(:status).label).to eq("Active") - expect(declared).to have_status_tag(:status, "Active") expect(declared).to have_declared_rows expect(declared).to have_exact_rows(only: %i[name email]) expect(declared.exact_mismatches).to include(missing: [], labels: {}) Capybara.using_wait_time(0) do expect { declared.row(:email, visible: :visible) }.to raise_error(Capybara::ElementNotFound) expect(declared.has_row?(:email, visible: :visible)).to be(false) - expect(declared.has_status_tag?(:status, "Active", visible: :visible)).to be(false) end expect(declared.declared_label_mismatches(visible: :visible)).to eq("email" => nil, "status" => nil) end @@ -168,9 +161,6 @@ def declared_table(&) expect { strict.has_no_row?(:notes) }.to raise_error(ArgumentError, message) expect { strict.row(:notes) }.to raise_error(ArgumentError, message) expect { strict.value(:notes) }.to raise_error(ArgumentError, message) - expect { strict.status_tag(:notes) }.to raise_error(ArgumentError, message) - expect { strict.has_status_tag?(:notes, "Active") }.to raise_error(ArgumentError, message) - expect { strict.has_no_status_tag?(:notes, "Active") }.to raise_error(ArgumentError, message) end # An empty scope compares nothing, so every matcher would pass on any page. diff --git a/spec/active_admin_page_objects/batch_actions_spec.rb b/spec/active_admin_page_objects/batch_actions_spec.rb index 3380750..5820389 100644 --- a/spec/active_admin_page_objects/batch_actions_spec.rb +++ b/spec/active_admin_page_objects/batch_actions_spec.rb @@ -11,7 +11,6 @@ expect(batch_actions).to have_action("Flag Selected") expect(batch_actions).to have_action("delete selected") expect(batch_actions).to have_action(:archive) - expect(batch_actions).to have_action(:set_status) expect(batch_actions).to have_no_action("Export Selected") expect(batch_actions).to have_no_action(:export) end @@ -26,31 +25,18 @@ # The button toggles the menu: a second click would close it. it "applies an action when the menu is already open" do batch_actions.select_all - find(".batch_actions_selector a.dropdown_menu_button").click - expect(page).to have_css(".batch_actions_selector .dropdown_menu_list_wrapper") + find(:active_admin, :batch_actions_button).click + expect(batch_actions).to have_selector(:active_admin, :batch_action_item, text: "Flag Selected") batch_actions.apply("Flag Selected") expect(index.flashes).to have_flash(:notice, "Flagged 3 customers") end - it "confirms the dialog of an action with a confirmation" do - batch_actions.select_all - batch_actions.apply("Archive Selected") - expect(index.flashes).to have_flash(:notice, "Archived 3 customers") - expect(index).to have_no_modal_dialog - end - - it "applies an action by its name" do + it "applies an action after accepting its confirmation" do batch_actions.select_all batch_actions.apply(:archive) expect(index.flashes).to have_flash(:notice, "Archived 3 customers") end - it "fills the dialog inputs of an action with a form" do - batch_actions.select_all - batch_actions.apply("Set Status Selected", status: "pending") - expect(index.flashes).to have_flash(:notice, "Set pending on 3 customers") - end - it "applies the default destroy action" do index.table.row(customers.first.id).select batch_actions.apply("Delete Selected") diff --git a/spec/active_admin_page_objects/breadcrumbs_spec.rb b/spec/active_admin_page_objects/breadcrumbs_spec.rb index 740e422..61c3161 100644 --- a/spec/active_admin_page_objects/breadcrumbs_spec.rb +++ b/spec/active_admin_page_objects/breadcrumbs_spec.rb @@ -6,10 +6,9 @@ before { show.load(id: customer.id) } - # ActiveAdmin 3 uppercases the trail in CSS and Chrome reports the uppercased text. it "lists the links and labels" do expect(show.breadcrumbs.links.size).to eq(2) - expect(show.breadcrumbs.labels.map(&:downcase)).to eq(%w[admin customers]) + expect(show.breadcrumbs.labels).to eq(%w[Admin Customers]) end it "matches the exact label sequence, ignoring case" do @@ -17,10 +16,4 @@ expect(show.breadcrumbs).to have_no_labels("Admin") expect(show.breadcrumbs).to have_no_labels("Customers", "Admin") end - - context "with rack_test", driver: :rack_test do - it "reads the labels as written" do - expect(show.breadcrumbs.labels).to eq(%w[Admin Customers]) - end - end end diff --git a/spec/active_admin_page_objects/comments_spec.rb b/spec/active_admin_page_objects/comments_spec.rb index 91c52d4..1f56843 100644 --- a/spec/active_admin_page_objects/comments_spec.rb +++ b/spec/active_admin_page_objects/comments_spec.rb @@ -3,21 +3,23 @@ RSpec.describe ActiveAdminPageObjects::Comments do let(:page_class) do Class.new(ActiveAdminPageObjects::Page) do - set_url "/admin/customers/{id}" + set_url "/admin/documents/{id}" section :comments, ActiveAdminPageObjects::Comments end end let(:show) { page_class.new } - let(:customer) { create_customer } + let(:document) { create_document } + + before { ActiveAdmin::Comment.delete_all } def create_comment(body) - author = AdminUser.first_or_create!(email: "admin@example.com") - ActiveAdmin::Comment.create!(namespace: "admin", resource: customer, author: author, body: body) + author = AdminUser.find_or_create_by!(name: "Demo Admin") + ActiveAdmin::Comment.create!(namespace: "admin", resource: document, author: author, body: body) end it "is empty without comments" do - show.load(id: customer.id) + show.load(id: document.id) expect(show.comments.count).to eq(0) expect(show.comments.bodies).to eq([]) @@ -26,23 +28,24 @@ def create_comment(body) end it "adds a comment" do - show.load(id: customer.id) + show.load(id: document.id) show.comments.add("First comment") expect(show.comments).to have_comment("First comment") expect(show.comments.count).to eq(1) expect(show.comments.bodies).to eq(["First comment"]) - expect(show.comments.authors).to eq(["admin@example.com"]) + expect(show.comments.authors).to eq(["Demo Admin"]) expect(ActiveAdmin::Comment.pluck(:body)).to eq(["First comment"]) end it "reads existing comments" do create_comment("First comment") create_comment("Second comment") - show.load(id: customer.id) + show.load(id: document.id) expect(show.comments.count).to eq(2) - expect(show.comments.bodies).to contain_exactly("First comment", "Second comment") + expect(show.comments.bodies).to eq(["First comment", "Second comment"]) + expect(show.comments.authors).to eq(["Demo Admin", "Demo Admin"]) expect(show.comments).to have_comment("Second") expect(show.comments).to have_no_comment("Third", wait: 0) end @@ -50,7 +53,7 @@ def create_comment(body) it "deletes a comment by its body" do create_comment("First comment") create_comment("Second comment") - show.load(id: customer.id) + show.load(id: document.id) show.comments.delete("First comment") expect(show.comments).to have_no_comment("First comment") @@ -58,4 +61,22 @@ def create_comment(body) expect(show.comments.count).to eq(1) expect(ActiveAdmin::Comment.pluck(:body)).to eq(["Second comment"]) end + + it "raises when no comment has the text to delete" do + create_comment("First comment") + show.load(id: document.id) + + expect { show.comments.delete("Missing") }.to raise_error(Capybara::ElementNotFound, /Missing/) + end + + context "with rack_test", driver: :rack_test do + it "reads existing comments" do + create_comment("First comment") + show.load(id: document.id) + + expect(show.comments.count).to eq(1) + expect(show.comments.bodies).to eq(["First comment"]) + expect(show.comments.authors).to eq(["Demo Admin"]) + end + end end diff --git a/spec/active_admin_page_objects/disabled_fields_spec.rb b/spec/active_admin_page_objects/disabled_fields_spec.rb index 28ce2ba..57634b4 100644 --- a/spec/active_admin_page_objects/disabled_fields_spec.rb +++ b/spec/active_admin_page_objects/disabled_fields_spec.rb @@ -104,26 +104,4 @@ expect(form).to have_disabled_field(:code, visible: :all) expect(form.has_disabled_field?(:code, wait: 0)).to be(false) end - - shared_examples "disabled fieldset fields" do - it "matches the disabled fields of a has_many fieldset" do - customer = create_customer - Order.create!(customer: customer, reference: "REF-1", state: "paid", quantity: 2) - customers = Pages::CustomerForm.new - customers.load(id: customer.id, action: "edit", query: { lock_quantity: 1 }) - fieldset = customers.form.has_many(:orders).fieldset(0) - - expect(fieldset).to have_disabled_field(:quantity) - expect(fieldset).to have_enabled_field(:reference) - expect(fieldset).to have_no_disabled_field(:state) - expect(fieldset.field(:quantity)).to be_disabled - expect(customers.form).to have_enabled_field(:name) - end - end - - it_behaves_like "disabled fieldset fields" - - context "with rack_test", driver: :rack_test do - it_behaves_like "disabled fieldset fields" - end end diff --git a/spec/active_admin_page_objects/extension_spec.rb b/spec/active_admin_page_objects/extension_spec.rb index 6a19647..6985285 100644 --- a/spec/active_admin_page_objects/extension_spec.rb +++ b/spec/active_admin_page_objects/extension_spec.rb @@ -89,12 +89,11 @@ def paragraphs ChooseOptionSpy.chosen.clear end - it "registers a selector for a key ActiveAdmin 3 lacks" do - ActiveAdminPageObjects.register_selectors(dark_mode_toggle: "#site_title") - dashboard = Pages::Dashboard.new - dashboard.load - expect(dashboard).to have_dark_mode_toggle - expect(dashboard).to have_theme_switcher + it "registers a selector for a removed key" do + ActiveAdminPageObjects.register_selectors(tabs: "[data-test-page-header]") + show = Pages::CustomerShow.new + show.load(id: create_customer.id) + expect(show).to have_tabs end it "adds a section to every class that includes Layout" do diff --git a/spec/active_admin_page_objects/filters_spec.rb b/spec/active_admin_page_objects/filters_spec.rb index 0c38577..309fb0f 100644 --- a/spec/active_admin_page_objects/filters_spec.rb +++ b/spec/active_admin_page_objects/filters_spec.rb @@ -91,10 +91,8 @@ def declared_filters(&) Capybara::ExpectationNotMet, ":email is declared as ActiveAdminPageObjects::NumericFilter, but the page has ActiveAdminPageObjects::StringFilter" ) - expect { mistyped.filter(:email) }.to raise_error(Capybara::ExpectationNotMet, /NumericFilter/) - expect do - mistyped.filter(:balance) - end.to raise_error(Capybara::ExpectationNotMet, /PredicateFilter, but the page has .*NumericFilter/) + expect { mistyped.filter(:balance) } + .to raise_error(Capybara::ExpectationNotMet, /PredicateFilter, but the page has .*NumericFilter/) expect(mistyped).to have_declared_filters end @@ -153,12 +151,6 @@ def declared_filters(&) .to raise_error(ArgumentError, '`filter :email` needs a section class, got "StringFilter"') end - it "declares a name that is a method of the section and reaches it with filter" do - index.load - named = Class.new(described_class) { filter :name, "Name", ActiveAdminPageObjects::StringFilter } - expect(named.new(index, filters.root_element).filter(:name)).to be_an_instance_of(ActiveAdminPageObjects::StringFilter) - end - it "inherits declarations and leaves the superclass unchanged" do subclass = Class.new(strict_class) do filter :status, "Status", ActiveAdminPageObjects::SelectFilter @@ -207,8 +199,7 @@ def declared_filters(&) expect(filters.filter(:category)).to be_a(ActiveAdminPageObjects::SelectFilter) expect(filters.filter(:active)).to be_a(ActiveAdminPageObjects::BooleanFilter) expect(filters.filter(:created_at)).to be_a(ActiveAdminPageObjects::DateRangeFilter) - # ActiveAdmin 3 uppercases sidebar labels in CSS and Chrome reports the uppercased text. - expect(filters.filter(:name).label).to match(/\Aname\z/i) + expect(filters.filter(:name).label).to eq("Name") end it "has no type registry" do @@ -219,7 +210,7 @@ def declared_filters(&) it "returns a Filter for a wrapper class the gem has no class for" do index.load - page.execute_script("document.querySelector('#q_created_at_input').className = 'date_time_picker input filter_form_field'") + page.execute_script("document.querySelector('#q_created_at_input').className = 'date_time_picker input filters-form-field'") expect(described_class.new(index, filters.root_element).filter(:created_at)) .to be_an_instance_of(ActiveAdminPageObjects::Filter) end @@ -526,7 +517,6 @@ def native_select_visibility = :all expect(index.table).to have_rows(count: 3) end - # "Clear Filters" is left out: ActiveAdmin 3 clears in JavaScript. context "with rack_test", driver: :rack_test do it_behaves_like "declared filters" @@ -540,6 +530,8 @@ def native_select_visibility = :all expect(names).to eq(["Alpha"]) expect(filters.filter(:status)).to have_selected("active") expect(filters.filter(:created_at)).to have_range("2026-01-01", "2026-12-31") + filters.clear + expect(index.table).to have_rows(count: 3) end end end diff --git a/spec/active_admin_page_objects/flashes_spec.rb b/spec/active_admin_page_objects/flashes_spec.rb index d345b38..499395f 100644 --- a/spec/active_admin_page_objects/flashes_spec.rb +++ b/spec/active_admin_page_objects/flashes_spec.rb @@ -13,7 +13,6 @@ expect(index.flashes).to have_flash(:error, "Report failed") expect(index.flashes).to have_flash(:error) expect(index.flashes).to have_no_flash(:notice) - expect(index.flashes).to have_no_flash(:warning) expect(index.flashes).to have_no_flash(:alert, "Report failed") end @@ -22,16 +21,10 @@ expect(index.flashes.messages(:error)).to eq(["Report failed"]) end - it "rejects a type outside TYPES" do - expect { index.flashes.has_flash?(:info) }.to raise_error(ArgumentError, /flash type/) + it "rejects a type ActiveAdmin does not render" do + expect { index.flashes.has_flash?(:warning) }.to raise_error(ArgumentError, /flash type/) expect { index.flashes.has_flash?(nil) }.to raise_error(ArgumentError, /flash type must be one of .*got nil/) expect { index.flashes.has_no_flash?(nil) }.to raise_error(ArgumentError, /flash type/) expect { index.flashes.messages(42) }.to raise_error(ArgumentError, /got 42/) end - - it "finds no flash on a page without flashes" do - index.load - expect(index.flashes).to have_no_flash(:notice) - expect(index.flashes.messages).to eq([]) - end end diff --git a/spec/active_admin_page_objects/form_spec.rb b/spec/active_admin_page_objects/form_spec.rb index 74c4302..47c4b66 100644 --- a/spec/active_admin_page_objects/form_spec.rb +++ b/spec/active_admin_page_objects/form_spec.rb @@ -146,7 +146,7 @@ def declared_form(&) expect(partial.has_exact_fields?(wait: 0)).to be(false) expect(partial.exact_mismatches).to eq( missing: ["secret"], - unexpected: %w[name external_id category balance active notes website phone password tier channels signed_on orders], + unexpected: %w[name external_id category balance active notes website phone password tier channels signed_on], labels: { "email" => "Email" } ) end @@ -164,7 +164,7 @@ def declared_form(&) expect(partial.exact_mismatches(except: :secret)[:missing]).to eq([]) expect(partial.exact_mismatches(except: :email)).to include(missing: ["secret"], labels: {}) expect(partial.exact_mismatches(except: :email)[:unexpected]).not_to include("email") - expect(form).to have_exact_fields(except: %i[notes orders]) + expect(form).to have_exact_fields(except: %i[notes signed_on]) expect { form.has_exact_fields?(only: :secret) }.to raise_error(ArgumentError, /:secret is not declared/) expect { form.has_declared_fields?(except: [:secret]) }.to raise_error(ArgumentError, /:secret is not declared/) expect { form.exact_mismatches(except: :secret) }.to raise_error(ArgumentError, /:secret is not declared/) @@ -195,19 +195,29 @@ def declared_form(&) "but the page has ActiveAdminPageObjects::Form::SelectField" ) expect { mistyped.fill(status: "pending") }.to raise_error(Capybara::ExpectationNotMet, /RadioField/) - expect do - mistyped.field(:signed_on) - end.to raise_error(Capybara::ExpectationNotMet, /StringField, but the page has .*DatePickerField/) + expect { mistyped.field(:signed_on) } + .to raise_error(Capybara::ExpectationNotMet, /StringField, but the page has .*DatePickerField/) expect { mistyped.field(:email) }.to raise_error(Capybara::ExpectationNotMet, /Form::Field, but the page has .*StringField/) expect(mistyped).to have_declared_fields end + it "takes a name that is a method of the section" do + form_page.load(action: "new") + reserved = declared_form do + field :name, "Name", ActiveAdminPageObjects::Form::StringField + field :title, "Title", ActiveAdminPageObjects::Form::StringField + end + reserved.field(:name).fill("Acme") + expect(reserved.field(:name).value).to eq("Acme") + expect(reserved).to have_no_field_error(:name) + expect(reserved).to have_declared_fields(only: :name) + end + it "takes any key without declarations" do form_page.load(action: "new") lenient = described_class.new(form_page, form.root_element) expect(lenient).to have_no_field_error(:secret) expect(lenient.field(:name)).to be_an_instance_of(ActiveAdminPageObjects::Form::StringField) - expect(lenient.has_many(:orders)).to be_an_instance_of(ActiveAdminPageObjects::HasMany) expect { lenient.has_declared_fields? }.to raise_error(ArgumentError, /declares no labels/) expect { lenient.has_exact_fields? }.to raise_error(ArgumentError, /declares no labels/) expect { lenient.exact_mismatches }.to raise_error(ArgumentError, /declares no labels/) @@ -272,7 +282,7 @@ def declared_form(&) expect(channels.checked).to eq([]) end - it "returns a DatePickerField for a datepicker" do + it "returns a DatePickerField for a date_picker" do signed_on = form.field(:signed_on) expect(signed_on).to be_an_instance_of(ActiveAdminPageObjects::Form::DatePickerField) signed_on.fill("2026-01-31") @@ -282,8 +292,10 @@ def declared_form(&) end it "saves what the typed fields set" do - form.fill(name: "Acme", email: "acme@example.com", website: "https://acme.example.com", - phone: "+1 555 0100", tier: "Gold", channels: %w[Email Post], signed_on: "2026-01-31") + form.fill( + name: "Acme", email: "acme@example.com", website: "https://acme.example.com", + phone: "+1 555 0100", tier: "Gold", channels: %w[Email Post], signed_on: "2026-01-31" + ) form.submit expect(form_page.flashes).to have_flash(:notice, "Customer was successfully created.") @@ -291,34 +303,6 @@ def declared_form(&) channels: %w[Email Post], signed_on: Date.new(2026, 1, 31)) end end - - describe "declared has_many blocks" do - before { form_page.load(action: "new") } - - it "returns the declared has_many by its name" do - expect(form.has_many(:orders).class).to be < ActiveAdminPageObjects::HasMany - expect(form.has_many(:orders).heading).to eq("Orders") - expect { form.has_many(:tags) }.to raise_error(ArgumentError, /:tags is not declared; declared keys: orders/) - expect { form.field(:orders) }.to raise_error(ArgumentError, /:orders is declared as a has_many, not as a field/) - expect { form.has_field_error?(:orders) }.to raise_error(ArgumentError, /has_many/) - end - - it "compares the heading with the label matchers" do - relabeled = declared_form { has_many :orders, "Order list" } - expect(relabeled).to have_no_declared_fields - expect(relabeled.declared_label_mismatches).to eq("orders" => "Orders") - expect(relabeled.exact_mismatches[:unexpected]).not_to include("orders") - expect(declared_form { has_many :orders, nil }.declared_label_mismatches).to eq("orders" => "Orders") - expect(declared_form { has_many :tags, "Tags" }.exact_mismatches).to include(missing: ["tags"]) - expect(declared_form { has_many :tags, nil }.declared_label_mismatches).to eq("tags" => nil) - end - - it "takes an undeclared has_many when the form declares none" do - fields_only = declared_form { field :email, "Email", ActiveAdminPageObjects::Form::StringField } - expect(fields_only.has_many(:orders)).to be_an_instance_of(ActiveAdminPageObjects::HasMany) - expect(fields_only.exact_mismatches[:unexpected]).to include("orders") - end - end end it_behaves_like "resource form" @@ -327,13 +311,6 @@ def declared_form(&) it_behaves_like "resource form" end - it "matches a has_many without a heading when nil is declared" do - form_page.load(action: "new") - page.execute_script("document.querySelector('.has_many_container.orders > h3').remove()") - expect(declared_form { has_many :orders, nil }).to have_declared_fields - expect(declared_form { has_many :orders, "Orders" }.declared_label_mismatches).to eq("orders" => "") - end - it "tells required fields and reads a field's control" do form_page.load(action: "new") expect(form.field(:name)).to be_required @@ -432,33 +409,6 @@ def declared_form(&) expect(declared.field(:notes, visible: :hidden)).to be_an_instance_of(klass) end - it "does not require a hidden has_many block" do - hide(".has_many_container.orders") - fields = form.class.declarations.reject { |_name, declaration| declaration[:kind] == :has_many } - fields_only = declared_form { fields.each { |name, declaration| field name, declaration[:label], declaration[:type] } } - expect(fields_only).to have_exact_fields - expect(fields_only).to have_no_exact_fields(visible: :all) - expect(fields_only.exact_mismatches(visible: :all)).to eq(missing: [], unexpected: ["orders"], labels: {}) - end - - it "finds a hidden has_many block with visible: :all" do - hide(".has_many_container.orders") - Capybara.using_wait_time(0) { expect { form.has_many(:orders) }.to raise_error(Capybara::ElementNotFound) } - expect(form.exact_mismatches).to eq(missing: ["orders"], unexpected: [], labels: {}) - expect(form.has_many(:orders, visible: :all).class).to be < ActiveAdminPageObjects::HasMany - expect(form).to have_exact_fields(visible: :all) - expect(described_class.new(form_page, form.root_element).has_many(:orders, visible: :all)) - .to be_an_instance_of(ActiveAdminPageObjects::HasMany) - - declared = declared_form { has_many :orders, "Orders", visible: :all } - expect(declared.class.declarations["orders"]).to include(label: "Orders", kind: :has_many, visible: :all) - expect(declared.has_many(:orders).class).to be < ActiveAdminPageObjects::HasMany - expect(declared).to have_declared_fields - Capybara.using_wait_time(0) do - expect { declared.has_many(:orders, visible: :visible) }.to raise_error(Capybara::ElementNotFound) - end - end - it "counts the errors of a hidden field when it is declared or queried with visible: :all" do form.fill(name: "", email: "not-an-email") form.submit @@ -610,18 +560,6 @@ def native_select_visibility = :all .to raise_error(ArgumentError, "`field :email` needs a section class, got nil") end - it "declares names that are methods of the section and reaches them with field" do - form_page.load(action: "new") - named = declared_form do - field :name, "Name", ActiveAdminPageObjects::Form::StringField - field :title, "Title", ActiveAdminPageObjects::Form::StringField - end - expect(named.class.declarations.keys).to eq(%w[name title]) - expect(named.field(:name)).to be_an_instance_of(ActiveAdminPageObjects::Form::StringField) - named.field(:name).fill("Acme") - expect(named.field(:name).value).to eq("Acme") - end - it "lets a subclass declare an inherited name again" do select_class = Class.new(ActiveAdminPageObjects::Form::SelectField) subclass = Class.new(strict_class) { field :email, "E-mail", select_class } diff --git a/spec/active_admin_page_objects/has_many_spec.rb b/spec/active_admin_page_objects/has_many_spec.rb index cafad09..555d1bf 100644 --- a/spec/active_admin_page_objects/has_many_spec.rb +++ b/spec/active_admin_page_objects/has_many_spec.rb @@ -1,104 +1,108 @@ # frozen_string_literal: true RSpec.describe ActiveAdminPageObjects::HasMany do - let(:form_page) { Pages::CustomerForm.new } + let(:form_page) { Pages::OrderForm.new } let(:form) { form_page.form } - let(:orders) { form.has_many(:orders) } - let(:customer) { create_customer(status: "pending") } + let(:line_items) { form.has_many(:line_items) } + let(:customer) { create_customer } + let(:order) { Order.create!(customer: customer, reference: "ORD-1", state: "new", quantity: 1) } - def create_order(reference, state, quantity) - Order.create!(customer: customer, reference: reference, state: state, quantity: quantity) + def create_line_item(sku, kind, quantity) + LineItem.create!(order: order, sku: sku, kind: kind, quantity: quantity) end - # The orders has_many of the form, with the fieldset fields the block declares. - def declared_orders(&) - form_class = Class.new(ActiveAdminPageObjects::Form) { has_many(:orders, "Orders", &) } - form_class.new(form_page, form.root_element).has_many(:orders) + # A form over the page's element, with the fields and has_many blocks the block declares. + def declared_form(&) + Class.new(ActiveAdminPageObjects::Form, &).new(form_page, form.root_element) + end + + # The line_items has_many of the form, with the fieldset fields the block declares. + def declared_line_items(&) + declared_form { has_many(:line_items, "Line Items", &) }.has_many(:line_items) end shared_examples "saved fieldsets" do before do - create_order("REF-1", "paid", 2) - create_order("REF-B1", "new", 1) - form_page.load(id: customer.id, action: "edit") + create_line_item("SKU-1", "Goods", 2) + create_line_item("SKU-B1", "Service", 1) + form_page.load(id: order.id, action: "edit") end it "reads the heading and counts the fieldsets" do - expect(orders.heading).to eq("Orders") - expect(orders.count).to eq(2) - expect(orders.fieldsets.size).to eq(2) - expect(orders).to have_fieldsets(count: 2) - expect(orders).to have_no_fieldsets(count: 3) + expect(line_items.heading).to eq("Line Items") + expect(line_items.count).to eq(2) + expect(line_items.fieldsets.size).to eq(2) + expect(line_items).to have_fieldsets(count: 2) + expect(line_items).to have_no_fieldsets(count: 3) end it "reads the declared fields of a fieldset by index" do - expect(orders.fieldset(0).field(:reference)).to have_field(with: "REF-1") - expect(orders.fieldset(1).field(:reference).value).to eq("REF-B1") - expect(orders.fieldset(0).field(:quantity).value).to eq("2") - expect(orders.fieldset(0).field(:quantity)).to be_an_instance_of(ActiveAdminPageObjects::Form::StringField) - expect(orders.fieldset(0).field(:state).selected).to eq("paid") - expect(orders.fieldsets.map { |fieldset| fieldset.field(:reference).value }).to eq(%w[REF-1 REF-B1]) - expect { orders.fieldset(0).field(:price) } - .to raise_error(ArgumentError, /:price is not declared; declared keys: reference, state, quantity/) + expect(line_items.fieldset(0).field(:sku)).to have_field(with: "SKU-1") + expect(line_items.fieldset(1).field(:sku).value).to eq("SKU-B1") + expect(line_items.fieldset(0).field(:quantity).value).to eq("2") + expect(line_items.fieldset(0).field(:quantity)).to be_an_instance_of(ActiveAdminPageObjects::Form::StringField) + expect(line_items.fieldset(0).field(:kind).selected).to eq("Goods") + expect(line_items.fieldsets.map { |fieldset| fieldset.field(:sku).value }).to eq(%w[SKU-1 SKU-B1]) + expect { line_items.fieldset(0).field(:price) } + .to raise_error(ArgumentError, /:price is not declared; declared keys: sku, kind, quantity/) end it "types the fields of an undeclared has_many by the page" do - fieldset = ActiveAdminPageObjects::Form.new(form_page, form.root_element).has_many(:orders).fieldset(0) + fieldset = ActiveAdminPageObjects::Form.new(form_page, form.root_element).has_many(:line_items).fieldset(0) expect(fieldset).to be_an_instance_of(described_class::Fieldset) - expect(fieldset.field(:reference)).to be_an_instance_of(ActiveAdminPageObjects::Form::StringField) - expect(fieldset.field(:state)).to be_an_instance_of(ActiveAdminPageObjects::Form::SelectField) + expect(fieldset.field(:sku)).to be_an_instance_of(ActiveAdminPageObjects::Form::StringField) + expect(fieldset.field(:kind)).to be_an_instance_of(ActiveAdminPageObjects::Form::SelectField) expect { fieldset.has_exact_fields? }.to raise_error(ArgumentError, /declares no labels/) end it "has the declared fields in each fieldset and no other" do - expect(orders).to have_fieldsets(count: 2) - expect(orders.fieldsets).to all(have_declared_fields) - expect(orders.fieldsets).to all(have_exact_fields) - expect(orders.fieldset(1).exact_mismatches).to eq(missing: [], unexpected: [], labels: {}) + expect(line_items).to have_fieldsets(count: 2) + expect(line_items.fieldsets).to all(have_declared_fields) + expect(line_items.fieldsets).to all(have_exact_fields) + expect(line_items.fieldset(1).exact_mismatches).to eq(missing: [], unexpected: [], labels: {}) end it "reports the fieldset fields that differ from the declared ones" do - partial = declared_orders do - field :reference, "Code", ActiveAdminPageObjects::Form::StringField - field :state, "State", ActiveAdminPageObjects::Form::SelectField + partial = declared_line_items do + field :sku, "Code", ActiveAdminPageObjects::Form::StringField + field :kind, "Kind", ActiveAdminPageObjects::Form::SelectField field :price, "Price", ActiveAdminPageObjects::Form::StringField end fieldset = partial.fieldset(0) - expect(fieldset.field(:reference).value).to eq("REF-1") + expect(fieldset.field(:sku).value).to eq("SKU-1") expect(fieldset).to have_no_exact_fields expect(fieldset).to have_no_declared_fields - expect(fieldset.declared_label_mismatches).to eq("reference" => "Reference", "price" => nil) - expect(fieldset.exact_mismatches).to eq(missing: ["price"], unexpected: ["quantity"], - labels: { "reference" => "Reference" }) - expect(fieldset).to have_exact_fields(only: :state) - expect(fieldset).to have_declared_fields(except: %i[reference price]) + expect(fieldset.declared_label_mismatches).to eq("sku" => "Sku", "price" => nil) + expect(fieldset.exact_mismatches).to eq(missing: ["price"], unexpected: ["quantity"], labels: { "sku" => "Sku" }) + expect(fieldset).to have_exact_fields(only: :kind) + expect(fieldset).to have_declared_fields(except: %i[sku price]) end it "builds the class a fieldset field is declared with" do select_class = Class.new(ActiveAdminPageObjects::Form::SelectField) - typed = declared_orders do - field :state, "State", select_class - field :reference, "Reference", ActiveAdminPageObjects::Form::SelectField + typed = declared_line_items do + field :kind, "Kind", select_class + field :sku, "Sku", ActiveAdminPageObjects::Form::SelectField end - expect(typed.fieldset(0).field(:state)).to be_an_instance_of(select_class) - expect { typed.fieldset(0).field(:reference) } - .to raise_error(Capybara::ExpectationNotMet, /SelectField, but the page has .*StringField/) + expect(typed.fieldset(0).field(:kind)).to be_an_instance_of(select_class) + expect { typed.fieldset(0).field(:sku) } + .to raise_error(ActiveAdminPageObjects::DeclaredClassMismatch, /SelectField, but the page has .*StringField/) end it "compares the inline errors of a fieldset" do - orders.fieldset(1).fill(reference: "REF-B2", quantity: 0) + line_items.fieldset(1).fill(sku: "SKU-B2", quantity: 0) form.submit expect(form).to have_field_errors expect(form).to have_exact_field_errors - expect(orders.fieldset(0)).to have_no_field_errors - expect(orders.fieldset(0)).to have_exact_field_errors - expect(orders.fieldset(1)).to have_field_errors - expect(orders.fieldset(1)).to have_field_error(:quantity, "must be greater than 0") - expect(orders.fieldset(1)).to have_no_field_error(:reference) - expect(orders.fieldset(1)).to have_exact_field_errors(quantity: "must be greater than 0") - expect(orders.fieldset(1)).to have_no_exact_field_errors - expect(orders.fieldset(1)).to have_no_exact_field_errors(reference: "must be greater than 0") + expect(line_items.fieldset(0)).to have_no_field_errors + expect(line_items.fieldset(0)).to have_exact_field_errors + expect(line_items.fieldset(1)).to have_field_errors + expect(line_items.fieldset(1)).to have_field_error(:quantity, "must be greater than 0") + expect(line_items.fieldset(1)).to have_no_field_error(:sku) + expect(line_items.fieldset(1)).to have_exact_field_errors(quantity: "must be greater than 0") + expect(line_items.fieldset(1)).to have_no_exact_field_errors + expect(line_items.fieldset(1)).to have_no_exact_field_errors(sku: "must be greater than 0") Capybara.using_wait_time(0) { expect(form.has_no_field_errors?).to be(false) } end end @@ -109,28 +113,28 @@ def declared_orders(&) it_behaves_like "saved fieldsets" end - context "when editing a customer with two orders" do + context "when editing an order with two line items" do before do - create_order("REF-1", "paid", 2) - create_order("REF-B1", "new", 1) - form_page.load(id: customer.id, action: "edit") + create_line_item("SKU-1", "Goods", 2) + create_line_item("SKU-B1", "Service", 1) + form_page.load(id: order.id, action: "edit") end - it "adds a fieldset, fills it and saves the order" do - fieldset = orders.add - expect(orders).to have_fieldsets(count: 3) + it "adds a fieldset, fills it and saves the line item" do + fieldset = line_items.add + expect(line_items).to have_fieldsets(count: 3) expect(fieldset).to have_exact_fields - fieldset.fill(reference: "REF-NEW", state: "shipped", quantity: 5) + fieldset.fill(sku: "SKU-NEW", kind: "Service", quantity: 5) form.submit - expect(form_page.flashes).to have_flash(:notice, "Customer was successfully updated.") - expect(customer.orders.pluck(:reference)).to match_array(%w[REF-1 REF-B1 REF-NEW]) - expect(customer.orders.find_by(reference: "REF-NEW")).to have_attributes(state: "shipped", quantity: 5) + expect(form_page.flashes).to have_flash(:notice, "Order was successfully updated.") + expect(order.line_items.pluck(:sku)).to match_array(%w[SKU-1 SKU-B1 SKU-NEW]) + expect(order.line_items.find_by(sku: "SKU-NEW")).to have_attributes(kind: "Service", quantity: 5) end it "leaves a hidden fieldset field out unless it is declared or queried with visible: :all" do - hide("#customer_orders_attributes_0_quantity_input") - fieldset = orders.fieldset(0) + hide("#order_line_items_attributes_0_quantity_input") + fieldset = line_items.fieldset(0) Capybara.using_wait_time(0) do expect { fieldset.field(:quantity) }.to raise_error(Capybara::ElementNotFound) expect(fieldset.has_exact_fields?).to be(false) @@ -138,15 +142,15 @@ def declared_orders(&) expect(fieldset.exact_mismatches).to eq(missing: ["quantity"], unexpected: [], labels: {}) expect(fieldset.field(:quantity, visible: :all)).to be_an_instance_of(ActiveAdminPageObjects::Form::StringField) expect(fieldset).to have_exact_fields(visible: :all) - expect(orders.fieldset(1)).to have_exact_fields + expect(line_items.fieldset(1)).to have_exact_fields - partial = declared_orders { field :reference, "Reference", ActiveAdminPageObjects::Form::StringField }.fieldset(0) - expect(partial.exact_mismatches[:unexpected]).to eq(["state"]) - expect(partial.exact_mismatches(visible: :all)[:unexpected]).to eq(%w[state quantity]) + partial = declared_line_items { field :sku, "Sku", ActiveAdminPageObjects::Form::StringField }.fieldset(0) + expect(partial.exact_mismatches[:unexpected]).to eq(["kind"]) + expect(partial.exact_mismatches(visible: :all)[:unexpected]).to eq(%w[kind quantity]) - declared = declared_orders do - field :reference, "Reference", ActiveAdminPageObjects::Form::StringField - field :state, "State", ActiveAdminPageObjects::Form::SelectField + declared = declared_line_items do + field :sku, "Sku", ActiveAdminPageObjects::Form::StringField + field :kind, "Kind", ActiveAdminPageObjects::Form::SelectField field :quantity, "Quantity", ActiveAdminPageObjects::Form::StringField, visible: :all end expect(declared).to have_fieldsets(count: 2) @@ -155,48 +159,47 @@ def declared_orders(&) end it "removes a new fieldset with its remove link" do - orders.add - expect(orders).to have_fieldsets(count: 3) - orders.remove(2) - expect(orders).to have_fieldsets(count: 2) + line_items.add + expect(line_items).to have_fieldsets(count: 3) + line_items.remove(2) + expect(line_items).to have_fieldsets(count: 2) end it "raises when a fieldset has neither a remove link nor a delete checkbox" do - page.execute_script("document.querySelectorAll('li.has_many_delete').forEach((node) => node.remove())") - expect { orders.remove(0) }.to raise_error(ArgumentError, /no remove link and no delete checkbox/) - expect(orders).to have_fieldsets(count: 2) + page.execute_script("document.querySelectorAll('li.has-many-delete').forEach((node) => node.remove())") + expect { line_items.remove(0) }.to raise_error(ArgumentError, /no remove link and no delete checkbox/) + expect(line_items).to have_fieldsets(count: 2) end - it "marks a saved fieldset for deletion and destroys the order on save" do - expect(orders.fieldset(0)).not_to be_marked_for_destroy - orders.remove(0) - expect(orders.fieldset(0)).to be_marked_for_destroy + it "marks a saved fieldset for deletion and destroys the line item on save" do + expect(line_items.fieldset(0)).not_to be_marked_for_destroy + line_items.remove(0) + expect(line_items.fieldset(0)).to be_marked_for_destroy form.submit - expect(form_page.flashes).to have_flash(:notice, "Customer was successfully updated.") - expect(customer.orders.pluck(:reference)).to eq(["REF-B1"]) + expect(form_page.flashes).to have_flash(:notice, "Order was successfully updated.") + expect(order.line_items.pluck(:sku)).to eq(["SKU-B1"]) end end - # The dummy form puts a check_boxes input first for this customer: its - # hidden input is named `customer[orders_attributes][0][tags][]`. + # The dummy form puts a check_boxes input first for this order: its + # hidden input is named `order[line_items_attributes][0][tags][]`. shared_examples "a fieldset that starts with a check_boxes input" do - let(:customer) { create_customer(external_id: "ORDER-TAGS") } + let(:order) { Order.create!(customer: customer, reference: "LINE-TAGS") } # Found again on each call: the form is rendered anew after a submit. def fieldset - ActiveAdminPageObjects::Form.new(form_page, form_page.form.root_element).has_many(:orders).fieldset(0) + ActiveAdminPageObjects::Form.new(form_page, form_page.form.root_element).has_many(:line_items).fieldset(0) end before do - create_order("REF-1", "paid", 2) - form_page.load(id: customer.id, action: "edit") + create_line_item("SKU-1", "Goods", 2) + form_page.load(id: order.id, action: "edit") end it "finds the fields by the fieldset prefix" do expect(fieldset.field(:tags)).to be_an_instance_of(ActiveAdminPageObjects::Form::CheckBoxesField) - expect(fieldset.field(:reference).value).to eq("REF-1") - expect(fieldset).to have_enabled_field(:quantity) + expect(fieldset.field(:sku).value).to eq("SKU-1") end it "sees the inline errors of the fieldset" do @@ -216,22 +219,77 @@ def fieldset it_behaves_like "a fieldset that starts with a check_boxes input" end - context "when creating a customer" do - before { form_page.load(action: "new") } + context "when creating an order" do + before do + customer + form_page.load(action: "new") + end it "starts without fieldsets" do - expect(orders.count).to eq(0) - expect(orders).to have_no_fieldsets + expect(line_items.count).to eq(0) + expect(line_items).to have_no_fieldsets end - it "adds a fieldset and saves the customer with its order" do - form.fill(name: "Acme", email: "acme@example.com") - orders.add.field(:reference).fill("REF-NEW") - form.add_order("REF-2") + it "adds a fieldset and saves the order with its line item" do + form.fill(reference: "ORD-NEW", customer: customer.name) + line_items.add.field(:sku).fill("SKU-NEW") + line_items.add.fill(sku: "SKU-2", kind: "Service") form.submit - expect(form_page.flashes).to have_flash(:notice, "Customer was successfully created.") - expect(Customer.last.orders.pluck(:reference)).to eq(%w[REF-NEW REF-2]) + expect(form_page.flashes).to have_flash(:notice, "Order was successfully created.") + expect(Order.last.line_items.pluck(:sku)).to eq(%w[SKU-NEW SKU-2]) + end + end + + describe "the has_many block of the form" do + before { form_page.load(action: "new") } + + it "counts the block once, as its declared element" do + expect(form).to have_exact_fields + expect(form).to have_declared_fields + expect(form.exact_mismatches).to eq(missing: [], unexpected: [], labels: {}) + expect(form.declared_label_mismatches).to eq({}) + end + + it "does not count the inputs of its fieldsets" do + line_items.add + expect(form).to have_exact_fields + expect(form.exact_mismatches).to eq(missing: [], unexpected: [], labels: {}) + end + + it "reports a block that is not declared, or declared with another heading" do + fields = lambda do |heading| + declared_form do + field :reference, "Reference", ActiveAdminPageObjects::Form::StringField + field :state, "State", ActiveAdminPageObjects::Form::SelectField + field :quantity, "Quantity", ActiveAdminPageObjects::Form::StringField + field :customer, "Customer", ActiveAdminPageObjects::Form::SelectField + has_many :line_items, heading if heading + end + end + expect(fields.call(nil).exact_mismatches).to eq(missing: [], unexpected: ["line_items"], labels: {}) + expect(fields.call("Items").exact_mismatches).to eq(missing: [], unexpected: [], labels: { "line_items" => "Line Items" }) + end + + it "reports a declared block the page lacks" do + absent = declared_form { has_many :parts, "Parts" } + expect(absent.declared_label_mismatches).to eq("parts" => nil) + end + + it "is not a field" do + expect { form.field(:line_items) }.to raise_error(ArgumentError, /:line_items is declared as a has_many, not as a field/) + expect { form.has_many(:orders) }.to raise_error(ArgumentError, /:orders is not declared; declared keys: line_items/) + end + + it "is found when hidden only with visible: :all, or when declared with it" do + hide(".has-many-container") + Capybara.using_wait_time(0) do + expect { form.has_many(:line_items) }.to raise_error(Capybara::ElementNotFound) + expect(form.has_exact_fields?).to be(false) + end + expect(form.has_many(:line_items, visible: :all)).to be_a(described_class) + expect(form).to have_exact_fields(visible: :all) + expect(declared_form { has_many :line_items, "Line Items", visible: :all }.has_many(:line_items)).to be_a(described_class) end end diff --git a/spec/active_admin_page_objects/layout_spec.rb b/spec/active_admin_page_objects/layout_spec.rb index 0fdcda8..a2aeda2 100644 --- a/spec/active_admin_page_objects/layout_spec.rb +++ b/spec/active_admin_page_objects/layout_spec.rb @@ -7,30 +7,14 @@ it "exposes the header elements" do expect(dashboard).to have_site_title(text: "Page Objects Dummy") + expect(dashboard).to have_dark_mode_toggle + expect(dashboard).to have_theme_switcher + expect(dashboard).to have_user_menu_button expect(dashboard).to have_page_title(text: "Dashboard") expect(dashboard).to have_main_menu - expect(dashboard).to have_breadcrumbs + expect(dashboard).to have_no_action_items + expect(dashboard).to have_no_flashes expect(dashboard).to have_no_blank_slate - expect(dashboard).to have_no_modal_dialog - end - - # ActiveAdmin 3 renders both containers on every page. - it "finds the empty action items and flashes" do - expect(dashboard.action_items.labels).to eq([]) - expect(dashboard.action_items).to have_no_item("New Customer") - expect(dashboard.flashes.messages).to eq([]) - expect(dashboard.flashes).to have_no_flash(:notice) - end - - it "raises for the elements ActiveAdmin 3 lacks" do - expect { dashboard.dark_mode_toggle } - .to raise_error(ActiveAdminPageObjects::NotInActiveAdmin3, /dark mode toggle is not in ActiveAdmin 3/) - expect { dashboard.theme_switcher } - .to raise_error(ActiveAdminPageObjects::NotInActiveAdmin3, /dark mode toggle is not in ActiveAdmin 3/) - expect { dashboard.user_menu_button } - .to raise_error(ActiveAdminPageObjects::NotInActiveAdmin3, /user menu button is not in ActiveAdmin 3/) - expect { dashboard.has_dark_mode_toggle? }.to raise_error(ActiveAdminPageObjects::NotInActiveAdmin3) - expect { dashboard.has_no_user_menu_button? }.to raise_error(ActiveAdminPageObjects::NotInActiveAdmin3) end it "finds a panel by title, ignoring case" do @@ -39,38 +23,28 @@ expect(panel.body).to have_text("Nothing yet.") end - it "finds a sidebar section by title, ignoring case" do - index = Pages::CustomerIndex.new - index.load - sidebar = index.sidebar("help") - expect(sidebar).to be_a(ActiveAdminPageObjects::Sidebar) - expect(sidebar.body).to have_text("Use the filters to narrow the list.") - expect(index).to have_no_selector(:active_admin_sidebar, "Missing") - end - - it "returns the utility navigation" do - expect(dashboard.utility_navigation).to be_a(ActiveAdminPageObjects::UtilityNavigation) - expect(dashboard.utility_navigation.current_user).to eq("admin@example.com") + it "raises for the utility navigation removed in ActiveAdmin 4" do + expect { dashboard.utility_navigation }.to raise_error(ActiveAdminPageObjects::RemovedInActiveAdmin4, /utility navigation/) end describe ".add_element" do - after { described_class.elements.delete(:footer_note) } + after { described_class.elements.delete(:heading_note) } it "declares the element on pages defined before and after the call" do - described_class.add_element(:footer_note, "#footer p") + described_class.add_element(:heading_note, "[data-test-page-header] h2") later = Class.new(SitePrism::Page) { include ActiveAdminPageObjects::Layout }.new - expect(described_class.elements[:footer_note]).to eq(["#footer p"]) - expect(dashboard.footer_note.text).to start_with("Powered by") - expect(dashboard).to have_footer_note - expect(later).to have_footer_note + expect(described_class.elements[:heading_note]).to eq(["[data-test-page-header] h2"]) + expect(dashboard.heading_note.text).to eq("Dashboard") + expect(dashboard).to have_heading_note + expect(later).to have_heading_note end it "replaces an element that is added again" do - described_class.add_element(:footer_note, "#no_such_footer") - expect(dashboard).to have_no_footer_note - described_class.add_element(:footer_note, :active_admin, :site_title) - expect(dashboard.footer_note.text).to eq("Page Objects Dummy") + described_class.add_element(:heading_note, "#no_such_heading") + expect(dashboard).to have_no_heading_note + described_class.add_element(:heading_note, :active_admin, :site_title) + expect(dashboard.heading_note.text).to eq("Page Objects Dummy") end end @@ -79,7 +53,6 @@ expect(dashboard).to have_site_title(text: "Page Objects Dummy") expect(dashboard).to have_page_title(text: "Dashboard") expect(dashboard.welcome.title).to eq("Welcome") - expect(dashboard.utility_navigation.labels).to eq(["admin@example.com", "Logout"]) end end end diff --git a/spec/active_admin_page_objects/main_menu_spec.rb b/spec/active_admin_page_objects/main_menu_spec.rb index 5c5303c..cefab1b 100644 --- a/spec/active_admin_page_objects/main_menu_spec.rb +++ b/spec/active_admin_page_objects/main_menu_spec.rb @@ -63,12 +63,19 @@ context "when clicking" do before { dashboard.load } - it "hovers the parent and clicks a nested item" do + it "opens the collapsed parent and clicks a nested item" do + expect(page).to have_no_css("#main-menu li[data-item-id='catalog'] ul", visible: :visible) dashboard.main_menu.click("catalog", "Orders") expect(page).to have_current_path("/admin/orders") expect(dashboard.main_menu.current_labels).to eq(%w[Catalog Orders]) end + it "does not toggle a parent that is already open" do + dashboard.main_menu.click("Catalog", "Orders") + dashboard.main_menu.click("Catalog", "Categories") + expect(page).to have_current_path("/admin/categories") + end + it "clicks a top-level item" do dashboard.main_menu.click("Customers") expect(page).to have_current_path("/admin/customers") @@ -80,13 +87,13 @@ end it "raises for a hidden submenu item" do - hide("#tabs li li") + hide("#main-menu li li") expect { dashboard.main_menu.click("Catalog", "Orders") }.to raise_error(Capybara::ElementNotFound) expect(page).to have_current_path("/admin/dashboard") end it "raises for a hidden top-level item" do - hide("#tabs > li") + hide("#main-menu > ul > li") expect { dashboard.main_menu.click("Customers") }.to raise_error(Capybara::ElementNotFound) end end @@ -94,10 +101,10 @@ context "with rack_test", driver: :rack_test do it_behaves_like "menu navigation" - it "clicks a top-level item without hovering" do + it "clicks a nested item without toggling" do dashboard.load - dashboard.main_menu.click("Customers") - expect(page).to have_current_path("/admin/customers") + dashboard.main_menu.click("Catalog", "Orders") + expect(page).to have_current_path("/admin/orders") end end end diff --git a/spec/active_admin_page_objects/modal_dialog_spec.rb b/spec/active_admin_page_objects/modal_dialog_spec.rb deleted file mode 100644 index dd6cf04..0000000 --- a/spec/active_admin_page_objects/modal_dialog_spec.rb +++ /dev/null @@ -1,52 +0,0 @@ -# frozen_string_literal: true - -RSpec.describe ActiveAdminPageObjects::ModalDialog do - let(:index) { Pages::CustomerIndex.new } - let(:dialog) { index.modal_dialog } - - def open_batch_action(label) - find("#collection_selection_toggle_all").check - find(".batch_actions_selector a.dropdown_menu_button").click - click_link label - end - - before do - create_customers(3) - index.load - end - - it "asks for input, fills it and confirms" do - open_batch_action("Set Status Selected") - - expect(dialog.title).to eq("Are you sure you want to do this?") - expect(dialog).to have_field("status") - expect(dialog).to have_no_field("missing", wait: 0) - dialog.fill("status", with: "pending") - dialog.confirm - - expect(index.flashes).to have_flash(:notice, "Set pending on 3 customers") - end - - it "closes on cancel without running the action" do - open_batch_action("Set Status Selected") - expect(dialog.title).to eq("Are you sure you want to do this?") - dialog.cancel - - expect(index).to have_no_modal_dialog - expect(index.flashes).to have_no_flash(:notice) - # The page is still the index with its rows, so the action had its chance to run. - expect(index.table).to have_rows(count: 3) - expect(Customer.where(status: "pending")).to be_empty - expect(Customer.count).to eq(3) - end - - it "shows the custom confirmation of an action" do - open_batch_action("Archive Selected") - - expect(dialog.title).to eq("Archive the selected customers?") - expect(dialog).to have_no_field("status", wait: 0) - dialog.confirm - - expect(index.flashes).to have_flash(:notice, "Archived 3 customers") - end -end diff --git a/spec/active_admin_page_objects/panel_spec.rb b/spec/active_admin_page_objects/panel_spec.rb index 492a699..05a2424 100644 --- a/spec/active_admin_page_objects/panel_spec.rb +++ b/spec/active_admin_page_objects/panel_spec.rb @@ -18,6 +18,14 @@ ) expect(dashboard.panel("Stats").links).to eq([]) end + + it "tells a panel from the panel nested in it" do + dashboard = Pages::Dashboard.new + dashboard.load + expect(dashboard.panel("Inner stats").body).to have_text("Nested.") + expect(dashboard.panel("Overview").title).to eq("Overview") + expect(dashboard.panel("Inner stats").title).to eq("Inner stats") + end end it_behaves_like "panel links" @@ -26,15 +34,6 @@ it_behaves_like "panel links" end - it "is found by title on a show page" do - customer = create_customer(notes: "Pays late") - show = Pages::CustomerShow.new - show.load(id: customer.id) - expect(show.notes.body).to have_text("Pays late") - expect(show.panel("NOTES").title).to eq("Notes") - expect(show).to have_no_selector(:active_admin_panel, "Missing") - end - shared_examples "a title with a count" do it "is found by a regexp title" do show = Pages::DocumentShow.new @@ -46,7 +45,6 @@ expect(show).to have_selector(:active_admin_panel, /\APossible Routes/) expect(show).to have_no_selector(:active_admin_panel, "Possible Routes") expect(show).to have_no_selector(:active_admin_panel, /\ARoutes/) - expect(show).to have_no_selector(:active_admin_panel, /Versions/) end end @@ -56,13 +54,12 @@ it_behaves_like "a title with a count" end - it "leaves out sidebar sections and the comments panel" do + it "is found by title on a show page" do + customer = create_customer(notes: "Pays late") show = Pages::CustomerShow.new - show.load(id: create_customer.id) - expect(show).to have_selector(:active_admin_sidebar, "Summary") - expect(show).to have_css(".comments.panel", text: "Comments (0)") - expect(show).to have_no_selector(:active_admin_panel, "Summary") - expect(show).to have_no_selector(:active_admin_panel, "Comments (0)") - expect(show).to have_selector(:active_admin_panel, count: 2) + show.load(id: customer.id) + expect(show.notes.body).to have_text("Pays late") + expect(show.panel("NOTES").title).to eq("Notes") + expect(show).to have_no_selector(:active_admin_panel, "Missing") end end diff --git a/spec/active_admin_page_objects/rspec_matchers_spec.rb b/spec/active_admin_page_objects/rspec_matchers_spec.rb index 19d69e1..7a09a66 100644 --- a/spec/active_admin_page_objects/rspec_matchers_spec.rb +++ b/spec/active_admin_page_objects/rspec_matchers_spec.rb @@ -5,11 +5,11 @@ # Stands in for capybara_active_admin: matchers of the same names, written for Capybara's `page`. module OtherLibraryMatchers def have_page_title(text, options = {}) - have_css("#page_title", text: text, **options) + have_css("[data-test-page-header] h2", text: text, **options) end def have_table(options = {}) - have_css("table.index_table", **options) + have_css("table.data-table", **options) end def have_semantic_errors(options = {}) @@ -17,17 +17,25 @@ def have_semantic_errors(options = {}) end def have_status_tag(type, **options) - have_css("span.status_tag.#{type}", **options) + have_css("span.status-tag[data-status='#{type}']", **options) end def have_flash_message(text, options = {}) - satisfy("show the flash #{text}") { |actual| actual.has_css?(".flash", text: text, **options) } + satisfy("show the flash #{text}") { |actual| actual.has_css?("[data-test-page-header] + div div", text: text, **options) } end end RSpec.describe ActiveAdminPageObjects::RSpec::Matchers do let(:index) { Pages::CustomerIndex.new } - let!(:customer) { create_customer(status: "pending") } + let(:form_page) { Pages::CustomerForm.new } + + let!(:customer) { create_customer(active: false) } + + def submit_reserved_name + form_page.load(action: "new") + form_page.form.fill(name: "Reserved", email: "acme@example.com") + form_page.form.submit + end # Every `def have_*` under lib/capybara/active_admin/matchers of the capybara_active_admin v1.0.0 tag. it "names every matcher of capybara_active_admin 1.0.0" do @@ -63,21 +71,22 @@ def have_flash_message(text, options = {}) it "asks a page object its predicate" do expect(index).to have_page_title(text: "Customers") expect(index).to have_table - expect(index.table.row(customer.id)).to have_status_tag(:status, "Pending", type: "pending") + submit_reserved_name + expect(form_page.form).to have_semantic_errors("Name is reserved") end it "asks a page object its has_no predicate when negated" do - row = index.table.row(customer.id) - allow(row).to receive(:has_no_status_tag?).and_call_original - expect(row).not_to have_status_tag(:status, "Active") - expect(row).to have_received(:has_no_status_tag?).with(:status, "Active") + submit_reserved_name + form = form_page.form + allow(form).to receive(:has_no_semantic_errors?).and_call_original + expect(form).not_to have_semantic_errors("Email is taken") + expect(form).to have_received(:has_no_semantic_errors?).with("Email is taken") tags = Pages::TagIndex.new tags.load expect(tags).not_to have_table end it "negates the predicate of a page object without a has_no predicate" do - form_page = Pages::CustomerForm.new form_page.load(action: "new") form = form_page.form allow(form).to receive(:respond_to?).and_call_original @@ -89,8 +98,8 @@ def have_flash_message(text, options = {}) expect(page).to have_page_title("Customers") expect(page).not_to have_page_title("Orders") expect(page).to have_table(count: 1) - expect(page).to have_status_tag(:pending, text: /pending/i) - expect(page).not_to have_status_tag(:active) + expect(page).to have_status_tag(:no, text: /no/i) + expect(page).not_to have_status_tag(:yes) expect(page).not_to have_flash_message("Saved", wait: 0) end @@ -98,10 +107,10 @@ def have_flash_message(text, options = {}) it "uses the other library's matcher for have_table on a page object without a table section" do show = Pages::CustomerShow.new show.load(id: customer.id) - expect(show).to have_css(".attributes_table table") + expect(show).to have_css(".attributes-table table") expect(show).not_to have_table expect { expect(show).to have_table(wait: 0) } - .to raise_error(RSpec::Expectations::ExpectationNotMetError, /expected to find .*table\.index_table/) + .to raise_error(RSpec::Expectations::ExpectationNotMetError, /expected to find .*table\.data-table/) expect(show.attributes_table).not_to have_table end @@ -118,10 +127,11 @@ def have_flash_message(text, options = {}) expect { Capybara.using_wait_time(0) { expect(index).not_to have_table } } .to raise_error(RSpec::Expectations::ExpectationNotMetError, /has_no_table\?` to be truthy, got false/) expect { expect(page).to have_page_title("Orders", wait: 0) } - .to raise_error(RSpec::Expectations::ExpectationNotMetError, /expected to find .*#page_title/) + .to raise_error(RSpec::Expectations::ExpectationNotMetError, /expected to find .*data-test-page-header/) expect { expect(page).not_to have_page_title("Customers", wait: 0) } - .to raise_error(RSpec::Expectations::ExpectationNotMetError, /expected not to find .*#page_title/) - expect(have_page_title(text: "Customers").description).to match(/\Ahave page title \{:?text(: |=>)"Customers"\}\z/) + .to raise_error(RSpec::Expectations::ExpectationNotMetError, /expected not to find .*data-test-page-header/) + # Ruby 3.3 and 3.4 inspect the options hash differently. + expect(have_page_title(text: "Customers").description).to match(/\Ahave page title \{.*"Customers"\}\z/) end end @@ -132,7 +142,7 @@ 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(index).not_to have_page_title(text: "Orders") expect { expect(page).to have_footer } .to raise_error(RSpec::Expectations::ExpectationNotMetError, /to respond to `has_footer\?`/) end @@ -234,17 +244,15 @@ def fail_with(message) expect { expect(index.filters).to have_no_declared_filters(wait: 0) } .to fail_with("expected a declared filter to be missing or to have another label, but every one matches") - form_page = Pages::CustomerForm.new form_page.load(action: "new") form = Class.new(ActiveAdminPageObjects::Form) do - field :email, "Email", ActiveAdminPageObjects::Form::StringField + field :email, "E-mail", ActiveAdminPageObjects::Form::StringField field :secret, "Secret", ActiveAdminPageObjects::Form::StringField - has_many :orders, "Order list" end.new(form_page, form_page.form.root_element) - expect { expect(form).to have_exact_fields(only: %i[secret orders], wait: 0) }.to fail_with(<<~MESSAGE.chomp) - expected exactly the declared fields (only: secret, orders), but: + expect { expect(form).to have_exact_fields(only: %i[secret email], wait: 0) }.to fail_with(<<~MESSAGE.chomp) + expected exactly the declared fields (only: secret, email), but: missing: secret - label of orders: expected "Order list", got "Orders" + label of email: expected "E-mail", got "Email" MESSAGE expect(form_page.form).to have_exact_fields end @@ -289,7 +297,6 @@ def has_exact_rows?(**) = exact describe "failure messages of the exact error matchers" do include ActiveAdminPageObjects::RSpec::Matchers - let(:form_page) { Pages::CustomerForm.new } let(:form) { form_page.form } def fail_with(message) @@ -366,21 +373,6 @@ def without_waiting(&) expect(form).to have_exact_field_errors.and have_exact_semantic_errors end - it "reports the errors of a has_many fieldset" do - customer.orders.create!(reference: "REF-1", state: "new", quantity: 1) - form_page.load(id: customer.id, action: "edit") - form.has_many(:orders).fieldset(0).fill(quantity: 0) - form.submit - fieldset = form.has_many(:orders).fieldset(0) - expect(fieldset).to have_exact_field_errors(quantity: "must be greater than 0") - expect { without_waiting { expect(fieldset).to have_exact_field_errors(reference: "can't be blank") } } - .to fail_with(<<~MESSAGE.chomp) - expected exactly the given field errors, but: - reference: missing "can't be blank" - quantity: unexpected "must be greater than 0" - MESSAGE - end - context "with base errors" do before do form_page.load(action: "new") diff --git a/spec/active_admin_page_objects/section_spec.rb b/spec/active_admin_page_objects/section_spec.rb index 5873788..d4443de 100644 --- a/spec/active_admin_page_objects/section_spec.rb +++ b/spec/active_admin_page_objects/section_spec.rb @@ -7,16 +7,13 @@ # Capybara's synchronize builds its timer from `false` and fails on the second try. it "takes wait: false as no wait in the predicates that retry" do - expect(show.tabs.has_tab?("Missing", wait: false)).to be(false) - expect(show.tabs.has_no_tab?("Overview", wait: false)).to be(false) - expect(show.tabs.has_tab?("Overview", wait: false)).to be(true) expect(show.attributes_table.has_exact_rows?(only: :name, wait: false)).to be(true) expect(show.attributes_table.has_no_exact_rows?(only: :name, wait: false)).to be(false) end it "keeps the text helpers private" do - expect(show.tabs).not_to respond_to(:squish) - expect(show.tabs).not_to respond_to(:slug) - expect(show.tabs.send(:slug, "External ID")).to eq("external_id") + expect(show.attributes_table).not_to respond_to(:squish) + expect(show.attributes_table).not_to respond_to(:slug) + expect(show.attributes_table.send(:slug, "External ID")).to eq("external_id") end end diff --git a/spec/active_admin_page_objects/selectors_spec.rb b/spec/active_admin_page_objects/selectors_spec.rb index 86059d7..43db202 100644 --- a/spec/active_admin_page_objects/selectors_spec.rb +++ b/spec/active_admin_page_objects/selectors_spec.rb @@ -9,20 +9,13 @@ end it "reads the map and fills placeholders" do - expect(ActiveAdminPageObjects.selector(:table)).to eq("table.index_table") + expect(ActiveAdminPageObjects.selector(:table)).to eq("table.data-table") expect(ActiveAdminPageObjects.selector(:filter, "name")).to eq("#q_name_input") - expect(ActiveAdminPageObjects.selector(:form_input, "customer", "name")).to eq("li#customer_name_input") end - it "raises for a key ActiveAdmin 3 lacks" do - expect { ActiveAdminPageObjects.selector(:dark_mode_toggle) } - .to raise_error(ActiveAdminPageObjects::NotInActiveAdmin3, /dark mode toggle is not in ActiveAdmin 3/) - expect { ActiveAdminPageObjects.selector(:user_menu_button) } - .to raise_error(ActiveAdminPageObjects::NotInActiveAdmin3, /user menu button is not in ActiveAdmin 3/) - end - - it "has a selector for the components ActiveAdmin 4 removed" do - expect(described_class::DEFAULTS.values_at(:tabs, :utility_navigation, :action_item_dropdown)).to all(be_a(String)) + it "raises for a key ActiveAdmin 4 removed" do + expect { ActiveAdminPageObjects.selector(:tabs) } + .to raise_error(ActiveAdminPageObjects::RemovedInActiveAdmin4, /tabs was removed in ActiveAdmin 4/) end it "raises KeyError for an unknown key" do @@ -35,14 +28,14 @@ expect(ActiveAdminPageObjects.selector(:table)).to eq("table.themed") end - it "replaces an entry ActiveAdmin 3 lacks" do - ActiveAdminPageObjects.register_selectors(dark_mode_toggle: ".my-toggle") - expect(ActiveAdminPageObjects.selector(:dark_mode_toggle)).to eq(".my-toggle") + it "replaces a removed key" do + ActiveAdminPageObjects.register_selectors(tabs: ".my-tabs") + expect(ActiveAdminPageObjects.selector(:tabs)).to eq(".my-tabs") end it "leaves the defaults untouched" do ActiveAdminPageObjects.register_selectors(table: "table.themed") - expect(described_class::DEFAULTS[:table]).to eq("table.index_table") + expect(described_class::DEFAULTS[:table]).to eq("table.data-table") end end end diff --git a/spec/active_admin_page_objects/sidebar_spec.rb b/spec/active_admin_page_objects/sidebar_spec.rb deleted file mode 100644 index 06d5e17..0000000 --- a/spec/active_admin_page_objects/sidebar_spec.rb +++ /dev/null @@ -1,58 +0,0 @@ -# frozen_string_literal: true - -RSpec.describe ActiveAdminPageObjects::Sidebar do - it "is found by title on the index page" do - create_customer - index = Pages::CustomerIndex.new - index.load - - help = index.sidebar("help") - expect(help.title).to eq("Help") - expect(help.body).to have_text("Use the filters to narrow the list.") - expect(index.sidebar("Filters").title).to eq("Filters") - end - - shared_examples "sidebar links" do - it "lists the links of the body with their href attributes" do - index = Pages::CustomerIndex.new - index.load - - expect(index.sidebar("Help").links).to eq( - [ - { text: "Report", href: "/admin/customers/report" }, - { text: "Active customers", href: "/admin/customers?scope=active" }, - { text: "Top", href: "#" } - ] - ) - end - end - - it_behaves_like "sidebar links" - - context "with rack_test", driver: :rack_test do - it_behaves_like "sidebar links" - end - - it "is found by a regexp title" do - show = Pages::DocumentShow.new - show.load(id: create_document.id) - expect(show.versions.title).to eq("Versions (2)") - expect(show.versions.body).to have_text("Two versions.") - expect(show.sidebar(/\AVersions \(\d+\)\z/).title).to eq("Versions (2)") - expect(show).to have_no_selector(:active_admin_sidebar, "Versions") - expect(show).to have_no_selector(:active_admin_sidebar, /Routes/) - end - - it "is found by title on the show page" do - customer = create_customer - Order.create!(customer: customer, reference: "REF-1", state: "new", quantity: 1) - Order.create!(customer: customer, reference: "REF-2", state: "paid", quantity: 2) - show = Pages::CustomerShow.new - show.load(id: customer.id) - - summary = show.sidebar("SUMMARY") - expect(summary.title).to eq("Summary") - expect(summary.body).to have_text("Orders: 2") - expect(summary.links).to eq([]) - end -end diff --git a/spec/active_admin_page_objects/status_tag_spec.rb b/spec/active_admin_page_objects/status_tag_spec.rb index f928110..317f34b 100644 --- a/spec/active_admin_page_objects/status_tag_spec.rb +++ b/spec/active_admin_page_objects/status_tag_spec.rb @@ -1,94 +1,132 @@ # frozen_string_literal: true RSpec.describe ActiveAdminPageObjects::StatusTag do - let!(:customer) { create_customer(status: "pending") } + let(:index) { Pages::CustomerIndex.new } + let(:show) { Pages::CustomerShow.new } + let!(:customer) { create_customer(status: "pending", active: false) } + let(:row) { index.table.row(customer.id) } - shared_examples "a pending tag" do - it "reads the label and type" do - expect(tag.label).to eq("Pending") - expect(tag.type).to eq("pending") - end + shared_examples "status tags" do + describe "in an index row" do + before { index.load } - it "matches the type and the label" do - expect(tag).to have_type("pending") - expect(tag).to have_no_type("active", wait: 0) - expect(tag).to have_label("pending") - expect(tag).to have_label("PENDING") - expect(tag).to have_no_label("Active", wait: 0) - end + it "reads a tag's label and status" do + tag = row.status_tag(:status) + expect(tag).to be_a(described_class) + expect(tag.label).to eq("Pending") + expect(tag.status).to eq("pending") + expect(row.status_tag(:active).status).to eq("no") + expect(row.status_tag(:active).label).to eq("No") + end - it "matches the label and the type at once" do - expect(tag.match?("PENDING")).to be(true) - expect(tag.match?("Pending", type: "pending")).to be(true) - expect(tag.match?("Pending", type: "active")).to be(false) - expect(tag.match?("Active", type: "pending")).to be(false) - end - end + it "compares a tag's status and label" do + tag = row.status_tag(:status) + expect(tag).to have_status(:pending) + expect(tag).to have_status("pending") + expect(tag).to have_no_status(:active) + expect(tag).to have_label("PENDING") + expect(tag).to have_no_label("Pend") + expect(tag.has_status?(:active, wait: 0)).to be(false) + expect(tag.has_no_status?(:pending, wait: 0)).to be(false) + expect(row.status_tag(:active)).to have_status(false) + expect { tag.has_status?(1) }.to raise_error(ArgumentError, /status must be a String, a Symbol/) + end - shared_examples "two tags in a cell" do - it "matches any status tag of the cell" do - expect(cells).to have_status_tag(:flags, "Draft") - expect(cells).to have_status_tag(:flags, "archived", type: "warning") - expect(cells).to have_status_tag(:flags, "Archived", type: "archived warning") - expect(cells).to have_no_status_tag(:flags, "Published") - expect(cells).to have_no_status_tag(:flags, "Draft", type: "warning") - Capybara.using_wait_time(0) do - expect(cells.has_status_tag?(:flags, "Published")).to be(false) - expect(cells.has_no_status_tag?(:flags, "Draft")).to be(false) - expect(cells.has_no_status_tag?(:flags, "Archived")).to be(false) + it "has a status tag by label, status or both" do + expect(row).to have_status_tag(:status) + expect(row).to have_status_tag(:status, "Pending") + expect(row).to have_status_tag(:status, "PENDING") + expect(row).to have_status_tag("Status", /Pend/) + expect(row).to have_status_tag(:status, status: :pending) + expect(row).to have_status_tag(:status, "pending", status: "pending") + expect(row).to have_status_tag(:status, type: :pending) + expect(row).to have_status_tag(:active, "No", status: false) + expect(row).to have_status_tag(:active, status: :no) end - end - it "lists the status tags of the cell" do - expect(cells.status_tags(:flags).map(&:label)).to eq(%w[Draft Archived]) - expect(cells.status_tags(:flags).map(&:type)).to eq(["draft", "archived warning"]) - expect(cells.status_tags(:name)).to eq([]) - expect { cells.status_tag(:flags) }.to raise_error(Capybara::Ambiguous) - end - end + it "has no status tag when the label or the status differs" do + expect(row).to have_no_status_tag(:status, "Pend") + expect(row).to have_no_status_tag(:status, "Active") + expect(row).to have_no_status_tag(:status, status: :active) + expect(row).to have_no_status_tag(:status, type: :active) + expect(row).to have_no_status_tag(:status, "Pending", status: :active) + expect(row).to have_no_status_tag(:active, status: true) + expect(row).to have_no_status_tag(:name) + end - context "with two tags in an index cell" do - let(:cells) do - document = create_document(archived: true) - index = Pages::DocumentIndex.new - index.load - index.table.row(document.id) - end + it "does not wait for a tag that is there, or give a false pass" do + expect(row.has_status_tag?(:status, "Active", wait: 0)).to be(false) + expect(row.has_status_tag?(:status, status: :active, wait: 0)).to be(false) + expect(row.has_no_status_tag?(:status, "Pending", wait: 0)).to be(false) + expect(row.has_no_status_tag?(:status, status: :pending, wait: 0)).to be(false) + end - it_behaves_like "two tags in a cell" + it "passes Capybara options on" do + expect(row).to have_status_tag(:status, count: 1) + expect(row).to have_no_status_tag(:status, count: 2) + end - context "with rack_test", driver: :rack_test do - it_behaves_like "two tags in a cell" - end - end + it "rejects a call that would match nothing" do + expect { row.has_status_tag?(:status, status: :pending, type: :pending) } + .to raise_error(ArgumentError, /status: or type:, not both/) + expect { row.has_no_status_tag?(:status, status: :pending, type: :active) } + .to raise_error(ArgumentError, /status: or type:, not both/) + expect { row.has_no_status_tag?(:status, status: 1) }.to raise_error(ArgumentError, /status must be a String/) + expect { row.has_no_status_tag?(:status, type: Object.new) }.to raise_error(ArgumentError, /status must be a String/) + expect { row.has_status_tag?(:secret) }.to raise_error(ArgumentError, /:secret is not declared/) + expect { row.status_tag(:secret) }.to raise_error(ArgumentError, /:secret is not declared/) + end - context "with two tags in a show row" do - let(:cells) do - show = Pages::DocumentShow.new - show.load(id: create_document(archived: true).id) - show.attributes_table + it "finds no tag in a cell without one" do + expect { row.status_tag(:name) }.to raise_error(Capybara::ElementNotFound) + expect(row.status_tags(:name)).to eq([]) + end end - it_behaves_like "two tags in a cell" - end + describe "in a cell with several tags" do + let(:lenient_row) do + ActiveAdminPageObjects::Table.new(index, index.table.root_element).row(customer.id) + end + + before { index.load(query: { with_flags: 1 }) } - context "in an index row" do - let(:tag) do - index = Pages::CustomerIndex.new - index.load - index.table.row(customer.id).status_tag(:status) + it "lists the tags in page order" do + tags = lenient_row.status_tags(:flags) + expect(tags.map(&:status)).to eq(%w[pending no]) + expect(tags.map(&:label)).to eq(%w[Pending No]) + end + + it "is ambiguous for one tag, and has a tag when any matches" do + expect { lenient_row.status_tag(:flags) }.to raise_error(Capybara::Ambiguous) + expect(lenient_row).to have_status_tag(:flags, "No") + expect(lenient_row).to have_status_tag(:flags, status: :pending) + expect(lenient_row).to have_status_tag(:flags, count: 2) + expect(lenient_row).to have_no_status_tag(:flags, "Active") + end end - it_behaves_like "a pending tag" - end + describe "on a show page" do + before { show.load(id: customer.id) } - context "in the show attributes" do - let(:tag) do - show = Pages::CustomerShow.new - show.load(id: customer.id) - show.attributes_table.status_tag(:status) + it "reads and compares the tag of a row" do + tag = show.attributes_table.status_tag(:status) + expect(tag.label).to eq("Pending") + expect(tag.status).to eq("pending") + expect(show.attributes_table.status_tags(:status).size).to eq(1) + expect(show.attributes_table).to have_status_tag(:status, "pending", status: :pending) + expect(show.attributes_table).to have_status_tag("Status", type: "pending") + expect(show.attributes_table).to have_no_status_tag(:status, "Active") + expect(show.attributes_table).to have_no_status_tag(:status, status: :active) + expect(show.attributes_table).to have_no_status_tag(:name) + expect { show.attributes_table.has_status_tag?(:secret) }.to raise_error(ArgumentError, /:secret is not declared/) + expect { show.attributes_table.has_status_tag?(:status, status: :a, type: :b) }.to raise_error(ArgumentError) + end end + end + + it_behaves_like "status tags" - it_behaves_like "a pending tag" + context "with rack_test", driver: :rack_test do + it_behaves_like "status tags" end end diff --git a/spec/active_admin_page_objects/table_spec.rb b/spec/active_admin_page_objects/table_spec.rb index 227684f..3e009fb 100644 --- a/spec/active_admin_page_objects/table_spec.rb +++ b/spec/active_admin_page_objects/table_spec.rb @@ -61,15 +61,17 @@ def declared_table(&) expect { partial.has_declared_columns?(except: :email) }.to raise_error(ArgumentError, /:email is not declared/) end - it "matches the status tag of a cell" do - row = table.row(customers.first.id) - expect(row).to have_status_tag(:status, "Active") - expect(row).to have_status_tag(:status, "active", type: :active) - expect(row).to have_no_status_tag(:status, "Pending") - expect(row).to have_no_status_tag(:status, "Active", type: "pending") - expect(row).to have_no_status_tag(:name, "Active") - expect(row.has_status_tag?(:status, "Pending", wait: 0)).to be(false) - expect(row.has_no_status_tag?(:status, "Active", wait: 0)).to be(false) + it "keys the untitled selection and actions columns" do + untitled = declared_table do + column :selectable, "Select" + column :actions, "Actions" + end + expect(untitled.declared_label_mismatches).to eq("selectable" => "", "actions" => "") + expect(untitled.exact_mismatches[:missing]).to eq([]) + expect(declared_table { column :actions, "" }).to have_declared_columns + index.load(query: { with_notes: 1 }) + expect(declared_table { column :actions, "" }).to have_declared_columns + expect(table.exact_mismatches[:unexpected]).to eq([]) end it "compares a declared label exactly" do @@ -87,7 +89,6 @@ def declared_table(&) it "takes any key without declarations" do lenient = described_class.new(index, table.root_element) expect(lenient.rows.first).to have_no_cell(:secret) - Capybara.using_wait_time(0) { expect(lenient.has_sortable_column?(:secret)).to be(false) } expect { lenient.has_declared_columns? }.to raise_error(ArgumentError, /declares no labels/) expect { lenient.has_exact_columns? }.to raise_error(ArgumentError, /declares no labels/) expect { lenient.declared_label_mismatches }.to raise_error(ArgumentError, /declares no labels/) @@ -108,6 +109,7 @@ def declared_table(&) expect(table).to have_no_row(customers.last.id + 1) expect(table).to have_row(customers.first.id, text: customers.first.name) expect(table).to have_no_row(customers.first.id, text: "No such customer") + expect(table).to have_row(customers.first.id, text: customers.first.name.upcase) expect(table.has_no_row?(customers.first.id, wait: 0)).to be(false) expect(table.has_row?(customers.last.id + 1, wait: 0)).to be(false) end @@ -129,44 +131,24 @@ def declared_table(&) expect(row).to have_cell(:name, exact_text: customer.name) expect(row).to have_cell("CATEGORY", exact_text: "Retail") expect(row).to have_no_cell(:name, exact_text: "Nobody") + expect(row).to have_cell(:category, exact_text: "RETAIL") + expect(row).to have_cell(:category, text: "retail") + expect(row).to have_cell(:category, text: "RET", exact_text: false) + expect(row).to have_no_cell(:category, exact_text: "RET") + expect(row).to have_cell(:category, text: "ret", exact_text: "Retail") + expect(row.has_cell?(:category, text: "xyz", exact_text: "Retail", wait: 0)).to be(false) + expect(row.has_no_cell?(:category, exact_text: "retail", wait: 0)).to be(false) expect(row.cell(:email)).to have_text(customer.email) + expect(row.cell(:actions)).to have_link("Delete") + expect(row).to have_cell(:actions, text: "edit") + expect(row.cell(:selectable)).to have_css("input[type=checkbox]") + expect(row).to have_cell(:selectable) end it "keeps rows in table order" do expect(table.rows.map(&:record_id)).to eq(customers.reverse.map { |c| c.id.to_s }) end - it "reads the sort order and the sortable columns" do - expect(table.sorted_by).to eq(["id", :desc]) - expect(table).to have_sortable_column(:name) - expect(table).to have_sortable_column("Created") - Capybara.using_wait_time(0) { expect(table.has_sortable_column?(:category)).to be(false) } - end - - it "sorts by clicking a header" do - table.sort_by(:name) - expect(page).to have_current_path(/order=name_desc/) - expect(index.table.sorted_by).to eq(["name", :desc]) - end - - it "sorts in a given direction" do - table.sort_by(:name, :asc) - expect(page).to have_current_path(/order=name_asc/) - expect(index.table.sorted_by).to eq(["name", :asc]) - expect(index.table.rows.map(&:record_id)).to eq(customers.map { |c| c.id.to_s }) - - index.table.sort_by("Name", "desc") - expect(index.table.sorted_by).to eq(["name", :desc]) - expect(index.table.rows.map(&:record_id)).to eq(customers.reverse.map { |c| c.id.to_s }) - - index.table.sort_by(:name, :desc) - expect(page).to have_current_path(/order=name_desc/) - end - - it "rejects an unknown sort direction" do - expect { table.sort_by(:name, :up) }.to raise_error(ArgumentError, /direction/) - end - it "finds a row by a cell's text" do customer = customers[1] expect(table.row_with(:name, customer.name).record_id).to eq(customer.id.to_s) @@ -177,6 +159,75 @@ def declared_table(&) expect(table.has_row_with?(:name, "Nobody", wait: 0)).to be(false) expect { table.row_with(:name, "Nobody", wait: 0) }.to raise_error(Capybara::ElementNotFound, /no row with :name/) end + + it "tells the sortable columns" do + expect(table).to have_sortable_column(:name) + expect(table).to have_sortable_column("External ID") + expect(table).to have_sortable_column(:status) + expect(table).to have_sortable_column(:created) + expect(table).to have_no_sortable_column(:category) + expect(table).to have_no_sortable_column(:actions) + expect(table.has_sortable_column?(:category, wait: 0)).to be(false) + expect(table.has_no_sortable_column?(:name, wait: 0)).to be(false) + expect { table.has_sortable_column?(:secret) }.to raise_error(ArgumentError, /:secret is not declared/) + end + + it "shows the sort the page loads with" do + expect(table).to have_sort(:id) + expect(table).to have_sort(:id, :desc) + expect(table).to have_no_sort(:id, :asc) + expect(table).to have_no_sort(:name) + expect(table.sort_direction(:id)).to eq(:desc) + expect(table.sort_direction(:name)).to be_nil + expect(table.has_sort?(:id, :asc, wait: 0)).to be(false) + expect(table.has_no_sort?(:id, wait: 0)).to be(false) + expect { table.has_sort?(:id, :up) }.to raise_error(ArgumentError, /:asc or :desc/) + expect { table.has_no_sort?(:id, "") }.to raise_error(ArgumentError, /:asc or :desc/) + end + + describe "sorting" do + def sorted_names + index.table.rows.map { |row| row.cell(:name).text } + end + + it "follows the header link, which sorts an unsorted column descending first" do + expect(index.table.sort_by(:name)).to eq(:desc) + expect(index.table).to have_sort(:name, :desc) + expect(index.table).to have_no_sort(:id) + expect(sorted_names).to eq(customers.map(&:name).reverse) + expect(index.table.sort_by(:name)).to eq(:asc) + expect(sorted_names).to eq(customers.map(&:name)) + end + + it "clicks until the column shows the direction" do + index.table.sort_by(:name, :asc) + expect(index.table).to have_sort(:name, :asc) + expect(sorted_names).to eq(customers.map(&:name)) + index.table.sort_by(:name, :desc) + expect(index.table).to have_sort(:name, :desc) + expect(sorted_names).to eq(customers.map(&:name).reverse) + end + + it "does not click when the column already shows the direction" do + expect(index.table.sort_by(:id, :desc)).to eq(:desc) + expect(sorted_names).to eq(customers.map(&:name).reverse) + expect(index.table.sort_by(:id, "asc")).to eq(:asc) + expect(sorted_names).to eq(customers.map(&:name)) + end + + it "takes a column by its label and a sort key that differs from it" do + expect(index.table.sort_by("Created", :asc)).to eq(:asc) + expect(index.table).to have_sort(:created, :asc) + expect(index.table).to have_no_sort(:id) + end + + it "rejects a direction or a column it cannot sort by" do + expect { table.sort_by(:name, :up) }.to raise_error(ArgumentError, /:asc or :desc/) + expect { table.sort_by(:category) }.to raise_error(ArgumentError, /:category is not a sortable column/) + expect { table.sort_by(:secret) }.to raise_error(ArgumentError, /:secret is not declared/) + expect(table).to have_sort(:id, :desc) + end + end end it_behaves_like "index table" @@ -203,7 +254,7 @@ def declared_table(&) before do index.load - hide(".col-email") + hide('[data-column="email"]') end it "leaves a hidden column out by default" do @@ -236,7 +287,7 @@ def declared_table(&) end it "takes a hidden column declared with visible: :all" do - hide(".col-status") + hide('[data-column="status"]') declared = declared_table do column :name, "Name" column :email, "Email", visible: :all @@ -246,19 +297,26 @@ def declared_table(&) row = declared.row(customer.id) expect(row.cell(:email).text(:all)).to eq(customer.email) expect(row).to have_cell(:email, exact_text: customer.email) - expect(row.status_tag(:status).label).to eq("Active") - expect(row).to have_status_tag(:status, "Active") - expect(declared).to have_sortable_column(:email) expect(declared).to have_declared_columns expect(declared).to have_exact_columns(only: %i[name email]) expect(declared.exact_mismatches).to include(missing: [], labels: {}) Capybara.using_wait_time(0) do expect { row.cell(:email, visible: :visible) }.to raise_error(Capybara::ElementNotFound) expect(row.has_cell?(:email, visible: :visible)).to be(false) - expect(row.has_status_tag?(:status, "Active", visible: :visible)).to be(false) end expect(declared.declared_label_mismatches(visible: :visible)).to eq("email" => nil, "status" => nil) end + + it "leaves a hidden selection or actions column out by default" do + hide("thead th:first-child, thead th:last-child") + expect(table.exact_mismatches(except: %i[email notes])).to eq(missing: %w[selectable actions], unexpected: [], labels: {}) + expect(table).to have_exact_columns(except: :notes, visible: :all) + + partial = declared_table { column :name, "Name" } + expect(partial.exact_mismatches[:unexpected]).not_to include("selectable", "actions") + expect(partial.exact_mismatches(visible: :all)[:unexpected]).to include("selectable", "actions") + expect(declared_table { column :actions, "", visible: :all }).to have_declared_columns + end end describe "declared columns" do @@ -270,18 +328,12 @@ def declared_table(&) end it "rejects an undeclared key before it queries the page" do - strict = strict_class.new(nil, nil) + row = described_class::Row.new(strict_class.new(nil, nil), nil) message = /:secret is not declared; declared keys: id, name/ - expect { strict.sort_by(:secret) }.to raise_error(ArgumentError, message) - expect { strict.has_sortable_column?(:secret) }.to raise_error(ArgumentError, message) - - row = described_class::Row.new(strict, nil) expect { row.cell(:secret) }.to raise_error(ArgumentError, message) expect { row.has_cell?(:secret) }.to raise_error(ArgumentError, message) expect { row.has_no_cell?(:secret) }.to raise_error(ArgumentError, message) - expect { row.status_tag("Secret") }.to raise_error(ArgumentError, /"Secret" is not declared/) - expect { row.has_status_tag?(:secret, "Active") }.to raise_error(ArgumentError, message) - expect { row.has_no_status_tag?(:secret, "Active") }.to raise_error(ArgumentError, message) + expect { row.cell("Secret") }.to raise_error(ArgumentError, /"Secret" is not declared/) end it "requires a label" do diff --git a/spec/active_admin_page_objects/tabs_spec.rb b/spec/active_admin_page_objects/tabs_spec.rb index 88472ad..3ae3386 100644 --- a/spec/active_admin_page_objects/tabs_spec.rb +++ b/spec/active_admin_page_objects/tabs_spec.rb @@ -1,77 +1,9 @@ # frozen_string_literal: true RSpec.describe ActiveAdminPageObjects::Tabs do - let(:show) { Pages::CustomerShow.new } - let(:customer) { create_customer } - - before do - Order.create!(customer: customer, reference: "REF-1", state: "paid", quantity: 2) - show.load(id: customer.id) - end - - it "lists the tabs and reads the open one" do - expect(show.tabs.labels).to eq(%w[Overview Orders]) - expect(show.tabs).to have_tab("orders") - expect(show.tabs).to have_no_tab("Missing") - expect(show.tabs.current).to eq("Overview") - expect(show.tabs.body).to have_text("Overview body") - expect(show.tabs.body).to have_no_text("REF-1") - end - - it "switches to another tab" do - show.tabs.switch("Orders") - expect(show.tabs.current).to eq("Orders") - expect(show.tabs.body).to have_text("REF-1") - expect(show.tabs.body).to have_no_text("Overview body") - end - - it "raises for a missing tab" do - expect { show.tabs.switch("Missing") }.to raise_error(Capybara::ElementNotFound, /Missing/) - end - - context "with a count in a tab label" do - let(:document) { Pages::DocumentShow.new } - - before { document.load(id: create_document.id) } - - it "finds the tab by a regexp" do - expect(document.tabs.labels).to eq(["Details", "Files (3)"]) - expect(document.tabs).to have_tab(/\AFiles \(\d+\)\z/) - expect(document.tabs).to have_tab("files (3)") - expect(document.tabs).to have_no_tab("Files") - expect(document.tabs).to have_no_tab(/\AFiles\z/) - expect(document.tabs.has_tab?(/\AFiles\z/, wait: 0)).to be(false) - expect(document.tabs.has_no_tab?(/Files/, wait: 0)).to be(false) - end - - it "switches to the tab a regexp matches" do - document.tabs.switch(/\AFiles/) - expect(document.tabs.current).to eq("Files (3)") - expect(document.tabs.body).to have_text("Three files.") - expect { document.tabs.switch(/Missing/) }.to raise_error(Capybara::ElementNotFound, /Missing/) - expect { document.tabs.switch("Files") }.to raise_error(Capybara::ElementNotFound) - end - end - - it "does not take the main menu for tabs" do - dashboard = Pages::Dashboard.new - dashboard.load - expect(dashboard).to have_no_css(ActiveAdminPageObjects.selector(:tabs)) - end - - context "with rack_test", driver: :rack_test do - it "finds a tab by a regexp" do - documents = Pages::DocumentShow.new - documents.load(id: create_document.id) - expect(documents.tabs).to have_tab(/\AFiles \(\d+\)\z/) - expect(documents.tabs).to have_no_tab(/\Afiles/) - expect(documents.tabs).to have_tab(/\Afiles/i) - end - - it "lists the tabs without an open one" do - expect(show.tabs.labels).to eq(%w[Overview Orders]) - expect(show.tabs.current).to be_nil - expect(show.tabs.body).to have_text("Overview body") - end + it "raises because ActiveAdmin 4 removed the tabs component" do + show = Pages::CustomerShow.new + show.load(id: create_customer.id) + expect { show.tabs }.to raise_error(ActiveAdminPageObjects::RemovedInActiveAdmin4, /tabs was removed/) end end diff --git a/spec/active_admin_page_objects/text_spec.rb b/spec/active_admin_page_objects/text_spec.rb index ea3896a..21c91fc 100644 --- a/spec/active_admin_page_objects/text_spec.rb +++ b/spec/active_admin_page_objects/text_spec.rb @@ -14,11 +14,27 @@ expect(ActiveAdminPageObjects.same_text?("Created", "Created at")).to be(false) end + it "turns a String text option into a case-insensitive Regexp" do + expect(ActiveAdminPageObjects.case_insensitive_text(exact_text: "a.b c", visible: :all)) + .to eq(text: /\A\s*a\.b\s+c\s*\z/i, visible: :all) + expect(ActiveAdminPageObjects.case_insensitive_text(text: "No", exact_text: true)).to eq(text: /\A\s*No\s*\z/i) + expect(ActiveAdminPageObjects.case_insensitive_text(text: "No")).to eq(text: /No/i) + expect(ActiveAdminPageObjects.case_insensitive_text(text: /No/)).to eq(text: /No/) + expect(ActiveAdminPageObjects.case_insensitive_text(count: 1)).to eq(count: 1) + end + + it "keeps both a String text and a String exact_text" do + both = ActiveAdminPageObjects.case_insensitive_text(text: "Ac", exact_text: "Acme")[:text] + expect([both.match?("ACME"), both.match?("Acorn")]).to eq([true, false]) + conflicting = ActiveAdminPageObjects.case_insensitive_text(text: "xyz", exact_text: "Acme")[:text] + expect(conflicting.match?("Acme")).to be(false) + end + it "squishes whitespace and keeps the case" do expect(ActiveAdminPageObjects.squish(" External\n ID ")).to eq("External ID") end - it "slugs keys the way ActiveAdmin writes the col- and row- classes" do + it "slugs keys the way ActiveAdmin writes data-column" do expect(ActiveAdminPageObjects.slug("EXTERNAL ID")).to eq("external_id") expect(ActiveAdminPageObjects.slug(:external_id)).to eq("external_id") expect(ActiveAdminPageObjects.slug("Signed up")).to eq("signed_up") @@ -43,22 +59,22 @@ RSpec.describe ActiveAdminPageObjects do describe ".check_version!" do it "passes for a satisfied requirement" do - expect { described_class.check_version!(">= 1.0.0.a", "< 2.0.0.a", plugin: "demo") }.not_to raise_error + expect { described_class.check_version!(">= 2.0.0.a", "< 3.0.0.a", plugin: "demo") }.not_to raise_error end - it "keeps the 2.x prereleases out with an upper bound of 2.0.0.a" do - stub_const("ActiveAdminPageObjects::VERSION", "2.0.0.alpha") - expect { described_class.check_version!(">= 1.0.0.a", "< 2.0.0.a", plugin: "demo") } + it "keeps the 3.x prereleases out with an upper bound of 3.0.0.a" do + stub_const("ActiveAdminPageObjects::VERSION", "3.0.0.alpha") + expect { described_class.check_version!(">= 2.0.0.a", "< 3.0.0.a", plugin: "demo") } .to raise_error(ActiveAdminPageObjects::IncompatibleVersion) end it "raises for an unsatisfied requirement" do - expect { described_class.check_version!(">= 2.0", plugin: "demo") } - .to raise_error(ActiveAdminPageObjects::IncompatibleVersion, /demo page objects need active_admin_page_objects >= 2.0/) + expect { described_class.check_version!(">= 3.0", plugin: "demo") } + .to raise_error(ActiveAdminPageObjects::IncompatibleVersion, /demo page objects need active_admin_page_objects >= 3.0/) end end it "has a version" do - expect(ActiveAdminPageObjects::VERSION).to eq("1.0.0") + expect(ActiveAdminPageObjects::VERSION).to eq("2.0.0.beta1") end end diff --git a/spec/active_admin_page_objects/utility_navigation_spec.rb b/spec/active_admin_page_objects/utility_navigation_spec.rb deleted file mode 100644 index 0613155..0000000 --- a/spec/active_admin_page_objects/utility_navigation_spec.rb +++ /dev/null @@ -1,28 +0,0 @@ -# frozen_string_literal: true - -RSpec.describe ActiveAdminPageObjects::UtilityNavigation do - let(:index) { Pages::CustomerIndex.new } - - shared_examples "utility navigation" do - before { index.load } - - it "reads the current user and the labels" do - navigation = index.utility_navigation - expect(navigation).to be_a(described_class) - expect(navigation.current_user).to eq("admin@example.com") - expect(navigation.labels).to eq(["admin@example.com", "Logout"]) - end - - it "clicks the logout link" do - index.utility_navigation.logout - expect(page).to have_current_path("/admin") - expect(Pages::Dashboard.new).to have_page_title(text: "Dashboard") - end - end - - it_behaves_like "utility navigation" - - context "with rack_test", driver: :rack_test do - it_behaves_like "utility navigation" - end -end diff --git a/spec/dummy/app/admin/customers.rb b/spec/dummy/app/admin/customers.rb index 98e7420..a296ecf 100644 --- a/spec/dummy/app/admin/customers.rb +++ b/spec/dummy/app/admin/customers.rb @@ -3,11 +3,9 @@ ActiveAdmin.register Customer do menu priority: 2 config.per_page = 5 - config.comments = true permit_params :name, :email, :external_id, :status, :balance, :active, :category_id, :notes, - :website, :phone, :password, :tier, :signed_on, - channels: [], orders_attributes: [:id, :reference, :state, :quantity, :_destroy, { tags: [] }] + :website, :phone, :password, :tier, :signed_on, channels: [] scope :all, default: true scope(:active) { |customers| customers.where(active: true) } @@ -30,34 +28,10 @@ redirect_to collection_path, notice: "Archived #{ids.size} customers" end - batch_action :set_status, form: { status: Customer::STATUSES } do |ids, inputs| - redirect_to collection_path, notice: "Set #{inputs['status']} on #{ids.size} customers" - end - action_item :report, only: :index do link_to "Report", report_admin_customers_path, class: "action-item-button" end - action_item :more, only: :show do - dropdown_menu "More" do - item "Report", report_admin_customers_path - item "Customers", admin_customers_path - end - end - - sidebar "Help", only: :index do - para "Use the filters to narrow the list." - ul do - li link_to("Report", report_admin_customers_path) - li link_to("Active customers", admin_customers_path(scope: "active")) - li link_to("Top", "#") - end - end - - sidebar "Summary", only: :show do - para "Orders: #{resource.orders.count}" - end - collection_action :report do flash[:alert] = "Report is not ready" flash[:error] = "Report failed" @@ -70,12 +44,18 @@ column :name column :email column :external_id - column(:status) { |customer| status_tag(customer.status) } + column(:status) { |customer| status_tag customer.status } column :balance column :active column :category column "Created", :created_at column :notes if params[:with_notes] + if params[:with_flags] + column :flags do |customer| + status_tag customer.status + status_tag customer.active + end + end actions end @@ -84,7 +64,7 @@ row :name row :email row :external_id - row(:status) { |customer| status_tag(customer.status) } + row(:status) { |customer| status_tag customer.status } row :balance row :category row "Signed up", &:created_at @@ -92,18 +72,6 @@ panel "Notes" do para resource.notes end - tabs do - tab "Overview" do - para "Overview body" - end - tab "Orders" do - table_for resource.orders do - column :reference - column :state - end - end - end - active_admin_comments end form do |f| @@ -122,14 +90,7 @@ f.input :password, as: :password f.input :tier, as: :radio, collection: Customer::TIERS f.input :channels, as: :check_boxes, collection: Customer::CHANNELS - f.input :signed_on, as: :datepicker - end - f.has_many :orders, heading: "Orders", allow_destroy: true do |o| - # A check_boxes input first: its hidden input is named `...[tags][]`. - o.input :tags, as: :check_boxes, collection: %w[Gift Rush] if f.object.external_id == "ORDER-TAGS" - o.input :reference - o.input :state, as: :select, collection: Order::STATES - o.input :quantity, input_html: { disabled: params[:lock_quantity].present? } + f.input :signed_on, as: :date_picker end f.actions end diff --git a/spec/dummy/app/admin/dashboard.rb b/spec/dummy/app/admin/dashboard.rb index cfa4b07..26f8ce5 100644 --- a/spec/dummy/app/admin/dashboard.rb +++ b/spec/dummy/app/admin/dashboard.rb @@ -14,5 +14,10 @@ panel "Stats" do para "Nothing yet." end + panel "Overview" do + panel "Inner stats" do + para "Nested." + end + end end end diff --git a/spec/dummy/app/admin/documents.rb b/spec/dummy/app/admin/documents.rb index 43e4472..88a9d26 100644 --- a/spec/dummy/app/admin/documents.rb +++ b/spec/dummy/app/admin/documents.rb @@ -1,47 +1,29 @@ # frozen_string_literal: true # Not in the menu. It holds what the customer pages cannot take without -# changing their declared elements: a file input, disabled inputs, two status -# tags in one cell, and titles with a count. +# changing their declared elements: a file input, disabled inputs and a +# title with a count, and the comments. ActiveAdmin.register Document do menu false + config.comments = true permit_params :name, :attachment, :state, :kind, :code, :archived filter :name - sidebar "Versions (2)", only: :show do - para "Two versions." - end - index do id_column column :name - column(:flags) do |document| - status_tag(document.state) - status_tag("archived", class: "warning") if document.archived - end end show do attributes_table do row :name row :attachment_name - row(:flags) do |document| - status_tag(document.state) - status_tag("archived", class: "warning") if document.archived - end end panel "Possible Routes (2)" do para "Two routes." end - tabs do - tab "Details" do - para "Details body" - end - tab "Files (3)" do - para "Three files." - end - end + active_admin_comments_for(resource) end form do |f| diff --git a/spec/dummy/app/admin/orders.rb b/spec/dummy/app/admin/orders.rb index 04f32e7..89f3ee1 100644 --- a/spec/dummy/app/admin/orders.rb +++ b/spec/dummy/app/admin/orders.rb @@ -3,6 +3,9 @@ ActiveAdmin.register Order do menu parent: "Catalog" + permit_params :reference, :state, :quantity, :customer_id, + line_items_attributes: [:id, :sku, :kind, :quantity, :_destroy, { tags: [] }] + filter :reference, filters: %i[not_eq eq] filter :quantity filter :customer @@ -15,4 +18,22 @@ column :quantity column :customer end + + form do |f| + f.semantic_errors + f.inputs do + f.input :reference + f.input :state, as: :select, collection: Order::STATES + f.input :quantity + f.input :customer, as: :select + end + f.has_many :line_items, heading: "Line Items", allow_destroy: true do |item| + # A check_boxes input first: its hidden input is named `...[tags][]`. + item.input :tags, as: :check_boxes, collection: %w[Gift Rush] if f.object.reference == "LINE-TAGS" + item.input :sku + item.input :kind, as: :select, collection: LineItem::KINDS + item.input :quantity + end + f.actions + end end diff --git a/spec/dummy/app/assets/config/manifest.js b/spec/dummy/app/assets/config/manifest.js deleted file mode 100644 index 694c926..0000000 --- a/spec/dummy/app/assets/config/manifest.js +++ /dev/null @@ -1,2 +0,0 @@ -//= link active_admin.css -//= link active_admin.js diff --git a/spec/dummy/app/assets/javascripts/active_admin.js b/spec/dummy/app/assets/javascripts/active_admin.js deleted file mode 100644 index d2b66c5..0000000 --- a/spec/dummy/app/assets/javascripts/active_admin.js +++ /dev/null @@ -1 +0,0 @@ -//= require active_admin/base diff --git a/spec/dummy/app/assets/stylesheets/active_admin.scss b/spec/dummy/app/assets/stylesheets/active_admin.scss deleted file mode 100644 index 65d1ea3..0000000 --- a/spec/dummy/app/assets/stylesheets/active_admin.scss +++ /dev/null @@ -1,2 +0,0 @@ -@import "active_admin/mixins"; -@import "active_admin/base"; diff --git a/spec/dummy/app/controllers/application_controller.rb b/spec/dummy/app/controllers/application_controller.rb index 99f02a7..2d4239a 100644 --- a/spec/dummy/app/controllers/application_controller.rb +++ b/spec/dummy/app/controllers/application_controller.rb @@ -4,6 +4,6 @@ class ApplicationController < ActionController::Base private def current_admin_user - AdminUser.first_or_create!(email: "admin@example.com") + AdminUser.find_or_create_by!(name: "Demo Admin") end end diff --git a/spec/dummy/app/models/admin_user.rb b/spec/dummy/app/models/admin_user.rb index b270f7c..fd53bc2 100644 --- a/spec/dummy/app/models/admin_user.rb +++ b/spec/dummy/app/models/admin_user.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +# The comment author: ActiveAdmin::Comment needs an ActiveRecord author. class AdminUser < ActiveRecord::Base - def display_name = email + def to_s = name end diff --git a/spec/dummy/app/models/customer.rb b/spec/dummy/app/models/customer.rb index 23eb513..5b2be2a 100644 --- a/spec/dummy/app/models/customer.rb +++ b/spec/dummy/app/models/customer.rb @@ -8,8 +8,6 @@ class Customer < ActiveRecord::Base belongs_to :category, optional: true has_many :orders, dependent: :destroy - accepts_nested_attributes_for :orders, allow_destroy: true - serialize :channels, type: Array, coder: JSON attr_accessor :password diff --git a/spec/dummy/app/models/line_item.rb b/spec/dummy/app/models/line_item.rb new file mode 100644 index 0000000..6ff45d8 --- /dev/null +++ b/spec/dummy/app/models/line_item.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +class LineItem < ActiveRecord::Base + KINDS = %w[Goods Service].freeze + + belongs_to :order + + # Not stored: the form shows it as a check_boxes input. + attr_accessor :tags + + validates :quantity, numericality: { greater_than: 0, allow_nil: true } +end diff --git a/spec/dummy/app/models/order.rb b/spec/dummy/app/models/order.rb index ef318b4..781e42a 100644 --- a/spec/dummy/app/models/order.rb +++ b/spec/dummy/app/models/order.rb @@ -4,11 +4,9 @@ class Order < ActiveRecord::Base STATES = %w[new paid shipped].freeze belongs_to :customer + has_many :line_items, dependent: :destroy - # Not stored: the form shows it as a check_boxes input. - attr_accessor :tags - - validates :quantity, numericality: { greater_than: 0, allow_nil: true } + accepts_nested_attributes_for :line_items, allow_destroy: true def self.ransackable_attributes(_auth = nil) = %w[reference state quantity customer_id] def self.ransackable_associations(_auth = nil) = %w[customer] diff --git a/spec/dummy/app/tailwind/active_admin.css b/spec/dummy/app/tailwind/active_admin.css new file mode 100644 index 0000000..886f8c6 --- /dev/null +++ b/spec/dummy/app/tailwind/active_admin.css @@ -0,0 +1,3 @@ +@import "tailwindcss"; + +@config "../../tailwind-active_admin.config.js"; diff --git a/spec/dummy/app/views/active_admin/_html_head.html.erb b/spec/dummy/app/views/active_admin/_html_head.html.erb new file mode 100644 index 0000000..afbfd32 --- /dev/null +++ b/spec/dummy/app/views/active_admin/_html_head.html.erb @@ -0,0 +1,13 @@ +<%= stylesheet_link_tag "active_admin" %> + +<%= csrf_meta_tags %> +<%= csp_meta_tag %> +<% # On page load or when changing themes, best to add inline in `head` to avoid FOUC %> +<%= javascript_tag nonce: true do %> + if (localStorage.theme === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)) { + document.documentElement.classList.add('dark') + } else { + document.documentElement.classList.remove('dark') + } +<% end %> +<%= javascript_importmap_tags "active_admin", importmap: ActiveAdmin.importmap %> diff --git a/spec/dummy/config/application.rb b/spec/dummy/config/application.rb index 8ea0a6e..ad9ce27 100644 --- a/spec/dummy/config/application.rb +++ b/spec/dummy/config/application.rb @@ -1,12 +1,13 @@ # frozen_string_literal: true -# Minimal ActiveAdmin 3 host app (sprockets, jQuery from jquery-rails, Sass) -# that the specs drive through the page objects. +# Minimal ActiveAdmin 4 host app (importmap + propshaft, Tailwind CSS built by +# the npm CLI) that the specs drive through the page objects. require "rails" require "active_record/railtie" require "action_controller/railtie" require "action_view/railtie" -require "sprockets/railtie" +require "propshaft" +require "importmap-rails" require "activeadmin" module Dummy diff --git a/spec/dummy/config/importmap.rb b/spec/dummy/config/importmap.rb new file mode 100644 index 0000000..9b4aa5d --- /dev/null +++ b/spec/dummy/config/importmap.rb @@ -0,0 +1,4 @@ +# frozen_string_literal: true + +# The ActiveAdmin layout renders ActiveAdmin.importmap (see the initializer). +# This file only exists because importmap-rails expects it. diff --git a/spec/dummy/config/schema.rb b/spec/dummy/config/schema.rb index a602386..e292fb3 100644 --- a/spec/dummy/config/schema.rb +++ b/spec/dummy/config/schema.rb @@ -2,20 +2,6 @@ ActiveRecord::Schema.verbose = false ActiveRecord::Schema.define do - create_table :admin_users do |t| - t.string :email - t.timestamps - end - - create_table :active_admin_comments do |t| - t.string :namespace - t.text :body - t.references :resource, polymorphic: true - t.references :author, polymorphic: true - t.timestamps - end - add_index :active_admin_comments, :namespace - create_table :categories do |t| t.string :name end @@ -32,6 +18,11 @@ t.timestamps end + create_table :documents do |t| + t.string :name, :state, :kind, :code, :attachment_name + t.boolean :archived, default: false, null: false + end + create_table :orders do |t| t.string :reference, :state t.integer :quantity @@ -39,12 +30,26 @@ t.timestamps end - create_table :documents do |t| - t.string :name, :state, :kind, :code, :attachment_name - t.boolean :archived, default: false, null: false + create_table :tags do |t| + t.string :name end - create_table :tags do |t| + create_table :line_items do |t| + t.references :order + t.string :sku, :kind + t.integer :quantity + end + + create_table :active_admin_comments do |t| + t.string :namespace + t.text :body + t.references :resource, polymorphic: true + t.references :author, polymorphic: true + t.timestamps + end + add_index :active_admin_comments, :namespace + + create_table :admin_users do |t| t.string :name end end diff --git a/spec/dummy/package-lock.json b/spec/dummy/package-lock.json new file mode 100644 index 0000000..225ebc1 --- /dev/null +++ b/spec/dummy/package-lock.json @@ -0,0 +1,1309 @@ +{ + "name": "active_admin_page_objects_dummy", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "active_admin_page_objects_dummy", + "dependencies": { + "@activeadmin/activeadmin": "4.0.0-beta23", + "@tailwindcss/cli": "^4.1.0", + "tailwindcss": "^4.1.0" + } + }, + "node_modules/@activeadmin/activeadmin": { + "version": "4.0.0-beta23", + "resolved": "https://registry.npmjs.org/@activeadmin/activeadmin/-/activeadmin-4.0.0-beta23.tgz", + "integrity": "sha512-7hNiy0T/p1XEPAgYqLWYT9/03+0zBZ8dnjP+B8igr7FNE7KOYa8Mbv1LFJvZuN9P4AKLc1lMHTJzu7BVLY/PZw==", + "license": "MIT", + "dependencies": { + "@rails/ujs": "7.1.600", + "flowbite": "3.1.2" + } + }, + "node_modules/@jridgewell/gen-mapping": { + "version": "0.3.13", + "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.13.tgz", + "integrity": "sha512-2kkt/7niJ6MgEPxF0bYdQ6etZaA+fQvDcLKckhy1yIQOzaoKjBBjSj63/aLVjYE3qhRt5dvM+uUyfCg6UKCBbA==", + "license": "MIT", + "dependencies": { + "@jridgewell/sourcemap-codec": "^1.5.0", + "@jridgewell/trace-mapping": "^0.3.24" + } + }, + "node_modules/@jridgewell/remapping": { + "version": "2.3.5", + "resolved": "https://registry.npmjs.org/@jridgewell/remapping/-/remapping-2.3.5.tgz", + "integrity": "sha512-LI9u/+laYG4Ds1TDKSJW2YPrIlcVYOwi2fUC6xB43lueCjgxV4lffOCZCtYFiH6TNOX+tQKXx97T4IKHbhyHEQ==", + "license": "MIT", + "dependencies": { + "@jridgewell/gen-mapping": "^0.3.5", + "@jridgewell/trace-mapping": "^0.3.24" + } + }, + "node_modules/@jridgewell/resolve-uri": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz", + "integrity": "sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==", + "license": "MIT", + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/sourcemap-codec": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.6.0.tgz", + "integrity": "sha512-T7jf+5zgsZHwNJ4lvQ7/aezbyk0nNX+zJVWpmHA7VYsEx7a7qr5Rg5IbtJFqkgze5Y2sruq1RUY8Q837Od7iFw==", + "license": "MIT" + }, + "node_modules/@jridgewell/trace-mapping": { + "version": "0.3.31", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.31.tgz", + "integrity": "sha512-zzNR+SdQSDJzc8joaeP8QQoCQr8NuYx2dIIytl1QeBEZHJ9uW6hebsrYgbz8hJwUQao3TWCMtmfV8Nu1twOLAw==", + "license": "MIT", + "dependencies": { + "@jridgewell/resolve-uri": "^3.1.0", + "@jridgewell/sourcemap-codec": "^1.4.14" + } + }, + "node_modules/@parcel/watcher": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/@parcel/watcher/-/watcher-2.6.0.tgz", + "integrity": "sha512-7FNeNl8NCE7aINx7WXiKQrPYZWC/hvrTsmk6zmxbI7LTXE7hVek/n8AfVgpe2y82zl3w0HvCHN0bVKMBoJcC0w==", + "hasInstallScript": true, + "license": "MIT", + "dependencies": { + "detect-libc": "^2.0.3", + "is-glob": "^4.0.3", + "node-addon-api": "^7.0.0", + "picomatch": "^4.0.4" + }, + "engines": { + "node": ">= 10.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + }, + "optionalDependencies": { + "@parcel/watcher-android-arm64": "2.6.0", + "@parcel/watcher-darwin-arm64": "2.6.0", + "@parcel/watcher-darwin-x64": "2.6.0", + "@parcel/watcher-freebsd-x64": "2.6.0", + "@parcel/watcher-linux-arm-glibc": "2.6.0", + "@parcel/watcher-linux-arm-musl": "2.6.0", + "@parcel/watcher-linux-arm64-glibc": "2.6.0", + "@parcel/watcher-linux-arm64-musl": "2.6.0", + "@parcel/watcher-linux-x64-glibc": "2.6.0", + "@parcel/watcher-linux-x64-musl": "2.6.0", + "@parcel/watcher-win32-arm64": "2.6.0", + "@parcel/watcher-win32-x64": "2.6.0" + } + }, + "node_modules/@parcel/watcher-android-arm64": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/@parcel/watcher-android-arm64/-/watcher-android-arm64-2.6.0.tgz", + "integrity": "sha512-trgpLSCKRC/huFjXX/Smh+0sWe4+YtKfktIToiMl59ghz7z+qkH6kMvNnUbLyRs9N11t8l4svSCs1+5B3rOAhA==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">= 10.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/@parcel/watcher-darwin-arm64": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/@parcel/watcher-darwin-arm64/-/watcher-darwin-arm64-2.6.0.tgz", + "integrity": "sha512-Y3QV0gl7Q1zbfueunkWIERICbEojQFCgpyG7YqOGNFLsckXyI1xu9mAIUpKY9QBYzBtSkN8dBPwd3yiAO9ovMw==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/@parcel/watcher-darwin-x64": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/@parcel/watcher-darwin-x64/-/watcher-darwin-x64-2.6.0.tgz", + "integrity": "sha512-Ohv6OpzhUfKYD7Beb8kDvG0jbIxORCYY1JRdZnaBtnjjkJxgD7ZVL0nw2sCYd0yTMKTvz3nnTnOF3cDifK+kvw==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/@parcel/watcher-freebsd-x64": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/@parcel/watcher-freebsd-x64/-/watcher-freebsd-x64-2.6.0.tgz", + "integrity": "sha512-5HmXvDgs8VK+74jF9y9/2FE3/OnlcKmc56tjmSrEuZjpSZOGL+fvAu+HKJBdPs9uwoP2hE6TlSUpXZ/C5jUFmQ==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">= 10.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/@parcel/watcher-linux-arm-glibc": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/@parcel/watcher-linux-arm-glibc/-/watcher-linux-arm-glibc-2.6.0.tgz", + "integrity": "sha512-Ps/hui3A+vMbjdqlqAowK2ZL8+BO8dBjxeWXj6npTBs3jx4wWmbPpaLuqwrQrSqIVMCnpWo238bJ1U37GhQOYg==", + "cpu": [ + "arm" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/@parcel/watcher-linux-arm-musl": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/@parcel/watcher-linux-arm-musl/-/watcher-linux-arm-musl-2.6.0.tgz", + "integrity": "sha512-9c6AUHgHoG+IY88MRIHupztQiQnrbqHYQjkM2btA+Bf/wQnQMuiD0Wfk1EVv3TlNT3x41uU71rn6E4xh/+zvkw==", + "cpu": [ + "arm" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/@parcel/watcher-linux-arm64-glibc": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/@parcel/watcher-linux-arm64-glibc/-/watcher-linux-arm64-glibc-2.6.0.tgz", + "integrity": "sha512-yHRqS2owEXe6Hic9z6Mh1ECsCd+ODVOGvZDyciqRd21+v+o+DnXMOrw50DSpIG2sb8GPEaPPmfeCAWKPJdq46g==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/@parcel/watcher-linux-arm64-musl": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/@parcel/watcher-linux-arm64-musl/-/watcher-linux-arm64-musl-2.6.0.tgz", + "integrity": "sha512-WhB2e/V7rqdHHWZusBSPuy5Ei8S6lSz6FE5TKKQz5h3a0O+C+mhY7vxU9b/stqvMb8beLnPY82ZrFTLKs+SrKA==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/@parcel/watcher-linux-x64-glibc": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/@parcel/watcher-linux-x64-glibc/-/watcher-linux-x64-glibc-2.6.0.tgz", + "integrity": "sha512-ulGE6x6Oz6iAwg75T8YQSoguBWasniIbX+QWpaYPcCnDOpdWX3k+4xbEYPZVLxOuoJI+svJJPD3sEj8G7lrQ3A==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/@parcel/watcher-linux-x64-musl": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/@parcel/watcher-linux-x64-musl/-/watcher-linux-x64-musl-2.6.0.tgz", + "integrity": "sha512-tkBYKt7YQrjIJWYDnto2YgO8MRkjlMTSNoRHzsXinBqbLdeOM3L32wPZJvIZxqaLMfSlS/4sUjH/6STVP/XDLw==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/@parcel/watcher-win32-arm64": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/@parcel/watcher-win32-arm64/-/watcher-win32-arm64-2.6.0.tgz", + "integrity": "sha512-gIZAP23jaHjGWasY/TY6yL7NHFClf0Ga7FN+iINvk+KN94rhm94lYZhFsbYFNcA04/onvGD9kKmiJLJB2HbNwQ==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/@parcel/watcher-win32-x64": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/@parcel/watcher-win32-x64/-/watcher-win32-x64-2.6.0.tgz", + "integrity": "sha512-cA+/pXV2YkfxlIcXOQ5fSWqAzzPyD78/x5qbK/I0vUkrlYHA8TIz+MXjAbGouguKVSI4bOmkTSJ1/poVSsgt+A==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/@popperjs/core": { + "version": "2.11.8", + "resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.8.tgz", + "integrity": "sha512-P1st0aksCrn9sGZhp8GMYwBnQsbvAWsZAX44oXNNvLHGqAOcoVxmjZiohstwQ7SqKnbR47akdNi+uleWD8+g6A==", + "license": "MIT", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/popperjs" + } + }, + "node_modules/@rails/ujs": { + "version": "7.1.600", + "resolved": "https://registry.npmjs.org/@rails/ujs/-/ujs-7.1.600.tgz", + "integrity": "sha512-ntMYJ8++n1zcIJ1g75or7Va9IU3ueCHgp9IJk7Ny7eFEbu0Kx40EHZ2FNhoxoUEjlF5NifCFCbvoK5rDK5HpIQ==", + "license": "MIT" + }, + "node_modules/@rollup/plugin-node-resolve": { + "version": "15.3.1", + "resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-15.3.1.tgz", + "integrity": "sha512-tgg6b91pAybXHJQMAAwW9VuWBO6Thi+q7BCNARLwSqlmsHz0XYURtGvh/AuwSADXSI4h/2uHbs7s4FzlZDGSGA==", + "license": "MIT", + "dependencies": { + "@rollup/pluginutils": "^5.0.1", + "@types/resolve": "1.20.2", + "deepmerge": "^4.2.2", + "is-module": "^1.0.0", + "resolve": "^1.22.1" + }, + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "rollup": "^2.78.0||^3.0.0||^4.0.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + } + } + }, + "node_modules/@rollup/pluginutils": { + "version": "5.5.1", + "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.5.1.tgz", + "integrity": "sha512-P9ZvnfouRu4MSC+ilERaw6FmZs8zqKhpHxEs4aGDGWQAMzQGXnhvCSvoNwokfNvdt7t3Y5Y4p6gStQgezeIqug==", + "license": "MIT", + "dependencies": { + "@types/estree": "^1.0.0", + "estree-walker": "^2.0.2", + "picomatch": "^4.0.2" + }, + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "rollup": "^1.20.0||^2.0.0||^3.0.0||^4.0.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + } + } + }, + "node_modules/@tailwindcss/cli": { + "version": "4.3.5", + "resolved": "https://registry.npmjs.org/@tailwindcss/cli/-/cli-4.3.5.tgz", + "integrity": "sha512-+evrrLZEgNPDXgdIxD6Zfc23WhSYZQeGwniO5u9M4zC92kbEtIjKd8l2QWeO7du8kl4gF8z7YArnUGHG4y2Jzg==", + "license": "MIT", + "dependencies": { + "@parcel/watcher": "2.6.0", + "@tailwindcss/node": "4.3.5", + "@tailwindcss/oxide": "4.3.5", + "enhanced-resolve": "^5.24.5", + "mri": "^1.2.0", + "picocolors": "^1.1.1", + "tailwindcss": "4.3.5" + }, + "bin": { + "tailwindcss": "dist/index.mjs" + } + }, + "node_modules/@tailwindcss/node": { + "version": "4.3.5", + "resolved": "https://registry.npmjs.org/@tailwindcss/node/-/node-4.3.5.tgz", + "integrity": "sha512-yT53FzV4ke0cr/BguDxhWMpm5MJu1O2muzk+tKw6lKHjODAsYArBbWwFbJiaksfzFv1tpkO9QHGzmfs1hJT66g==", + "license": "MIT", + "dependencies": { + "@jridgewell/remapping": "^2.3.5", + "enhanced-resolve": "^5.24.5", + "jiti": "^2.7.0", + "lightningcss": "1.33.0", + "magic-string": "^1.1.0", + "source-map-js": "^1.2.1", + "tailwindcss": "4.3.5" + } + }, + "node_modules/@tailwindcss/oxide": { + "version": "4.3.5", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide/-/oxide-4.3.5.tgz", + "integrity": "sha512-PynqGLZsZvwM9tqD/CUxkOIfyd6K5elZ2MooauzJryP/UqXYgi3yYbtt3N0Xe+MHV/eFKPFQCEfIKAqlAS1CBg==", + "license": "MIT", + "engines": { + "node": ">= 20" + }, + "optionalDependencies": { + "@tailwindcss/oxide-android-arm64": "4.3.5", + "@tailwindcss/oxide-darwin-arm64": "4.3.5", + "@tailwindcss/oxide-darwin-x64": "4.3.5", + "@tailwindcss/oxide-freebsd-x64": "4.3.5", + "@tailwindcss/oxide-linux-arm-gnueabihf": "4.3.5", + "@tailwindcss/oxide-linux-arm64-gnu": "4.3.5", + "@tailwindcss/oxide-linux-arm64-musl": "4.3.5", + "@tailwindcss/oxide-linux-x64-gnu": "4.3.5", + "@tailwindcss/oxide-linux-x64-musl": "4.3.5", + "@tailwindcss/oxide-wasm32-wasi": "4.3.5", + "@tailwindcss/oxide-win32-arm64-msvc": "4.3.5", + "@tailwindcss/oxide-win32-x64-msvc": "4.3.5" + } + }, + "node_modules/@tailwindcss/oxide-android-arm64": { + "version": "4.3.5", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-android-arm64/-/oxide-android-arm64-4.3.5.tgz", + "integrity": "sha512-Se0z5xMqcSQanJD1IYmO0cGpK3iv0fp3ZsIT7xRJZ1Da5PghvNoc46zz4jIQn+aan3dV9T8AermFNN9QPmsh0Q==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">= 20" + } + }, + "node_modules/@tailwindcss/oxide-darwin-arm64": { + "version": "4.3.5", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-darwin-arm64/-/oxide-darwin-arm64-4.3.5.tgz", + "integrity": "sha512-UPrgTDuUbvmqGMZuCnmI3FKee/tYKzKdp00/kuB4oSGB213VYg8QTdF7lVhnPoBXq/mIfJ+ILoBFqNOboWcMwQ==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 20" + } + }, + "node_modules/@tailwindcss/oxide-darwin-x64": { + "version": "4.3.5", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-darwin-x64/-/oxide-darwin-x64-4.3.5.tgz", + "integrity": "sha512-E+p7HEtjI0b8D7kbbWxH067cGui6d4c79COGko9fAPVE3rwc1E7ld2HFCbaG86AOGWS5VKQYqZOaf38ya4uxTQ==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 20" + } + }, + "node_modules/@tailwindcss/oxide-freebsd-x64": { + "version": "4.3.5", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-freebsd-x64/-/oxide-freebsd-x64-4.3.5.tgz", + "integrity": "sha512-yWEWcWyAG7rWOcTpJTjdhQ3pcaFY2h+0bqTRfgU3G2fz87ZU3AKdvdZKhslD+kyHnjBUWKvNdRYwIYC5dI1tIg==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">= 20" + } + }, + "node_modules/@tailwindcss/oxide-linux-arm-gnueabihf": { + "version": "4.3.5", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-linux-arm-gnueabihf/-/oxide-linux-arm-gnueabihf-4.3.5.tgz", + "integrity": "sha512-WmeVjtJhZlr+smpqcdR2kQkkn6arHIJnUIBxTO2EJcTLGY1ecVXNo2hbSn8xc0IH2aEtys936iMWKGyj0GaKnA==", + "cpu": [ + "arm" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 20" + } + }, + "node_modules/@tailwindcss/oxide-linux-arm64-gnu": { + "version": "4.3.5", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-linux-arm64-gnu/-/oxide-linux-arm64-gnu-4.3.5.tgz", + "integrity": "sha512-DTCSyucc6ShMp1QMqV5R94Z7xlgNgUzkGmFF1rL5HH2Qjy4eSmEqy+YLGkqqYvWa4sILtgrBt1JjRKbneQtiFQ==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 20" + } + }, + "node_modules/@tailwindcss/oxide-linux-arm64-musl": { + "version": "4.3.5", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-linux-arm64-musl/-/oxide-linux-arm64-musl-4.3.5.tgz", + "integrity": "sha512-H9lsvO4x9E4nE4Hi8h7NHHw0O/kcVSu+iOyFHNGdYzazGgDjFHZbE6S3hQ8kMcbNXSBlMdNi67LV5EVqtpaJtw==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 20" + } + }, + "node_modules/@tailwindcss/oxide-linux-x64-gnu": { + "version": "4.3.5", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-linux-x64-gnu/-/oxide-linux-x64-gnu-4.3.5.tgz", + "integrity": "sha512-4uxQvtBvPuIdl13WfUBj9xMZHH14PtHZ8OZdtLmdyDtG66sCa1t599NZT+jagkUzRtWhuul1qRZQ1nAJscXN5g==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 20" + } + }, + "node_modules/@tailwindcss/oxide-linux-x64-musl": { + "version": "4.3.5", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-linux-x64-musl/-/oxide-linux-x64-musl-4.3.5.tgz", + "integrity": "sha512-0JQAzs7jwbA7O6+z/adU+Jk3AXwsu3npAhtr5escXS7TqEqWcaDV7qHuI+0Vy/KQRuVGnLQREcSJWYauyV3oqg==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 20" + } + }, + "node_modules/@tailwindcss/oxide-wasm32-wasi": { + "version": "4.3.5", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-wasm32-wasi/-/oxide-wasm32-wasi-4.3.5.tgz", + "integrity": "sha512-OJhFmlEfdzMr+avACdi40RPtnkW0B6hXyxL/8r+tnEHBWZji36CYRjEXrrvgBmaYsD3oEOBqwYFRKsYvzFe7Bw==", + "bundleDependencies": [ + "@napi-rs/wasm-runtime", + "@emnapi/core", + "@emnapi/runtime", + "@tybys/wasm-util", + "@emnapi/wasi-threads", + "tslib" + ], + "license": "MIT", + "optional": true, + "dependencies": { + "@emnapi/core": "^1.11.3", + "@emnapi/runtime": "^1.11.3", + "@emnapi/wasi-threads": "^1.2.3", + "@napi-rs/wasm-runtime": "^1.2.2", + "@tybys/wasm-util": "^0.10.3", + "tslib": "^2.8.1" + }, + "engines": { + "node": "^20.19.0 || ^22.13.0 || >=23.5.0" + } + }, + "node_modules/@tailwindcss/oxide-wasm32-wasi/node_modules/@emnapi/core": { + "version": "1.11.3", + "inBundle": true, + "license": "MIT", + "optional": true, + "dependencies": { + "@emnapi/wasi-threads": "1.2.3", + "tslib": "^2.4.0" + } + }, + "node_modules/@tailwindcss/oxide-wasm32-wasi/node_modules/@emnapi/runtime": { + "version": "1.11.3", + "inBundle": true, + "license": "MIT", + "optional": true, + "dependencies": { + "tslib": "^2.4.0" + } + }, + "node_modules/@tailwindcss/oxide-wasm32-wasi/node_modules/@emnapi/wasi-threads": { + "version": "1.2.3", + "inBundle": true, + "license": "MIT", + "optional": true, + "dependencies": { + "tslib": "^2.4.0" + } + }, + "node_modules/@tailwindcss/oxide-wasm32-wasi/node_modules/@napi-rs/wasm-runtime": { + "version": "1.2.2", + "inBundle": true, + "license": "MIT", + "optional": true, + "dependencies": { + "@tybys/wasm-util": "^0.10.3" + }, + "engines": { + "node": "^20.19.0 || ^22.13.0 || >=23.5.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Brooooooklyn" + }, + "peerDependencies": { + "@emnapi/core": "^1.7.1 || ^2.0.0-alpha.3", + "@emnapi/runtime": "^1.7.1 || ^2.0.0-alpha.3" + } + }, + "node_modules/@tailwindcss/oxide-wasm32-wasi/node_modules/@tybys/wasm-util": { + "version": "0.10.3", + "inBundle": true, + "license": "MIT", + "optional": true, + "dependencies": { + "tslib": "^2.4.0" + } + }, + "node_modules/@tailwindcss/oxide-wasm32-wasi/node_modules/tslib": { + "version": "2.8.1", + "inBundle": true, + "license": "0BSD", + "optional": true + }, + "node_modules/@tailwindcss/oxide-win32-arm64-msvc": { + "version": "4.3.5", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-win32-arm64-msvc/-/oxide-win32-arm64-msvc-4.3.5.tgz", + "integrity": "sha512-9o8jgthi+QE5eandnboiJT64VQfnIArfZzSTdgbhEK5aafdiu2jTW9Honi/mwYHxBZuH1vAC57IFyrh+0iK5Gg==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 20" + } + }, + "node_modules/@tailwindcss/oxide-win32-x64-msvc": { + "version": "4.3.5", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-win32-x64-msvc/-/oxide-win32-x64-msvc-4.3.5.tgz", + "integrity": "sha512-XiKFfIy1RWe7qK4WqByxNW7Oz1/nkOy8o/BWhHminyV1PmpUd8Eedj5v2A8h2kpqeVlz6xRnwk9Fr/ZXNLcZfg==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 20" + } + }, + "node_modules/@types/estree": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.10.tgz", + "integrity": "sha512-lTyOMnOcmRBzdCv6/4zUZCrEhV0xrqQiUZBZtVcbmLHBXKLnN8q89v/wKRF/Q0HbwVsqbIG3o5HDoFl9sduM+g==", + "license": "MIT" + }, + "node_modules/@types/resolve": { + "version": "1.20.2", + "resolved": "https://registry.npmjs.org/@types/resolve/-/resolve-1.20.2.tgz", + "integrity": "sha512-60BCwRFOZCQhDncwQdxxeOEEkbc5dIMccYLwbxsS4TUNeVECQ/pBJ0j09mrHOl/JJvpRPGwO9SvE4nR2Nb/a4Q==", + "license": "MIT" + }, + "node_modules/deepmerge": { + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-4.3.1.tgz", + "integrity": "sha512-3sUqbMEc77XqpdNO7FRyRog+eW3ph+GYCbj+rK+uYyRMuwsVy0rMiVtPn+QJlKFvWP/1PYpapqYn0Me2knFn+A==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/detect-libc": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz", + "integrity": "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==", + "license": "Apache-2.0", + "engines": { + "node": ">=8" + } + }, + "node_modules/enhanced-resolve": { + "version": "5.26.1", + "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.26.1.tgz", + "integrity": "sha512-PPnnSJq3azKOIewXR/uppBV/6h98dprBJ/WaQ9Qgj10xX1lJLNfg+XShpbsrSqcDSy2yYYyhfXM1wWhftqgyzw==", + "license": "MIT", + "dependencies": { + "graceful-fs": "^4.2.4", + "tapable": "^2.3.3" + }, + "engines": { + "node": ">=10.13.0" + } + }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/estree-walker": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz", + "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==", + "license": "MIT" + }, + "node_modules/flowbite": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/flowbite/-/flowbite-3.1.2.tgz", + "integrity": "sha512-MkwSgbbybCYgMC+go6Da5idEKUFfMqc/AmSjm/2ZbdmvoKf5frLPq/eIhXc9P+rC8t9boZtUXzHDgt5whZ6A/Q==", + "license": "MIT", + "dependencies": { + "@popperjs/core": "^2.9.3", + "flowbite-datepicker": "^1.3.1", + "mini-svg-data-uri": "^1.4.3", + "postcss": "^8.5.1" + } + }, + "node_modules/flowbite-datepicker": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/flowbite-datepicker/-/flowbite-datepicker-1.3.2.tgz", + "integrity": "sha512-6Nfm0MCVX3mpaR7YSCjmEO2GO8CDt6CX8ZpQnGdeu03WUCWtEPQ/uy0PUiNtIJjJZWnX0Cm3H55MOhbD1g+E/g==", + "license": "MIT", + "dependencies": { + "@rollup/plugin-node-resolve": "^15.2.3", + "flowbite": "^2.0.0" + } + }, + "node_modules/flowbite-datepicker/node_modules/flowbite": { + "version": "2.5.2", + "resolved": "https://registry.npmjs.org/flowbite/-/flowbite-2.5.2.tgz", + "integrity": "sha512-kwFD3n8/YW4EG8GlY3Od9IoKND97kitO+/ejISHSqpn3vw2i5K/+ZI8Jm2V+KC4fGdnfi0XZ+TzYqQb4Q1LshA==", + "license": "MIT", + "dependencies": { + "@popperjs/core": "^2.9.3", + "flowbite-datepicker": "^1.3.0", + "mini-svg-data-uri": "^1.4.3" + } + }, + "node_modules/function-bind": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/graceful-fs": { + "version": "4.2.11", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", + "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==", + "license": "ISC" + }, + "node_modules/hasown": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.4.tgz", + "integrity": "sha512-T2UbfbBEF32wiepXIsMlTW9+dDYC6wMh/t/vYA4tuOMKqWz/n3vr1NFSxQiyP+zk2mXsoMA/i/7qV6LKut1t1A==", + "license": "MIT", + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/is-core-module": { + "version": "2.18.0", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.18.0.tgz", + "integrity": "sha512-qyax9fgaKOEC4qK8WZn7Q4IcoZC9RC1O1fFxRcRTq/oMMkWT/uXpqpXa12kzWR409zAt1drYN9N9BO26UmBCmw==", + "license": "MIT", + "dependencies": { + "hasown": "^2.0.4" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/is-extglob": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", + "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-glob": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", + "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", + "license": "MIT", + "dependencies": { + "is-extglob": "^2.1.1" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-module": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-module/-/is-module-1.0.0.tgz", + "integrity": "sha512-51ypPSPCoTEIN9dy5Oy+h4pShgJmPCygKfyRCISBI+JoWT/2oJvK8QPxmwv7b/p239jXrm9M1mlQbyKJ5A152g==", + "license": "MIT" + }, + "node_modules/jiti": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/jiti/-/jiti-2.7.0.tgz", + "integrity": "sha512-AC/7JofJvZGrrneWNaEnJeOLUx+JlGt7tNa0wZiRPT4MY1wmfKjt2+6O2p2uz2+skll8OZZmJMNqeke7kKbNgQ==", + "license": "MIT", + "bin": { + "jiti": "lib/jiti-cli.mjs" + } + }, + "node_modules/lightningcss": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss/-/lightningcss-1.33.0.tgz", + "integrity": "sha512-WkUDrojuJs0xkgGf2udWxa3yGBRxPtxUkB79i6aCZLRgc7PM8fZe9TosfPDcvEpQZbuFASnHYmRLBLUbmLOIIA==", + "license": "MPL-2.0", + "dependencies": { + "detect-libc": "^2.0.3" + }, + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + }, + "optionalDependencies": { + "lightningcss-android-arm64": "1.33.0", + "lightningcss-darwin-arm64": "1.33.0", + "lightningcss-darwin-x64": "1.33.0", + "lightningcss-freebsd-x64": "1.33.0", + "lightningcss-linux-arm-gnueabihf": "1.33.0", + "lightningcss-linux-arm64-gnu": "1.33.0", + "lightningcss-linux-arm64-musl": "1.33.0", + "lightningcss-linux-x64-gnu": "1.33.0", + "lightningcss-linux-x64-musl": "1.33.0", + "lightningcss-win32-arm64-msvc": "1.33.0", + "lightningcss-win32-x64-msvc": "1.33.0" + } + }, + "node_modules/lightningcss-android-arm64": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-android-arm64/-/lightningcss-android-arm64-1.33.0.tgz", + "integrity": "sha512-gEpRTalKdosp4Bb8qWtc2iOgE5SeIHlpS1up9bFq2wAyYhl1UdTObYiHe98zEM9SQvSoqQZ1IQD0JNpg3Ml5pg==", + "cpu": [ + "arm64" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-darwin-arm64": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-darwin-arm64/-/lightningcss-darwin-arm64-1.33.0.tgz", + "integrity": "sha512-Sciaz8eenNTKn9b3t7+xr0ipTp9YxKQY4npwQ3mrRuL0BAVHBLyZxofhaKBAVtzmtRZ/zTyo0/to4B1uWG/Djg==", + "cpu": [ + "arm64" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-darwin-x64": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-darwin-x64/-/lightningcss-darwin-x64-1.33.0.tgz", + "integrity": "sha512-Z5UPAxzrjlWNNyGy6i65cJzzvgJ5D3T6wMvs+gWpY9d7qRhANrxqAp6LhxIgZhWEw18RfJTGcRxjuLIBr+m8XQ==", + "cpu": [ + "x64" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-freebsd-x64": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-freebsd-x64/-/lightningcss-freebsd-x64-1.33.0.tgz", + "integrity": "sha512-QQM/Ti/hQajJwCY+RiWuCZ9sdtI/XQk7nDK5vC8kkdwixezOlDgvDx7+RT+QjK6FcFT4MpsuoBnHIo/O3StRRg==", + "cpu": [ + "x64" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-arm-gnueabihf": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-arm-gnueabihf/-/lightningcss-linux-arm-gnueabihf-1.33.0.tgz", + "integrity": "sha512-N7FVBe6iS24MlM6R/4RBTxGhQheZGs7tiQ9U32UtF75NzP5Q7xWPRqLBCKxlRQRk3rY1jCIPLzx7WzOhuUIRLQ==", + "cpu": [ + "arm" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-arm64-gnu": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-gnu/-/lightningcss-linux-arm64-gnu-1.33.0.tgz", + "integrity": "sha512-j2v/itmy4HlNxlc6voKXYgBqNi0Ng2LShg4z7GufpEgs05P+2suBVyi9I6YHq5uoVFx9ETin3eCEhLVyXGQnKg==", + "cpu": [ + "arm64" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-arm64-musl": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-musl/-/lightningcss-linux-arm64-musl-1.33.0.tgz", + "integrity": "sha512-yiO5ROMuYQgXbC60yjZU5CYSFZGKXL0HFATXt9mHJn1+zW55oCtMI9NfcVhYLMFDL7gV7oBPon/EmMMGg2OvtQ==", + "cpu": [ + "arm64" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-x64-gnu": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-gnu/-/lightningcss-linux-x64-gnu-1.33.0.tgz", + "integrity": "sha512-ar+Ju7LmcN0Jo4FpL4hpFybwNG9/3A/Br5KW2n2jyODg3MEZXaDYADdemoNS+BDNfMgKvylJLj4S5tyRActuAg==", + "cpu": [ + "x64" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-x64-musl": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-musl/-/lightningcss-linux-x64-musl-1.33.0.tgz", + "integrity": "sha512-RYiYbkokw0trfKqqzfF55lginwEPrD3OJDfTuJzFs1MK6iFnDenaz1fqLLtX4ITG3OktJQXOeTaw1awrBAlZPw==", + "cpu": [ + "x64" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-win32-arm64-msvc": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-win32-arm64-msvc/-/lightningcss-win32-arm64-msvc-1.33.0.tgz", + "integrity": "sha512-1K+MPfLSFVpphzpdbfkhlWk6wBrTObBzS2T6db10PNOZgR9GoVsAWzwNyuhUYYbTp23j+4RrncfujZ4uAzXvwA==", + "cpu": [ + "arm64" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-win32-x64-msvc": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-win32-x64-msvc/-/lightningcss-win32-x64-msvc-1.33.0.tgz", + "integrity": "sha512-OlEICDx/Xl0FqSp4bry8zFnCvGpig3Gl4gCquvYwHuqJKEC1+n9NgDniFvqHGmMv1ZkqDJrDqKKSykTDX+ehuA==", + "cpu": [ + "x64" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/magic-string": { + "version": "1.4.5", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-1.4.5.tgz", + "integrity": "sha512-oLLC2+YvQUfAa+vxoufE/yc1icb87M9iXIRqAoR/2EhE/8cb3SF/+Gi0c2By1B+5Vz2e2vQtUvHiu1+63Znh+w==", + "license": "MIT", + "dependencies": { + "@jridgewell/sourcemap-codec": "^1.6.0" + } + }, + "node_modules/mini-svg-data-uri": { + "version": "1.4.4", + "resolved": "https://registry.npmjs.org/mini-svg-data-uri/-/mini-svg-data-uri-1.4.4.tgz", + "integrity": "sha512-r9deDe9p5FJUPZAk3A59wGH7Ii9YrjjWw0jmw/liSbHl2CHiyXj6FcDXDu2K3TjVAXqiJdaw3xxwlZZr9E6nHg==", + "license": "MIT", + "bin": { + "mini-svg-data-uri": "cli.js" + } + }, + "node_modules/mri": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/mri/-/mri-1.2.0.tgz", + "integrity": "sha512-tzzskb3bG8LvYGFF/mDTpq3jpI6Q9wc3LEmBaghu+DdCssd1FakN7Bc0hVNmEyGq1bq3RgfkCb3cmQLpNPOroA==", + "license": "MIT", + "engines": { + "node": ">=4" + } + }, + "node_modules/nanoid": { + "version": "3.3.20", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.20.tgz", + "integrity": "sha512-uKdg2G3GNCKQn9byYOpxbGqrT2fGO5KRt5J/8b3pok8rT6qxGWF6hxMyJiEYtAf+FVyYuD9hRaDqX5uPFYJ4ZQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "bin": { + "nanoid": "bin/nanoid.cjs" + }, + "engines": { + "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" + } + }, + "node_modules/node-addon-api": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-7.1.1.tgz", + "integrity": "sha512-5m3bsyrjFWE1xf7nz7YXdN4udnVtXK6/Yfgn5qnahL6bCkf2yKt4k3nuTKAtT4r3IG8JNR2ncsIMdZuAzJjHQQ==", + "license": "MIT" + }, + "node_modules/path-parse": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", + "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", + "license": "MIT" + }, + "node_modules/picocolors": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", + "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==", + "license": "ISC" + }, + "node_modules/picomatch": { + "version": "4.0.7", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.7.tgz", + "integrity": "sha512-qcJu88Q2IWqJsDD529JKMdwGm/dvInW4HvQnRwiH9JtihJvzGOscDtHE3x1pBKeUOTysQ8kVmLnJ2kJu7yhcGA==", + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, + "node_modules/postcss": { + "version": "8.5.32", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.32.tgz", + "integrity": "sha512-LJlKCCAUFKOuZxipUdYw1NzIITEsPcgyOG9LkvRJvuKj/bRzbuRY0ARXvL0pWGpsZvn8jku+LMep2eU0seHp8g==", + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/postcss/" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/postcss" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "dependencies": { + "nanoid": "^3.3.20", + "picocolors": "^1.1.1", + "source-map-js": "^1.2.2" + }, + "engines": { + "node": "^10 || ^12 || >=14" + } + }, + "node_modules/resolve": { + "version": "1.22.14", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.14.tgz", + "integrity": "sha512-1ZjYvR9sbkiwC5+9QHetqW5HmA2pHRMaoupD01t2HlYnV/vydC2zPwLixhsMieSWVZt0JJRg5LVIk0Ow1D/TrA==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "is-core-module": "^2.18.0", + "path-parse": "^1.0.7", + "supports-preserve-symlinks-flag": "^1.0.0" + }, + "bin": { + "resolve": "bin/resolve" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/source-map-js": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.2.tgz", + "integrity": "sha512-KGj/8Y43x35aZVDtt+J4mK1hoLGHULMYfSkODJNQjNDC3oW1PqPoxMwo0pLUsWM/UEGzON/NxeHywEfNXNP3Vw==", + "license": "BSD-3-Clause", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/supports-preserve-symlinks-flag": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", + "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/tailwindcss": { + "version": "4.3.5", + "resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-4.3.5.tgz", + "integrity": "sha512-FcQk9BuffmEHJP2G0XmB2SplU1aLTI7j07Kunk+U74Ny+XiWOtzXz9aujFZ/avntw1e2cOv/3PkgzflQ7gX2vQ==", + "license": "MIT" + }, + "node_modules/tapable": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/tapable/-/tapable-2.3.3.tgz", + "integrity": "sha512-uxc/zpqFg6x7C8vOE7lh6Lbda8eEL9zmVm/PLeTPBRhh1xCgdWaQ+J1CUieGpIfm2HdtsUpRv+HshiasBMcc6A==", + "license": "MIT", + "engines": { + "node": ">=6" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/webpack" + } + } + } +} diff --git a/spec/dummy/package.json b/spec/dummy/package.json new file mode 100644 index 0000000..dbb12ac --- /dev/null +++ b/spec/dummy/package.json @@ -0,0 +1,13 @@ +{ + "name": "active_admin_page_objects_dummy", + "private": true, + "type": "module", + "dependencies": { + "@activeadmin/activeadmin": "4.0.0-beta23", + "@tailwindcss/cli": "^4.1.0", + "tailwindcss": "^4.1.0" + }, + "scripts": { + "build": "tailwindcss -i ./app/tailwind/active_admin.css -o ./app/assets/builds/active_admin.css" + } +} diff --git a/spec/dummy/tailwind-active_admin.config.js b/spec/dummy/tailwind-active_admin.config.js new file mode 100644 index 0000000..6ae7d7e --- /dev/null +++ b/spec/dummy/tailwind-active_admin.config.js @@ -0,0 +1,20 @@ +import { execSync } from 'child_process'; +import activeAdminPlugin from '@activeadmin/activeadmin/plugin'; + +// Last line only: Bundler's DEBUG env prints extra lines. +const activeAdminPath = execSync('bundle show activeadmin', { encoding: 'utf-8' }).trim().split(/\r?\n/).pop(); + +export default { + content: [ + `${activeAdminPath}/vendor/javascript/flowbite.js`, + `${activeAdminPath}/plugin.js`, + `${activeAdminPath}/app/views/**/*.{arb,erb,html,rb}`, + './app/admin/**/*.{arb,erb,html,rb}', + './app/views/active_admin/**/*.{arb,erb,html,rb}', + './app/javascript/**/*.js' + ], + darkMode: "selector", + plugins: [ + activeAdminPlugin + ] +} diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7321e3e..4885414 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -40,7 +40,7 @@ config.before do |example| Capybara.current_driver = example.metadata[:driver] || Capybara.default_driver - [Order, Customer, Category, Tag, Document, ActiveAdmin::Comment, AdminUser].each(&:delete_all) + [LineItem, Order, Customer, Category, Tag, Document, ActiveAdmin::Comment].each(&:delete_all) end config.after do diff --git a/spec/support/pages.rb b/spec/support/pages.rb index 44dcbbc..7893559 100644 --- a/spec/support/pages.rb +++ b/spec/support/pages.rb @@ -53,14 +53,14 @@ class CustomerShow < ActiveAdminPageObjects::Page row :status, "Status" row :balance, "Balance" row :category, "Category" - row :signed_up, "Signed Up" + row :signed_up, "Signed up" end section :notes, ActiveAdminPageObjects::Panel, :active_admin_panel, "Notes" section :tabs, ActiveAdminPageObjects::Tabs end class CustomerForm < ActiveAdminPageObjects::Page - set_url "/admin/customers{/id}{/action}{?query*}" + set_url "/admin/customers{/id}{/action}" section :form, ActiveAdminPageObjects::Form do field :name, "Name", ActiveAdminPageObjects::Form::StringField @@ -77,15 +77,6 @@ class CustomerForm < ActiveAdminPageObjects::Page field :tier, "Tier", ActiveAdminPageObjects::Form::RadioField field :channels, "Channels", ActiveAdminPageObjects::Form::CheckBoxesField field :signed_on, "Signed on", ActiveAdminPageObjects::Form::DatePickerField - has_many :orders, "Orders" do - field :reference, "Reference", ActiveAdminPageObjects::Form::StringField - field :state, "State", ActiveAdminPageObjects::Form::SelectField - field :quantity, "Quantity", ActiveAdminPageObjects::Form::StringField - end - - def add_order(reference) - has_many(:orders).add.field(:reference).fill(reference) - end end end @@ -99,10 +90,7 @@ class DocumentIndex < ActiveAdminPageObjects::Page class DocumentShow < ActiveAdminPageObjects::Page set_url "/admin/documents/{id}" - section :attributes_table, ActiveAdminPageObjects::AttributesTable section :routes, ActiveAdminPageObjects::Panel, :active_admin_panel, /\APossible Routes \(\d+\)\z/ - section :versions, ActiveAdminPageObjects::Sidebar, :active_admin_sidebar, /\AVersions/ - section :tabs, ActiveAdminPageObjects::Tabs end class DocumentForm < ActiveAdminPageObjects::Page @@ -137,4 +125,20 @@ class TagIndex < ActiveAdminPageObjects::Page section :table, ActiveAdminPageObjects::Table end + + class OrderForm < ActiveAdminPageObjects::Page + set_url "/admin/orders{/id}{/action}" + + section :form, ActiveAdminPageObjects::Form do + field :reference, "Reference", ActiveAdminPageObjects::Form::StringField + field :state, "State", ActiveAdminPageObjects::Form::SelectField + field :quantity, "Quantity", ActiveAdminPageObjects::Form::StringField + field :customer, "Customer", ActiveAdminPageObjects::Form::SelectField + has_many :line_items, "Line Items" do + field :sku, "Sku", ActiveAdminPageObjects::Form::StringField + field :kind, "Kind", ActiveAdminPageObjects::Form::SelectField + field :quantity, "Quantity", ActiveAdminPageObjects::Form::StringField + end + end + end end