Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Add tests for product carousel

Matthew Kennedy88178645c86b
diff --git a/frontend/app/views/spree/home/index.html.erb b/frontend/app/views/spree/home/index.html.erb
index c15b67a9ae..87e20bd2a9 100644
--- a/frontend/app/views/spree/home/index.html.erb
+++ b/frontend/app/views/spree/home/index.html.erb
@@ -61,7 +61,7 @@
</div>
</div>
-<div data-product-carousel data-product-carousel-taxon-id='bestsellers' class="my-3"></div>
+<div id="BestSellersTaxonProductCarousel" data-product-carousel data-product-carousel-taxon-id='bestsellers' class="my-3"></div>
<div class="homepage-fashion-trends-box mb-3">
<div class="text-center">
@@ -74,7 +74,7 @@
</div>
</div>
-<div data-product-carousel data-product-carousel-taxon-id='trending' class="mb-3"></div>
+<div id="TrendingTaxonProductCarousel" data-product-carousel data-product-carousel-taxon-id='trending' class="mb-3"></div>
<div class="container">
<div class="row">
diff --git a/frontend/app/views/spree/shared/_carousel_4_products.html.erb b/frontend/app/views/spree/shared/_carousel_4_products.html.erb
index bd084adb3a..e4ab75ddde 100644
--- a/frontend/app/views/spree/shared/_carousel_4_products.html.erb
+++ b/frontend/app/views/spree/shared/_carousel_4_products.html.erb
@@ -66,7 +66,7 @@
<div class="row carousel-items-container">
<% sliced_items.each do |item| %>
- <div class="col-3">
+ <div class="col-3 carouselItem">
<%= render 'spree/shared/product', product: item, image_class: 'w-100' %>
</div>
<% end %>
diff --git a/frontend/spec/features/home_spec.rb b/frontend/spec/features/home_spec.rb
new file mode 100644
index 0000000000..cde8911e26
--- /dev/null
+++ b/frontend/spec/features/home_spec.rb
@@ -0,0 +1,48 @@
+require 'spec_helper'
+
+describe 'Visiting the homepage', type: :feature, js: true do
+ let!(:store) { Spree::Store.default }
+ let!(:taxonomy_a) { create(:taxonomy, name: 'Bestsellers') }
+ let!(:bestsellers) { taxonomy_a.root.children.create(name: 'Bestsellers') }
+ let!(:taxonomy_b) { create(:taxonomy, name: 'Trending') }
+ let!(:trending) { taxonomy_b.root.children.create(name: 'Trending') }
+ let!(:product_a) { create(:product, name: 'Superman T-Shirt', taxons: [bestsellers]) }
+ let!(:product_b) { create(:product, name: 'Batman Socks', taxons: [bestsellers]) }
+
+ context 'when taxon bestsellers exists and has products available in current store currency' do
+ before do
+ visit spree.root_path + '#BestSellersTaxonProductCarousel'
+ end
+
+ it 'loads the carousel with the products displayed' do
+ within '#BestSellersTaxonProductCarousel' do
+ expect(page).to have_content('BESTSELLERS')
+ expect(page).to have_content('Superman T-Shirt')
+ expect(page).to have_content('Batman Socks')
+ end
+ end
+
+ it 'loads carousel items in order of position' do
+ within ".carouselItem:nth-child(1)" do
+ expect(page).to have_content('Superman T-Shirt')
+ end
+
+ within ".carouselItem:nth-child(2)" do
+ expect(page).to have_content('Batman Socks')
+ end
+ end
+ end
+
+ context 'when products exist but not available in the current store currency' do
+ before do
+ store.update(default_currency: 'GBP')
+ visit spree.root_path + '#BestSellersTaxonProductCarousel'
+ end
+
+ it 'the carousel is not loaded' do
+ expect(page).not_to have_content('BESTSELLERS')
+ expect(page).not_to have_content('Superman T-Shirt')
+ expect(page).not_to have_content('Batman Socks')
+ end
+ end
+end