Skip to content

Commit

Permalink
🥗 Marketplace: Spec for Product#tags
Browse files Browse the repository at this point in the history
- #2189

Lil' quick sketch through the workflow. Only interesting things of note
here are I am using `scenario` syntax (which feels better to me, and was
validated by @ExMember in antoher context yesterday.)

I am also doing something "weird" where I overload the `visit` method to
rely on our `Record#location` method to interject a `polymorphic_path`
call; saving us the burden of including the `polymorphic_path` call on
our own every time we use `visit`; but adding the burden of a layer of
indirection.

I also did this with `within`, because omg that awkward
`"##{dom_id(model)"` drives me nuts every time I type it. It makes me
want to scream. I can't stand it.
  • Loading branch information
zspencer committed Mar 7, 2024
1 parent 491e920 commit 3514d4d
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions spec/furniture/marketplace/product_tags_system_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require "rails_helper"

describe "Product 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")

visit(marketplace)
click_link("Tags")

click_link("Add Tag")

fill_in("Label", with: "🚫🌾 Gluten Free")

click_button("Create")

click_link("Products")
within(muffins) do
click_link("⚙️ Edit")
end

visit(marketplace)

within(muffins) do
expect(page).to have_content("🚫🌾 Gluten Free")
end
end

def visit(object_or_path)
if object_or_path.respond_to?(:location)
super(polymorphic_path(object_or_path.location))
else
super
end
end

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

0 comments on commit 3514d4d

Please sign in to comment.