-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…1373) - #1185 As we were beginning to implement how we communicate the different expectations based on delivery area, we noticed there were not many tests on the current behavior; and that chunk of behavior had many many many permutations that were meaningful. So we took some time to pull out a `DeliveryExpectationsComponent` that can take care of handling those permutations, and start to test them. There is some minor wording improvements included here, specifically because we noticed things didn't always make a ton of sense as we added those tests; so it *does* include a bit of behavior changes.
- Loading branch information
Showing
5 changed files
with
66 additions
and
7 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
app/furniture/marketplace/cart/delivery_expectations_component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<%- 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) %> | ||
<%- elsif cart.delivery_window.present? %> | ||
Delivering at <%= render(cart.delivery_window) %> | ||
<%- end %> |
13 changes: 13 additions & 0 deletions
13
app/furniture/marketplace/cart/delivery_expectations_component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class Marketplace | ||
class Cart | ||
class DeliveryExpectationsComponent < ApplicationComponent | ||
attr_accessor :cart | ||
|
||
def initialize(cart:, **kwargs) | ||
super(**kwargs) | ||
|
||
self.cart = cart | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
spec/furniture/marketplace/cart/delivery_expectations_component_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe Marketplace::Cart::DeliveryExpectationsComponent, type: :component do | ||
subject(:output) { render_inline(component) } | ||
|
||
let(:operator) { create(:person, operator: true) } | ||
|
||
let(:component) { described_class.new(cart: cart, current_person: operator) } | ||
let(:marketplace) { build(:marketplace) } | ||
|
||
context "when the cart does not have a `delivery_area`" do | ||
let(:cart) { build(:marketplace_cart, marketplace: marketplace, delivery_window: 1.hour.from_now) } | ||
|
||
context "when the `marketplace` has an `order_by` without a `delivery_window`" do | ||
let(:marketplace) { build(:marketplace, order_by: "by 8AM") } | ||
|
||
it { is_expected.to have_content("to ensure an on-time delivery for #{I18n.l(1.hour.from_now, format: :day_month_date_hour_minute)}", normalize_ws: true) } | ||
end | ||
|
||
context "when the `marketplace` has a `delivery_window` without an `order_by`" do | ||
let(:marketplace) { build(:marketplace, delivery_window: "at Noon") } | ||
|
||
it { is_expected.to have_content("Orders are delivered at Noon", normalize_ws: true) } | ||
end | ||
|
||
context "when the `marketplace` has `delivery_window` and an `order_by`" do | ||
let(:marketplace) { build(:marketplace, delivery_window: "at Noon", order_by: "by 8AM") } | ||
|
||
it { is_expected.to have_content("Orders placed by 8AM are delivered at Noon", normalize_ws: true) } | ||
end | ||
|
||
context "when the `marketplace` has neither an `order_by` nor a `delivery_window`" do | ||
let(:marketplace) { build(:marketplace) } | ||
|
||
it { | ||
expect(output).to have_content("Delivering at #{I18n.l(1.hour.from_now, format: :day_month_date_hour_minute)}", | ||
normalize_ws: true) | ||
} | ||
end | ||
end | ||
end |