docbrown/spec/helpers/listing_helper_spec.rb
Miguel Nieto A 148f242892
Replace listings tag component (#16855)
* wip

* feat:  Use MultiSelectAutocomplete for Tags

* feat:  Add additional tags for listings

* refactor: ♻️ Use preact/hooks and refactor propTypes

* fix: 🐛 Fix addiional tags support depending on the selected category

- Add slug to returned array in select_options_for_categories helper
- Differentiate the fields categoryId and categorySlug

* fix: 🐛 Adjust propTypes

* test: 🚨 Change test for select_options_for_categories helper

* refactor: ♻️ Apply requested changes

* refactor: ♻️ Remove border prop - default is true

* test: 🚨 Add test suite for ListingTagsField component

* refactor: ♻️ Apply requested changes

* refactor: ♻️ Remove unnecessary forEach + Improve code legibility

* docs: 📚 Remove topTags from hook documentation

* refactor: ♻️ Use the alias for crayons folder + Use loclaCompare in sort

* test: 🚨 Clean up mock response

* fix: 🐛 Reorder styles

* style: 🎨 Add comment to TagAutocompleteOption/Selection components
2022-03-30 16:51:40 +01:00

40 lines
1.2 KiB
Ruby

require "rails_helper"
RSpec.describe ListingHelper, type: :helper do
let!(:cat1) { create(:listing_category, cost: 1) }
let!(:cat2) { create(:listing_category, :cfp, cost: 5) }
describe "select_options_for_categories" do
it "returns the correct options array" do
expect(helper.select_options_for_categories).to match_array(
[
["#{cat1.name} (1 Credit)", cat1.slug, cat1.id],
["#{cat2.name} (5 Credits)", cat2.slug, cat2.id],
],
)
end
end
describe "categories_for_display" do
it "return the correct hash of slug and name pairs" do
expect(helper.categories_for_display).to match_array(
[
{ slug: cat1.slug, name: cat1.name },
{ slug: cat2.slug, name: cat2.name },
],
)
end
end
describe "categories_available" do
it "returns a hash with slugs as keys" do
expected = [cat1.slug.to_sym, cat2.slug.to_sym]
expect(helper.categories_available.keys).to match_array(expected)
end
it "categories have the correct keys" do
cfp_category = helper.categories_available[:cfp]
expect(cfp_category.keys).to match_array(%i[cost name rules])
end
end
end