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 frontend feature tests for cms_page standard with content and feature with sections.

Matthew Kennedyc7870e97c99e
diff --git a/core/lib/spree/testing_support/factories/cms_section_factory.rb b/core/lib/spree/testing_support/factories/cms_section_factory.rb
index a3643fa9b3..66bf204b89 100644
--- a/core/lib/spree/testing_support/factories/cms_section_factory.rb
+++ b/core/lib/spree/testing_support/factories/cms_section_factory.rb
@@ -1,5 +1,29 @@
FactoryBot.define do
factory :cms_section, class: Spree::CmsSection do
name { generate(:random_string) }
+
+ factory :cms_hero_section do
+ type { 'Spree::Cms::Sections::FullScreenHeroImage' }
+ end
+
+ factory :cms_featured_article_section do
+ type { 'Spree::Cms::Sections::FeaturedArticle' }
+ end
+
+ factory :cms_product_carousel_section do
+ type { 'Spree::Cms::Sections::ProductCarousel' }
+ end
+
+ factory :cms_three_taxon_categories_section do
+ type { 'Spree::Cms::Sections::ThreeTaxonCategoriesBlock' }
+ end
+
+ factory :cms_static_branding_bar_section do
+ type { 'Spree::Cms::Sections::StaticBrandingBar' }
+ end
+
+ factory :cms_side_by_side_promotion_section do
+ type { 'Spree::Cms::Sections::SideBySidePromotion' }
+ end
end
end
diff --git a/frontend/app/controllers/spree/cms_pages_controller.rb b/frontend/app/controllers/spree/cms_pages_controller.rb
index 7d7c07a03a..aa5052880e 100644
--- a/frontend/app/controllers/spree/cms_pages_controller.rb
+++ b/frontend/app/controllers/spree/cms_pages_controller.rb
@@ -19,7 +19,7 @@ module Spree
private
def accurate_title
- @page.seo_title || super
+ @page&.seo_title || super
end
def load_cms_page
diff --git a/frontend/spec/features/cms_page.rb b/frontend/spec/features/cms_page.rb
new file mode 100644
index 0000000000..590763467c
--- /dev/null
+++ b/frontend/spec/features/cms_page.rb
@@ -0,0 +1,95 @@
+require 'spec_helper'
+
+describe 'cms_page standard page', type: :feature, js: true do
+ let!(:store) { create(:store, default: true, supported_currencies: 'USD') }
+
+ describe 'page' do
+ let!(:cms_page) { create(:cms_standard_page, store: store, locale: 'en', content: '<h2>About Us</h2>') }
+
+ before do
+ visit spree.page_path(cms_page.slug)
+ end
+
+ it 'displays content' do
+ expect(page).to have_text('About Us')
+ end
+
+ it 'displays meta_title as page title if no meta_title is set' do
+ expect(page).to have_title("#{cms_page.title} - #{store.name}")
+ end
+ end
+
+ describe 'page has metas' do
+ let!(:cms_page_with_metas) do
+ create(:cms_standard_page, store: store,
+ locale: 'en',
+ content: '<h2>Contact Us</h2>',
+ meta_title: 'Hello From Contact Us Page',
+ meta_description: 'This is a wonderful meta description, search engines will be happy!')
+ end
+
+ before do
+ visit spree.page_path(cms_page_with_metas.slug)
+ end
+
+ it 'displays meta_title as the set meta_title when one is set' do
+ expect(page).to have_title("#{cms_page_with_metas.meta_title} - #{store.name}")
+ end
+
+ it 'displays meta_description as the set meta_description when one is set' do
+ expect(page).to have_meta(:description, cms_page_with_metas.meta_description)
+ end
+ end
+end
+
+describe 'cms_page feature page', type: :feature, js: true do
+ let!(:store) { create(:store, default: true, supported_currencies: 'USD') }
+
+ describe 'feature page' do
+ let!(:cms_feature_page) { create(:cms_feature_page, store: store, locale: 'en', content: '<h2>About Us</h2>') }
+ let!(:fa_section) { create(:cms_featured_article_section, cms_page: cms_feature_page) }
+
+ before do
+ fa_sect = Spree::CmsSection.find(fa_section.id)
+ fa_sect.content[:title] = 'Hot Sellers This Season'
+ fa_sect.save!
+ fa_sect.reload
+
+ visit spree.page_path(cms_feature_page.slug)
+ end
+
+ it 'does not display content, even if it is present in the database' do
+ expect(page).not_to have_text('About Us')
+ end
+
+ it 'displays meta_title as page title if no meta_title is set' do
+ expect(page).to have_title("#{cms_feature_page.title} - #{store.name}")
+ end
+
+ it 'displays sections' do
+ expect(page).to have_text('Hot Sellers This Season')
+ end
+ end
+
+ describe 'when feature page has metas' do
+ let!(:cms_feature_page_with_metas) do
+ create(:cms_feature_page, store: store,
+ locale: 'en',
+ content: '<h2>Contact Us</h2>',
+ meta_title: 'Hello From Contact Us Page',
+ meta_description: 'This is a wonderful meta description, search engines will be happy!')
+ end
+
+ before do
+ visit spree.page_path(cms_feature_page_with_metas.slug)
+ end
+
+ it 'displays meta_title as the set meta_title when one is set' do
+ expect(page).to have_title("#{cms_feature_page_with_metas.meta_title} - #{store.name}")
+ end
+
+ it 'displays meta_description as the set meta_description when one is set' do
+ expect(page).to have_meta(:description, cms_feature_page_with_metas.meta_description)
+ end
+ end
+end