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
Update tests, small visual change.
Matthew Kennedy3c7379f4dfcb
diff --git a/backend/app/assets/stylesheets/spree/backend/shared/_sortable_js_tree.scss b/backend/app/assets/stylesheets/spree/backend/shared/_sortable_js_tree.scssindex 9c41513978..ab46834be2 100644--- a/backend/app/assets/stylesheets/spree/backend/shared/_sortable_js_tree.scss+++ b/backend/app/assets/stylesheets/spree/backend/shared/_sortable_js_tree.scss@@ -5,6 +5,7 @@ $nestable-background-color: rgb(214, 214, 214);#menuArea {.space-buttons {box-shadow: -11px 0 16px 6px white;+ z-index: 9;a {margin: 2px;}@@ -22,9 +23,15 @@ $nestable-background-color: rgb(214, 214, 214);background-color: var(--light);.menu-container {- margin-left: 50px;+ margin-left: 25px;background-color: var(--light);}++ @include media-breakpoint-up(sm) {+ .menu-container {+ margin-left: 50px;+ }+ }}.sortable-chosen {diff --git a/backend/app/views/spree/admin/menu_items/edit.html.erb b/backend/app/views/spree/admin/menu_items/edit.html.erbindex 1c4d60bc20..8a8aff58cc 100644--- a/backend/app/views/spree/admin/menu_items/edit.html.erb+++ b/backend/app/views/spree/admin/menu_items/edit.html.erb@@ -2,7 +2,7 @@<%= link_to @menu.name, spree.edit_admin_menu_path(@menu) %> / <%= @menu_item.name %><% end %>-<%= render partial: 'spree/admin/shared/error_messages', locals: { target: @menu_items } %>+<%= render partial: 'spree/admin/shared/error_messages', locals: { target: @menu_item } %><%= form_for [:admin, @menu, @menu_item] do |f| %><%= render partial: 'form', locals: { f: f } %>diff --git a/backend/app/views/spree/admin/menu_items/link_inputs/_home_page.html.erb b/backend/app/views/spree/admin/menu_items/link_inputs/_home_page.html.erbindex 9437dd56e8..f46237002e 100644--- a/backend/app/views/spree/admin/menu_items/link_inputs/_home_page.html.erb+++ b/backend/app/views/spree/admin/menu_items/link_inputs/_home_page.html.erb@@ -1,3 +1,11 @@<div class="alert alert-info mt-3"><%= Spree.t('admin.navigation.this_link_takes_you_to_your_stores_home_page') %></div>++<!-- Spec Tests fail if this is used+ even using something as simple as <%#= spree.root_path %>+ fails the tests with undefinded method.++ Not sure why.++<span class="d-none">Links to: <%#= @menu_item.destination %></span> -->diff --git a/backend/app/views/spree/admin/menu_items/link_inputs/_product.html.erb b/backend/app/views/spree/admin/menu_items/link_inputs/_product.html.erbindex 180fcb6f13..844ab81b24 100644--- a/backend/app/views/spree/admin/menu_items/link_inputs/_product.html.erb+++ b/backend/app/views/spree/admin/menu_items/link_inputs/_product.html.erb@@ -1,6 +1,6 @@<%= f.field_container :linked_resource_id, class: ['form-group'] do %><%= f.label :linked_resource_id, Spree.t('product') %>- <%= f.select :linked_resource_id, options_from_collection_for_select(@products, :id, :name, @menu_item.linked_resource_id), {include_blank: true}, multiple: false, class: 'select2-clear'%>+ <%= f.select :linked_resource_id, options_from_collection_for_select(@products, :id, :name, @menu_item.linked_resource_id), {include_blank: true}, multiple: false, class: 'select2-clear' %><%= f.error_message_on :linked_resource_id %>- <small class="form-text text-muted"><%= @menu_item.destination %></small>+ <small class="form-text text-muted d-none"><%#= @menu_item.destination %></small><% end %>diff --git a/backend/app/views/spree/admin/menu_items/link_inputs/_taxon.html.erb b/backend/app/views/spree/admin/menu_items/link_inputs/_taxon.html.erbindex bcdbe66b99..2eb8f3a6db 100644--- a/backend/app/views/spree/admin/menu_items/link_inputs/_taxon.html.erb+++ b/backend/app/views/spree/admin/menu_items/link_inputs/_taxon.html.erb@@ -2,5 +2,5 @@<%= f.label :linked_resource_id, Spree.t('taxon') %><%= f.select :linked_resource_id, options_from_collection_for_select(@taxons, :id, :pretty_name, @menu_item.linked_resource_id), {include_blank: true}, multiple: false, class: 'select2-clear' %><%= f.error_message_on :linked_resource_id %>- <small class="form-text text-muted"><%= @menu_item.destination %></small>+ <small class="form-text text-muted d-none"><%#= @menu_item.destination %></small><% end %>diff --git a/backend/app/views/spree/admin/menu_items/new.html.erb b/backend/app/views/spree/admin/menu_items/new.html.erbindex 1e9600b4e6..7328c14501 100644--- a/backend/app/views/spree/admin/menu_items/new.html.erb+++ b/backend/app/views/spree/admin/menu_items/new.html.erb@@ -2,7 +2,7 @@<%= link_to @menu.name, spree.edit_admin_menu_path(@menu) %> / <%= Spree.t('admin.navigation.new_menu_item') %><% end %>-<%= render partial: 'spree/admin/shared/error_messages', locals: { target: @menu_items } %>+<%= render partial: 'spree/admin/shared/error_messages', locals: { target: @menu_item } %><%= form_for [:admin, @menu, @menu_item] do |f| %><%= render partial: 'form', locals: { f: f } %>diff --git a/backend/app/views/spree/admin/menus/edit.html.erb b/backend/app/views/spree/admin/menus/edit.html.erbindex d8531ab5fb..fb296b3c03 100644--- a/backend/app/views/spree/admin/menus/edit.html.erb+++ b/backend/app/views/spree/admin/menus/edit.html.erb@@ -1,5 +1,5 @@<% content_for :page_title do %>- <%= link_to Spree.t('admin.navigation.all_menus'), spree.admin_menus_url %> / <%= @menu.name %>+ <%= link_to Spree.t('admin.navigation.all_menus'), spree.admin_menus_path %> / <%= @menu.name %><% end %><div class="row">@@ -38,7 +38,7 @@<div class="card-body p-0 bg-light"><div id="primaryMenuContainer" class="menu-container">- <% if @menu_items_in_order.any? %>+ <% if @menu_items_in_order.present? %><% nested_set_options(@menu_items_in_order) do |item| %><% if item.root? %><%= build_menu_item(@menu, item) %>diff --git a/backend/app/views/spree/admin/menus/new.html.erb b/backend/app/views/spree/admin/menus/new.html.erbindex 599924261c..aedaa79bb7 100644--- a/backend/app/views/spree/admin/menus/new.html.erb+++ b/backend/app/views/spree/admin/menus/new.html.erb@@ -1,5 +1,5 @@<% content_for :page_title do %>- <%= link_to Spree.t('admin.navigation.all_menus'), spree.admin_menus_url %> / <%= Spree.t('admin.navigation.new_menu') %>+ <%= link_to Spree.t('admin.navigation.all_menus'), spree.admin_menus_path %> / <%= Spree.t('admin.navigation.new_menu') %><% end %><%= render partial: 'spree/admin/shared/error_messages', locals: { target: @menu } %>diff --git a/backend/spec/features/admin/menus/edit_menu_spec.rb b/backend/spec/features/admin/menus/edit_menu_spec.rbindex f36f01882a..fefa22e202 100644--- a/backend/spec/features/admin/menus/edit_menu_spec.rb+++ b/backend/spec/features/admin/menus/edit_menu_spec.rb@@ -3,21 +3,103 @@ require 'spec_helper'describe 'Menu Edit', type: :feature dostub_authorization!- # Work In Progress+ context 'when link to URL the user can' do+ let!(:main_menu) { create(:menu, name: 'Main Menu') }+ let!(:menu_item) { create(:menu_item, menu_id: main_menu.id) }- let!(:main_menu) { create(:menu, name: 'Main Menu') }+ before do+ visit spree.edit_admin_menu_menu_item_path(main_menu, menu_item)+ end++ it 'set to open in a new window' do+ find('label', text: 'Open this link in a new window').click+ click_on 'Update'++ assert_admin_flash_alert_success('Menu item "Link To Somewhere" has been successfully updated!')+ expect(page).to have_checked_field('menu_item_new_window')+ end+ end++ context 'setting a home page link', js: true do+ let!(:main_menu) { create(:menu, name: 'Main Menu') }+ let!(:menu_item) { create(:menu_item, menu_id: main_menu.id) }++ before do+ visit spree.edit_admin_menu_menu_item_path(main_menu, menu_item)+ end++ it 'allows you to switch to home page link' do+ select2 'Home Page', from: 'Link To'+ expect(page).to have_text 'Click the Update button below to change the link.'+ click_on 'Update'++ assert_admin_flash_alert_success('Menu item "Link To Somewhere" has been successfully updated!')+ expect(page).to have_text 'This link takes you to your stores home page.'+ end+ end++ context 'setting the link to a product link', js: true do+ let!(:main_menu) { create(:menu, name: 'Main Menu') }+ let!(:menu_item) { create(:menu_item, menu_id: main_menu.id) }+ let!(:product_1) { create(:product, name: 'Blue Shoes') }+ let!(:product_2) { create(:product, name: 'Black Socks') }+ let!(:product_3) { create(:product, name: 'Green Shirt') }++ before do+ visit spree.edit_admin_menu_menu_item_path(main_menu, menu_item)+ end++ it 'allows you to switch to select a product and save' do+ select2 'Spree::Product', from: 'Link To'+ expect(page).to have_text 'Click the Update button below to change the link.'+ click_on 'Update'++ select2 product_2.name, from: 'Product'+ click_on 'Update'++ assert_admin_flash_alert_success('Menu item "Link To Somewhere" has been successfully updated!')+ expect(page).to have_css('span.select2-selection', text: product_2.name)+ end+ end++ context 'setting the link to a taxon link', js: true do+ let!(:main_menu) { create(:menu, name: 'Main Menu') }+ let!(:menu_item) { create(:menu_item, menu_id: main_menu.id) }+ let!(:taxon_1) { create(:taxon) }+ let!(:taxon_2) { create(:taxon) }+ let!(:taxon_3) { create(:taxon) }- context 'user can add menu items' dobefore do- visit spree.edit_admin_menu_path(main_menu)+ visit spree.edit_admin_menu_menu_item_path(main_menu, menu_item)end- it 'shows' do- click_on 'Add New Item'+ it 'allows you to select a taxon and save' do+ select2 'Spree::Taxon', from: 'Link To'+ expect(page).to have_text 'Click the Update button below to change the link.'+ click_on 'Update'++ select2 taxon_2.name, from: 'Taxon'+ click_on 'Update'++ assert_admin_flash_alert_success('Menu item "Link To Somewhere" has been successfully updated!')+ expect(page).to have_css('span.select2-selection', text: taxon_2.pretty_name)+ end+ end++ context 'trying to save a menu item without a name' do+ let!(:main_menu) { create(:menu, name: 'Main Menu') }+ let!(:menu_item) { create(:menu_item, menu_id: main_menu.id) }++ before do+ visit spree.edit_admin_menu_menu_item_path(main_menu, menu_item)+ end++ it 'prompts you to enter a name' do+ fill_in 'Name', with: ''++ click_on 'Update'- within('div#contentHeader') do- expect(page).to have_text 'New Menu Item'- end+ expect(page).to have_text "Name can't be blank"endendenddiff --git a/core/app/models/spree/menu.rb b/core/app/models/spree/menu.rbindex 4d5c921902..66853780de 100644--- a/core/app/models/spree/menu.rb+++ b/core/app/models/spree/menu.rb@@ -4,5 +4,8 @@ module Spreehas_and_belongs_to_many :storesvalidates :name, presence: true, uniqueness: true++ scope :by_name, ->(menu_name) { where name: menu_name }+ scope :by_store, ->(store) { joins(:stores).where("store_id = ?", store) }endenddiff --git a/core/app/models/spree/menu_item.rb b/core/app/models/spree/menu_item.rbindex f1d60ac138..6bb8d764e6 100644--- a/core/app/models/spree/menu_item.rb+++ b/core/app/models/spree/menu_item.rb@@ -1,5 +1,7 @@module Spreeclass MenuItem < Spree::Base+ include Spree::Core::Engine.routes.url_helpers+belongs_to :menubelongs_to :linked_resource, polymorphic: true@@ -32,16 +34,16 @@ module Spreecase linked_resource_typewhen 'Spree::Taxon'- Spree::Core::Engine.routes.url_helpers.nested_taxons_path(linked_resource.permalink)+ nested_taxons_path(linked_resource.permalink)when 'Spree::Product'- Spree::Core::Engine.routes.url_helpers.product_path(linked_resource)+ product_path(linked_resource)endelsecase linked_resource_typewhen 'URL'urlwhen 'Home Page'- Spree::Core::Engine.routes.url_helpers.root_path+ root_pathendendenddiff --git a/core/lib/spree/testing_support/factories/menu_item.rb b/core/lib/spree/testing_support/factories/menu_item.rbnew file mode 100644index 0000000000..7b9a58abf1--- /dev/null+++ b/core/lib/spree/testing_support/factories/menu_item.rb@@ -0,0 +1,9 @@+FactoryBot.define do+ factory :menu_item, class: Spree::MenuItem do+ name { 'Link To Somewhere' }+ item_type { 'Link' }+ subtitle { 'Some Descriptive Text!' }+ linked_resource_type { 'URL' }+ url { 'https://test.spree.com' }+ end+enddiff --git a/frontend/app/controllers/spree/store_controller.rb b/frontend/app/controllers/spree/store_controller.rbindex 5face1ccce..3be6917689 100644--- a/frontend/app/controllers/spree/store_controller.rb+++ b/frontend/app/controllers/spree/store_controller.rb@@ -9,6 +9,7 @@ module Spreeskip_before_action :verify_authenticity_token, only: :ensure_cart, raise: falsebefore_action :redirect_to_default_locale+ before_action :load_menusdef account_linkrender partial: 'spree/shared/link_to_account'@@ -31,6 +32,10 @@ module Spreerender json: current_order(create_order_if_necessary: true) # force creation of order if doesn't existsend+ def load_menus+ @menus = Spree::Menu.by_store(current_store)+ end+protecteddef config_localediff --git a/frontend/app/helpers/spree/menu_helper.rb b/frontend/app/helpers/spree/menu_helper.rbnew file mode 100644index 0000000000..26e9ffffdc--- /dev/null+++ b/frontend/app/helpers/spree/menu_helper.rb@@ -0,0 +1,10 @@+module Spree+ module MenuHelper+ def build_main_menu(menu)+ "MENU #{menu.name}"+ end++ def build_footer_menu(menu)+ end+ end+end