Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix removing existing image and adding a new one #4599

Merged
merged 3 commits into from
Jul 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/assets/javascripts/imageable.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
$("#nested-image").on("cocoon:after-remove", function() {
$("#new_image_link").removeClass("hide");
});
$("#nested-image").on("cocoon:before-insert", function() {
$(".js-image-attachment").closest(".image").remove();
});
$("#nested-image").on("cocoon:after-insert", function(e, nested_image) {
var input;
$("#new_image_link").addClass("hide");
Expand Down
3 changes: 1 addition & 2 deletions app/assets/stylesheets/mixins/uploads.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@

.attachment-errors {

> .js-image-attachment,
> .js-document-attachment {
> [type=file] {
@include element-invisible;

~ .error {
Expand Down
24 changes: 11 additions & 13 deletions spec/shared/system/nested_imageable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,38 +207,36 @@
end

if path.include? "edit"
scenario "Should show persisted image" do
scenario "show persisted image" do
create(:image, imageable: imageable)
do_login_for user
visit send(path, arguments)

expect(page).to have_css ".image", count: 1
end

scenario "Should not show add image button when image already exists" do
create(:image, imageable: imageable)
do_login_for user
visit send(path, arguments)

expect(page).to have_css ".image", count: 1
expect(page).not_to have_css "a#new_image_link"
end

scenario "Should remove nested field after remove image" do
scenario "remove nested field after removing the image" do
create(:image, imageable: imageable)
do_login_for user

visit send(path, arguments)
click_on "Remove image"
click_link "Remove image"

expect(page).not_to have_css ".image"
expect(page).to have_css "a#new_image_link"
end

scenario "Should show add image button after remove image" do
scenario "don't duplicate fields after removing and adding an image" do
create(:image, imageable: imageable)
do_login_for user

visit send(path, arguments)
click_on "Remove image"
click_link "Remove image"
click_link "Add image"

expect(page).to have_css "a#new_image_link"
expect(page).to have_css ".image", count: 1, visible: :all
end
end
end
Expand Down