Fix removing item twice

Add spec which is fixed with this commit.

In the `sTagsArea` zone there are two elements with the same `data-val`:
the `<span class="amsify-select-tag>` containing the selected tag and
the `<li class="amsify-list-item" data-val="1">` containing the
suggested tag.

This means every time we call `removeTag`, the `removeTagByItem`
function is called twice, and might remove extra items.

Suggested PR:
c8765a6915
This commit is contained in:
taitus
2021-01-20 13:36:56 +01:00
parent 23f72d939a
commit f463baf14a
2 changed files with 12 additions and 2 deletions

View File

@@ -303,7 +303,17 @@ describe "SDG Relations", :js do
end end
scenario "allows remove a Goal" do scenario "allows remove a Goal" do
skip("Pending to fix removing item twice") process = create(:legislation_process, title: "SDG process")
process.sdg_goals = [SDG::Goal[1], SDG::Goal[2]]
visit sdg_management_edit_legislation_process_path(process)
find("li[data-code='1']").click
click_button "Update Process"
click_link "Marked as reviewed"
within("tr", text: "SDG process") do
expect(page).to have_css "td", exact_text: "2"
end
end end
end end

View File

@@ -626,7 +626,7 @@ var AmsifySuggestags;
removeTag: function(value, animate=true) { removeTag: function(value, animate=true) {
var _self = this; var _self = this;
$findTags = $(this.selectors.sTagsArea).find('[data-val="'+value+'"]'); $findTags = $(this.selectors.inputArea).find('[data-val="'+value+'"]');
if($findTags.length) { if($findTags.length) {
$findTags.each(function(){ $findTags.each(function(){
_self.removeTagByItem(this, animate); _self.removeTagByItem(this, animate);