Skip to content

Commit

Permalink
Correct how the tags helper gets the text for tags (#3398)
Browse files Browse the repository at this point in the history
* Correct how the tags helper gets the text for tags

It was getting the `label` attribute of `.tagify__tag` elements before but so far as I can see `.tagify__tag` elements do not have a label. Because of that the tags helper was always returning an array of `nil` values (one for each tag).

Instead I've changed them to get the text of the tag, which is what  the `wait_for_tag_to_appear` and  `wait_for_tag_to_disappear` helpers do. This correctly returns the text of the tag.

It looks like this was not spotted before because the only test in the avo test suite that uses the tags helper just checks that an empty array of tags is returned.

* tags helper test

* fix test

* wait_for_loaded

* acts_as_ordered_taggable_on

---------

Co-authored-by: Paul Bob <paul.ionut.bob@gmail.com>
Co-authored-by: Paul Bob <69730720+Paul-Bob@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 12, 2024
1 parent ab973b6 commit c9de4df
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/avo/test_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ def remove_tag(field:, tag:)
# expect(tags(field: :tags)).to eq []
def tags(field:)
# Find all elements with class 'tagify__tag'
# Map the elements to their 'label' attribute values and return the array of labels
page.all(".tagify__tag").map { |element| element[:label] }
# Map the elements to text and return the array of texts
page.all(".tagify__tag").map(&:text)
end

# Example usage:
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy/app/models/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Post < ApplicationRecord
has_many :comments, as: :commentable
has_many :reviews, as: :reviewable

acts_as_taggable_on :tags
acts_as_ordered_taggable_on :tags

before_save :update_slug

Expand Down
10 changes: 10 additions & 0 deletions spec/system/avo/test_helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,16 @@
expect(remove_tag(field: :tags, tag: "one")).to eq ["three"]
expect(tag_suggestions(field: :tags, input: "")).to eq ["one", "two"]
end

let!(:post) { create :post, tag_list: ["one", "two"] }

it "verify tags" do
visit avo.edit_resources_post_path(post)

wait_for_loaded

expect(tags(field: :tags)).to eq ["one", "two"]
end
# end
end
end
Expand Down

0 comments on commit c9de4df

Please sign in to comment.