Skip to content

Commit

Permalink
🧹 Marketplace: Re-use DeliveryExpectationsComponent
Browse files Browse the repository at this point in the history
So, this brings all the places we render examples for delivery
communications together and handles some more cases that we were not yet
handling.

It's not great, but it should fix the red `main`
  • Loading branch information
zspencer committed Apr 17, 2023
1 parent b9b032e commit 8b5de33
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
<%- if cart.marketplace.order_by.present? && cart.marketplace.delivery_window.present? %>
Orders placed <%= cart.marketplace.order_by %>
are delivered <%= cart.marketplace.delivery_window %>
<%- elsif cart.marketplace.order_by.blank? && cart.marketplace.delivery_window.present? %>
Orders are delivered <%= cart.marketplace.delivery_window %>
<%- elsif cart.delivery_window.present? && cart.marketplace.order_by.present? %>
Place orders <%= cart.marketplace.order_by %> to ensure an on-time delivery for <%= render(cart.delivery_window) %>
<%- if order_by.present? && delivery_window.present? %>
Orders placed <%= order_by %>
are delivered <%= delivery_window %>
<%- elsif order_by.blank? && delivery_window.present? %>
Orders are delivered <%= delivery_window %>
<%- elsif order_by.present? && delivery_window.blank? && cart.delivery_window.blank? %>
Order <%= order_by %>
<%- elsif cart.delivery_window.present? && order_by.present? %>
Order <%= order_by %> to ensure an on-time delivery for <%= render(cart.delivery_window) %>
<%- elsif cart.delivery_window.present? %>
Delivering at <%= render(cart.delivery_window) %>
<%- else %>
Delivers at your chosen time
<%- end %>
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
class Marketplace
class Cart
class DeliveryExpectationsComponent < ApplicationComponent
attr_accessor :cart
attr_accessor :cart, :delivery_window, :order_by

def initialize(cart:, **kwargs)
def initialize(cart:, order_by: cart.marketplace.order_by,
delivery_window: cart.marketplace.delivery_window, **kwargs)
super(**kwargs)

self.cart = cart
self.delivery_window = delivery_window
self.order_by = order_by
end
end
end
Expand Down
5 changes: 1 addition & 4 deletions app/furniture/marketplace/delivery_area_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@

<div class="grow flex flex-col justify-between">
<div class="text-sm">
<%- if order_by.present? %>
Place orders by <%= order_by %> to ensure an on-time
<%- end %>
<%= render(delivery_window) %>
<%= render Marketplace::Cart::DeliveryExpectationsComponent.new(order_by: delivery_area.order_by, delivery_window: delivery_area.delivery_window, cart: example_cart) %>
</div>

<div class="text-right mt-3 italic">
Expand Down
4 changes: 4 additions & 0 deletions app/furniture/marketplace/delivery_area_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ def price
helpers.humanized_money_with_symbol(delivery_area.price)
end

def example_cart
delivery_area.marketplace.carts.new
end

delegate :order_by, to: :delivery_area

def delivery_window
Expand Down
6 changes: 3 additions & 3 deletions spec/furniture/marketplace/delivery_area_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
it { is_expected.to have_content "at your chosen time" }
end

context "when `#delivery_window`` is a string" do
context "when `#delivery_window` is a string" do
let(:delivery_area) { create(:marketplace_delivery_area, delivery_window: "dinnertime same day") }

it { is_expected.to have_content "for #{delivery_area.delivery_window}" }
it { is_expected.to have_content delivery_area.delivery_window }
end

context "when #order_by is blank" do
Expand All @@ -31,6 +31,6 @@
context "when `#order_by` is set" do
let(:delivery_area) { create(:marketplace_delivery_area, order_by: "noon") }

it { is_expected.to have_content "by #{delivery_area.order_by}" }
it { is_expected.to have_content delivery_area.order_by }
end
end

0 comments on commit 8b5de33

Please sign in to comment.