From 61142b1570029997e833115c165235082f93733c Mon Sep 17 00:00:00 2001 From: Claire Carden <96350691+smclairecarden@users.noreply.github.com> Date: Wed, 3 Apr 2024 19:16:30 -0500 Subject: [PATCH] AO3-6608 Delete Alt Text With Pseud Icon (#4765) * AO3-6608 - fix the bug * AO3-6608 - write a test * AO3-6608 - make rubocop happy * AO3-6608 - address pr feedback * AO3-6608 - rubocop * Update app/models/pseud.rb --- app/models/pseud.rb | 5 ++++- features/collections/icon.feature | 12 ++++++++++++ features/step_definitions/icon_steps.rb | 11 +++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/app/models/pseud.rb b/app/models/pseud.rb index 91940f84131..ac298bc5fee 100644 --- a/app/models/pseud.rb +++ b/app/models/pseud.rb @@ -418,7 +418,10 @@ def delete_icon alias_method :delete_icon?, :delete_icon def clear_icon - self.icon = nil if delete_icon? && !icon.dirty? + return unless delete_icon? + + self.icon = nil unless icon.dirty? + self.icon_alt_text = nil end ################################# diff --git a/features/collections/icon.feature b/features/collections/icon.feature index 6d9a5495a21..e7e5ab86106 100644 --- a/features/collections/icon.feature +++ b/features/collections/icon.feature @@ -40,3 +40,15 @@ Feature: User icons When I delete the icon from the collection "Pretty" Then I should see "Collection was successfully updated." And the "Pretty" collection should not have an icon + + Scenario: Users can delete icon and alt text + + Given I have an icon uploaded + When I follow "Edit Pseud" + And I fill in "pseud_icon_alt_text" with "Some test description" + And I press "Update" + Then I should see the image "alt" text "Some test description" + When I delete the icon from my pseud + Then I should see "Pseud was successfully updated." + When I follow "Edit Pseud" + Then I should see the icon and alt text boxes are blank diff --git a/features/step_definitions/icon_steps.rb b/features/step_definitions/icon_steps.rb index 6edd808c42b..0cb200d2d80 100644 --- a/features/step_definitions/icon_steps.rb +++ b/features/step_definitions/icon_steps.rb @@ -34,6 +34,12 @@ step %{I press "Update"} end +When "I delete the icon from my pseud" do + visit edit_user_pseud_path(User.current_user, User.current_user.default_pseud) + check("pseud_delete_icon") + step %{I press "Update"} +end + Then /^the "([^"]*)" collection should have an icon$/ do |title| collection = Collection.find_by(title: title) assert !collection.icon_file_name.blank? @@ -45,3 +51,8 @@ end ### THEN + +Then "I should see the icon and alt text boxes are blank" do + expect(find("#pseud_icon").value).to be_blank + expect(find("#pseud_icon_alt_text").value).to be_nil +end