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.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Add some feature tests for admin UI pages.
Matthew Kennedybc72a60b21ec
diff --git a/backend/app/assets/javascripts/spree/backend/cms/live_preview.es6 b/backend/app/assets/javascripts/spree/backend/cms/live_preview.es6index 730e67a211..69f8d937ac 100644--- a/backend/app/assets/javascripts/spree/backend/cms/live_preview.es6+++ b/backend/app/assets/javascripts/spree/backend/cms/live_preview.es6@@ -20,9 +20,9 @@ document.addEventListener('DOMContentLoaded', function() {cmsSectionEditorFullScreen.addEventListener('click', function(event) {if (this.getAttribute('aria-pressed') === 'true') {- document.body.classList.remove('cmsSectionFullScreenMode')+ document.body.removeAttribute('data-sections-editor-full-screen')} else {- document.body.classList.add('cmsSectionFullScreenMode')+ document.body.setAttribute('data-sections-editor-full-screen', '')}})diff --git a/backend/app/assets/stylesheets/spree/backend/views/_cms_pages.scss b/backend/app/assets/stylesheets/spree/backend/views/_cms_pages.scssindex 630a4b3c09..441fc40910 100644--- a/backend/app/assets/stylesheets/spree/backend/views/_cms_pages.scss+++ b/backend/app/assets/stylesheets/spree/backend/views/_cms_pages.scss@@ -121,7 +121,7 @@ button#cmsSectionEditorFullScreen {}}-body.cmsSectionFullScreenMode {+body[data-sections-editor-full-screen] {.hide-on-full-screen-mode {display: none;}diff --git a/backend/app/views/spree/admin/cms_pages/_form.html.erb b/backend/app/views/spree/admin/cms_pages/_form.html.erbindex 30c0454f64..e6b42ec478 100644--- a/backend/app/views/spree/admin/cms_pages/_form.html.erb+++ b/backend/app/views/spree/admin/cms_pages/_form.html.erb@@ -61,7 +61,7 @@<% end %></div>- <div class="<% unless %w[new create].include? controller.action_name %>collapse<% end %>" id="cmsSeoSettings">+ <div class="<% unless %w[new create].include? controller.action_name %>collapse<% end %>" id="cmsPageSettings"><div class="row pb-0"><div class="col-12"><hr></div><%= f.field_container :cms_page_stores, class: ['form-group col-6'] do %>@@ -71,7 +71,7 @@<% end %><%= f.field_container :locale, class: ['form-group col-6'] do %>- <%= f.label :locale %>+ <%= f.label :language %><%= f.select :locale, options_from_collection_for_select(all_locales_options, :last, :first, @cms_page.locale || I18n.locale), {}, { class: 'select2' } %><%= f.error_message_on :default_locale %><% end %>@@ -85,7 +85,7 @@<%= f.field_container :slug, class: ['form-group col-6'] do %><div id="noHomePage"><%= f.label :slug, Spree.t('slug') %>- <%= f.text_field :slug, class: 'form-control' %>+ <%= f.text_field :slug, class: 'form-control', disabled: @cms_page.homepage? %><%= f.error_message_on :slug %></div><% end %>@@ -109,7 +109,7 @@<% end %><div class="col-12 col-md text-right pt-3 pt-md-0">- <button class="btn btn-outline-secondary" type="button" data-toggle="collapse" data-target="#cmsSeoSettings" aria-expanded="false" aria-controls="collapseExample">+ <button id="toggleMorePageSettingsButton" class="btn btn-outline-secondary" type="button" data-toggle="collapse" data-target="#cmsPageSettings" aria-expanded="false" aria-controls="collapsePageSettings"><%= raw Spree.t('admin.cms.more_page_settings') %></button></div>diff --git a/backend/app/views/spree/admin/cms_pages/edit.html.erb b/backend/app/views/spree/admin/cms_pages/edit.html.erbindex 91b74feb37..ca025505ba 100644--- a/backend/app/views/spree/admin/cms_pages/edit.html.erb+++ b/backend/app/views/spree/admin/cms_pages/edit.html.erb@@ -51,7 +51,7 @@<div class="row"><div class="col-12"><div class="alert alert-info no-objects-found m-4">- <%= Spree.t('admin.cms.no_sections_found_please_add_one') %>+ <%= raw Spree.t('admin.cms.no_sections_found_please_add_one') %></div></div></div>diff --git a/backend/app/views/spree/admin/cms_pages/index.html.erb b/backend/app/views/spree/admin/cms_pages/index.html.erbindex 1ccba11825..6741eb4c99 100644--- a/backend/app/views/spree/admin/cms_pages/index.html.erb+++ b/backend/app/views/spree/admin/cms_pages/index.html.erb@@ -48,6 +48,6 @@</div><% else %><div class="alert alert-info no-objects-found">- <%= Spree.t('admin.cms.you_have_no_pages') %>+ <%= raw Spree.t('admin.cms.you_have_no_pages') %></div><% end %>diff --git a/backend/spec/features/admin/cms_pages/edit_feature_page_spec.rb b/backend/spec/features/admin/cms_pages/edit_feature_page_spec.rbnew file mode 100644index 0000000000..7c0a8638a1--- /dev/null+++ b/backend/spec/features/admin/cms_pages/edit_feature_page_spec.rb@@ -0,0 +1,59 @@+require 'spec_helper'++describe 'Edit Feature Page', type: :feature do+ stub_authorization!++ context 'when a user creates a Feature Page' do+ let!(:store_1) { create(:store) }++ before do+ visit spree.new_admin_cms_page_path+ fill_in 'Title *', with: 'Homepage (English)'+ select 'Feature Page', from: 'cms_page[type]'++ click_on 'Create'+ end++ it 'saves the basic setting fields and generates a slug' do+ expect(page).to have_field('Title *', with: 'Homepage (English)')+ expect(page).to have_field('Slug', disabled: false)+ end++ it 'displays the Section Manager' do+ expect(page).to have_selector(:link_or_button, 'Add New Section')+ expect(page).to have_content('Mobile')+ expect(page).to have_content('Tablet')+ expect(page).to have_content('Desktop')+ expect(page).to have_content('Add your first section to this page by clicking the + Add New Section button above.')+ end++ it 'user can enter and exit full screen mode', js: true do+ find('[id="cmsSectionEditorFullScreen"]').click++ expect(page).to have_selector('body[data-sections-editor-full-screen]')+ end++ it 'displays the language of the page' do+ expect(page).to have_text ('English (US)')+ end++ it 'allows user to toggle visability' do+ expect(page).to have_text ('Visible')++ find(:xpath, '//*[@id="cms_page_visible"]/..').click++ expect(page).to have_text ('Draft Mode')+ end++ it 'allows user to switch language', js: true do+ find('[aria-controls="collapsePageSettings"]').click++ select2 'fr', from: 'Language'++ click_on 'Update'++ # TODO: Not the best translation ever.+ expect(page).to have_text('This File Language')+ end+ end+enddiff --git a/backend/spec/features/admin/cms_pages/edit_homepage_spec.rb b/backend/spec/features/admin/cms_pages/edit_homepage_spec.rbnew file mode 100644index 0000000000..c6d908e773--- /dev/null+++ b/backend/spec/features/admin/cms_pages/edit_homepage_spec.rb@@ -0,0 +1,59 @@+require 'spec_helper'++describe 'Edit Homepage', type: :feature do+ stub_authorization!++ context 'when a user creates a Homepage' do+ let!(:store_1) { create(:store) }++ before do+ visit spree.new_admin_cms_page_path+ fill_in 'Title *', with: 'Homepage (English)'+ select 'Homepage', from: 'cms_page[type]'++ click_on 'Create'+ end++ it 'saves the basic setting fields and generates a slug' do+ expect(page).to have_field('Title *', with: 'Homepage (English)')+ expect(page).to have_field('Slug', disabled: true)+ end++ it 'displays the Section Manager' do+ expect(page).to have_selector(:link_or_button, 'Add New Section')+ expect(page).to have_content('Mobile')+ expect(page).to have_content('Tablet')+ expect(page).to have_content('Desktop')+ expect(page).to have_content('Add your first section to this page by clicking the + Add New Section button above.')+ end++ it 'user can enter and exit full screen mode', js: true do+ find('[id="cmsSectionEditorFullScreen"]').click++ expect(page).to have_selector('body[data-sections-editor-full-screen]')+ end++ it 'displays the language of the page' do+ expect(page).to have_text ('English (US)')+ end++ it 'allows user to toggle visability' do+ expect(page).to have_text ('Visible')++ find(:xpath, '//*[@id="cms_page_visible"]/..').click++ expect(page).to have_text ('Draft Mode')+ end++ it 'allows user to switch language', js: true do+ find('[aria-controls="collapsePageSettings"]').click++ select2 'fr', from: 'Language'++ click_on 'Update'++ # TODO: Not the best translation ever.+ expect(page).to have_text('This File Language')+ end+ end+enddiff --git a/backend/spec/features/admin/cms_pages/edit_standard_page_spec.rb b/backend/spec/features/admin/cms_pages/edit_standard_page_spec.rbnew file mode 100644index 0000000000..f08081843a--- /dev/null+++ b/backend/spec/features/admin/cms_pages/edit_standard_page_spec.rb@@ -0,0 +1,67 @@+require 'spec_helper'++describe 'Edit Standard Page', type: :feature do+ stub_authorization!++ context 'when a user creates a Standard Page' do+ let!(:store_1) { create(:store) }++ before do+ visit spree.new_admin_cms_page_path++ fill_in 'Title *', with: 'Privacy Policy'+ fill_in 'Meta Title', with: 'Meta-T-Content'+ fill_in 'Meta Description', with: 'Meta-Description-Content'++ click_on 'Create'+ end++ it 'saves the basic setting fields and generates a slug' do+ expect(page).to have_field('Title *', with: 'Privacy Policy')+ expect(page).to have_field('Slug', with: 'privacy-policy')+ expect(page).to have_field('Meta Title', with: 'Meta-T-Content')+ expect(page).to have_text ('Meta-Description-Content')+ end++ it 'slug should not be disabled' do+ expect(page).to have_field('Slug', disabled: false)+ end++ it 'loads the RTE', js: true do+ expect(page).to have_css '.tox-editor-container'+ end++ it 'displays the language of the page' do+ expect(page).to have_text ('English (US)')+ end++ it 'allows user to switch language', js: true do+ find('[aria-controls="collapsePageSettings"]').click++ select2 'fr', from: 'Language'++ click_on 'Update'++ # TODO: Not the best translation ever.+ expect(page).to have_text('This File Language')+ end++ it 'allows user to toggle visability', js: true do+ expect(page).to have_text ('Visible')++ find(:xpath, '//*[@id="cms_page_visible"]/..').click++ expect(page).to have_text ('Draft Mode')+ end++ it 'allows user to toggle more page settings enter data and save', js: true do+ find('[aria-controls="collapsePageSettings"]').click+ fill_in 'Meta Description', with: 'M-Descript'++ click_on 'Update'++ find('[aria-controls="collapsePageSettings"]').click+ expect(page).to have_text ('M-Descript')+ end+ end+enddiff --git a/backend/spec/features/admin/cms_pages/index_pages_spec.rb b/backend/spec/features/admin/cms_pages/index_pages_spec.rbnew file mode 100644index 0000000000..4789f9bce9--- /dev/null+++ b/backend/spec/features/admin/cms_pages/index_pages_spec.rb@@ -0,0 +1,15 @@+require 'spec_helper'++describe 'Pages Index', type: :feature do+ stub_authorization!++ context 'when no pages are present' do+ before do+ visit spree.admin_menus_path+ end++ it 'prompts the user to create a menu' do+ expect(page).to have_text 'You have no Menus, click the Add New Menu button to create your first Menu.'+ end+ end+enddiff --git a/backend/spec/features/admin/cms_pages/new_page_spec.rb b/backend/spec/features/admin/cms_pages/new_page_spec.rbnew file mode 100644index 0000000000..e140fd0dcb--- /dev/null+++ b/backend/spec/features/admin/cms_pages/new_page_spec.rb@@ -0,0 +1,52 @@+require 'spec_helper'++describe 'New Page', type: :feature do+ stub_authorization!++ context 'when a user creates a new page' do+ before do+ visit spree.new_admin_cms_page_path+ end++ it 'shows in the contextual header bar the user is creating a new page' do+ within('h1') do+ expect(page).to have_text Spree.t('admin.cms.new_page')+ end+ end++ it 'shows the breadcrumb link back to all pages' do+ expect(page).to have_text Spree.t('admin.cms.all_pages')+ end++ it 'has no missing translations' do+ expect(page).not_to have_css('.translation_missing', visible: :all)+ end+ end++ context 'when a user tries to create a new page with no title' do+ before do+ visit spree.new_admin_cms_page_path+ end++ it "warns that the title can't be blank" do+ click_on 'Create'+ expect(page).to have_text ("Title can't be blank")+ end+ end++ context 'when a user tries to create a page with a duplicate slug' do+ let!(:store_1) { create(:store) }+ let!(:cms_page) { create(:cms_page, title: 'About Us', store: store_1) }++ before do+ visit spree.new_admin_cms_page_path+ end++ it 'warns the user that the slug has already been taken' do+ fill_in 'Title *', with: 'About Us'++ click_on 'Create'+ expect(page).to have_text ('Slug has already been taken')+ end+ end+enddiff --git a/backend/spec/features/admin/menus/new_menu_spec.rb b/backend/spec/features/admin/menus/new_menu_spec.rbindex 724dcd8c8c..64e546e807 100644--- a/backend/spec/features/admin/menus/new_menu_spec.rb+++ b/backend/spec/features/admin/menus/new_menu_spec.rb@@ -42,7 +42,7 @@ describe 'New Menu', type: :feature dovisit spree.new_admin_menu_pathend- it 'warns the user that the Unique code has already been taken' do+ it 'warns the user that the location has already been taken' dofill_in 'Name', with: 'Main Menu'select2 'Header', from: 'Location'diff --git a/core/config/locales/en.yml b/core/config/locales/en.ymlindex 9190a65e9d..ff9aa80e3c 100644--- a/core/config/locales/en.yml+++ b/core/config/locales/en.yml@@ -566,7 +566,7 @@ en:button_text: Button Textexit_to_full_screen_mode: Exit To Full Screenpage_type: Page Type- you_have_no_pages: You have no pages, click the Add New Page button to get started.+ you_have_no_pages: You have no Pages, click the <b>+ Add New Page</b> button to get started.new_page: New Pagetoggle_page_visibility: Toggle page visibilitymeta_title: Meta Title@@ -580,7 +580,7 @@ en:click_button_to_change_page_type: Click the <b>%{button_type}</b> button to load the options for this page type.more_page_settings: '<span class="more">More</span><span class="less">Less</span> Page Settings'seo_settings: SEO Settings- no_sections_found_please_add_one: Add your first section to this page by clicking the + Add New Section button above.+ no_sections_found_please_add_one: Add your first section to this page by clicking the <b>+ Add New Section</b> button above.click_create_to_load_new_link: 'Click the <b>Create</b> button below to save your new page section, and load the section settings.'click_update_to_load_new_link: 'Click the <b>Update</b> button below to load the new section settings.'settings_for: 'Options For: <b>%{section} Section</b>'diff --git a/core/lib/spree/testing_support/factories/page_factory.rb b/core/lib/spree/testing_support/factories/page_factory.rbnew file mode 100644index 0000000000..1b0a39cb37--- /dev/null+++ b/core/lib/spree/testing_support/factories/page_factory.rb@@ -0,0 +1,6 @@+FactoryBot.define do+ factory :cms_page, class: Spree::CmsPage do+ title { generate(:random_string) }+ locale { 'en' }+ end+end