Add tests for budget images with brackets / quotes

This commit is contained in:
karim-semmoud
2023-06-13 11:38:27 +02:00
committed by Javi Martín
parent 5630a24d7a
commit 3a623c070f
4 changed files with 43 additions and 0 deletions

View File

@@ -36,4 +36,43 @@ describe Budgets::BudgetComponent do
end
end
end
describe "budget image" do
it "does not show a background image when the budget has no image" do
render_inline Budgets::BudgetComponent.new(budget)
expect(page).to have_css ".budget-header"
expect(page).not_to have_css ".with-background-image"
expect(page).not_to have_css ".budget-header[style*='background-image:']"
end
it "shows a background image when the bugdet image is defined" do
budget = create(:budget, :with_image)
render_inline Budgets::BudgetComponent.new(budget)
expect(page).to have_css ".budget-header.with-background-image"
expect(page).to have_css ".budget-header[style*='background-image:'][style*='clippy.jpg']"
end
it "quotes the background image filename so it works with filenames with brackets" do
budget.update!(image: create(:image, attachment: fixture_file_upload("clippy(with_brackets).jpg")))
render_inline Budgets::BudgetComponent.new(budget)
expect(page).to have_css ".budget-header.with-background-image"
expect(page).to have_css ".budget-header[style*='background-image:']"\
"[style*='url(\\''][style*='clippy(with_brackets).jpg\\'']"
end
it "escapes single quotes in the background image filename" do
budget.update!(image: create(:image, attachment: fixture_file_upload("clippy_with_'quotes'.jpg")))
render_inline Budgets::BudgetComponent.new(budget)
expect(page).to have_css ".budget-header.with-background-image"
expect(page).to have_css ".budget-header[style*='background-image:']"\
"[style*='url(\\''][style*='clippy_with_\\\\\'quotes\\\\\'.jpg']"
end
end
end