From e8cc993120516043ff2a5f3224d9f59ec8d2b660 Mon Sep 17 00:00:00 2001 From: Patrick Cartlidge Date: Wed, 24 Jan 2024 16:37:04 +0000 Subject: [PATCH] Create new Design System layout Create design_system.html.erb layout. Make the ReportsController use the new layout. Create a helper to build the navigation link structure for the navbar. Write tests for the NavigationItems helper. --- app/controllers/reports_controller.rb | 2 + app/helpers/navigation_items_helper.rb | 16 +++++++ app/views/layouts/design_system.html.erb | 43 +++++++++++++++++++ .../helpers/naviation_items_helper_test.rb | 25 +++++++++++ 4 files changed, 86 insertions(+) create mode 100644 app/helpers/navigation_items_helper.rb create mode 100644 app/views/layouts/design_system.html.erb create mode 100644 test/unit/helpers/naviation_items_helper_test.rb diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index 8e5955aae..64c44955f 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -1,4 +1,6 @@ class ReportsController < ApplicationController + layout "design_system" + include ActionView::Helpers::TagHelper before_action :authenticate_user! diff --git a/app/helpers/navigation_items_helper.rb b/app/helpers/navigation_items_helper.rb new file mode 100644 index 000000000..fc7e3a058 --- /dev/null +++ b/app/helpers/navigation_items_helper.rb @@ -0,0 +1,16 @@ +module NavigationItemsHelper + def navigation_items(is_editor) + list = [ + { text: "Publications", href: root_path }, + ] + + if is_editor + list << { text: "Add artefact", href: new_artefact_path } + list << { text: "Downtime", href: downtimes_path } + end + + list << { text: "Reports", href: reports_path } + list << { text: "Search by user", href: user_search_path } + list << { text: "Sign out", href: "/auth/gds/sign_out" } + end +end \ No newline at end of file diff --git a/app/views/layouts/design_system.html.erb b/app/views/layouts/design_system.html.erb new file mode 100644 index 000000000..61a22a8c8 --- /dev/null +++ b/app/views/layouts/design_system.html.erb @@ -0,0 +1,43 @@ +<% environment = GovukPublishingComponents::AppHelpers::Environment.current_acceptance_environment %> + +<%= render "govuk_publishing_components/components/layout_for_admin", product_title: "Publisher", browser_title: yield(:page_title), environment: environment do %> + + <% render "layouts/google_tag_manager" %> + + <%= render "govuk_publishing_components/components/skip_link" %> + + <% user = current_user %> + + <%= render "govuk_publishing_components/components/layout_header", { + product_name: "Publisher", + environment: environment, + navigation_items: navigation_items(current_user.govuk_editor?) + } %> + +
+ <% [:success, :info, :warning, :danger, :notice, :alert].select { |k| flash[k].present? }.each do |k| %> + <% + case k + when :notice + alert_class = "success" + when :alert + alert_class = "danger" + else + alert_class = k + end + %> +
+ <%= flash[k] %> +
+ <% end %> + + <%= yield %> +
+ + <%= render "govuk_publishing_components/components/layout_footer", { + navigation: [], + } %> +<% end %> diff --git a/test/unit/helpers/naviation_items_helper_test.rb b/test/unit/helpers/naviation_items_helper_test.rb new file mode 100644 index 000000000..a4759ace0 --- /dev/null +++ b/test/unit/helpers/naviation_items_helper_test.rb @@ -0,0 +1,25 @@ +require "test_helper" + +class NavigationItemsHelperTest < ActionView::TestCase + context "NavigationItemsHelper" do + should "include editor only links when user is an editor" do + assert_equal [ + { text: "Publications", href: root_path }, + { text: "Add artefact", href: new_artefact_path }, + { text: "Downtime", href: downtimes_path }, + { text: "Reports", href: reports_path }, + { text: "Search by user", href: user_search_path }, + { text: "Sign out", href: "/auth/gds/sign_out" } + ], navigation_items(true) + end + + should "include not include editor only links when user is not an editor" do + assert_equal [ + { text: "Publications", href: root_path }, + { text: "Reports", href: reports_path }, + { text: "Search by user", href: user_search_path }, + { text: "Sign out", href: "/auth/gds/sign_out" } + ], navigation_items(false) + end + end +end \ No newline at end of file