Skip to content

Commit

Permalink
Merge pull request #162 from Christine-horrocks/Add_highlight_to_lists
Browse files Browse the repository at this point in the history
Add highlight to lists
  • Loading branch information
katylouise authored Jan 30, 2019
2 parents 0eecc86 + a41db87 commit a9f75da
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 4 deletions.
5 changes: 4 additions & 1 deletion app/controllers/statutory_instruments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ def index

heading = ComponentSerializer::Heading1ComponentSerializer.new(heading: I18n.t('statutory_instruments.index.title'))

serializer = PageSerializer::ListPageSerializer.new(request: request, heading_component: heading, list_components: list_components, data_alternates: @alternates)
status_text = ComponentSerializer::ParagraphComponentSerializer.new(content: [ContentDataHelper.content_data(content: 'statutory-instruments.index.status-message', link: find_a_statutory_instrument_path)]).to_h
status = ComponentSerializer::StatusComponentSerializer.new(type: 'highlight', display_data: [{ component: 'status', variant: 'highlight' }], components: [status_text])

serializer = PageSerializer::ListPageSerializer.new(request: request, heading_component: heading, status_component: status, list_components: list_components, data_alternates: @alternates)

render_page(serializer)
end
Expand Down
8 changes: 6 additions & 2 deletions app/serializers/page_serializer/list_page_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ class ListPageSerializer < PageSerializer::BasePageSerializer
# @param [ComponentSerializer::Heading1ComponentSerializer] heading_component a heading object used for heading information
# @param [Array<Hash>] list_components an array of components to be passed into the list
# @param [Array<Hash>] data_alternates array containing the href and type of the alternative data url
def initialize(request: nil, heading_component: nil, list_components: nil, data_alternates: nil)
def initialize(request: nil, heading_component: nil, status_component: nil, list_components: nil, data_alternates: nil)
@heading_component = heading_component
@status_component = status_component
@list_components = list_components
@data_alternates = data_alternates

Expand All @@ -28,7 +29,10 @@ def content
end

def section_primary_components
[@heading_component.to_h]
[].tap do |content|
content << @heading_component.to_h
content << @status_component.to_h if @status_component
end
end

def section_components
Expand Down
5 changes: 4 additions & 1 deletion spec/controllers/statutory_instruments_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@
end

let(:heading) { 'a heading component' }
let(:status) {'a status component'}

before(:each) do
allow(PageSerializer::ListPageSerializer).to receive(:new)
allow(ComponentSerializer::Heading1ComponentSerializer).to receive(:new).with(heading: 'Statutory instruments') { heading }
allow(ComponentSerializer::StatusComponentSerializer).to receive(:new).with(type: 'highlight', display_data: [{ component: 'status', variant: 'highlight' }], components: [{"data"=> [{"content"=>"statutory-instruments.index.status-message", "data"=>{"link"=>"/find-a-statutory-instrument"}}],"name"=>"paragraph"}]) { status }


allow(controller.request).to receive(:env).and_return({ 'ApplicationInsights.request.id' => '|1234abcd.' })

Expand Down Expand Up @@ -53,7 +56,7 @@
'list-description' =>
{ 'data' => { 'items'=>[{ 'description' => [{ 'content' => 'shared.time-html', 'data' => { 'date' => '23 April 2018', 'datetime-value' => '2018-04-23' } }], 'term' => { 'content'=>'laid-thing.laid-date' } }, { 'description' => [{ 'content'=>'groupName - 1' }], 'term' => { 'content'=>'laid-thing.laying-body' } }, { 'description' => [{ 'content'=>'procedureName - 1' }], 'term' => { 'content'=>'laid-thing.procedure' } }] }, 'name' => 'list__description' } }, 'name' => 'card__generic' }]

expect(PageSerializer::ListPageSerializer).to have_received(:new).with(request: request, heading_component: heading, list_components: list_components, data_alternates: data_alternates)
expect(PageSerializer::ListPageSerializer).to have_received(:new).with(request: request, heading_component: heading, status_component: status, list_components: list_components, data_alternates: data_alternates)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ main-components:
data:
heading:
content: Statutory instruments
- name: status__highlight
data:
display:
name: partials__display
data:
- component: status
variant: highlight
components:
- name: paragraph
data:
- content: statutory-instruments.index.status-message
data:
link: "/find-a-statutory-instrument"
- name: section__section
data:
components:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
---
layout:
template: layout
meta:
title: some meta heading - UK Parliament
request-id: 123456
open-graph:
title: some meta heading - UK Parliament
original-url: https://example.com/
image-url: https://static.parliament.uk/assets-public/opengraph-oblong.png
image-width: '1200'
image-height: '630'
twitter-card: summary_large_image
opensearch-description-url: https://example.com/search/opensearch
header-components:
- name: link
data:
link: "#content"
display:
name: partials__display
data:
- component: skip-to-content
selector: skiplink
content: shared.header.skip-to-content
- name: status__banner
data:
display:
name: partials__display
data:
- component: status
variant: banner
- component: theme
variant: caution
- component: cookie
selector: cookie
components:
- name: paragraph
data:
- content: shared.header.cookie-banner-text
data:
link: "/meta/cookie-policy"
- name: status__banner
data:
display:
name: partials__display
data:
- component: status
variant: banner
components:
- name: paragraph
data:
- content: shared.header.beta-status
- name: header
data:
components:
- name: link
data:
link: "/"
display:
name: partials__display
data:
- component: uk_parliament
label: shared.header.label
components:
- name: icon__uk-parliament
data: shared.header.label
- name: form__search
data:
global: true
label: search.label
components:
- name: icon__search
data: search.search-icon
search-action: "/search"
main-components:
- name: section__primary
data:
content-flag: true
components:
- name: heading1
data:
heading:
content: Test page
- name: status__highlight
data:
display:
- name: partials__display
data:
- component: status
variant: highlight
components:
name: paragraph
data:
- content: search.new-search
- name: section__section
data:
components:
- name: list__generic
data:
type: ol
display:
name: partials__display
data:
- component: list
variant: block
components:
- list-component: list component
footer-components:
- name: footer
data:
heading:
name: heading
data:
content: shared.meta.title
size: 2
list-generic:
name: list__generic
data:
type: ul
display:
name: partials__display
data:
- component: list
contents:
- content: shared.footer.current-website
- content: shared.footer.cookie-policy
data:
link: "/meta/cookie-policy"
- content: shared.footer.data-protection-privacy
9 changes: 9 additions & 0 deletions spec/serializers/page_serializer/list_page_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

# let(:heading) { double('heading', heading_content: 'Test page', subheading_content: nil, linkify_subheading: nil, to_h: { name: 'heading1', data: { heading: { content: 'Test page' } } }) }
let(:heading) { double('heading', to_s: 'some meta heading', to_h: { name: 'heading1', data: { heading: { content: 'Test page' } } }) }
let(:status) { double('status', to_s: 'some status information', to_h: { name: 'status__highlight', data: { display: [{ name: "partials__display", data: [{ component: "status", variant: "highlight" }] }], components: { name: "paragraph", data: [{ content: "search.new-search" }] } } }) }

subject { described_class.new(request: request, heading_component: heading, list_components: [{ list_component: 'list component' }]) }

Expand Down Expand Up @@ -67,6 +68,14 @@

expect(serializer.to_yaml).to eq expected
end

it 'produces the expected JSON hash when a status is given' do
serializer = described_class.new(request: request, heading_component: heading, status_component: status,list_components: [{ list_component: 'list component' }])

expected = get_fixture('with_status')

expect(serializer.to_yaml).to eq expected
end
end
end
end

0 comments on commit a9f75da

Please sign in to comment.