Skip to content
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
4 changes: 3 additions & 1 deletion app/components/cms/page_title_component.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# frozen_string_literal: true

class Cms::PageTitleComponent < ViewComponent::Base
def initialize(title:, sub_text: nil, title_image: nil, title_video_url: nil, status_message: nil)
def initialize(title:, sub_text: nil, title_image: nil, title_video_url: nil, status_message: nil, background_color: nil, i_belong_flag: false)
@title = title
@sub_text = sub_text
@title_image = title_image
@title_video_url = title_video_url
@status_message = status_message
@background_color = background_color.presence || "lime-green"
@i_belong_flag = i_belong_flag
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= render GovGridRowComponent.new(background_color: "lime-green", padding: {top: 7, bottom: 7}) do |row| %>
<%= render GovGridRowComponent.new(background_color: @background_color, padding: {top: 7, bottom: 7}) do |row| %>
<%= row.with_column("full") do %>

<div class="page-title__wrapper">
Expand Down Expand Up @@ -26,6 +26,10 @@
<div class="page-title__media">
<%= render Cms::ImageComponent.new(@title_image, show_caption: false) %>
</div>
<% elsif @i_belong_flag %>
<div class="page-title__i-belong-flag">
<%= render IBelongFlagComponent.new %>
</div>
<% end %>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
background-color: $white;
display: flex;
flex-direction: column;

@include govuk-media-query($from: tablet) {
flex-direction: row;
}
Expand Down Expand Up @@ -87,4 +87,23 @@
}
}
}

&__i-belong-flag {
display: none; // no logo in mobile
grid-area: logo;
.i-belong-flag {
position: relative;
}
@include govuk-media-query($from: desktop) {
display: block;
text-align: right;
img {
margin: 0 2rem 2rem auto;
}
}

img {
display: block;
}
}
}
8 changes: 5 additions & 3 deletions app/services/cms/models/page_title.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
module Cms
module Models
class PageTitle
attr_accessor :title, :sub_text, :title_image, :title_video_url
attr_accessor :title, :sub_text, :title_image, :title_video_url, :background_color, :i_belong_flag

def initialize(title:, sub_text:, title_image: nil, title_video_url: nil)
def initialize(title:, sub_text:, title_image: nil, title_video_url: nil, background_color: nil, i_belong_flag: false)
@title = title
@sub_text = sub_text
@title_image = title_image
@title_video_url = title_video_url
@background_color = background_color
@i_belong_flag = i_belong_flag
end

def render
Cms::PageTitleComponent.new(title:, sub_text:, title_image:, title_video_url:)
Cms::PageTitleComponent.new(title:, sub_text:, title_image:, title_video_url:, background_color:, i_belong_flag:)
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion app/services/cms/providers/strapi/factories/model_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ def self.process_model(mapping, all_data)
title: strapi_data[:title],
sub_text: strapi_data[:subText],
title_image: to_image(strapi_data, :titleImage),
title_video_url: strapi_data[:titleVideoUrl]
title_video_url: strapi_data[:titleVideoUrl],
background_color: extract_color_name(strapi_data, :bkColor),
i_belong_flag: strapi_data[:iBelongFlag]
)
elsif model_class == Models::BlogPreview
to_blog_preview(strapi_data)
Expand Down
4 changes: 4 additions & 0 deletions app/services/cms/providers/strapi/mocks/page_title.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ module Mocks
class PageTitle < StrapiMock
attribute(:title) { Faker::Lorem.words(number: 5) }
attribute(:subText) { nil }
attribute(:titleImage) { nil }
attribute(:titleVideoUrl) { nil }
attribute(:bkColor) { nil }
attribute(:iBelongFlag) { false }
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions app/services/cms/providers/strapi/queries/page_title.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ def self.embed(name)
subText
titleVideoUrl
#{SharedFields.image_fields("titleImage")}
#{SharedFields.color_theme(:bkColor)}
iBelongFlag
}
GRAPHQL
end
Expand Down
17 changes: 17 additions & 0 deletions previews/components/cms/page_title_component_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,21 @@ def with_video
title_video_url: "https://www.youtube.com/watch?v=-fTboqiyjxk&list=PLwcV67XMdDdJT0TkvZo6cTDSR0uJgP3Ku"
))
end

def with_background_color
render(Cms::PageTitleComponent.new(
title: "Page title",
sub_text: "Welcome to the page",
background_color: "orange"
))
end

def with_i_belong_flag
render(Cms::PageTitleComponent.new(
title: "Page title",
sub_text: "Welcome to the page",
background_color: "orange",
i_belong_flag: true
))
end
end
28 changes: 28 additions & 0 deletions spec/components/cms/page_title_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
it "doesnt render status_message container when non present" do
expect(page).not_to have_css(".page-title__status-message")
end

it "applies the default background color" do
expect(page).to have_css(".lime-green-bg")
end

it "doesnt render i belong flag when false" do
expect(page).to_not have_css(".i-belong-flag")
end
end

context "With Media" do
Expand Down Expand Up @@ -82,4 +90,24 @@
expect(page).to have_css(".page-title__status-message", text: "You completed")
end
end

context "with background color" do
before do
render_inline(described_class.new(title: "Page title", background_color: "orange"))
end

it "applies the background class" do
expect(page).to have_css(".orange-bg")
end
end

context "with i belong flag" do
before do
render_inline(described_class.new(title: "Page title", i_belong_flag: true))
end

it "renders the i belong image" do
expect(page).to have_css(".i-belong-flag")
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require "rails_helper"

RSpec.describe Cms::Providers::Strapi::Queries::PageTitle do
it_should_behave_like "a strapi graphql embed", {key: "pageTitle",
required_fields: %w[
title
subText
titleImage
titleVideoUrl
bkColor
iBelongFlag
]}
end
2 changes: 1 addition & 1 deletion spec/support/cms/providers/strapi/schema.json

Large diffs are not rendered by default.