docbrown/spec/helpers/social_image_helper_spec.rb
Ben Halpern ec7adf56fe
Allow admins to set cover image height configs (#19936)
* Initial basic work

* Bulk of related work, including find/replace on the inputs

* Adjust some tests

* Adjust some specs

* Fix a few more tests

* Clean up tests

* Adjust tests

* Test fiddle

* Adjust crop back to be a param

* Update tests

* Set proper defaults

* Fix some styling

* Adjust enrichment logic and tests

* Adjust form JS

* Update test snapshot

* Clean up formatting

* Fix spec name

* Adjust some css and defaults

* Adjust translation for image provider options

* Switch from fill to fill-down

* Proper fallback image

* Fix tests

* Update app/services/images/optimizer.rb

Co-authored-by: Mac Siri <mac@forem.com>

---------

Co-authored-by: Mac Siri <mac@forem.com>
2023-08-21 13:25:16 -04:00

51 lines
2.1 KiB
Ruby

require "rails_helper"
describe SocialImageHelper do
let(:user) { create(:user) }
let(:article) { create(:article, main_image: nil) }
describe ".article_social_image_url" do
it "returns social preview path for newer articles" do
allow(Settings::General).to receive(:app_domain).and_return("hello.com")
url = helper.article_social_image_url(article)
expect(url).to eq article_social_preview_url(article, format: :png, host: "hello.com")
end
it "returns the main image if set", cloudinary: true do
article.main_image = Faker::CryptoCoin.url_logo
url = helper.article_social_image_url(article)
expect(url).to match(/#{article.main_image}/)
expect(url).to include("c_fill,f_auto,fl_progressive,h_500,q_auto,w_1000/")
end
it "returns older url2png image if already generated" do
article.updated_at = Articles::SocialImage::SOCIAL_PREVIEW_MIGRATION_DATETIME - 1.week
url = helper.article_social_image_url(article)
expect(url).to eq Images::GenerateSocialImage.call(article)
end
it "returns social preview path for newer decorated articles" do
allow(Settings::General).to receive(:app_domain).and_return("hello.com")
url = helper.article_social_image_url(article.decorate)
expect(url).to eq article_social_preview_url(article, format: :png, host: "hello.com")
end
it "returns correct manipulation of cloudinary links", cloudinary: true do
article.update_column(
:main_image,
"https://res.cloudinary.com/practicaldev/image/fetch/s--A-gun7rr--/c_imagga_scale,f_auto,fl_progressive,h_420,q_auto,w_1000/https://res.cloudinary.com/practicaldev/image/fetch/s--hcD8ZkbP--/c_imagga_scale%2Cf_auto%2Cfl_progressive%2Ch_420%2Cq_auto%2Cw_1000/https://dev-to-uploads.s3.amazonaws.com/i/th93d625o27nuz63oeen.png", # rubocop:disable Layout/LineLength
)
url = helper.article_social_image_url(article.decorate, width: 1600, height: 900)
expect(url.scan(/res.cloudinary.com/).length).to be 1
expect(url.scan(/w_1600/).length).to be 1
expect(url.scan(/w_1000/).length).to be 0
end
end
end