Skip to content

Commit 99003db

Browse files
committed
Refactored component to use box color from strapi
Updated mocks and testing Added previews for new components
1 parent eafc8d8 commit 99003db

File tree

11 files changed

+104
-22
lines changed

11 files changed

+104
-22
lines changed
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
# frozen_string_literal: true
22

33
class Cms::TwoColumnVideoSectionComponent < ViewComponent::Base
4-
def initialize(left_column_content:, video:, right_column_content: nil, background_color: nil, left_column_button: nil)
4+
def initialize(left_column_content:, video:, right_column_content: nil, background_color: nil, left_column_button: nil, box_color: nil)
55
@left_column_content = left_column_content
66
@video = video
77
@right_column_content = right_column_content
88
@background_color = background_color
99
@left_column_button = left_column_button
10+
@box_color = box_color
1011
end
1112

12-
def background_color_classes
13-
if @background_color == "isaac"
14-
"cms-two-column-video-section-component--wrapper__white"
13+
def content_background_color_classes
14+
classes = []
15+
16+
if @box_color
17+
classes << "cms-two-column-video-section-component__wrapper--padded"
18+
classes << "#{@box_color}-bg"
1519
else
16-
"cms-two-column-video-section-component--wrapper"
20+
classes << "cms-two-column-video-section-component__wrapper"
1721
end
22+
classes
1823
end
1924
end

app/components/cms/two_column_video_section_component/two_column_video_section_component.html.erb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<%= render GovGridRowComponent.new(background_color: @background_color, additional_classes: "cms-two-column-video-section-component") do |row| %>
22
<%= row.with_column("full") do %>
3-
<%= content_tag :div, class: background_color_classes do %>
4-
<div class="cms-two-column-video-section-component--left-content">
3+
<%= content_tag :div, class: content_background_color_classes do %>
4+
<div class="cms-two-column-video-section-component__left-content">
55
<%= render @left_column_content.render %>
66
<% if @left_column_button %>
77
<%= render @left_column_button.render %>
88
<% end %>
99
</div>
10-
<div class="cms-two-column-video-section-component--right-content">
10+
<div class="cms-two-column-video-section-component__right-content">
1111
<%= render @video.render %>
1212
<% if @right_column_content %>
13-
<div class="cms-two-column-video-section-component--right-text">
13+
<div class="cms-two-column-video-section-component__right-text">
1414
<%= render @right_column_content.render %>
1515
</div>
1616
<% end %>

app/components/cms/two_column_video_section_component/two_column_video_section_component.scss

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.cms-two-column-video-section-component {
2-
&--wrapper {
2+
&__wrapper {
33
display: flex;
44
gap: 30px;
55

@@ -8,10 +8,9 @@
88
gap: 15px;
99
}
1010

11-
&__white {
11+
&--padded {
1212
display: flex;
1313
gap: 30px;
14-
background-color: $white;
1514
padding: 15px;
1615

1716
@include govuk-media-query($until: tablet) {
@@ -21,7 +20,7 @@
2120
}
2221
}
2322

24-
&--left-content {
23+
&__left-content {
2524
width: 50%;
2625
flex: 0 0 calc(50% - 15px);
2726

@@ -30,7 +29,7 @@
3029
}
3130
}
3231

33-
&--right {
32+
&__right {
3433
&-content {
3534
width: 50%;
3635
flex: 0 0 calc(50% - 15px);

app/services/cms/dynamic_components/two_column_video_section.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
module Cms
22
module DynamicComponents
33
class TwoColumnVideoSection
4-
attr_accessor :left_column_content, :video, :right_column_content, :background_color, :left_column_button
4+
attr_accessor :left_column_content, :video, :right_column_content, :background_color, :left_column_button, :box_color
55

6-
def initialize(left_column_content:, video:, right_column_content:, background_color:, left_column_button:)
6+
def initialize(left_column_content:, video:, right_column_content:, background_color:, left_column_button:, box_color:)
77
@left_column_content = left_column_content
88
@video = video
99
@right_column_content = right_column_content
1010
@background_color = background_color
1111
@left_column_button = left_column_button
12+
@box_color = box_color
1213
end
1314

1415
def render
@@ -17,7 +18,8 @@ def render
1718
video:,
1819
right_column_content:,
1920
background_color:,
20-
left_column_button:
21+
left_column_button:,
22+
box_color:
2123
)
2224
end
2325
end

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ def self.to_two_column_video_section(strapi_data)
5858
video: to_embedded_video(strapi_data[:video]),
5959
right_column_content: to_content_block(strapi_data[:rightColumnContent]),
6060
background_color: extract_color_name(strapi_data, :bkColor),
61-
left_column_button: to_ncce_button(strapi_data[:leftColumnButton])
61+
left_column_button: to_ncce_button(strapi_data[:leftColumnButton]),
62+
box_color: extract_color_name(strapi_data, :boxColor),
6263
)
6364
end
6465

app/services/cms/providers/strapi/mocks/dynamic_components/two_column_video_section.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class TwoColumnVideoSection < StrapiMock
99
attribute(:leftColumnContent) { RichBlocks.generate_data }
1010
attribute(:rightColumnContent) { RichBlocks.generate_data }
1111
attribute(:bkColor) { ColorScheme.generate_data(name: "light_grey") }
12+
attribute(:boxColor) { ColorScheme.generate_data(name: "white") }
1213
attribute(:video) { Cms::Mocks::DynamicComponents::EmbeddedVideo.generate_data }
1314
attribute(:leftColumnButton) { Cms::Mocks::NcceButton.generate_data }
1415
end

app/services/cms/providers/strapi/queries/components/blocks/two_column_video_section.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def self.base_fields
1313
rightColumnContent
1414
#{ContentBlocks::EmbeddedVideo.embed(:video)}
1515
#{SharedFields.color_theme(:bkColor)}
16+
#{SharedFields.color_theme(:boxColor)}
1617
#{Buttons::NcceButton.embed(:leftColumnButton)}
1718
GRAPHQL
1819
end
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
class Cms::EmbeddedVideoComponentPreview < ViewComponent::Preview
4+
def local
5+
render(
6+
Cms::EmbeddedVideoComponent.new(
7+
url: "https://static.teachcomputing.org/How_important_is_the_I_Belong_programme.mp4"
8+
)
9+
)
10+
end
11+
12+
def youtube
13+
render(
14+
Cms::EmbeddedVideoComponent.new(
15+
url: "https://www.youtube.com/watch?v=-fTboqiyjxk&list=PLwcV67XMdDdJT0TkvZo6cTDSR0uJgP3Ku"
16+
)
17+
)
18+
end
19+
end
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
class Cms::TwoColumnVideoSectionComponentPreview < ViewComponent::Preview
2+
layout "full-width"
3+
4+
def default
5+
render Cms::TwoColumnVideoSectionComponent.new(
6+
left_column_content: Cms::Mocks::RichBlocks.as_model,
7+
video: Cms::Mocks::DynamicComponents::EmbeddedVideo.as_model
8+
)
9+
end
10+
11+
def with_right_column_content
12+
render Cms::TwoColumnVideoSectionComponent.new(
13+
left_column_content: Cms::Mocks::RichBlocks.as_model,
14+
video: Cms::Mocks::DynamicComponents::EmbeddedVideo.as_model,
15+
right_column_content: Cms::Mocks::RichBlocks.as_model
16+
)
17+
end
18+
19+
def with_background_color
20+
render Cms::TwoColumnVideoSectionComponent.new(
21+
left_column_content: Cms::Mocks::RichBlocks.as_model,
22+
video: Cms::Mocks::DynamicComponents::EmbeddedVideo.as_model,
23+
background_color: "isaac"
24+
)
25+
end
26+
27+
def with_button
28+
render Cms::TwoColumnVideoSectionComponent.new(
29+
left_column_content: Cms::Mocks::RichBlocks.as_model,
30+
video: Cms::Mocks::DynamicComponents::EmbeddedVideo.as_model,
31+
left_column_button: Cms::Mocks::NcceButton.as_model
32+
)
33+
end
34+
35+
def with_content_background_color
36+
render Cms::TwoColumnVideoSectionComponent.new(
37+
left_column_content: Cms::Mocks::RichBlocks.as_model,
38+
video: Cms::Mocks::DynamicComponents::EmbeddedVideo.as_model,
39+
left_column_button: Cms::Mocks::NcceButton.as_model,
40+
background_color: "isaac",
41+
box_color: "white"
42+
)
43+
end
44+
end

spec/components/cms/two_column_video_section_component_spec.rb

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,26 @@
5252
end
5353
end
5454

55-
context "with yellow background color" do
55+
context "with background colors" do
5656
before do
5757
render_inline(described_class.new(
5858
left_column_content: Cms::Mocks::RichBlocks.as_model,
5959
video: Cms::Mocks::DynamicComponents::EmbeddedVideo.as_model,
60-
background_color: "isaac"
60+
background_color: "isaac",
61+
box_color: "white"
6162
))
6263
end
6364

64-
it "has white background color for content" do
65-
expect(page).to have_css(".cms-two-column-video-section-component--wrapper__white")
65+
it "has yellow background color" do
66+
expect(page).to have_css(".isaac-bg")
67+
end
68+
69+
it "has padded wrapper class" do
70+
expect(page).to have_css(".cms-two-column-video-section-component__wrapper--padded")
71+
end
72+
73+
it "has content background color" do
74+
expect(page).to have_css(".white-bg")
6675
end
6776
end
6877

0 commit comments

Comments
 (0)