From 54a056f1c6cdcaa8246f5ec417995a3056dbd01a Mon Sep 17 00:00:00 2001 From: Minno Dang Date: Thu, 14 Sep 2023 16:27:05 +0100 Subject: [PATCH 01/10] Added new controller to handle the document searching for document collections New route, controller, and view for the new page without any content just yet. Put the content behind a preview design system flag. --- ...ection_group_document_search_controller.rb | 16 +++++++++++++ .../search_options.html.erb | 0 config/routes.rb | 7 +++--- ...n_group_document_search_controller_test.rb | 23 +++++++++++++++++++ 4 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 app/controllers/admin/document_collection_group_document_search_controller.rb create mode 100644 app/views/admin/document_collection_group_document_search/search_options.html.erb create mode 100644 test/functional/admin/document_collection_group_document_search_controller_test.rb diff --git a/app/controllers/admin/document_collection_group_document_search_controller.rb b/app/controllers/admin/document_collection_group_document_search_controller.rb new file mode 100644 index 00000000000..6dd90bbfc43 --- /dev/null +++ b/app/controllers/admin/document_collection_group_document_search_controller.rb @@ -0,0 +1,16 @@ +class Admin::DocumentCollectionGroupDocumentSearchController < Admin::BaseController + before_action :check_new_design_system_permissions + layout :get_layout + + def search_options; end + +private + + def check_new_design_system_permissions + forbidden! unless new_design_system? + end + + def get_layout + preview_design_system?(next_release: false) ? "design_system" : "admin" + end +end diff --git a/app/views/admin/document_collection_group_document_search/search_options.html.erb b/app/views/admin/document_collection_group_document_search/search_options.html.erb new file mode 100644 index 00000000000..e69de29bb2d diff --git a/config/routes.rb b/config/routes.rb index 59dda2462ae..3b24614acbe 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -29,13 +29,12 @@ def redirect(path, options = { prefix: Whitehall.router_prefix }) resources :authors, only: [:show] resource :document_searches, only: [:show] + resources :document_collections, path: "collections", except: [:index] do resources :document_collection_groups, as: :groups, path: "groups" do + get :search_options, to: "document_collection_group_document_search#search_options" member { get :confirm_destroy } - resource :document_collection_group_membership, - as: :members, - path: "members", - only: [:destroy] + resource :document_collection_group_membership, as: :members, path: "members", only: [:destroy] resources :document_collection_group_memberships, path: "members", only: %i[index destroy] do get :confirm_destroy, on: :member end diff --git a/test/functional/admin/document_collection_group_document_search_controller_test.rb b/test/functional/admin/document_collection_group_document_search_controller_test.rb new file mode 100644 index 00000000000..513abab47f6 --- /dev/null +++ b/test/functional/admin/document_collection_group_document_search_controller_test.rb @@ -0,0 +1,23 @@ +require "test_helper" + +class Admin::DocumentCollectionGroupDocumentSearchControllerTest < ActionController::TestCase + extend Minitest::Spec::DSL + + let(:params) { { document_collection_id: collection, group_id: group } } + let(:collection) { create(:document_collection, :with_group) } + let(:group) { collection.groups.first } + + should_be_an_admin_controller + + test "GET #search_options renders search options" do + login_as_preview_design_system_user :writer + get(:search_options, params:) + assert_template "document_collection_group_document_search/search_options" + end + + test "GET #search_options blocks out users with no permissions" do + login_as create(:writer) + get(:search_options, params:) + assert_template :forbidden + end +end From e6c7278a88f54fd63ecab01e5b0ca9e68a3fefde Mon Sep 17 00:00:00 2001 From: Minno Dang Date: Thu, 14 Sep 2023 17:36:16 +0100 Subject: [PATCH 02/10] Added Document Collections Search Options page Linked Add Document from Document Collection Group documents page so it takes you to search options --- ...ection_group_document_search_controller.rb | 11 +++++ .../search_options.html.erb | 48 +++++++++++++++++++ .../index.html.erb | 2 +- config/routes.rb | 1 + features/document-collections.feature | 8 +++- .../document_collection_steps.rb | 8 +++- ...ction_group_memberships_controller_test.rb | 6 ++- 7 files changed, 79 insertions(+), 5 deletions(-) diff --git a/app/controllers/admin/document_collection_group_document_search_controller.rb b/app/controllers/admin/document_collection_group_document_search_controller.rb index 6dd90bbfc43..733989c9f76 100644 --- a/app/controllers/admin/document_collection_group_document_search_controller.rb +++ b/app/controllers/admin/document_collection_group_document_search_controller.rb @@ -1,4 +1,6 @@ class Admin::DocumentCollectionGroupDocumentSearchController < Admin::BaseController + before_action :load_document_collection + before_action :load_document_collection_group before_action :check_new_design_system_permissions layout :get_layout @@ -13,4 +15,13 @@ def check_new_design_system_permissions def get_layout preview_design_system?(next_release: false) ? "design_system" : "admin" end + + def load_document_collection + @collection = DocumentCollection.includes(document: :latest_edition).find(params[:document_collection_id]) + end + + def load_document_collection_group + @group = @collection.groups.find(params[:group_id]) + session[:document_collection_selected_group_id] = params[:group_id] + end end diff --git a/app/views/admin/document_collection_group_document_search/search_options.html.erb b/app/views/admin/document_collection_group_document_search/search_options.html.erb index e69de29bb2d..5242e040046 100644 --- a/app/views/admin/document_collection_group_document_search/search_options.html.erb +++ b/app/views/admin/document_collection_group_document_search/search_options.html.erb @@ -0,0 +1,48 @@ +<% content_for :back_link do %> + <%= render "govuk_publishing_components/components/back_link", { + href: admin_document_collection_group_document_collection_group_memberships_path(@collection, @group), + } %> +<% end %> +<% content_for :page_title, 'Add document' %> +<% content_for :title, 'Add document' %> +<% content_for :context, @group.heading %> +<% content_for :title_margin_bottom, 4 %> + +<% + search_options = [ + { + value: 'url', + text: 'Search via URL' + },{ + value: 'title-or-slug', + text: 'Search via title or slug', + hint_text: 'This only applies to documents made in Whitehall' + }, + ] +%> + +
+
+ <%= render "govuk_publishing_components/components/radio", { + heading: "Search options", + name: "search_options", + id: "search_options", + heading_size: "l", + items: search_options + } %> + +
+ <%= render "govuk_publishing_components/components/button", { + text: "Next", + data_attributes: { + module: "gem-track-click", + "track-category": "form-button", + "track-action": "document-collection-search-options-next-button", + "track-label": "Next" + } + } %> + + <%= link_to("Cancel", admin_document_collection_group_document_collection_group_memberships_path(@collection, @group), class: "govuk-link govuk-link--no-visited-state") %> +
+
+
diff --git a/app/views/admin/document_collection_group_memberships/index.html.erb b/app/views/admin/document_collection_group_memberships/index.html.erb index 8cdfcda7472..7e034d2d27c 100644 --- a/app/views/admin/document_collection_group_memberships/index.html.erb +++ b/app/views/admin/document_collection_group_memberships/index.html.erb @@ -27,7 +27,7 @@ } %>

- <%= link_to "Add document", "#", class: "govuk-link" %> + <%= link_to "Add document", admin_document_collection_group_search_options_path(@collection, @group), class: "govuk-link" %>

diff --git a/config/routes.rb b/config/routes.rb index 3b24614acbe..e43de799cce 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -45,6 +45,7 @@ def redirect(path, options = { prefix: Whitehall.router_prefix }) post "non-whitehall-member" => "document_collection_group_memberships#create_non_whitehall_member", as: :new_non_whitehall_member post "groups/update_memberships" => "document_collection_groups#update_memberships", as: :update_group_memberships end + resources :organisations do resources :groups, except: [:show] resources :corporate_information_pages do diff --git a/features/document-collections.feature b/features/document-collections.feature index ba9836096d3..7c1eeeb0383 100644 --- a/features/document-collections.feature +++ b/features/document-collections.feature @@ -61,12 +61,18 @@ Feature: Grouping documents into a collection Then I can see that the group "Brand new group" has been added @design-system-only - Scenario: Adding a new group + Scenario: Editing a group Given a document collection "May 2012 Update" exists And a the document collection "May 2012 Update" has a group with the heading "Group to be edited" When I edit the group "Group to be edited"'s heading to "Interesting new heading" Then I can see that the heading has been updated to "Interesting new heading" + @design-system-only + Scenario: Adding a document to a group via slug + Given a document collection "Collection" exists + And a the document collection "Collection" has a group with the heading "Group" + When I select to add a new document to the collection group through "Search via title or slug" + @design-system-only Scenario: Removing a document from a group Given a published publication called "Document to be removed" in a published document collection diff --git a/features/step_definitions/document_collection_steps.rb b/features/step_definitions/document_collection_steps.rb index f43f892c3f1..f6bebcc4590 100644 --- a/features/step_definitions/document_collection_steps.rb +++ b/features/step_definitions/document_collection_steps.rb @@ -166,7 +166,7 @@ And(/^a the document collection "([^"]*)" has a group with the heading "([^"]*)"$/) do |collection_title, heading| document_collection = DocumentCollection.find_by!(title: collection_title) - create(:document_collection_group, heading:, document_collection:) + @group = create(:document_collection_group, heading:, document_collection:) end When(/^I delete the group "(.*?)"$/) do |title| @@ -249,3 +249,9 @@ expected_order = list.hashes.map(&:values).flatten expect(actual_order).to eq(expected_order) end + +When(/^I select to add a new document to the collection group through "([^"]*)"$/) do |search_option| + visit admin_document_collection_group_document_collection_group_memberships_path(@document_collection, @group) + click_link "Add document" + choose search_option +end diff --git a/test/functional/admin/document_collection_group_memberships_controller_test.rb b/test/functional/admin/document_collection_group_memberships_controller_test.rb index e847982f1be..ae1a43f6525 100644 --- a/test/functional/admin/document_collection_group_memberships_controller_test.rb +++ b/test/functional/admin/document_collection_group_memberships_controller_test.rb @@ -14,9 +14,10 @@ def id_params end view_test "GET #index renders a link to add a document and informs the user there are no documents in the group if none are present" do + document_add_search_options_path = admin_document_collection_group_search_options_path(@collection, @group) get :index, params: { document_collection_id: @collection, group_id: @group } - assert_select ".govuk-link[href='#']", text: "Add document" + assert_select ".govuk-link[href='#{document_add_search_options_path}']", text: "Add document" assert_select ".govuk-warning-text__text", text: /There are no documents inside this group/ end @@ -25,12 +26,13 @@ def id_params edition = create(:edition, document:) membership = create(:document_collection_group_membership, document:) confirm_destroy_path = confirm_destroy_admin_document_collection_group_document_collection_group_membership_path(@collection, @group, membership) + document_add_search_options_path = admin_document_collection_group_search_options_path(@collection, @group) @group.memberships << membership get :index, params: { document_collection_id: @collection, group_id: @group } - assert_select ".govuk-link[href='#']", text: "Add document" + assert_select ".govuk-link[href='#{document_add_search_options_path}']", text: "Add document" assert_select ".govuk-table__row:nth-child(1) .govuk-table__cell:nth-child(2) a[href='#{edition.public_url}']", text: "View #{edition.title}" assert_select ".govuk-table__row:nth-child(1) .govuk-table__cell:nth-child(2) a[href='#{confirm_destroy_path}']", text: "Remove #{edition.title}" end From 871ad0a77e175c8e1206320d0339556a47cb89d5 Mon Sep 17 00:00:00 2001 From: Minno Dang Date: Thu, 14 Sep 2023 18:58:30 +0100 Subject: [PATCH 03/10] Add next screen to document collection search via title or slug NOOP unless user selects option to search via title or slug. Title or slug redirects to the sceen with a search bar. --- ...ection_group_document_search_controller.rb | 6 +++ .../search_options.html.erb | 44 ++++++++++--------- .../search_title_slug.html.erb | 18 ++++++++ config/routes.rb | 2 + features/document-collections.feature | 1 + .../document_collection_steps.rb | 6 +++ ...n_group_document_search_controller_test.rb | 33 +++++++++----- ...n_group_document_search_controller_test.rb | 27 ++++++++++++ test/test_helper.rb | 6 +-- 9 files changed, 108 insertions(+), 35 deletions(-) create mode 100644 app/views/admin/document_collection_group_document_search/search_title_slug.html.erb create mode 100644 test/functional/admin/legacy_document_collection_group_document_search_controller_test.rb diff --git a/app/controllers/admin/document_collection_group_document_search_controller.rb b/app/controllers/admin/document_collection_group_document_search_controller.rb index 733989c9f76..35e9517d3e8 100644 --- a/app/controllers/admin/document_collection_group_document_search_controller.rb +++ b/app/controllers/admin/document_collection_group_document_search_controller.rb @@ -6,6 +6,12 @@ class Admin::DocumentCollectionGroupDocumentSearchController < Admin::BaseContro def search_options; end + def search + redirect_to(action: :search_title_slug, document_collection_id: @collection, group_id: @group) if params[:search_option] == "title-or-slug" + end + + def search_title_slug; end + private def check_new_design_system_permissions diff --git a/app/views/admin/document_collection_group_document_search/search_options.html.erb b/app/views/admin/document_collection_group_document_search/search_options.html.erb index 5242e040046..f384afc110d 100644 --- a/app/views/admin/document_collection_group_document_search/search_options.html.erb +++ b/app/views/admin/document_collection_group_document_search/search_options.html.erb @@ -13,36 +13,38 @@ { value: 'url', text: 'Search via URL' - },{ + }, { value: 'title-or-slug', text: 'Search via title or slug', - hint_text: 'This only applies to documents made in Whitehall' + hint_text: 'This only applies to documents made in Whitehall publisher' }, ] %>
- <%= render "govuk_publishing_components/components/radio", { - heading: "Search options", - name: "search_options", - id: "search_options", - heading_size: "l", - items: search_options - } %> - -
- <%= render "govuk_publishing_components/components/button", { - text: "Next", - data_attributes: { - module: "gem-track-click", - "track-category": "form-button", - "track-action": "document-collection-search-options-next-button", - "track-label": "Next" - } + <%= form_with url: admin_document_collection_group_search_options_path(@collection, @group) do %> + <%= render "govuk_publishing_components/components/radio", { + heading: "Search options", + name: "search_option", + id: "search_option", + heading_size: "l", + items: search_options } %> - <%= link_to("Cancel", admin_document_collection_group_document_collection_group_memberships_path(@collection, @group), class: "govuk-link govuk-link--no-visited-state") %> -
+
+ <%= render "govuk_publishing_components/components/button", { + text: "Next", + data_attributes: { + module: "gem-track-click", + "track-category": "form-button", + "track-action": "document-collection-search-options-next-button", + "track-label": "Next" + } + } %> + + <%= link_to("Cancel", admin_document_collection_group_document_collection_group_memberships_path(@collection, @group), class: "govuk-link govuk-link--no-visited-state") %> +
+ <% end %>
diff --git a/app/views/admin/document_collection_group_document_search/search_title_slug.html.erb b/app/views/admin/document_collection_group_document_search/search_title_slug.html.erb new file mode 100644 index 00000000000..ae98bd2c585 --- /dev/null +++ b/app/views/admin/document_collection_group_document_search/search_title_slug.html.erb @@ -0,0 +1,18 @@ +<% content_for :back_link do %> + <%= render "govuk_publishing_components/components/back_link", { + href: admin_document_collection_group_search_options_path(@collection, @group), + } %> +<% end %> +<% content_for :page_title, 'Add document' %> +<% content_for :title, 'Add document' %> +<% content_for :context, @group.heading %> +<% content_for :title_margin_bottom, 4 %> + +
+
+ <%= render "govuk_publishing_components/components/search", { + label_text: 'Search by title or slug', + label_size: "l" + } %> +
+
diff --git a/config/routes.rb b/config/routes.rb index e43de799cce..b9561830fd8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -33,6 +33,8 @@ def redirect(path, options = { prefix: Whitehall.router_prefix }) resources :document_collections, path: "collections", except: [:index] do resources :document_collection_groups, as: :groups, path: "groups" do get :search_options, to: "document_collection_group_document_search#search_options" + post :search_options, to: "document_collection_group_document_search#search" + get :search_title_slug, to: "document_collection_group_document_search#search_title_slug" member { get :confirm_destroy } resource :document_collection_group_membership, as: :members, path: "members", only: [:destroy] resources :document_collection_group_memberships, path: "members", only: %i[index destroy] do diff --git a/features/document-collections.feature b/features/document-collections.feature index 7c1eeeb0383..ce5ec93cac1 100644 --- a/features/document-collections.feature +++ b/features/document-collections.feature @@ -72,6 +72,7 @@ Feature: Grouping documents into a collection Given a document collection "Collection" exists And a the document collection "Collection" has a group with the heading "Group" When I select to add a new document to the collection group through "Search via title or slug" + And I search by "title or slug" for "Document 1" @design-system-only Scenario: Removing a document from a group diff --git a/features/step_definitions/document_collection_steps.rb b/features/step_definitions/document_collection_steps.rb index f6bebcc4590..b781e9a044b 100644 --- a/features/step_definitions/document_collection_steps.rb +++ b/features/step_definitions/document_collection_steps.rb @@ -254,4 +254,10 @@ visit admin_document_collection_group_document_collection_group_memberships_path(@document_collection, @group) click_link "Add document" choose search_option + click_button "Next" +end + +And(/^I search by "([^"]*)" for "([^"]*)"$/) do |search_type, search_term| + fill_in "Search by #{search_type.downcase}", with: search_term + click_button "Search" end diff --git a/test/functional/admin/document_collection_group_document_search_controller_test.rb b/test/functional/admin/document_collection_group_document_search_controller_test.rb index 513abab47f6..76502961d29 100644 --- a/test/functional/admin/document_collection_group_document_search_controller_test.rb +++ b/test/functional/admin/document_collection_group_document_search_controller_test.rb @@ -1,23 +1,34 @@ require "test_helper" class Admin::DocumentCollectionGroupDocumentSearchControllerTest < ActionController::TestCase - extend Minitest::Spec::DSL - - let(:params) { { document_collection_id: collection, group_id: group } } - let(:collection) { create(:document_collection, :with_group) } - let(:group) { collection.groups.first } + setup do + @collection = create(:document_collection, :with_group) + @group = @collection.groups.first + @request_params = { document_collection_id: @collection, group_id: @group } + login_as_preview_design_system_user :writer + end should_be_an_admin_controller test "GET #search_options renders search options" do - login_as_preview_design_system_user :writer - get(:search_options, params:) + get :search_options, params: @request_params assert_template "document_collection_group_document_search/search_options" end - test "GET #search_options blocks out users with no permissions" do - login_as create(:writer) - get(:search_options, params:) - assert_template :forbidden + test "POST #search is a noop when passed param is unrecognised" do + @request_params[:search_option] = "non-existant" + post :search, params: @request_params + assert_template nil + end + + test "POST #search redirects to #search_title_slug if search option passed is title-or-slug" do + @request_params[:search_option] = "title-or-slug" + post :search, params: @request_params + assert_redirected_to admin_document_collection_group_search_title_slug_path(@collection, @group) + end + + test "GET #search_title_slug renders search for title & slug" do + get :search_title_slug, params: @request_params + assert_template "document_collection_group_document_search/search_title_slug" end end diff --git a/test/functional/admin/legacy_document_collection_group_document_search_controller_test.rb b/test/functional/admin/legacy_document_collection_group_document_search_controller_test.rb new file mode 100644 index 00000000000..29fab6a5e97 --- /dev/null +++ b/test/functional/admin/legacy_document_collection_group_document_search_controller_test.rb @@ -0,0 +1,27 @@ +require "test_helper" + +class Admin::LegacyDocumentCollectionGroupDocumentSearchControllerTest < ActionController::TestCase + tests Admin::DocumentCollectionGroupDocumentSearchController + + setup do + @collection = create(:document_collection, :with_group) + @group = @collection.groups.first + @request_params = { document_collection_id: @collection, group_id: @group } + login_as create(:writer) + end + + test "GET #search_options blocks out users with no permissions" do + get :search_options, params: @request_params + assert_template :forbidden + end + + test "POST #search blocks out users with no permissions" do + post :search, params: @request_params + assert_template :forbidden + end + + test "GET #search_title_slug blocks out users with no permissions" do + get :search_title_slug, params: @request_params + assert_template :forbidden + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb index 2a9b482ba52..b0d27eb5b3d 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -231,11 +231,11 @@ def login_as(role_or_user, organisation = nil) end def login_as_admin - login_as(create(:user, name: "user-name", email: "user@example.com")) + login_as(create(:user, name: "admin-name", email: "admin@example.com")) end def login_as_preview_design_system_user(role, organisation = nil) - login_as(create(role, :with_preview_design_system, name: "user-name", email: "user@example.com", organisation:)) + login_as(create(role, :with_preview_design_system, name: "preview-user-name", email: "preview-user@example.com", organisation:)) end def login_as_use_non_legacy_endpoints_user(role, organisation = nil) @@ -260,7 +260,7 @@ def login_as(user) end def login_as_admin - login_as(create(:user, name: "user-name", email: "user@example.com")) + login_as(create(:user, name: "admin-name", email: "admin@example.com")) end def login_as_use_non_legacy_endpoints_user(role, organisation = nil) From 9656c0b817e0b0353cf83e9a3caf439bde0d1d66 Mon Sep 17 00:00:00 2001 From: Minno Dang Date: Mon, 25 Sep 2023 14:03:25 +0100 Subject: [PATCH 04/10] Search for documents and add it to the collection group Using the scope that is used by the edition filter in the documents search - :with_title_containing to search for live documents containing the query entered by user. If query is empty then alert the user to enter a search query. Link the Add button to the existing POST create_whitehall_member in the original document collection group membership controller. This creates the membership link between the document and the collection group. Redirect to the documents page if it is new design system. The 'Add' button is a button rather than a link as discussed within the team and design because it is posting data, and Rails no longer supports links posting data via query params. We are collectively of the opinion that buttons should not be disguised as links, so instead of styling the button to look like a link, we should just use a secondary button. --- ...oup-document-search-search-title-slug.scss | 15 ++++++ app/assets/stylesheets/application.scss | 1 + ...ection_group_document_search_controller.rb | 5 +- ...collection_group_memberships_controller.rb | 17 +++++-- .../search_title_slug.html.erb | 51 ++++++++++++++++--- ...n_group_document_search_controller_test.rb | 36 ++++++++++++- ...ction_group_memberships_controller_test.rb | 13 +++++ 7 files changed, 125 insertions(+), 13 deletions(-) create mode 100644 app/assets/stylesheets/admin/views/_document-collection-group-document-search-search-title-slug.scss diff --git a/app/assets/stylesheets/admin/views/_document-collection-group-document-search-search-title-slug.scss b/app/assets/stylesheets/admin/views/_document-collection-group-document-search-search-title-slug.scss new file mode 100644 index 00000000000..eeb943ea39c --- /dev/null +++ b/app/assets/stylesheets/admin/views/_document-collection-group-document-search-search-title-slug.scss @@ -0,0 +1,15 @@ +.app-view-document-collection-document-search-results__table { + .govuk-table__cell, + .govuk-table__cell > * { + vertical-align: middle; + } + + form { + display: inline; + + .govuk-button--secondary { + margin-left: govuk-spacing(3); + vertical-align: middle; + } + } +} diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 911cc4c327f..fe5ed4d3537 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -24,6 +24,7 @@ $govuk-page-width: 1140px; @import "./admin/views/dashboard-index"; @import "./admin/views/document-history-tab"; @import "./admin/views/document-collection-group-memberships-index"; +@import "./admin/views/document-collection-group-document-search-search-title-slug"; @import "./admin/views/edit-edition"; @import "./admin/views/edit-person"; @import "./admin/views/edition-resource"; diff --git a/app/controllers/admin/document_collection_group_document_search_controller.rb b/app/controllers/admin/document_collection_group_document_search_controller.rb index 35e9517d3e8..669cd7627bc 100644 --- a/app/controllers/admin/document_collection_group_document_search_controller.rb +++ b/app/controllers/admin/document_collection_group_document_search_controller.rb @@ -10,7 +10,10 @@ def search redirect_to(action: :search_title_slug, document_collection_id: @collection, group_id: @group) if params[:search_option] == "title-or-slug" end - def search_title_slug; end + def search_title_slug + flash.now[:alert] = "Please enter a search query" if params[:query] && params[:query].empty? + @results = Edition.published.with_title_containing(params[:query].strip) if params[:query].present? + end private diff --git a/app/controllers/admin/document_collection_group_memberships_controller.rb b/app/controllers/admin/document_collection_group_memberships_controller.rb index f377bbc3375..5b432d0f380 100644 --- a/app/controllers/admin/document_collection_group_memberships_controller.rb +++ b/app/controllers/admin/document_collection_group_memberships_controller.rb @@ -11,10 +11,11 @@ def index; end def create_whitehall_member membership = DocumentCollectionGroupMembership.new(document: @document, document_collection_group: @group) if membership.save - redirect_to admin_document_collection_groups_path(@collection), - notice: "'#{params[:title]}' added to '#{@group.heading}'" + title = @document.latest_edition.title + redirect_to create_redirect_path, + notice: "'#{title}' added to '#{@group.heading}'" else - redirect_to admin_document_collection_groups_path(@collection), + redirect_to create_redirect_path, alert: "#{membership.errors.full_messages.join('. ')}." end end @@ -59,8 +60,16 @@ def destroy private + def create_redirect_path + if get_layout == "design_system" + admin_document_collection_group_document_collection_group_memberships_path(@collection, @group) + else + admin_document_collection_groups_path(@collection) + end + end + def get_layout - design_system_actions = %w[index confirm_destroy destroy] if preview_design_system?(next_release: false) + design_system_actions = %w[index confirm_destroy destroy create_whitehall_member] if preview_design_system?(next_release: false) if design_system_actions&.include?(action_name) "design_system" diff --git a/app/views/admin/document_collection_group_document_search/search_title_slug.html.erb b/app/views/admin/document_collection_group_document_search/search_title_slug.html.erb index ae98bd2c585..6852cbf38d6 100644 --- a/app/views/admin/document_collection_group_document_search/search_title_slug.html.erb +++ b/app/views/admin/document_collection_group_document_search/search_title_slug.html.erb @@ -3,16 +3,53 @@ href: admin_document_collection_group_search_options_path(@collection, @group), } %> <% end %> -<% content_for :page_title, 'Add document' %> -<% content_for :title, 'Add document' %> +<% content_for :page_title, "Add document" %> +<% content_for :title, "Add document" %> <% content_for :context, @group.heading %> <% content_for :title_margin_bottom, 4 %>
-
- <%= render "govuk_publishing_components/components/search", { - label_text: 'Search by title or slug', - label_size: "l" - } %> + + + <% if @results %> +
+

<%= pluralize(number_with_delimiter(@results.count), "document") %>

+
+ <% if @results.empty? %> +

No documents found

+ <% else %> +
+ <%= render "govuk_publishing_components/components/table", { + rows: @results.map do |edition| + [{ + text: tag.span(index_table_title_row(edition), class: "govuk-!-font-weight-bold"), + }, { + text: + link_to(sanitize("View #{tag.span(edition.title, class: "govuk-visually-hidden")}"), edition.public_url, class: "govuk-link") + + button_to("Add", + admin_document_collection_new_whitehall_member_path(@collection), + method: :post, + params: { + group_id: @group.id, + document_id: edition.document.id, + }, + aria: { label: "Add document to the document collection group" }, + class: "gem-c-button govuk-button govuk-button--secondary", + ), + }] + end + } %> +
+ <% end %> +
+ <% end %>
diff --git a/test/functional/admin/document_collection_group_document_search_controller_test.rb b/test/functional/admin/document_collection_group_document_search_controller_test.rb index 76502961d29..7e83ab3e780 100644 --- a/test/functional/admin/document_collection_group_document_search_controller_test.rb +++ b/test/functional/admin/document_collection_group_document_search_controller_test.rb @@ -27,8 +27,42 @@ class Admin::DocumentCollectionGroupDocumentSearchControllerTest < ActionControl assert_redirected_to admin_document_collection_group_search_title_slug_path(@collection, @group) end - test "GET #search_title_slug renders search for title & slug" do + test "GET #search_title_slug without query renders search for title & slug page with no results section" do get :search_title_slug, params: @request_params assert_template "document_collection_group_document_search/search_title_slug" + assert_select ".app-view-document-collection-document-search-results", count: 0 + end + + view_test "GET #search_title_slug with a query returns the document with the query in the results" do + edition = build(:consultation, title: "Something", document: build(:document, slug: "something")) + + mock_live_editions = mock + mock_live_editions.expects(:with_title_containing).with("Something").once.returns([edition]) + + Edition.expects(:published).once.returns(mock_live_editions) + + @request_params[:query] = "Something " + get :search_title_slug, params: @request_params + + assert_template "document_collection_group_document_search/search_title_slug" + assert_select ".govuk-table__row .govuk-table__cell a[href='#{edition.public_url}']", text: "View #{edition.title}" + end + + view_test "GET #search_title_slug with a query that returns no results renders empty results list" do + mock_live_editions = mock + mock_live_editions.expects(:with_title_containing).with("Something").once.returns([]) + Edition.expects(:published).once.returns(mock_live_editions) + + @request_params[:query] = "Something " + get :search_title_slug, params: @request_params + assert_template "document_collection_group_document_search/search_title_slug" + assert_select ".govuk-body", text: /No documents found/ + end + + view_test "GET #search_title_slug with an empty query string shows an alert flash" do + @request_params[:query] = "" + get :search_title_slug, params: @request_params + assert_template "document_collection_group_document_search/search_title_slug" + assert_select ".gem-c-error-alert__message", text: /Please enter a search query/ end end diff --git a/test/functional/admin/document_collection_group_memberships_controller_test.rb b/test/functional/admin/document_collection_group_memberships_controller_test.rb index ae1a43f6525..b12916adf0c 100644 --- a/test/functional/admin/document_collection_group_memberships_controller_test.rb +++ b/test/functional/admin/document_collection_group_memberships_controller_test.rb @@ -36,4 +36,17 @@ def id_params assert_select ".govuk-table__row:nth-child(1) .govuk-table__cell:nth-child(2) a[href='#{edition.public_url}']", text: "View #{edition.title}" assert_select ".govuk-table__row:nth-child(1) .govuk-table__cell:nth-child(2) a[href='#{confirm_destroy_path}']", text: "Remove #{edition.title}" end + + test "POST #create_whitehall_member adds a whitehall document to a group and redirects" do + document = create(:publication).document + assert_difference "@group.reload.documents.size" do + post :create_whitehall_member, params: id_params.merge(document_id: document.id) + end + assert_redirected_to admin_document_collection_group_document_collection_group_memberships_path(@collection, @group) + end + + test "POST #create_whitehall_member warns user when document not found" do + post :create_whitehall_member, params: id_params.merge(document_id: 1234, title: "blah") + assert_match %r{couldn't find.*blah}, flash[:alert] + end end From a7e809d697c1ea644cfd53c1e43bbe352bfbec61 Mon Sep 17 00:00:00 2001 From: Minno Dang Date: Mon, 25 Sep 2023 14:06:03 +0100 Subject: [PATCH 05/10] Document collection search options alerts the user If no radio button is selected, then set an alert --- ..._collection_group_document_search_controller.rb | 4 ++++ .../search_options.html.erb | 14 +++++++------- ...ection_group_document_search_controller_test.rb | 13 +++++++++++++ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/app/controllers/admin/document_collection_group_document_search_controller.rb b/app/controllers/admin/document_collection_group_document_search_controller.rb index 669cd7627bc..e181d2e0ec4 100644 --- a/app/controllers/admin/document_collection_group_document_search_controller.rb +++ b/app/controllers/admin/document_collection_group_document_search_controller.rb @@ -7,6 +7,10 @@ class Admin::DocumentCollectionGroupDocumentSearchController < Admin::BaseContro def search_options; end def search + if params[:search_option].blank? + flash.now[:alert] = "Please select a search option" + render :search_options + end redirect_to(action: :search_title_slug, document_collection_id: @collection, group_id: @group) if params[:search_option] == "title-or-slug" end diff --git a/app/views/admin/document_collection_group_document_search/search_options.html.erb b/app/views/admin/document_collection_group_document_search/search_options.html.erb index f384afc110d..e7b43783b6e 100644 --- a/app/views/admin/document_collection_group_document_search/search_options.html.erb +++ b/app/views/admin/document_collection_group_document_search/search_options.html.erb @@ -3,20 +3,20 @@ href: admin_document_collection_group_document_collection_group_memberships_path(@collection, @group), } %> <% end %> -<% content_for :page_title, 'Add document' %> -<% content_for :title, 'Add document' %> +<% content_for :page_title, "Add document" %> +<% content_for :title, "Add document" %> <% content_for :context, @group.heading %> <% content_for :title_margin_bottom, 4 %> <% search_options = [ { - value: 'url', - text: 'Search via URL' + value: "url", + text: "Search via URL" }, { - value: 'title-or-slug', - text: 'Search via title or slug', - hint_text: 'This only applies to documents made in Whitehall publisher' + value: "title-or-slug", + text: "Search via title or slug", + hint_text: "This only applies to documents made in Whitehall publisher" }, ] %> diff --git a/test/functional/admin/document_collection_group_document_search_controller_test.rb b/test/functional/admin/document_collection_group_document_search_controller_test.rb index 7e83ab3e780..e1d31709bf2 100644 --- a/test/functional/admin/document_collection_group_document_search_controller_test.rb +++ b/test/functional/admin/document_collection_group_document_search_controller_test.rb @@ -15,6 +15,19 @@ class Admin::DocumentCollectionGroupDocumentSearchControllerTest < ActionControl assert_template "document_collection_group_document_search/search_options" end + view_test "POST #search with an empty option shows an alert flash" do + @request_params[:search_option] = "" + post :search, params: @request_params + assert_template "document_collection_group_document_search/search_options" + assert_select ".gem-c-error-alert__message", text: /Please select a search option/ + end + + view_test "POST #search with no search options shows an alert flash" do + post :search, params: @request_params + assert_template "document_collection_group_document_search/search_options" + assert_select ".gem-c-error-alert__message", text: /Please select a search option/ + end + test "POST #search is a noop when passed param is unrecognised" do @request_params[:search_option] = "non-existant" post :search, params: @request_params From 6a3b2341363b93fae587f27c084e2d12a0828c4c Mon Sep 17 00:00:00 2001 From: Minno Dang Date: Mon, 25 Sep 2023 14:06:46 +0100 Subject: [PATCH 06/10] Complete feature testing for adding a document to document collection group --- features/document-collections.feature | 9 ++++++--- .../step_definitions/document_collection_steps.rb | 13 ++++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/features/document-collections.feature b/features/document-collections.feature index ce5ec93cac1..d78c3ac97aa 100644 --- a/features/document-collections.feature +++ b/features/document-collections.feature @@ -50,7 +50,7 @@ Feature: Grouping documents into a collection @design-system-only Scenario: Deleting a group Given a document collection "May 2012 Update" exists - And a the document collection "May 2012 Update" has a group with the heading "Temporary group" + And the document collection "May 2012 Update" has a group with the heading "Temporary group" When I delete the group "Temporary group" Then I can see that the group "Temporary group" has been deleted @@ -63,16 +63,19 @@ Feature: Grouping documents into a collection @design-system-only Scenario: Editing a group Given a document collection "May 2012 Update" exists - And a the document collection "May 2012 Update" has a group with the heading "Group to be edited" + And the document collection "May 2012 Update" has a group with the heading "Group to be edited" When I edit the group "Group to be edited"'s heading to "Interesting new heading" Then I can see that the heading has been updated to "Interesting new heading" @design-system-only Scenario: Adding a document to a group via slug Given a document collection "Collection" exists - And a the document collection "Collection" has a group with the heading "Group" + And the document collection "Collection" has a group with the heading "Group" + And a published document "Document 1" exists When I select to add a new document to the collection group through "Search via title or slug" And I search by "title or slug" for "Document 1" + And I add "Document 1" to the document collection + Then I should see "Document 1" in the list for the collection group "Group" @design-system-only Scenario: Removing a document from a group diff --git a/features/step_definitions/document_collection_steps.rb b/features/step_definitions/document_collection_steps.rb index b781e9a044b..9469d093f92 100644 --- a/features/step_definitions/document_collection_steps.rb +++ b/features/step_definitions/document_collection_steps.rb @@ -164,7 +164,7 @@ expect(body.index(doc_title1) < body.index(doc_title2)).to be(true) end -And(/^a the document collection "([^"]*)" has a group with the heading "([^"]*)"$/) do |collection_title, heading| +And(/^the document collection "([^"]*)" has a group with the heading "([^"]*)"$/) do |collection_title, heading| document_collection = DocumentCollection.find_by!(title: collection_title) @group = create(:document_collection_group, heading:, document_collection:) end @@ -261,3 +261,14 @@ fill_in "Search by #{search_type.downcase}", with: search_term click_button "Search" end + +And(/^I add "([^"]*)" to the document collection$/) do |document_title| + expect(page).to have_content document_title + click_button "Add" +end + +Then(/^I should see "([^"]*)" in the list for the collection group "([^"]*)"$/) do |document_title, collection_title| + expect(page).to have_content "'#{document_title}' added to '#{collection_title}'" + documents = all(".govuk-table__cell").map(&:text) + expect(documents).to include document_title +end From 6425f89fe6164be9d86130683d052412e42817fa Mon Sep 17 00:00:00 2001 From: Minno Dang Date: Mon, 25 Sep 2023 14:43:16 +0100 Subject: [PATCH 07/10] Fix linting errors --- .../search_options.html.erb | 13 +++--- .../search_title_slug.html.erb | 41 ++++++++++--------- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/app/views/admin/document_collection_group_document_search/search_options.html.erb b/app/views/admin/document_collection_group_document_search/search_options.html.erb index e7b43783b6e..38ddbf76c14 100644 --- a/app/views/admin/document_collection_group_document_search/search_options.html.erb +++ b/app/views/admin/document_collection_group_document_search/search_options.html.erb @@ -12,11 +12,12 @@ search_options = [ { value: "url", - text: "Search via URL" - }, { + text: "Search via URL", + }, + { value: "title-or-slug", text: "Search via title or slug", - hint_text: "This only applies to documents made in Whitehall publisher" + hint_text: "This only applies to documents made in Whitehall publisher", }, ] %> @@ -29,7 +30,7 @@ name: "search_option", id: "search_option", heading_size: "l", - items: search_options + items: search_options, } %>
@@ -39,8 +40,8 @@ module: "gem-track-click", "track-category": "form-button", "track-action": "document-collection-search-options-next-button", - "track-label": "Next" - } + "track-label": "Next", + }, } %> <%= link_to("Cancel", admin_document_collection_group_document_collection_group_memberships_path(@collection, @group), class: "govuk-link govuk-link--no-visited-state") %> diff --git a/app/views/admin/document_collection_group_document_search/search_title_slug.html.erb b/app/views/admin/document_collection_group_document_search/search_title_slug.html.erb index 6852cbf38d6..12de6f2c96e 100644 --- a/app/views/admin/document_collection_group_document_search/search_title_slug.html.erb +++ b/app/views/admin/document_collection_group_document_search/search_title_slug.html.erb @@ -22,32 +22,33 @@ <% if @results %>
+

<%= pluralize(number_with_delimiter(@results.count), "document") %>


+ <% if @results.empty? %>

No documents found

<% else %>
- <%= render "govuk_publishing_components/components/table", { - rows: @results.map do |edition| - [{ - text: tag.span(index_table_title_row(edition), class: "govuk-!-font-weight-bold"), - }, { - text: - link_to(sanitize("View #{tag.span(edition.title, class: "govuk-visually-hidden")}"), edition.public_url, class: "govuk-link") + - button_to("Add", - admin_document_collection_new_whitehall_member_path(@collection), - method: :post, - params: { - group_id: @group.id, - document_id: edition.document.id, - }, - aria: { label: "Add document to the document collection group" }, - class: "gem-c-button govuk-button govuk-button--secondary", - ), - }] - end - } %> + <%= render "govuk_publishing_components/components/table", + { + rows: @results.map do |edition| + title_span = tag.span(index_table_title_row(edition), class: "govuk-!-font-weight-bold") + view_link = link_to(sanitize("View #{tag.span(edition.title, class: "govuk-visually-hidden")}"), edition.public_url, class: "govuk-link") + add_button = button_to("Add", + admin_document_collection_new_whitehall_member_path(@collection), + method: :post, + params: { + group_id: @group.id, + document_id: edition.document.id, + }, + aria: { label: "Add document to the document collection group" }, + class: "gem-c-button govuk-button govuk-button--secondary", + ) + + [{ text: title_span }, { text: view_link + add_button }] + end, + } %>
<% end %>
From 3693160eacf12cceaccbb451387b1246f820fa5b Mon Sep 17 00:00:00 2001 From: Minno Dang Date: Mon, 25 Sep 2023 15:11:48 +0100 Subject: [PATCH 08/10] Add GA tracking for the Delete and Remove buttons in Document Collection Deleting document groups and removing documents from groups need to be tracked --- .../confirm_destroy.html.erb | 6 ++++++ .../document_collection_groups/confirm_destroy.html.erb | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/app/views/admin/document_collection_group_memberships/confirm_destroy.html.erb b/app/views/admin/document_collection_group_memberships/confirm_destroy.html.erb index 3d895804a1b..51937e2e5f2 100644 --- a/app/views/admin/document_collection_group_memberships/confirm_destroy.html.erb +++ b/app/views/admin/document_collection_group_memberships/confirm_destroy.html.erb @@ -11,6 +11,12 @@ <%= render "govuk_publishing_components/components/button", { text: "Remove", destructive: true, + data_attributes: { + module: "gem-track-click", + "track-category": "form-button", + "track-action": "remove-document-from-collection-group-button", + "track-label": "Remove" + } } %> <%= link_to("Cancel", admin_document_collection_group_members_path(@collection, @group), class: "govuk-link govuk-link--no-visited-state") %>
diff --git a/app/views/admin/document_collection_groups/confirm_destroy.html.erb b/app/views/admin/document_collection_groups/confirm_destroy.html.erb index de05f40b7ed..81236c08453 100644 --- a/app/views/admin/document_collection_groups/confirm_destroy.html.erb +++ b/app/views/admin/document_collection_groups/confirm_destroy.html.erb @@ -11,6 +11,12 @@ <%= render "govuk_publishing_components/components/button", { text: "Delete", destructive: true, + data_attributes: { + module: "gem-track-click", + "track-category": "form-button", + "track-action": "delete-document-collection-group-button", + "track-label": "Delete" + } } %> <%= link_to("Cancel", admin_document_collection_groups_path(@collection), class: "govuk-link govuk-link--no-visited-state") %>
From f9b01d1d19c8f7c722481786644427da209da9dc Mon Sep 17 00:00:00 2001 From: Minno Dang Date: Mon, 25 Sep 2023 15:15:01 +0100 Subject: [PATCH 09/10] GA track Adding document to document collection group --- .../search_title_slug.html.erb | 6 ++++++ .../confirm_destroy.html.erb | 4 ++-- .../document_collection_groups/confirm_destroy.html.erb | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/views/admin/document_collection_group_document_search/search_title_slug.html.erb b/app/views/admin/document_collection_group_document_search/search_title_slug.html.erb index 12de6f2c96e..5b6c44d27d2 100644 --- a/app/views/admin/document_collection_group_document_search/search_title_slug.html.erb +++ b/app/views/admin/document_collection_group_document_search/search_title_slug.html.erb @@ -44,6 +44,12 @@ }, aria: { label: "Add document to the document collection group" }, class: "gem-c-button govuk-button govuk-button--secondary", + data_attributes: { + module: "gem-track-click", + "track-category": "form-button", + "track-action": "add-document-to-collection-group-button", + "track-label": "Add", + }, ) [{ text: title_span }, { text: view_link + add_button }] diff --git a/app/views/admin/document_collection_group_memberships/confirm_destroy.html.erb b/app/views/admin/document_collection_group_memberships/confirm_destroy.html.erb index 51937e2e5f2..0cd11f880a5 100644 --- a/app/views/admin/document_collection_group_memberships/confirm_destroy.html.erb +++ b/app/views/admin/document_collection_group_memberships/confirm_destroy.html.erb @@ -15,8 +15,8 @@ module: "gem-track-click", "track-category": "form-button", "track-action": "remove-document-from-collection-group-button", - "track-label": "Remove" - } + "track-label": "Remove", + }, } %> <%= link_to("Cancel", admin_document_collection_group_members_path(@collection, @group), class: "govuk-link govuk-link--no-visited-state") %> diff --git a/app/views/admin/document_collection_groups/confirm_destroy.html.erb b/app/views/admin/document_collection_groups/confirm_destroy.html.erb index 81236c08453..5e2c696ae58 100644 --- a/app/views/admin/document_collection_groups/confirm_destroy.html.erb +++ b/app/views/admin/document_collection_groups/confirm_destroy.html.erb @@ -15,8 +15,8 @@ module: "gem-track-click", "track-category": "form-button", "track-action": "delete-document-collection-group-button", - "track-label": "Delete" - } + "track-label": "Delete", + }, } %> <%= link_to("Cancel", admin_document_collection_groups_path(@collection), class: "govuk-link govuk-link--no-visited-state") %> From c2e023381f09cb1b0c68445dacb4f88ac7c2b12a Mon Sep 17 00:00:00 2001 From: davidtrussler Date: Wed, 27 Sep 2023 16:46:02 +0100 Subject: [PATCH 10/10] Make content and style changes --- ...collection-group-document-search-search-title-slug.scss | 7 +++++-- .../search_options.html.erb | 3 +-- .../search_title_slug.html.erb | 4 ++-- features/document-collections.feature | 6 +++--- ...ent_collection_group_document_search_controller_test.rb | 2 +- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/app/assets/stylesheets/admin/views/_document-collection-group-document-search-search-title-slug.scss b/app/assets/stylesheets/admin/views/_document-collection-group-document-search-search-title-slug.scss index eeb943ea39c..c4d6f708f1a 100644 --- a/app/assets/stylesheets/admin/views/_document-collection-group-document-search-search-title-slug.scss +++ b/app/assets/stylesheets/admin/views/_document-collection-group-document-search-search-title-slug.scss @@ -1,6 +1,10 @@ .app-view-document-collection-document-search-results__table { + .govuk-table__cell:nth-child(2) { + white-space: nowrap; + } + .govuk-table__cell, - .govuk-table__cell > * { + .govuk-table__cell * { vertical-align: middle; } @@ -9,7 +13,6 @@ .govuk-button--secondary { margin-left: govuk-spacing(3); - vertical-align: middle; } } } diff --git a/app/views/admin/document_collection_group_document_search/search_options.html.erb b/app/views/admin/document_collection_group_document_search/search_options.html.erb index 38ddbf76c14..f28c6a9e499 100644 --- a/app/views/admin/document_collection_group_document_search/search_options.html.erb +++ b/app/views/admin/document_collection_group_document_search/search_options.html.erb @@ -16,8 +16,7 @@ }, { value: "title-or-slug", - text: "Search via title or slug", - hint_text: "This only applies to documents made in Whitehall publisher", + text: "Search via title", }, ] %> diff --git a/app/views/admin/document_collection_group_document_search/search_title_slug.html.erb b/app/views/admin/document_collection_group_document_search/search_title_slug.html.erb index 5b6c44d27d2..fdacddede67 100644 --- a/app/views/admin/document_collection_group_document_search/search_title_slug.html.erb +++ b/app/views/admin/document_collection_group_document_search/search_title_slug.html.erb @@ -14,7 +14,7 @@ <%= render "govuk_publishing_components/components/search", { name: "query", value: params[:query], - label_text: "Search by title or slug", + label_text: "Search by title", label_size: "l", } %> <% end %> @@ -27,7 +27,7 @@
<% if @results.empty? %> -

No documents found

+

No results found. Search again using the <%= link_to "full URL", "#", class: "govuk-link govuk-link--no-visited-state" %>.

<% else %>
<%= render "govuk_publishing_components/components/table", diff --git a/features/document-collections.feature b/features/document-collections.feature index d78c3ac97aa..3b8710a35d9 100644 --- a/features/document-collections.feature +++ b/features/document-collections.feature @@ -68,12 +68,12 @@ Feature: Grouping documents into a collection Then I can see that the heading has been updated to "Interesting new heading" @design-system-only - Scenario: Adding a document to a group via slug + Scenario: Adding a document to a group via title Given a document collection "Collection" exists And the document collection "Collection" has a group with the heading "Group" And a published document "Document 1" exists - When I select to add a new document to the collection group through "Search via title or slug" - And I search by "title or slug" for "Document 1" + When I select to add a new document to the collection group through "Search via title" + And I search by "title" for "Document 1" And I add "Document 1" to the document collection Then I should see "Document 1" in the list for the collection group "Group" diff --git a/test/functional/admin/document_collection_group_document_search_controller_test.rb b/test/functional/admin/document_collection_group_document_search_controller_test.rb index e1d31709bf2..16619fdd63e 100644 --- a/test/functional/admin/document_collection_group_document_search_controller_test.rb +++ b/test/functional/admin/document_collection_group_document_search_controller_test.rb @@ -69,7 +69,7 @@ class Admin::DocumentCollectionGroupDocumentSearchControllerTest < ActionControl @request_params[:query] = "Something " get :search_title_slug, params: @request_params assert_template "document_collection_group_document_search/search_title_slug" - assert_select ".govuk-body", text: /No documents found/ + assert_select ".govuk-body", text: /No results found. Search again using the full URL./ end view_test "GET #search_title_slug with an empty query string shows an alert flash" do