|
3 | 3 | require "rails_helper" |
4 | 4 |
|
5 | 5 | RSpec.describe Cms::CourseCardComponent, type: :component do |
| 6 | + let(:course) {Achiever::Course::Template.all.first} |
6 | 7 | before do |
7 | 8 | stub_course_templates |
8 | 9 | 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 | | - )) |
17 | 10 | end |
18 | 11 |
|
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 |
21 | 38 | end |
22 | 39 |
|
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 | + |
25 | 55 | end |
26 | 56 |
|
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 |
29 | 71 | end |
30 | 72 |
|
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 |
33 | 88 | end |
34 | 89 | end |
0 commit comments