diff --git a/Gemfile.lock b/Gemfile.lock index 796c09991f..0383b4d892 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -129,7 +129,7 @@ GEM safely_block (>= 1) bootsnap (1.22.0) msgpack (~> 1.2) - brakeman (8.1.0) + brakeman (8.1.1) racc builder (3.3.0) bullet (8.1.0) @@ -869,7 +869,7 @@ CHECKSUMS binding_of_caller (2.0.0) sha256=e53eebf8428a85587aede7b43a83e7419eb85b8b690938a96aa330d03052d517 blazer (3.5.0) sha256=734b883b843fbd6d5c9db7a09ec267a068f504908f2d01b94fce151bd00ad4e2 bootsnap (1.22.0) sha256=5820c9d42c2efef095bee6565484bdc511f1223bf950140449c9385ae775793e - brakeman (8.1.0) sha256=cfa9e5214e4925842f4bc849a64f8a7e6c5d0425fe98eac8d7b7bc60fdc17e07 + brakeman (8.1.1) sha256=a038d25ef911be910171222d2355e11ff5b5048cc4e2f08e7a4c11eccd4f418a builder (3.3.0) sha256=497918d2f9dca528fdca4b88d84e4ef4387256d984b8154e9d5d3fe5a9c8835f bullet (8.1.0) sha256=604b7e2636ec2137dcab3ba61a56248c39a0004a0c9405d58bad0686d23b98ff bundler-audit (0.9.3) sha256=81c8766c71e47d0d28a0f98c7eed028539f21a6ea3cd8f685eb6f42333c9b4e9 diff --git a/app/controllers/bookmarks_controller.rb b/app/controllers/bookmarks_controller.rb index f557e2d527..89b97dbc3c 100644 --- a/app/controllers/bookmarks_controller.rb +++ b/app/controllers/bookmarks_controller.rb @@ -1,5 +1,7 @@ class BookmarksController < ApplicationController VALID_SORTS = %w[created_at title popularity].freeze + # Label => value for the personal bookmarks "Sort by" strip (shared/_sort_strip) + SORT_OPTIONS = { "Newest" => "created_at", "Title" => "title", "Most bookmarked" => "popularity" }.freeze def index authorize! diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index e5b091155f..4459219cb9 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -205,6 +205,7 @@ def set_index_variables def populations_served authorize! @organization @sort = params[:sort].presence_in(Organization::BREAKDOWN_SORTS) || Organization::BREAKDOWN_SORTS.first + @sort_direction = params[:direction].presence_in(%w[asc desc]) || Organization.breakdown_default_direction(@sort) end # The org's workshop logs on their own page: the date rows of the one group a diff --git a/app/frontend/stylesheets/application.tailwind.css b/app/frontend/stylesheets/application.tailwind.css index e816f9eb67..f51bd952a9 100644 --- a/app/frontend/stylesheets/application.tailwind.css +++ b/app/frontend/stylesheets/application.tailwind.css @@ -245,6 +245,8 @@ @source inline("{hover:,}border-{indigo,purple,teal,violet,orange,rose,blue,sky,emerald,slate,lime,stone,amber,green,yellow,gray,cyan,fuchsia,pink,brand-navy,brand-yellow,brand-green,brand-magenta,brand-orange,brand-purple,brand-teal,brand-coral,brand-olive,brand-pink,brand-amber,brand-cyan,brand-emerald}-{200,300}"); @source inline("ring-{indigo,purple,teal,violet,orange,rose,blue,sky,emerald,slate,lime,stone,amber,green,yellow,gray,cyan,fuchsia,pink,brand-navy,brand-yellow,brand-green,brand-magenta,brand-orange,brand-purple,brand-teal,brand-coral,brand-olive,brand-pink,brand-amber,brand-cyan,brand-emerald}-{200,300,400,500}"); @source inline("{hover:,}text-{indigo,purple,teal,violet,orange,rose,blue,sky,emerald,slate,lime,stone,amber,green,yellow,gray,cyan,fuchsia,pink,brand-navy,brand-yellow,brand-green,brand-magenta,brand-orange,brand-purple,brand-teal,brand-coral,brand-olive,brand-pink,brand-amber,brand-cyan,brand-emerald}-{50,{100..900..100},950}"); +/* Active segment of shared/_sort_strip (radio mode) */ +@source inline("has-checked:bg-{indigo,purple,teal,violet,orange,rose,blue,sky,emerald,slate,lime,stone,amber,green,yellow,gray,cyan,fuchsia,pink,brand-navy,brand-yellow,brand-green,brand-magenta,brand-orange,brand-purple,brand-teal,brand-coral,brand-olive,brand-pink,brand-amber,brand-cyan,brand-emerald}-700"); /* Per-field form layout widths (generated from FormField::WIDTH_GRID_SPANS, which lives in a model file Tailwind does not scan) */ diff --git a/app/models/organization.rb b/app/models/organization.rb index 3499432714..e1dd7d1ddc 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -404,33 +404,37 @@ def active_facilitator_age_groups .sort_by { |group, count| [ -count, group.position || 0, group.name.to_s ] }.map(&:first) end - BREAKDOWN_SORT_OPTIONS = [ [ "Primary first", "primary" ], [ "Total", "total" ], [ "A–Z", "name" ] ].freeze + BREAKDOWN_SORT_OPTIONS = [ [ "Primary", "primary" ], [ "Total", "total" ], [ "Name", "name" ] ].freeze BREAKDOWN_SORTS = BREAKDOWN_SORT_OPTIONS.map(&:last).freeze + def self.breakdown_default_direction(sort) = sort == "name" ? "asc" : "desc" + TagBreakdown = Data.define(:tag, :primary_count, :additional_count) do def total = primary_count + additional_count - def sort_key(sort) + # Counts flip with the direction; ties stay A–Z. + def sort_key(sort, direction) name = tag.name.to_s.downcase + sign = direction == "asc" ? 1 : -1 case sort - when "total" then [ -total, -primary_count, name ] + when "total" then [ sign * total, sign * primary_count, name ] when "name" then [ name ] - else [ -primary_count, -additional_count, name ] + else [ sign * primary_count, sign * additional_count, name ] end end end # Every sector active facilitators hold, primary or additional, for the full breakdown page. - def active_facilitator_sector_breakdown(sort: nil) + def active_facilitator_sector_breakdown(sort: nil, direction: nil) tag_breakdown(active_facilitators.flat_map { |person| person.sectorable_items.filter_map { |item| [ item.sector, item.is_primary? ] if item.sector && item.sector.name != Sector::OTHER_SECTOR_NAME } - }, sort) + }, sort, direction) end - def active_facilitator_age_group_breakdown(sort: nil) + def active_facilitator_age_group_breakdown(sort: nil, direction: nil) tag_breakdown(active_facilitators.flat_map { |person| person.primary_age_groups.map { |group| [ group, true ] } + person.additional_age_groups.map { |group| [ group, false ] } - }, sort) + }, sort, direction) end # Reads preloaded affiliations, so a list page that nests PEOPLE_TAGGINGS under @@ -482,10 +486,12 @@ def website_link_url private - def tag_breakdown(tag_and_primary_pairs, sort) - tag_and_primary_pairs.group_by(&:first) + def tag_breakdown(tag_and_primary_pairs, sort, direction) + direction ||= Organization.breakdown_default_direction(sort) + rows = tag_and_primary_pairs.group_by(&:first) .map { |tag, pairs| TagBreakdown.new(tag:, primary_count: pairs.count(&:last), additional_count: pairs.count { |pair| !pair.last }) } - .sort_by { |row| row.sort_key(sort) } + .sort_by { |row| row.sort_key(sort, direction) } + sort == "name" && direction == "desc" ? rows.reverse : rows end def affiliation_dates_locked diff --git a/app/services/workshop_search_service.rb b/app/services/workshop_search_service.rb index f75b7fc67b..011298bc60 100644 --- a/app/services/workshop_search_service.rb +++ b/app/services/workshop_search_service.rb @@ -5,6 +5,14 @@ class WorkshopSearchService TITLE_SORT_SQL = "LOWER(TRIM(#{Workshop.strip_punctuation_sql_spaced('workshops.title')})) ASC".freeze + # Label => value for the index "Sort by" strip (shared/_sort_strip) + SORT_OPTIONS = { + "Newest" => "created", + "Title" => "title", + "Most bookmarked" => "popularity", + "Author" => "author" + }.freeze + attr_reader :params, :user, :admin attr_accessor :workshops, :sort diff --git a/app/views/bookmarks/_personal_bookmarks_results.html.erb b/app/views/bookmarks/_personal_bookmarks_results.html.erb index 2824753d39..617cbbb118 100644 --- a/app/views/bookmarks/_personal_bookmarks_results.html.erb +++ b/app/views/bookmarks/_personal_bookmarks_results.html.erb @@ -1,26 +1,15 @@ <%= turbo_stream.replace("bookmarks_count", partial: "bookmarks_count") %> <% sort_base = params.permit(:keyword, :bookmarkable_type, :windows_type, :user_id, :number_of_items_per_page).to_h.symbolize_keys - sort_icon = ->(column) { - if @sort == column - @sort_direction == "asc" ? "fa-arrow-up" : "fa-arrow-down" - else - "fa-sort" - end + # Clicking the active segment flips its direction; the arrow shows which way it runs. + sort_href = ->(col) { + personal_bookmarks_path(sort_base.merge(sort: col, direction: (@sort == col && @sort_direction == "desc") ? "asc" : "desc", page: nil)) } %>
- -
- Sort by: - <% [ [ "created_at", "Newest" ], [ "title", "Title" ], [ "popularity", "Most Bookmarked" ] ].each do |col, label| %> - <%= link_to personal_bookmarks_path(sort_base.merge(sort: col, direction: (@sort == col && @sort_direction == "desc") ? "asc" : "desc", page: nil)), - data: { turbo_frame: "personal_bookmarks_results" }, - class: "inline-flex items-center gap-1 text-sm font-medium #{@sort == col ? 'text-blue-700' : 'text-gray-600'} hover:text-gray-900" do %> - <%= label %> - - <% end %> - <% end %> +
+ <%= render "shared/sort_strip", options: BookmarksController::SORT_OPTIONS, selected: @sort, domain: :bookmarks, + href: sort_href, active_icon: (@sort_direction == "asc" ? "fa-arrow-up" : "fa-arrow-down"), link_data: { turbo_frame: "personal_bookmarks_results" } %>
diff --git a/app/views/organizations/populations_served.html.erb b/app/views/organizations/populations_served.html.erb index af7d44dbdf..186378605e 100644 --- a/app/views/organizations/populations_served.html.erb +++ b/app/views/organizations/populations_served.html.erb @@ -20,16 +20,14 @@ The organization's profile and list show only primary tags.

<% if show_sectors || show_age_groups %> -
- Sort by -
- <% Organization::BREAKDOWN_SORT_OPTIONS.each do |label, value| %> - <% active = value == @sort %> - <%= link_to label, populations_served_organization_path(@organization, sort: value, return_to: params[:return_to].presence_in(%w[organization_edit])), - aria: { current: (active ? "true" : nil) }, - class: "rounded-md px-3 py-1 font-medium #{active ? "#{DomainTheme.bg_class_for(:organizations, intensity: 700)} text-white" : "text-gray-600 hover:bg-gray-100"}" %> - <% end %> -
+
+ <%# Clicking the active option flips its direction; other options open in their default direction %> + <%= render "shared/sort_strip", options: Organization::BREAKDOWN_SORT_OPTIONS, selected: @sort, domain: :organizations, + active_icon: (@sort_direction == "asc" ? "fa-arrow-up" : "fa-arrow-down"), + href: ->(value) { + flipped = (@sort_direction == "asc" ? "desc" : "asc") if value == @sort + populations_served_organization_path(@organization, sort: value, direction: flipped, return_to: params[:return_to].presence_in(%w[organization_edit])) + } %>
<% end %>
@@ -40,11 +38,11 @@
"> <% if show_sectors %> <%= render "organizations/tag_breakdown", title: "Sectors", domain: :sectors, facilitator_count: facilitator_count, - rows: @organization.active_facilitator_sector_breakdown(sort: @sort), link_param: :sector_names_all %> + rows: @organization.active_facilitator_sector_breakdown(sort: @sort, direction: @sort_direction), link_param: :sector_names_all %> <% end %> <% if show_age_groups %> <%= render "organizations/tag_breakdown", title: "Age groups served", domain: :categories, facilitator_count: facilitator_count, - rows: @organization.active_facilitator_age_group_breakdown(sort: @sort), link_param: :category_names_all %> + rows: @organization.active_facilitator_age_group_breakdown(sort: @sort, direction: @sort_direction), link_param: :category_names_all %> <% end %> <% unless show_sectors || show_age_groups %>

This organization doesn't show sectors or age groups on its profile.

diff --git a/app/views/resources/_resources_count.html.erb b/app/views/resources/_resources_count.html.erb index ff7b7e753c..eb8e29c136 100644 --- a/app/views/resources/_resources_count.html.erb +++ b/app/views/resources/_resources_count.html.erb @@ -4,20 +4,9 @@

Resources (<%= @count_display %>)

<%= render "shared/copy_url" %> - <%# Radios inside the search form, so a change auto-submits via the collection - controller. The default option submits blank, so the server re-derives the - default (Title once kinds are picked) until someone picks a sort. %> -
- Sort by -
- <% Resource::SORT_OPTIONS.each do |label, value| %> - - <% end %> -
+ <%# Blank submits for the default, so the server re-derives it (Title once kinds are picked) %> +
+ <%= render "shared/sort_strip", options: Resource::SORT_OPTIONS, selected: @sort, domain: :resources, default: @default_sort %>
diff --git a/app/views/shared/_sort_strip.html.erb b/app/views/shared/_sort_strip.html.erb new file mode 100644 index 0000000000..af6c71bf26 --- /dev/null +++ b/app/views/shared/_sort_strip.html.erb @@ -0,0 +1,43 @@ +<%# The one "Sort by" control for card/list indexes (tables sort by column header instead). + Segments fill with the domain's 700 color when active. + + Two modes: + - Radios (no `href`): put it inside the search form so the collection controller + auto-submits; the checked segment is styled with `has-checked` (no JS). + `default` names the value that submits blank, so the server re-derives it. + - Links (`href` given): the server marks the active segment. + + locals: + options - { label => value } + selected - the active value + domain - DomainTheme key for the active fill + href - optional ->(value) { path } (link mode) + link_data - optional data attributes for each link (e.g. turbo_frame) + active_icon - optional Font Awesome class shown after the active link (e.g. a direction arrow) + default - optional radio value that submits blank %> +<% + href = local_assigns[:href] + active_icon = local_assigns[:active_icon] + active_bg = DomainTheme.bg_class_for(domain, intensity: 700) + segment = "inline-flex items-center gap-1 rounded-md px-3 py-1 font-medium" +%> +
+ Sort by +
+ <% options.each do |label, value| %> + <% if href %> + <% active = value == selected %> + <%# Built inline (not a block) so the link text is exactly the label %> + <% text = active && active_icon ? safe_join([ label, tag.i(class: "fa-solid #{active_icon} text-xs") ]) : label %> + <%= link_to text, href.call(value), data: local_assigns[:link_data], aria: { current: (active ? "true" : nil) }, + class: "#{segment} #{active ? "#{active_bg} text-white" : "text-gray-600 hover:bg-gray-100"}" %> + <% else %> + + <% end %> + <% end %> +
+
diff --git a/app/views/users/users_results.html.erb b/app/views/users/users_results.html.erb index f257d9922e..87908ac580 100644 --- a/app/views/users/users_results.html.erb +++ b/app/views/users/users_results.html.erb @@ -8,11 +8,11 @@ <% if @users.any? %>
-
- Sort by - <% [ %w[email Email], %w[person Person], %w[confirmed Confirmed], %w[access Access], %w[admin Admin] ].each do |column, label| %> - <%= sort_link.call(column, label) %> - <% end %> +
+ <%= render "shared/sort_strip", options: { "Email" => "email", "Person" => "person", "Confirmed" => "confirmed", "Access" => "access", "Admin" => "admin" }, + selected: @sort, domain: :admin_only, link_data: { turbo_frame: "users_results" }, + href: ->(column) { users_path(sort_base.merge(sort: column, direction: (@sort == column && @sort_direction == "desc") ? "asc" : "desc", page: nil)) }, + active_icon: (@sort_direction == "asc" ? "fa-arrow-up" : "fa-arrow-down") %>
    diff --git a/app/views/workshops/_sort_by_options.html.erb b/app/views/workshops/_sort_by_options.html.erb deleted file mode 100644 index 9284817f2e..0000000000 --- a/app/views/workshops/_sort_by_options.html.erb +++ /dev/null @@ -1,51 +0,0 @@ -
    - -
    - -
    - -
    - -
    - -
    - -
    - -
    - -<%# if params[:query].present? %> - - - - - -<%# - = radio_button_tag :sort, "keywords", - @sort == "keywords", # || (!params[:sort].present? && params[:query].present?), - onclick: "$('form').submit();" -%> - - - - - - - -<%# end %> diff --git a/app/views/workshops/_workshops_count.html.erb b/app/views/workshops/_workshops_count.html.erb index 23228cdf1c..a142f7b145 100644 --- a/app/views/workshops/_workshops_count.html.erb +++ b/app/views/workshops/_workshops_count.html.erb @@ -1,9 +1,14 @@

    -
    +

    Workshops (<%= number_with_delimiter(@workshops&.total_entries) %>)

    <%= render "shared/copy_url" %> + + <%# Radios inside the search form, so a change auto-submits via the collection controller %> +
    + <%= render "shared/sort_strip", options: WorkshopSearchService::SORT_OPTIONS, selected: @sort, domain: :workshops %> +
    diff --git a/app/views/workshops/index.html.erb b/app/views/workshops/index.html.erb index 25e587f24a..fd9b5b005f 100644 --- a/app/views/workshops/index.html.erb +++ b/app/views/workshops/index.html.erb @@ -37,17 +37,6 @@
    <%= render "filters_applied" %>
    -

    - - -
    -

    - Sort by -

    - - <%= render "sort_by_options" %> -
    - <%= render "workshops_count" %> <% end %> diff --git a/db/seeds/features/2026-11-20-one-sort-by-control.yml b/db/seeds/features/2026-11-20-one-sort-by-control.yml new file mode 100644 index 0000000000..4b45d6a2f4 --- /dev/null +++ b/db/seeds/features/2026-11-20-one-sort-by-control.yml @@ -0,0 +1,12 @@ +name: "One Sort by control on workshops, bookmarks, and users" +area: content +display_status: admin_facing +released_on: 2026-11-20 +pr_number: 2981 +action_path: "/workshops" +summary: >- + Workshops, My Bookmarks, and the users list on small screens now sort with the + same Sort by button strip as the resource library and an organization's + sectors and age groups page. +pro_tips: + - "On My Bookmarks and the users list, click the highlighted option again to flip between ascending and descending; the arrow shows which way it runs." diff --git a/docs/design/house-style.md b/docs/design/house-style.md index 8ca5c70766..d87eae95e6 100644 --- a/docs/design/house-style.md +++ b/docs/design/house-style.md @@ -105,8 +105,8 @@ users index (`app/views/users/users_results.html.erb`) is the reference. - Each card leads with the row's identity card (e.g. the person button) and its actions on one line, then the remaining fields below, ending with a wrapping `
    ` of muted label + value pairs. -- Keep sorting on small screens: a "Sort by" bar above the cards calls the same - `sort_header_link` generator as the table headers. +- Keep sorting on small screens: render the **Sort by strip** (below) above the + cards, in link mode, with the same sort/direction params as the table headers. - Let long unbroken values (emails, URLs) wrap with `wrap-anywhere`, plus a `` at the natural break (before the `@`). @@ -118,3 +118,24 @@ closed and rotating up when open. `events/_charts_toggle_bar` and `events/_panel_cta` are the reference. A chevron leads only on a disclosure row whose whole row is the click target (an accordion header), where it marks the row's state before its title. + +## Sort by strip + +Card and list pages sort with one control: `shared/_sort_strip`, a "Sort by" +label beside a segmented strip whose active segment fills with the domain's 700 +color. Tables sort by clicking column headers (`sort_header_link`) instead; a +table's small-screen card list uses the strip. + +- **Radio mode** (no `href:`) — inside a search form wired to the `collection` + controller, so a click auto-submits; `has-checked` styles the active segment + with no JS. `default:` names the value that submits blank, so the server + re-derives the default. Workshops and resources are the reference. +- **Link mode** (`href: ->(value) { path }`) — the server marks the active + segment with `aria-current`. Pass `link_data: { turbo_frame: … }` inside a + results frame. For a reversible sort, point the active segment's href at the + opposite direction and pass `active_icon:` (`fa-arrow-up` / `fa-arrow-down`). + My Bookmarks, the users small-screen cards, and the org sectors page are the + reference. Keep labels direction-neutral ("Name", not "A–Z") on a reversible sort. +- Options are a `{ label => value }` constant beside the sort logic (e.g. + `WorkshopSearchService::SORT_OPTIONS`); labels are sentence case. +- Place it at the right end of the count row (`ml-auto`) on index pages. diff --git a/lib/domain_theme.rb b/lib/domain_theme.rb index 9e399bdf1b..3a123f7db0 100644 --- a/lib/domain_theme.rb +++ b/lib/domain_theme.rb @@ -34,6 +34,7 @@ module DomainTheme banners: :yellow, users: :rose, + bookmarks: :sky, notifications: :purple, comments: :blue, topic_subscriptions: :stone, diff --git a/spec/models/resource_spec.rb b/spec/models/resource_spec.rb index 6709db6703..1b71ca31fa 100644 --- a/spec/models/resource_spec.rb +++ b/spec/models/resource_spec.rb @@ -70,8 +70,9 @@ end describe ".sorted_by" do - let!(:older) { create(:resource, title: "Bravo", kind: "Toolkit", created_at: 2.days.ago, updated_at: 1.hour.ago) } - let!(:newer) { create(:resource, title: "Alpha", kind: "Handout", created_at: 1.day.ago, updated_at: 2.hours.ago) } + # update_columns after create: the factory's after(:create) sector touches updated_at + let!(:older) { create(:resource, title: "Bravo", kind: "Toolkit", created_at: 2.days.ago).tap { |r| r.update_columns(updated_at: 1.hour.ago) } } + let!(:newer) { create(:resource, title: "Alpha", kind: "Handout", created_at: 1.day.ago).tap { |r| r.update_columns(updated_at: 2.hours.ago) } } it "sorts by created, modified, title, and kind" do expect(Resource.sorted_by("created")).to eq([ newer, older ]) diff --git a/spec/requests/bookmarks_spec.rb b/spec/requests/bookmarks_spec.rb index 58f7d84b81..6c24d21ba2 100644 --- a/spec/requests/bookmarks_spec.rb +++ b/spec/requests/bookmarks_spec.rb @@ -117,6 +117,16 @@ expect(response).to have_http_status(:ok) end + it "marks the active sort and links it to flip direction" do + get personal_bookmarks_path, params: { sort: "title", direction: "desc" }, + headers: { "Turbo-Frame" => "personal_bookmarks_results" } + + active = Capybara.string(response.body).find("a[aria-current='true']") + expect(active).to have_text("Title") + expect(active).to have_css("i.fa-arrow-down") + expect(active[:href]).to include("direction=asc") + end + it "can access personal bookmarks with keyword filter and title sort via turbo frame" do get personal_bookmarks_path, params: { sort: "title", keyword: "test" }, headers: { "Turbo-Frame" => "personal_bookmarks_results" } diff --git a/spec/requests/organization_sector_age_rollup_spec.rb b/spec/requests/organization_sector_age_rollup_spec.rb index ac7ac8ac1b..f075b63c35 100644 --- a/spec/requests/organization_sector_age_rollup_spec.rb +++ b/spec/requests/organization_sector_age_rollup_spec.rb @@ -189,6 +189,13 @@ def rows_for(section_title) expect(rows_for("Age groups served").keys).to eq(%w[Adults Children Teens]) end + it "marks the chosen sort on the sort strip" do + get populations_served_organization_path(harbor, sort: "total") + + expect(body).to have_css("a[aria-current='true']", text: "Total") + expect(body).to have_css("a", text: "Name") + end + it "counts only the active facilitator for an org with an ended one" do get populations_served_organization_path(beacon) diff --git a/spec/requests/organizations_spec.rb b/spec/requests/organizations_spec.rb index 99b2b8a02d..52206ea86e 100644 --- a/spec/requests/organizations_spec.rb +++ b/spec/requests/organizations_spec.rb @@ -252,7 +252,7 @@ expect(page).not_to have_content("Former Sector") end - it "sorts the breakdown by the chosen option, defaulting to primary first" do + it "sorts the breakdown by the chosen option, defaulting to most primary first" do person = organization_with_sectors.affiliations.first.person %w[Echo Foxtrot].each { |name| create(:sectorable_item, sector: create(:sector, name: name), sectorable: person, is_primary: false) } second = create(:person) @@ -263,7 +263,7 @@ get populations_served_organization_url(organization_with_sectors) expect(sector_order.call).to eq(%w[Alpha Bravo Charlie Delta Echo Foxtrot]) - expect(Capybara.string(response.body)).to have_css("a[aria-current='true']", exact_text: "Primary first") + expect(Capybara.string(response.body)).to have_css("a[aria-current='true']", exact_text: "Primary") get populations_served_organization_url(organization_with_sectors, sort: "total") expect(sector_order.call).to eq(%w[Echo Alpha Bravo Charlie Delta Foxtrot]) @@ -272,7 +272,26 @@ expect(sector_order.call).to eq(%w[Alpha Bravo Charlie Delta Echo Foxtrot]) get populations_served_organization_url(organization_with_sectors, sort: "bogus") - expect(Capybara.string(response.body)).to have_css("a[aria-current='true']", exact_text: "Primary first") + expect(Capybara.string(response.body)).to have_css("a[aria-current='true']", exact_text: "Primary") + end + + it "reverses the chosen sort and offers to flip it back" do + person = organization_with_sectors.affiliations.first.person + %w[Echo Foxtrot].each { |name| create(:sectorable_item, sector: create(:sector, name: name), sectorable: person, is_primary: false) } + second = create(:person) + create(:affiliation, organization: organization_with_sectors, person: second) + create(:sectorable_item, sector: Sector.find_by!(name: "Echo"), sectorable: second, is_primary: false) + sector_order = -> { Capybara.string(response.body).all("section", text: "Sectors").first.all("li a").map(&:text) } + + get populations_served_organization_url(organization_with_sectors, sort: "total", direction: "asc") + expect(sector_order.call).to eq(%w[Foxtrot Alpha Bravo Charlie Delta Echo]) + + get populations_served_organization_url(organization_with_sectors, sort: "name", direction: "desc") + expect(sector_order.call).to eq(%w[Foxtrot Echo Delta Charlie Bravo Alpha]) + active = Capybara.string(response.body).find("a[aria-current='true']") + expect(active).to have_text("Name") + expect(active).to have_css("i.fa-arrow-down") + expect(active[:href]).to include("direction=asc") end it "caps the edit page at three sectors with links to the breakdown that return to the edit page" do @@ -334,7 +353,7 @@ page = Capybara.string(response.body) expect(page).to have_content("This organization doesn't show sectors or age groups on its profile.") expect(page).not_to have_css("section h2") - expect(page).not_to have_link("Primary first") + expect(page).not_to have_link("Primary", exact: true) end it "hides the profile and edit links to the breakdown when both are hidden" do diff --git a/spec/requests/users_spec.rb b/spec/requests/users_spec.rb index 105aeed813..bb35d30695 100644 --- a/spec/requests/users_spec.rb +++ b/spec/requests/users_spec.rb @@ -60,6 +60,14 @@ expect(response.body).to include("direction=desc&search=sort%40example&sort=email") end + it "marks the active sort on the small-screen sort strip" do + get users_url(sort: "email", direction: "asc"), headers: { "Turbo-Frame" => "users_results" } + + active = Capybara.string(response.body).find("a[aria-current='true']") + expect(active).to have_text("Email") + expect(active).to have_css("i.fa-arrow-up") + end + it "sorts by person alongside a search" do get users_url(sort: "person", search: "example"), headers: { "Turbo-Frame" => "users_results" } diff --git a/spec/requests/workshops_spec.rb b/spec/requests/workshops_spec.rb index d51e4772ae..8a2735c486 100644 --- a/spec/requests/workshops_spec.rb +++ b/spec/requests/workshops_spec.rb @@ -484,6 +484,14 @@ expect(response).to have_http_status(:ok) end + + it "checks the chosen sort on the sort strip" do + get workshops_url, params: { sort: "popularity" } + + page = Capybara.string(response.body) + expect(page).to have_css("input[type=radio][name=sort][value=popularity][checked]", visible: :all) + expect(page).to have_css("label", text: "Author") + end end end end