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.

Added Post page specs, featured taxon spec, checkout complete page spec

Damian Legawiec07970a0667ec
diff --git a/storefront/spec/features/checkout_complete_page_spec.rb b/storefront/spec/features/checkout_complete_page_spec.rb
new file mode 100644
index 0000000000..ec89ab375c
--- /dev/null
+++ b/storefront/spec/features/checkout_complete_page_spec.rb
@@ -0,0 +1,13 @@
+require 'spec_helper'
+RSpec.describe 'Checkout complete page', js: true do
+ let(:store) { Spree::Store.default }
+ let(:order) { create(:completed_order_with_pending_payment, user: nil, store: store) }
+ let(:address) { order.bill_address }
+
+ scenario 'Customer sees a confirmation page' do
+ visit "/checkout/#{order.token}/complete"
+
+ expect(page).to have_text("Order #{order.number}")
+ expect(page).to have_text("Thanks #{address.first_name} for your order!")
+ end
+end
diff --git a/storefront/spec/features/featured_taxon_spec.rb b/storefront/spec/features/featured_taxon_spec.rb
new file mode 100644
index 0000000000..3028056da8
--- /dev/null
+++ b/storefront/spec/features/featured_taxon_spec.rb
@@ -0,0 +1,65 @@
+require 'spec_helper'
+
+RSpec.describe 'Featured taxon', type: :feature do
+ let(:store) { Spree::Store.default }
+ let!(:products) { create_list(:product, 10, price: 5.00, stores: [store]) }
+ let(:categories_taxonomy) { store.taxonomies.find_by(name: 'Categories') }
+ let(:taxon) { create(:taxon, taxonomy: categories_taxonomy) }
+ let(:section) { Spree::PageSections::FeaturedTaxon.create(preferred_taxon_id: taxon&.id, pageable: Spree::Page.find_by(name: 'Homepage')) }
+
+ before do
+ store.taxons.automatic.destroy_all
+ taxon.products << products if taxon.present?
+ visit spree.page_section_path(section.id)
+ end
+
+ describe 'swiper' do
+ it 'renders proper turbo frame id' do
+ expect(page).to have_css("turbo-frame[id='section-#{section.id}']")
+ end
+
+ it 'renders product names' do
+ products.each do |product|
+ expect(page).to have_content(product.name)
+ end
+ end
+
+ it 'renders header' do
+ expect(page).to have_content(section.preferred_heading)
+ end
+
+ it 'renders `Explore category` button' do
+ expect(page).to have_content('Explore category')
+ end
+
+ context 'when max products is less than products count' do
+ before do
+ section.update(preferred_max_products_to_show: 5)
+ visit spree.page_section_path(section.id)
+ end
+
+ it 'renders only selected products' do
+ products.first(5).each do |product|
+ expect(page).to have_content(product.name)
+ end
+
+ products.last(5).each do |product|
+ expect(page).not_to have_content(product.name)
+ end
+ end
+ end
+
+ context 'when taxon is not selected' do
+ let(:taxon) { nil }
+
+ it 'does not throw error' do
+ expect(page).to have_content(section.preferred_heading)
+ expect(page).not_to have_content(section.preferred_button_text)
+
+ products.each do |product|
+ expect(page).not_to have_content(product.name)
+ end
+ end
+ end
+ end
+end
diff --git a/storefront/spec/features/post_details_page_spec.rb b/storefront/spec/features/post_details_page_spec.rb
new file mode 100644
index 0000000000..953548bd32
--- /dev/null
+++ b/storefront/spec/features/post_details_page_spec.rb
@@ -0,0 +1,128 @@
+require 'spec_helper'
+
+RSpec.describe 'Post details page', type: :feature, js: true do
+ describe 'JSON-LD data' do
+ let(:store) { Spree::Store.default }
+ let!(:post) do
+ create(
+ :post,
+ post_category: post_category,
+ tag_list: tags,
+ title: 'New products on sale!',
+ author: create(:admin_user, name: 'John Doe'),
+ published_at: '2024-10-07T08:10:08-05:00'
+ )
+ end
+
+ let(:tags) { [] }
+
+ let(:json_ld) { JSON.parse(find('script[data-test-id="post-json-ld"]', visible: false)['innerHTML']) }
+ let(:json_ld_breadcrumbs) { JSON.parse(find('script[data-test-id="post-breadcrumbs-json-ld"]', visible: false)['innerHTML']) }
+
+ before do
+ visit spree.post_path(post)
+ end
+
+ context 'for a post with a category' do
+ let(:post_category) { create(:post_category, title: 'Articles') }
+
+ it 'renders BlogPosting JSON-LD' do
+ expect(json_ld).to eq(
+ '@context' => 'https://schema.org',
+ '@type' => 'BlogPosting',
+ 'headline' => 'New products on sale!',
+ 'image' => [],
+ 'datePublished' => post.published_at.iso8601,
+ 'dateModified' => post.updated_at.iso8601,
+ 'author' => [
+ {
+ '@type' => 'Person',
+ 'name' => 'John Doe'
+ }
+ ]
+ )
+ end
+
+ it 'renders BreadcrumbList JSON-LD with a link to category page' do
+ expect(json_ld_breadcrumbs).to eq(
+ {
+ '@context' => 'https://schema.org',
+ '@type' => 'BreadcrumbList',
+ 'itemListElement' => [
+ {
+ '@type' => 'ListItem',
+ 'position' => 1,
+ 'name' => Spree.t(:homepage),
+ 'item' => "#{store.formatted_url}/"
+ },
+ {
+ '@type' => 'ListItem',
+ 'position' => 2,
+ 'name' => Spree.t(:blog),
+ 'item' => [store.formatted_url, 'posts'].join('/')
+ },
+ {
+ '@type' => 'ListItem',
+ 'position' => 3,
+ 'name' => 'Articles',
+ 'item' => [store.formatted_url, 'posts', 'category', post_category.slug].join('/')
+ },
+ {
+ '@type' => 'ListItem',
+ 'position' => 4,
+ 'name' => 'New products on sale!'
+ }
+ ]
+ }
+ )
+ end
+ end
+
+ context 'for a post without a category' do
+ let(:post_category) { nil }
+
+ it 'renders JSON-LD' do
+ expect(json_ld).to eq(
+ '@context' => 'https://schema.org',
+ '@type' => 'BlogPosting',
+ 'headline' => 'New products on sale!',
+ 'image' => [],
+ 'datePublished' => post.published_at.iso8601,
+ 'dateModified' => post.updated_at.iso8601,
+ 'author' => [
+ {
+ '@type' => 'Person',
+ 'name' => 'John Doe'
+ }
+ ]
+ )
+
+ expect(json_ld_breadcrumbs).to eq(
+ {
+ '@context' => 'https://schema.org',
+ '@type' => 'BreadcrumbList',
+ 'itemListElement' => [
+ {
+ '@type' => 'ListItem',
+ 'position' => 1,
+ 'name' => Spree.t(:homepage),
+ 'item' => "#{store.formatted_url}/"
+ },
+ {
+ '@type' => 'ListItem',
+ 'position' => 2,
+ 'name' => Spree.t(:blog),
+ 'item' => [store.formatted_url, 'posts'].join('/')
+ },
+ {
+ '@type' => 'ListItem',
+ 'position' => 3,
+ 'name' => 'New products on sale!'
+ }
+ ]
+ }
+ )
+ end
+ end
+ end
+end