Skip to content

Commit

Permalink
Add update service page for both claims and placements
Browse files Browse the repository at this point in the history
  • Loading branch information
gms-gs committed Dec 20, 2023
1 parent f3d22de commit 62added
Show file tree
Hide file tree
Showing 14 changed files with 253 additions and 11 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ gem "bootsnap", require: false
# gem 'image_processing', '~> 1.2'

gem "flipflop"
gem "redcarpet", "~> 3.6"

gem "govuk-components", "~> 5.0.0"
gem "govuk_design_system_formbuilder", "~> 5.0.0"
Expand Down
25 changes: 14 additions & 11 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ GEM
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
addressable (2.8.5)
addressable (2.8.6)
public_suffix (>= 2.0.2, < 6.0)
aes_key_wrap (1.1.0)
annotate (3.2.0)
Expand Down Expand Up @@ -176,7 +176,7 @@ GEM
activemodel (>= 6.1)
activesupport (>= 6.1)
html-attributes-utils (~> 1)
haml (6.2.3)
haml (6.3.0)
temple (>= 0.8.2)
thor
tilt
Expand All @@ -185,7 +185,7 @@ GEM
activesupport (>= 6.1.4.4)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
io-console (0.7.0)
io-console (0.6.0)
irb (1.10.1)
rdoc
reline (>= 0.3.8)
Expand Down Expand Up @@ -227,7 +227,7 @@ GEM
minitest (5.20.0)
msgpack (1.7.2)
mutex_m (0.2.0)
net-imap (0.4.7)
net-imap (0.4.8)
date
net-protocol
net-pop (0.1.2)
Expand All @@ -237,7 +237,7 @@ GEM
net-smtp (0.4.0)
net-protocol
nio4r (2.7.0)
nokogiri (1.15.5-arm64-darwin)
nokogiri (1.15.5-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.15.5-x86_64-linux)
racc (~> 1.4)
Expand Down Expand Up @@ -292,7 +292,7 @@ GEM
puma (6.4.0)
nio4r (~> 2.0)
racc (1.7.3)
rack (2.2.8)
rack (3.0.8)
rack-oauth2 (2.2.0)
activesupport
attr_required
Expand All @@ -302,13 +302,13 @@ GEM
rack (>= 2.1.0)
rack-protection (3.0.6)
rack
rack-session (1.0.2)
rack (< 3)
rack-session (2.0.0)
rack (>= 3.0.0)
rack-test (2.1.0)
rack (>= 1.3)
rackup (1.0.0)
rack (< 3)
webrick
rackup (2.1.0)
rack (>= 3)
webrick (~> 1.8)
rails (7.1.2)
actioncable (= 7.1.2)
actionmailbox (= 7.1.2)
Expand Down Expand Up @@ -352,6 +352,7 @@ GEM
rbs (2.8.4)
rdoc (6.6.1)
psych (>= 4.0.0)
redcarpet (3.6.0)
regexp_parser (2.8.3)
reline (0.4.1)
io-console (~> 0.5)
Expand Down Expand Up @@ -503,6 +504,7 @@ GEM
PLATFORMS
arm64-darwin-22
arm64-darwin-23
x86_64-darwin-22
x86_64-linux

DEPENDENCIES
Expand Down Expand Up @@ -536,6 +538,7 @@ DEPENDENCIES
rails (~> 7.1.2)
rails-controller-testing
rails-erd
redcarpet (~> 3.6)
rladr
rspec
rspec-rails
Expand Down
5 changes: 5 additions & 0 deletions app/assets/components/service_update/view.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<section id="<%= service_update.id %>">
<%= title_element %>
<p class="govuk-body govuk-!-margin-bottom-2"><%= date_pretty %></p>
<div class="govuk-body"><%= content_html %></div>
</section>
26 changes: 26 additions & 0 deletions app/assets/components/service_update/view.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class ServiceUpdate::View < GovukComponent::Base
attr_reader :service_update

delegate :title, :content, :date, to: :service_update

TITLE_CLASS = "govuk-heading-m govuk-!-margin-bottom-2"

def initialize(service_update:)
@service_update = service_update
end

def title_element
tag.h2(title, class: TITLE_CLASS)
end

def date_pretty
date.to_date.strftime("%e %B %Y")
end

def content_html
custom_render =
Redcarpet::Render::HTML.new(link_attributes: { class: "govuk-link" })
markdown = Redcarpet::Markdown.new(custom_render)
markdown.render(content).html_safe
end
end
10 changes: 10 additions & 0 deletions app/controllers/service_updates_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

class ServiceUpdatesController < ApplicationController
include ApplicationHelper

def index
@service_name ||= current_service
@service_updates = ServiceUpdate.where(service: @service_name)
end
end
34 changes: 34 additions & 0 deletions app/models/service_update.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
class ServiceUpdate
CLAIMS_SERVICE_UPDATES_YAML_FILE =
Rails.root.join("db/claims_service_updates.yml").freeze
PLACEMENTS_SERVICE_UPDATES_YAML_FILE =
Rails.root.join("db/placements_service_updates.yml").freeze

attr_accessor :date, :title, :content

def initialize(title:, date:, content:)
@title = title
@date = date
@content = content
end

def id
title.parameterize
end

def self.where(service:)
path = file_path(service:)
updates = YAML.load_file(path, symbolize_names: true) || []

updates.map { |service_update| new(**service_update) }
end

def self.file_path(service:)
case service
when :claims
CLAIMS_SERVICE_UPDATES_YAML_FILE
when :placements
PLACEMENTS_SERVICE_UPDATES_YAML_FILE
end
end
end
17 changes: 17 additions & 0 deletions app/views/service_updates/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">
<h1 class="govuk-heading-xl"><%= t("service_updates.#{@service_name}.heading") %></h1>

<h2 class="govuk-heading-m"><%= t("service_updates.contents") %></h2>
<ul class="govuk-list app-list--dash govuk-!-margin-bottom-8 govuk-!-margin-left-3">
<% @service_updates.each do |service_update| %>
<li><a class="govuk-link" href="#<%= service_update.id %>"><%= service_update.title %></a></li>
<% end %>
</ul>

<% @service_updates.each do |service_update| %>
<hr class="govuk-section-break govuk-section-break--l govuk-section-break--visible">
<%= render ServiceUpdate::View.new(service_update:) %>
<% end %>
</div>
</div>
1 change: 1 addition & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Application < Rails::Application
"node_modules/govuk-frontend/dist/govuk/assets"
)

config.autoload_paths += %W[#{config.root}/app/assets/components]
config.exceptions_app = routes
end
end
6 changes: 6 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,9 @@ en:
roles_include: "%{persona_name}’s role includes:"
sign_in_as: "Sign In as %{persona_name}"
title: Test users
service_updates:
claims:
heading: Claims news and updates
placements:
heading: Placements news and updates
contents: Contents
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
post("/auth/developer/callback", to: "sessions#callback")
end

resources :service_updates, only: %i[index]

draw :placements
draw :claims

Expand Down
11 changes: 11 additions & 0 deletions db/claims_service_updates.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Example structure for adding service updates

# - date:
# type: String
# format: YYYY-MM-DD
# title:
# type: String
# format: Short text
# content:
# type: String
# format: Multi-line text
11 changes: 11 additions & 0 deletions db/placements_service_updates.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Example structure for adding service updates

# - date:
# type: String
# format: YYYY-MM-DD
# title:
# type: String
# format: Short text
# content:
# type: String
# format: Multi-line text
72 changes: 72 additions & 0 deletions spec/models/service_update_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# spec/models/service_update_spec.rb

require "rails_helper"

RSpec.describe ServiceUpdate do
describe ".where" do
context "when service is :claims" do
it "returns updates for claims" do
allow(YAML).to receive(:load_file).and_return(
[
{
date: "2023-12-14",
title: "Claim Update",
content: "Some content"
}
]
)
updates = ServiceUpdate.where(service: :claims)
expect(updates.length).to eq(1)
expect(updates.first.title).to eq("Claim Update")
end

it "returns an empty hash when no updates for claims" do
allow(YAML).to receive(:load_file).and_return(nil)
updates = ServiceUpdate.where(service: :claims)
expect(updates).to eq([])
end
end

context "when service is :placements" do
it "returns updates for placements" do
allow(YAML).to receive(:load_file).and_return(
[
{
date: "2023-12-14",
title: "Placement Update",
content: "Some content"
}
]
)
updates = ServiceUpdate.where(service: :placements)
expect(updates.length).to eq(1)
expect(updates.first.title).to eq("Placement Update")
end

it "returns an empty hash when no updates for placements" do
allow(YAML).to receive(:load_file).and_return(nil)
updates = ServiceUpdate.where(service: :placements)
expect(updates).to eq([])
end
end
end

describe ".yaml_file" do
it "returns claims YAML file path" do
file_path = ServiceUpdate.file_path(service: :claims)
expect(file_path).to eq(Rails.root.join("db/claims_service_updates.yml"))
end

it "returns placements YAML file path" do
file_path = ServiceUpdate.file_path(service: :placements)
expect(file_path).to eq(
Rails.root.join("db/placements_service_updates.yml")
)
end

it "returns nil for unknown service" do
file_path = ServiceUpdate.file_path(service: :some_other_random_service)
expect(file_path).to be_nil
end
end
end
43 changes: 43 additions & 0 deletions spec/system/service_updates_page_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require "rails_helper"

RSpec.feature "Service updates page" do
after { Capybara.app_host = nil }

scenario "User visits the claims Service updates" do
given_i_am_on_the_claims_site
and_i_am_on_the_service_updates_page
i_can_see_the_claims_service_title
end

scenario "User visits the placements Service updates" do
given_i_am_on_the_placements_site
and_i_am_on_the_service_updates_page
i_can_see_the_placements_service_title
end

private

def given_i_am_on_the_claims_site
Capybara.app_host = "http://#{ENV["CLAIMS_HOST"]}"
end

def given_i_am_on_the_placements_site
Capybara.app_host = "http://#{ENV["PLACEMENTS_HOST"]}"
end

def and_i_am_on_the_service_updates_page
visit "/service_updates"
end

def i_can_see_the_claims_service_title
within(".govuk-heading-xl") do
expect(page).to have_content("Claims news and updates")
end
end

def i_can_see_the_placements_service_title
within(".govuk-heading-xl") do
expect(page).to have_content("Placements news and updates")
end
end
end

0 comments on commit 62added

Please sign in to comment.