Skip to content

Commit

Permalink
Adds specs
Browse files Browse the repository at this point in the history
  • Loading branch information
rosschapman committed May 23, 2024
1 parent 94ea17d commit a02cd6e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 20 deletions.
2 changes: 1 addition & 1 deletion app/furniture/marketplace/tags/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
There are currently no tags marked as Menu Groups
<% else %>
<p>Drag and drop to change the order in which groups will display on your Marketplace</p>
<ul data-controller="sortable" data-sortable-animation-value="150" data-sortable-resource-name-value="tag" class="flex flex-col gap-2 p-0">
<ul data-tag-list-test data-controller="sortable" data-sortable-animation-value="150" data-sortable-resource-name-value="tag" class="flex flex-col gap-2 p-0">
<%- marketplace.tags.group_tag.by_position.each do |tag| %>
<li data-sortable-update-url="<%= polymorphic_path(tag.location) %>" id="<%= dom_id(tag)%>" class="items-center rounded-md bg-gray-50 px-2 py-1 font-medium text-gray-600 ring-1 ring-inset ring-gray-500/10 list-none cursor-move">
<%= render SvgComponent.new(icon: "bars_3", classes: "w-6 h-6 inline-block") %>
Expand Down
1 change: 1 addition & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@
t.boolean "is_group", default: false, null: false
t.integer "position", default: 0, null: false
t.uuid "marketplace_id", null: false
t.index ["marketplace_id", "position"], name: "index_marketplace_tags_on_marketplace_id_and_position", unique: true
t.index ["marketplace_id"], name: "index_marketplace_tags_on_marketplace_id"
end

Expand Down
1 change: 1 addition & 0 deletions spec/factories/furniture/marketplace/marketplace_tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
factory :marketplace_tag, class: "Marketplace::Tag" do
marketplace { association(:marketplace) }
sequence(:label) { |n| "#{Faker::Food.allergen} #{n}" }
sequence(:position) { |n| n }

trait :group do
is_group { true }
Expand Down
57 changes: 38 additions & 19 deletions spec/furniture/marketplace/marketplace_tags_system_spec.rb
Original file line number Diff line number Diff line change
@@ -1,37 +1,60 @@
require "rails_helper"

describe "Product Tags", type: :system do
describe "Marketplace Tags", type: :system do
let(:space) { create(:space, :with_entrance, :with_members) }
let(:marketplace) { create(:marketplace, :ready_for_shopping, room: space.entrance) }

before do
sign_in(space.members.first, space)
end

scenario "Adding Tags to a Product" do # rubocop:disable RSpec/Capybara/FeatureMethods,RSpec/ExampleLength
muffins = create(:marketplace_product, marketplace:, name: "Mazin' Muffins", description: "Buttery corn muffins")

scenario "Add a marketplace tag" do
visit(marketplace)
click_link("Tags")

click_link("Add Product Tag")

fill_in("Label", with: "๐Ÿšซ๐ŸŒพ Gluten Free")
click_button("Create")
expect(page).to have_content("๐Ÿšซ๐ŸŒพ Gluten Free")
end

scenario "Edit a Marketplace Tag" do
visit(marketplace)
click_link("Tags")
click_link("Add Product Tag")
fill_in("Label", with: "๐Ÿšซ๐ŸŒพ Gluten Free")
click_button("Create")
expect(page).to have_content("๐Ÿšซ๐ŸŒพ Gluten Free")

click_link("Products")
within(muffins) do
click_link("โš™๏ธ Edit")
end
click_link("๐Ÿšซ๐ŸŒพ Gluten Free")
fill_in("Label", with: "๐ŸŒพ Very Glutenous")
click_button("Save changes")
expect(page).to have_content("๐ŸŒพ Very Glutenous")

check("๐Ÿšซ๐ŸŒพ Gluten Free")
click_button("Save")
click_link("๐ŸŒพ Very Glutenous")
check("tag_is_group")
click_button("Save changes")
within("[data-tag-list-test]") do
expect(page).to have_content("๐ŸŒพ Very Glutenous")
end
end

visit(marketplace)
describe "Menu Groups" do
let!(:menu_tags) do
# The positioning gem won't let us manually assign positions on creation
create_list(:marketplace_tag, 3, :group, marketplace: marketplace).tap do |tags|
tags[0].update(position: :last)
tags[2].update(position: :first)
end
end

within(muffins) do
expect(page).to have_content("๐Ÿšซ๐ŸŒพ Gluten Free")
scenario "Displays Menu Groups in the correct order" do
visit(marketplace)
click_link("Tags")
within("[data-tag-list-test]") do
expect(page.find("li:nth-child(1)")).to have_content(menu_tags[2].label)
expect(page.find("li:nth-child(2)")).to have_content(menu_tags[1].label)
expect(page.find("li:nth-child(3)")).to have_content(menu_tags[0].label)
end
end
end

Expand All @@ -42,8 +65,4 @@ def visit(object_or_path)
super
end
end

def within(model, *, **, &block)
page.within("##{dom_id(model)}", *, **, &block)
end
end

0 comments on commit a02cd6e

Please sign in to comment.