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.

Storefront: fix for spree images

Szymon Chorobski0044d5a9a63c
diff --git a/core/lib/spree/testing_support/factories/post_factory.rb b/core/lib/spree/testing_support/factories/post_factory.rb
index a1a3ec7952..2223e0c8aa 100644
--- a/core/lib/spree/testing_support/factories/post_factory.rb
+++ b/core/lib/spree/testing_support/factories/post_factory.rb
@@ -6,5 +6,9 @@ FactoryBot.define do
published_at { Time.current }
author { create(:admin_user) }
store { Spree::Store.default || create(:store) }
+
+ trait :with_image do
+ image { Rack::Test::UploadedFile.new(Spree::Core::Engine.root.join('spec/fixtures/thinking-cat.jpg'), 'image/jpeg') }
+ end
end
end
diff --git a/storefront/app/helpers/spree/storefront_helper.rb b/storefront/app/helpers/spree/storefront_helper.rb
index ef5d27c2f6..5d91b90ad9 100644
--- a/storefront/app/helpers/spree/storefront_helper.rb
+++ b/storefront/app/helpers/spree/storefront_helper.rb
@@ -1,6 +1,7 @@
module Spree
module StorefrontHelper
include BaseHelper
+ include Spree::ImagesHelper
include Heroicon::Engine.helpers
# Renders the storefront partials for the given section.
@@ -71,9 +72,9 @@ module Spree
def show_account_pane?
!try_spree_current_user &&
- (defined?(spree_login_path) && !paths_equal?(canonical_path, spree_login_path)) &&
- (defined?(spree_signup_path) && !paths_equal?(canonical_path, spree_signup_path)) &&
- (defined?(spree_forgot_password_path) && !paths_equal?(canonical_path, spree_forgot_password_path))
+ defined?(spree_login_path) && !paths_equal?(canonical_path, spree_login_path) &&
+ defined?(spree_signup_path) && !paths_equal?(canonical_path, spree_signup_path) &&
+ defined?(spree_forgot_password_path) && !paths_equal?(canonical_path, spree_forgot_password_path)
end
def paths_equal?(path1, path2)
diff --git a/storefront/spec/features/post_details_page_spec.rb b/storefront/spec/features/post_details_page_spec.rb
index 953548bd32..4c7ae760a7 100644
--- a/storefront/spec/features/post_details_page_spec.rb
+++ b/storefront/spec/features/post_details_page_spec.rb
@@ -1,11 +1,11 @@
require 'spec_helper'
-RSpec.describe 'Post details page', type: :feature, js: true do
+RSpec.describe 'Post details page', :js, type: :feature do
describe 'JSON-LD data' do
let(:store) { Spree::Store.default }
let!(:post) do
create(
- :post,
+ :post, :with_image,
post_category: post_category,
tag_list: tags,
title: 'New products on sale!',
@@ -27,11 +27,11 @@ RSpec.describe 'Post details page', type: :feature, js: true do
let(:post_category) { create(:post_category, title: 'Articles') }
it 'renders BlogPosting JSON-LD' do
- expect(json_ld).to eq(
+ expect(json_ld).to match(
'@context' => 'https://schema.org',
'@type' => 'BlogPosting',
'headline' => 'New products on sale!',
- 'image' => [],
+ 'image' => array_including(kind_of(String)),
'datePublished' => post.published_at.iso8601,
'dateModified' => post.updated_at.iso8601,
'author' => [
@@ -44,7 +44,7 @@ RSpec.describe 'Post details page', type: :feature, js: true do
end
it 'renders BreadcrumbList JSON-LD with a link to category page' do
- expect(json_ld_breadcrumbs).to eq(
+ expect(json_ld_breadcrumbs).to match(
{
'@context' => 'https://schema.org',
'@type' => 'BreadcrumbList',
@@ -82,11 +82,11 @@ RSpec.describe 'Post details page', type: :feature, js: true do
let(:post_category) { nil }
it 'renders JSON-LD' do
- expect(json_ld).to eq(
+ expect(json_ld).to match(
'@context' => 'https://schema.org',
'@type' => 'BlogPosting',
'headline' => 'New products on sale!',
- 'image' => [],
+ 'image' => array_including(kind_of(String)),
'datePublished' => post.published_at.iso8601,
'dateModified' => post.updated_at.iso8601,
'author' => [