Skip to content

Commit

Permalink
search by lead organisation from Content Block Manager
Browse files Browse the repository at this point in the history
  • Loading branch information
Harriethw committed Oct 25, 2024
1 parent e498797 commit 6354ef7
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@
items: items_for_block_type,
} %>
<%= render "components/select_with_search", {
id: "lead_organisation",
name: "lead_organisation",
label: "Lead organisation",
heading_size: "s",
include_blank: true,
options: options_for_lead_organisation,
} %>
<%= render "govuk_publishing_components/components/button", {
text: "View results",
margin_bottom: 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,14 @@ def items_for_block_type
}
end
end

def options_for_lead_organisation
helpers.taggable_organisations_container.map do |name, id|
{
text: name,
value: id,
selected: !@filters.nil? && @filters[:lead_organisation] == id.to_s,
}
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def new_document_options_redirect
private

def params_filters
params.slice(:keyword, :block_type)
params.slice(:keyword, :block_type, :lead_organisation)
.permit!
.to_h
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ Feature: Search for a content object
Background:
Given the content block manager feature flag is enabled
Given I am a GDS admin
And the organisation "Ministry of Example" exists
And the organisation "Department of Placeholder" exists
And a schema "email_address" exists with the following fields:
| email_address |
And a schema "postal_address" exists with the following fields:
| an_address |
And an email address content block has been created
And an email address content block has been created with the following email address and title:
| title | "example search title" |
| email_address | "ministry@justice.com" |
| title | example search title |
| email_address | ministry@justice.com |
And a "postal_address" type of content block has been created with fields:
| an_address | "ABC123" |
| an_address | ABC123 |
| organisation | Department of Placeholder |

Scenario: GDS Editor searches for a content object by keyword in title
When I visit the Content Block Manager home page
Expand All @@ -39,3 +40,11 @@ Feature: Search for a content object
When I check the block type "Email address"
And I click to view results
And "2" content blocks are returned

Scenario: GDS Editor searches for a content object by lead organisation
When I visit the Content Block Manager home page
Then I should see the details for all documents
And "3" content blocks are returned
When I select the lead organisation "Department of Placeholder"
And I click to view results
And "1" content blocks are returned
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,12 @@

Given("a {string} type of content block has been created with fields:") do |block_type, table|
fields = table.rows_hash
organisation_name = fields.delete("organisation")
organisation = Organisation.where(name: organisation_name).first
create(
:content_block_edition,
block_type.to_sym,
organisation:,
details: fields,
creator: @user,
)
Expand Down Expand Up @@ -449,6 +452,10 @@ def should_show_edit_form_for_email_address_content_block(document_title, email_
check checkbox_name
end

Then("I select the lead organisation {string}") do |organisation|
select organisation, from: "lead_organisation"
end

When("I revisit the edit page") do
@content_block = @content_block.document.latest_edition
visit_edit_page
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
require "test_helper"

class ContentBlockManager::ContentBlock::Document::Index::FilterOptionsComponentTest < ViewComponent::TestCase
test "adds value of keyword to text input from filter" do
render_inline(ContentBlockManager::ContentBlock::Document::Index::FilterOptionsComponent.new(
filters: { keyword: "ministry defense" },
))

assert_selector "input[name='keyword'][value='ministry defense']"
end

test "renders checkbox items for all valid schemas" do
ContentBlockManager::ContentBlock::Schema.expects(:valid_schemas).returns(%w[email_address postal_address])
render_inline(ContentBlockManager::ContentBlock::Document::Index::FilterOptionsComponent.new(
Expand All @@ -20,4 +28,20 @@ class ContentBlockManager::ContentBlock::Document::Index::FilterOptionsComponent
assert_selector "input[type='checkbox'][name='block_type[]'][value='email_address'][checked]"
assert_selector "input[type='checkbox'][name='block_type[]'][value='postal_address']"
end

test "selects organisation if selected in filters" do
helper_mock = mock
ContentBlockManager::ContentBlock::Document::Index::FilterOptionsComponent.any_instance.stubs(:helpers).returns(helper_mock)
helper_mock.stubs(:content_block_manager).returns(helper_mock)
helper_mock.stubs(:content_block_manager_content_block_documents_path).returns("path")
helper_mock.stubs(:taggable_organisations_container).returns(
[["Department of Placeholder", 1], ["Ministry of Example", 2]],
)
render_inline(ContentBlockManager::ContentBlock::Document::Index::FilterOptionsComponent.new(
filters: { lead_organisation: "2" },
))

assert_selector "select[name='lead_organisation']"
assert_selector "option[selected='selected'][value=2]"
end
end

0 comments on commit 6354ef7

Please sign in to comment.