Skip to content

Commit 76fce4c

Browse files
committed
Adding testing for the Cms::ImageComponent
1 parent cc9114f commit 76fce4c

File tree

2 files changed

+75
-2
lines changed

2 files changed

+75
-2
lines changed

app/services/cms/providers/strapi/mocks/image.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ class Image
99
thumbnail: [250, 100]
1010
}
1111

12-
def self.as_model
13-
Factories::ModelFactory.as_image(generate_data)
12+
def self.as_model(caption: nil)
13+
Factories::ModelFactory.as_image(generate_data(caption:))
1414
end
1515

1616
def self.generate_raw_data(caption: nil)
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# frozen_string_literal: true
2+
3+
require "rails_helper"
4+
5+
RSpec.describe Cms::ImageComponent, type: :component do
6+
7+
let(:caption) { "This is a picture" }
8+
9+
context "with link" do
10+
before do
11+
render_inline(described_class.new(
12+
Cms::Mocks::Image.as_model,
13+
link: "https://www.google.com"
14+
))
15+
end
16+
17+
it "should show image" do
18+
expect(page).to have_css("img")
19+
end
20+
21+
it "should have link" do
22+
expect(page).to have_link(href: "https://www.google.com")
23+
end
24+
end
25+
26+
context "without caption" do
27+
before do
28+
render_inline(described_class.new(
29+
Cms::Mocks::Image.as_model,
30+
show_caption: false
31+
))
32+
end
33+
34+
it "should show image" do
35+
expect(page).to have_css("img")
36+
end
37+
end
38+
39+
context "with caption" do
40+
before do
41+
render_inline(described_class.new(
42+
Cms::Mocks::Image.as_model(caption:),
43+
show_caption: true
44+
))
45+
end
46+
47+
it "should show image" do
48+
expect(page).to have_css("img")
49+
end
50+
51+
it "should show caption" do
52+
expect(page).to have_text(caption)
53+
end
54+
end
55+
56+
context "with caption but show_caption is false" do
57+
before do
58+
render_inline(described_class.new(
59+
Cms::Mocks::Image.as_model(caption:),
60+
show_caption: false
61+
))
62+
end
63+
64+
it "should show image" do
65+
expect(page).to have_css("img")
66+
end
67+
68+
it "should not show caption" do
69+
expect(page).not_to have_text(caption)
70+
end
71+
end
72+
73+
end

0 commit comments

Comments
 (0)