Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare release and code cleanup header navigation #8447

Merged
merged 3 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions app/controllers/admin/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ def render_design_system(design_system_view, legacy_view)
end
end

def show_new_header?
current_user.can_preview_design_system?
end
helper_method :show_new_header?

private

def new_design_system?
Expand Down
19 changes: 1 addition & 18 deletions app/controllers/admin/more_controller.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
class Admin::MoreController < Admin::BaseController
before_action :check_new_design_system_permissions, only: %i[index]
layout :get_layout
layout "design_system"

def index; end

private

def check_new_design_system_permissions
forbidden! unless new_design_system?
end

def get_layout
design_system_actions = %w[index] if preview_design_system?(next_release: false)

if design_system_actions&.include?(action_name)
"design_system"
else
"admin"
end
end
end
4 changes: 1 addition & 3 deletions app/controllers/admin/new_document_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
class Admin::NewDocumentController < Admin::BaseController
before_action :check_new_design_system_permissions, only: %i[index]

layout :get_layout
layout "design_system"

def index; end

Expand Down
16 changes: 4 additions & 12 deletions app/views/layouts/design_system.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,16 @@
<% end %>

<%= render "govuk_publishing_components/components/layout_for_admin",
product_name: "Whitehall Publisher",
environment: environment,
browser_title: ("Error: " if yield(:error_summary).present?).to_s + sanitize((yield(:page_title).presence || yield(:title))) do %>
product_name: "Whitehall Publisher",
environment: environment,
browser_title: ("Error: " if yield(:error_summary).present?).to_s + sanitize((yield(:page_title).presence || yield(:title))) do %>

<!-- This element exists to initialise the JS module that configures custom Analytics behaviour -->
<div data-module="app-analytics"></div>

<%= render "govuk_publishing_components/components/skip_link" %>

<% if show_new_header? %>
<%= render partial: "shared/header" %>
<% else %>
<div class="legacy-whitehall">
<div class="environment-<%= environment %> navbar-wrapper">
<%= render partial: "shared/legacy_header" %>
</div>
</div>
<% end %>
<%= render partial: "shared/header" %>

<div class="govuk-width-container">
<%= render "shared/phase_banner", {
Expand Down
7 changes: 0 additions & 7 deletions app/views/shared/_header.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<% environment = GovukPublishingComponents::AppHelpers::Environment.current_acceptance_environment %>
<% admin_template ||= false %>
<% organisation = current_user&.organisation %>
<% user = current_user %>

Expand Down Expand Up @@ -46,9 +45,3 @@
],
} %>
</div>

<% if admin_template %>
<section class="notices">
<%= render partial: "shared/notices" %>
</section>
<% end %>
8 changes: 3 additions & 5 deletions features/support/document_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ def set_lead_organisation_on_document(organisation, order = 1)
def begin_drafting_document(options)
create(:organisation) if Organisation.count.zero?
visit admin_root_path
# Make sure the dropdown is visible first, otherwise Capybara won't see the links
find("li.create-new a", text: "New document").click
within "li.create-new" do
click_link options[:type].humanize
end
find("li.app-c-sub-navigation__list-item a", text: "New document").click
page.choose(options[:type].humanize)
click_button("Next")

if options[:locale]
check "Create a foreign language only"
Expand Down
1 change: 1 addition & 0 deletions features/support/person_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def person_image_path

def visit_people_admin
visit admin_root_path
click_link "More"
click_link "People"
end

Expand Down
1 change: 1 addition & 0 deletions features/support/topical_events_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
module TopicalEventsHelper
def create_topical_event_and_stub_in_content_store(options = {})
visit admin_root_path
click_link "More"
click_link "Topical events"
click_link "Create topical event"
fill_in "Name", with: options[:name] || "topic-name"
Expand Down
30 changes: 0 additions & 30 deletions test/functional/admin/base_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,36 +147,6 @@ class Admin::BaseControllerTest < ActionController::TestCase
assert_not_current_item("/government/admin/organisations/my-test-org/features")
end

view_test "only renders non-organisation header links if not logged in" do
# It's not possible, at the moment, to show the new design system layout if no user is signed in,
# but once we remove the legacy layout, the design system will be the default layout. In order to
# test this for now we stub some BaseController methods—this stubbing won't be necessary once the
# design system transition has been completed.
Admin::BaseController.any_instance.stubs(:show_new_header?).returns(true)
Admin::BaseController.any_instance.stubs(:preview_design_system?).returns(true)
@controller = Admin::NewDocumentController.new

get :index

assert_select ".app-c-sub-navigation__list .app-c-sub-navigation__list-item a[href=\"/government/admin/organisations/my-test-org/features\"]", false
assert_select ".app-c-sub-navigation__list .app-c-sub-navigation__list-item a[href=\"/government/admin/organisations/my-test-org/corporate_information_pages\"]", false

assert_select ".app-c-sub-navigation__list .app-c-sub-navigation__list-item a[href=\"/government/admin/new-document\"]"
assert_select ".app-c-sub-navigation__list .app-c-sub-navigation__list-item a[href=\"/government/admin/editions\"]"
assert_select ".app-c-sub-navigation__list .app-c-sub-navigation__list-item a[href=\"/government/admin/statistics_announcements\"]"
assert_select ".app-c-sub-navigation__list .app-c-sub-navigation__list-item a[href=\"/government/admin/more\"]"
end

view_test "renders legacy header component if login as a non design system user" do
login_as :gds_editor
@controller = Admin::NewDocumentController.new

get :index

assert_select ".govuk-header__navigation-item", false
assert_select ".nav.navbar-nav", text: /Dashboard/
end

private

def assert_not_current_item(path)
Expand Down
2 changes: 1 addition & 1 deletion test/functional/admin/more_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Admin::MoreControllerTest < ActionController::TestCase
setup do
login_as_preview_design_system_user :writer
login_as :writer
end

view_test "GET #index renders the 'More' page with a correctly formatted list of links" do
Expand Down
6 changes: 0 additions & 6 deletions test/functional/admin/new_document_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ class Admin::NewDocumentControllerTest < ActionController::TestCase
assert_select ".govuk-radios__item input[type=radio][name=new_document_options][value=fatality_notice]", count: 1
end

test "access to the New document index page is forbidden for users without design system permissions" do
login_as :writer
get :index
assert_response :forbidden
end

test "POST #new_document_options_redirect redirects each radio buttons to their expected paths" do
redirect_options.each do |selected_option, expected_path|
request_params = {
Expand Down