Skip to content

Commit

Permalink
Merge pull request #2219 from tvdeyen/2216-fix-image-cropper
Browse files Browse the repository at this point in the history
fix(ImageCropper): Add dom ids to picture crop fields
  • Loading branch information
tvdeyen authored Nov 23, 2021
2 parents 2f6f82c + d629309 commit ff981e0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/views/alchemy/ingredients/_picture_editor.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<%= f.hidden_field :link_title, data: { link_title: true }, id: nil %>
<%= f.hidden_field :link_class_name, data: { link_class: true }, id: nil %>
<%= f.hidden_field :link_target, data: { link_target: true }, id: nil %>
<%= f.hidden_field :crop_from, data: { crop_from: true }, id: nil %>
<%= f.hidden_field :crop_size, data: { crop_size: true }, id: nil %>
<%= f.hidden_field :crop_from, data: { crop_from: true }, id: picture_editor.form_field_id(:crop_from) %>
<%= f.hidden_field :crop_size, data: { crop_size: true }, id: picture_editor.form_field_id(:crop_size) %>
<% end %>
<% end %>
11 changes: 10 additions & 1 deletion spec/views/alchemy/ingredients/picture_editor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
let(:picture) { stub_model(Alchemy::Picture) }
let(:element) { build_stubbed(:alchemy_element, name: "all_you_can_eat_ingredients") }
let(:element_editor) { Alchemy::ElementEditor.new(element) }
let(:ingredient_editor) { Alchemy::IngredientEditor.new(ingredient) }

let(:ingredient) do
stub_model(
Expand All @@ -22,7 +23,7 @@
it_behaves_like "an alchemy ingredient editor"

before do
allow(element_editor).to receive(:ingredients) { [Alchemy::IngredientEditor.new(ingredient)] }
allow(element_editor).to receive(:ingredients) { [ingredient_editor] }
allow(ingredient).to receive(:settings) { settings }
view.class.send :include, Alchemy::Admin::BaseHelper
view.class.send :include, Alchemy::Admin::IngredientsHelper
Expand Down Expand Up @@ -66,6 +67,14 @@
it "shows cropping link" do
is_expected.to have_selector('a[href*="crop"]')
end

it "has crop_from hidden field" do
is_expected.to have_selector("input[type=\"hidden\"][id=\"#{ingredient_editor.form_field_id(:crop_from)}\"]")
end

it "has crop_size hidden field" do
is_expected.to have_selector("input[type=\"hidden\"][id=\"#{ingredient_editor.form_field_id(:crop_size)}\"]")
end
end

context "with image cropping disabled" do
Expand Down

0 comments on commit ff981e0

Please sign in to comment.