Skip to content

Commit e75a7d1

Browse files
A-Wheetomsquance-stem
authored andcommitted
Added new feedback banner cms component
Adding to block factory, queries and dynamic zone Testing for all the above
1 parent b6d9a1a commit e75a7d1

File tree

12 files changed

+149
-0
lines changed

12 files changed

+149
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal: true
2+
3+
class Cms::FeedbackBannerComponent < ViewComponent::Base
4+
def initialize(title:, button:)
5+
@title = title
6+
@button = button
7+
end
8+
end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<%= render GovGridRowComponent.new do |row| %>
2+
<%= row.with_column("full") do %>
3+
<div class="cms-feedback-banner-component">
4+
<h2 class="govuk-heading-m"><%= @title %></h2>
5+
<%= render @button.render %>
6+
<p class="govuk-body govuk-!-margin-bottom-0">
7+
Or email us at <a class="govuk-link ncce-link" href="mailto: info@teachcomputing.org">info@teachcomputing.org</a>
8+
</p>
9+
</div>
10+
<% end %>
11+
<% end %>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.cms-feedback-banner-component {
2+
border: 3px solid $hyper-link-blue;
3+
padding: 32px;
4+
5+
.govuk-button {
6+
@include govuk-media-query($until: desktop) {
7+
margin-bottom: 16px;
8+
}
9+
}
10+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module Cms
2+
module DynamicComponents
3+
module Blocks
4+
class FeedbackBanner
5+
attr_accessor :title, :button
6+
7+
def initialize(title:, button:)
8+
@title = title
9+
@button = button
10+
end
11+
12+
def render
13+
Cms::FeedbackBannerComponent.new(title:, button:)
14+
end
15+
end
16+
end
17+
end
18+
end

app/services/cms/providers/strapi/factories/blocks_factory.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,18 @@ def self.generate_component(component_name, strapi_data)
6767
DynamicComponents::SecondaryQuestionBank.new(title: strapi_data[:title])
6868
when "button-block"
6969
to_button_block(strapi_data)
70+
when "feedback-banner"
71+
to_feedback_banner(strapi_data)
7072
end
7173
end
7274

75+
def self.to_feedback_banner(strapi_data)
76+
DynamicComponents::Blocks::FeedbackBanner.new(
77+
title: strapi_data[:title],
78+
button: to_ncce_button(strapi_data[:button])
79+
)
80+
end
81+
7382
def self.to_button_block(strapi_data)
7483
DynamicComponents::Blocks::ButtonBlock.new(
7584
buttons: strapi_data[:buttons].map { to_ncce_button(_1) },
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module Cms
2+
module Providers
3+
module Strapi
4+
module Mocks
5+
module DynamicComponents
6+
module Blocks
7+
class FeedbackBanner < StrapiMock
8+
strapi_component "blocks.feedback-banner"
9+
10+
attribute(:title) { Faker::Lorem.sentence }
11+
attribute(:button) { Cms::Mocks::NcceButton.generate_data }
12+
end
13+
end
14+
end
15+
end
16+
end
17+
end
18+
end
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module Cms
2+
module Providers
3+
module Strapi
4+
module Queries
5+
module Components
6+
module Blocks
7+
class FeedbackBanner < BaseComponentQuery
8+
def self.name = "ComponentBlocksFeedbackBanner"
9+
10+
def self.base_fields
11+
<<~GRAPHQL.freeze
12+
fbb__title: title
13+
fbb__button: #{Buttons::NcceButton.embed(:button)}
14+
GRAPHQL
15+
end
16+
end
17+
end
18+
end
19+
end
20+
end
21+
end
22+
end

app/services/cms/providers/strapi/queries/dynamic_zone.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class DynamicZone
99
Components::Blocks::CourseCardsSection,
1010
Components::Blocks::EnrolmentSplitCourseCard,
1111
Components::Blocks::EnrolmentTestimonial,
12+
Components::Blocks::FeedbackBanner,
1213
Components::Blocks::FullWidthBanner,
1314
Components::Blocks::FullWidthImageBanner,
1415
Components::Blocks::FullWidthText,
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# frozen_string_literal: true
2+
3+
class Cms::FeedbackBannerComponentPreview < ViewComponent::Preview
4+
def default
5+
render(Cms::FeedbackBannerComponent.new(
6+
title: "title",
7+
button: Cms::Mocks::NcceButton.as_model
8+
))
9+
end
10+
end
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# frozen_string_literal: true
2+
3+
require "rails_helper"
4+
5+
RSpec.describe Cms::FeedbackBannerComponent, type: :component do
6+
before do
7+
render_inline(described_class.new(
8+
title: "Help us make these resources better",
9+
button: Cms::Mocks::NcceButton.as_model
10+
))
11+
end
12+
13+
it "renders the title" do
14+
expect(page).to have_text("Help us make these resources better")
15+
end
16+
17+
it "renders the ncce button" do
18+
expect(page).to have_css(".govuk-button")
19+
end
20+
end

0 commit comments

Comments
 (0)