-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add update service page for both claims and placements
- Loading branch information
Showing
14 changed files
with
253 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |