Skip to content

Commit a0204d5

Browse files
committed
Fixing layout issues raised in QA
Fixing the link if no title supplied Allow description to be nil as well Updated testing
1 parent d022726 commit a0204d5

File tree

4 files changed

+84
-20
lines changed

4 files changed

+84
-20
lines changed

app/components/cms/course_card_component.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ class Cms::CourseCardComponent < ViewComponent::Base
66
to: :helpers
77

88
def initialize(title:, banner_text:, course:, description:, image:)
9-
@title = title
109
@banner_text = banner_text
1110
@course = course
11+
@title = title.presence || @course&.title
1212
@description = description
1313
@image = image
1414
end

app/components/cms/course_card_component/course_card_component.html.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
<%= link_to @title, course_path(id: @course.activity_code, name: @course.title.parameterize), class: 'govuk-!-font-weight-bold govuk-body ncce-link' %>
1313
<div class="courses-cms-card__details">
14-
<p class="govuk-body">
15-
<%= render @description.render %>
16-
</p>
14+
<div class="courses-cms-card__details-content">
15+
<%= render @description.render if @description %>
16+
</div>
1717
<div class="courses-cms-card__icons">
1818
<div>
1919
<span class="govuk-body-s <%= course_meta_icon_class(@course) %> courses-cms-card__type">

app/components/cms/course_card_component/course_card_component.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11

22
.courses-cms-card {
3+
display: flex;
4+
flex-direction: column;
5+
flex: 1 1 auto;
36

47
&__image-wrapper {
58
margin-bottom: 12px;
@@ -36,6 +39,12 @@
3639
display: flex;
3740
flex-direction: column;
3841
justify-content: space-between;
42+
43+
flex: 1 1 auto;
44+
45+
&-content {
46+
flex: 1 1 auto;
47+
}
3948
}
4049

4150
&__icons {

spec/components/cms/course_card_component_spec.rb

Lines changed: 71 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,87 @@
33
require "rails_helper"
44

55
RSpec.describe Cms::CourseCardComponent, type: :component do
6+
let(:course) {Achiever::Course::Template.all.first}
67
before do
78
stub_course_templates
89
stub_duration_units
9-
@course = Achiever::Course::Template.all.first
10-
render_inline(described_class.new(
11-
title: "Learn how to teach computing",
12-
banner_text: "Banner text",
13-
course: @course,
14-
description: Cms::Mocks::RichBlocks.as_model,
15-
image: Cms::Mocks::Image.as_model
16-
))
1710
end
1811

19-
it "renders the banner text and makes it uppercase" do
20-
expect(page).to have_css(".courses-cms-card__banner", text: "BANNER TEXT")
12+
context "given title" do
13+
before do
14+
render_inline(described_class.new(
15+
title: "Learn how to teach computing",
16+
banner_text: "Banner text",
17+
course: course,
18+
description: Cms::Mocks::RichBlocks.as_model,
19+
image: Cms::Mocks::Image.as_model
20+
))
21+
end
22+
23+
it "renders the banner text and makes it uppercase" do
24+
expect(page).to have_css(".courses-cms-card__banner", text: "BANNER TEXT")
25+
end
26+
27+
it "renders title as link" do
28+
expect(page).to have_link("Learn how to teach computing", href: "/courses/#{course.activity_code}/#{course.title.parameterize}")
29+
end
30+
31+
it "renders description" do
32+
expect(page).to have_css(".cms-rich-text-block-component")
33+
end
34+
35+
it "renders image" do
36+
expect(page).to have_css(".cms-image")
37+
end
2138
end
2239

23-
it "renders title as link" do
24-
expect(page).to have_link("Learn how to teach computing", href: "/courses/#{@course.activity_code}/#{@course.title.parameterize}")
40+
context "without title" do
41+
before do
42+
render_inline(described_class.new(
43+
title: nil,
44+
banner_text: "Banner text",
45+
course:,
46+
description: Cms::Mocks::RichBlocks.as_model,
47+
image: Cms::Mocks::Image.as_model
48+
))
49+
end
50+
51+
it "renders title as link" do
52+
expect(page).to have_link(course.title, href: "/courses/#{course.activity_code}/#{course.title.parameterize}")
53+
end
54+
2555
end
2656

27-
it "renders description" do
28-
expect(page).to have_css(".cms-rich-text-block-component")
57+
context "when course is nil" do
58+
before do
59+
render_inline(described_class.new(
60+
title: nil,
61+
banner_text: "Banner text",
62+
course: nil,
63+
description: Cms::Mocks::RichBlocks.as_model,
64+
image: Cms::Mocks::Image.as_model
65+
))
66+
end
67+
68+
it "doesnt render" do
69+
expect(page).not_to have_css(".courses-cms-card")
70+
end
2971
end
3072

31-
it "renders image" do
32-
expect(page).to have_css(".cms-image")
73+
74+
context "when description is nil" do
75+
before do
76+
render_inline(described_class.new(
77+
title: nil,
78+
banner_text: "Banner text",
79+
course:,
80+
description: nil,
81+
image: Cms::Mocks::Image.as_model
82+
))
83+
end
84+
85+
it "does render" do
86+
expect(page).to have_css(".courses-cms-card")
87+
end
3388
end
3489
end

0 commit comments

Comments
 (0)