Skip to content

Commit

Permalink
Merge pull request #3489 from alphagov/section-status
Browse files Browse the repository at this point in the history
All content finder: Implement filter section status text
  • Loading branch information
csutter authored Oct 4, 2024
2 parents 0077783 + 39ced7d commit 393f4c1
Show file tree
Hide file tree
Showing 12 changed files with 153 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/models/facet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ def applied_filters
[]
end

def status_text
return nil unless has_filters?

"#{applied_filters.size} selected"
end

def query_params
{}
end
Expand Down
6 changes: 6 additions & 0 deletions app/models/sort_facet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ def applied_filters
}]
end

def status_text
return nil unless has_filters?

sort_options[selected_sort_option]
end

# The methods below are the minimum required for this virtual facet to take the place of a real
# `Facet`

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<%= render "components/filter_section", {
heading_text: date_facet.name,
visually_hidden_heading_prefix: "Filter by",
status_text: date_facet.status_text,
id: "facet_date_#{date_facet.key}",
index_section: index,
index_section_count: count,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<%= render "components/filter_section", {
heading_text: option_select_facet.name,
visually_hidden_heading_prefix: "Filter by",
status_text: option_select_facet.status_text,
id: "facet_option_select_#{option_select_facet.key}",
index_section: index,
index_section_count: count,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<%= render "components/filter_section", {
heading_text: sort_facet.name,
status_text: sort_facet.status_text,
id: "facet_sort",
index_section: index,
index_section_count: count,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<%= render "components/filter_section", {
heading_text: taxon_facet.name,
visually_hidden_heading_prefix: "Filter by",
status_text: taxon_facet.status_text,
id: "facet_taxon_#{taxon_facet.key}",
index_section: index,
index_section_count: count,
Expand Down
1 change: 1 addition & 0 deletions features/all_content_finder.feature
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Feature: All content finder ("site search")
And I enter "13/12/1989" for "Updated before"
And I apply the filters
Then I can see filtered results
And the filter panel shows status text for each section
Scenario: Changing the sort order of a search
When I search all content for "dark gray all alone"
Expand Down
10 changes: 10 additions & 0 deletions features/step_definitions/site_search_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@
expect(page).to have_link("Loving him was red")
end

Then("the filter panel shows status text for each section") do
click_on "Filter and sort"

within(".app-c-filter-panel") do
expect(page).to have_selector("summary", text: "Filter by Topic 2 selected", normalize_ws: true)
expect(page).to have_selector("summary", text: "Filter by Type 2 selected", normalize_ws: true)
expect(page).to have_selector("summary", text: "Filter by Updated 2 selected", normalize_ws: true)
end
end

Then("the filter panel is open by default") do
expect(page).to have_selector("button[aria-expanded='true']", text: "Filter and sort")
end
Expand Down
31 changes: 31 additions & 0 deletions spec/models/date_facet_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,37 @@
end
end

describe "#status_text" do
context "no value" do
let(:value) { nil }

it "returns no status text" do
expect(subject.status_text).to be_nil
end
end

context "single date value" do
let(:value) { { from: "22/09/1988" } }

it "returns the expected status text" do
expect(subject.status_text).to eq("1 selected")
end
end

context "multiple date values" do
let(:value) do
{
from: "22/09/1988",
to: "22/09/2014",
}
end

it "returns the expected status text" do
expect(subject.status_text).to eq("2 selected")
end
end
end

describe "#query_params" do
context "multiple date values" do
let(:value) do
Expand Down
34 changes: 34 additions & 0 deletions spec/models/option_select_facet_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,40 @@
end
end

describe "#status_text" do
context "single value" do
let(:value) { %w[allowed-value-1] }

it "returns the expected status text" do
expect(subject.status_text).to eq("1 selected")
end
end

context "multiple values" do
let(:value) { %w[allowed-value-1 allowed-value-2] }

it "returns the expected status text" do
expect(subject.status_text).to eq("2 selected")
end
end

context "disallowed values" do
let(:value) { ["disallowed-value-1, disallowed-value-2"] }

it "returns no status text" do
expect(subject.status_text).to be_nil
end
end

context "no value" do
let(:value) { nil }

it "returns no status text" do
expect(subject.status_text).to be_nil
end
end
end

describe "#query_params" do
context "value selected" do
let(:value) { "allowed-value-1" }
Expand Down
26 changes: 26 additions & 0 deletions spec/models/sort_facet_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,32 @@
end
end

describe "#status_text" do
subject(:status_text) { sort_facet.status_text }

context "when no sort order is selected" do
it { is_expected.to be_nil }
end

context "when a sort order is selected but it doesn't exist" do
let(:filter_params) { { "order" => "invalid" } }

it { is_expected.to be_nil }
end

context "when a default sort order is selected" do
let(:filter_params) { { "order" => "most-viewed" } }

it { is_expected.to be_nil }
end

context "when a custom sort order is selected" do
let(:filter_params) { { "order" => "updated-newest" } }

it { is_expected.to eq("Updated (newest)") }
end
end

it { is_expected.to be_user_visible }
it { is_expected.to be_filterable }
it { is_expected.not_to be_hide_facet_tag }
Expand Down
35 changes: 35 additions & 0 deletions spec/models/taxon_facet_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,39 @@
specify { expect(subject.applied_filters).to be_empty }
end
end

describe "#status_text" do
context "when no filters are applied" do
let(:allowed_values) { {} }

it "returns nil" do
expect(subject.status_text).to be_nil
end
end

context "when a topic filter is applied" do
let(:allowed_values) do
{
"level_one_taxon" => "allowed-value-1",
}
end

it "returns that one topic is selected" do
expect(subject.status_text).to eql("1 selected")
end
end

context "when a subtopic filter is applied" do
let(:allowed_values) do
{
"level_one_taxon" => "allowed-value-1",
"level_two_taxon" => "allowed-child-value",
}
end

it "returns that two topics are selected" do
expect(subject.status_text).to eql("2 selected")
end
end
end
end

0 comments on commit 393f4c1

Please sign in to comment.