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 some feature tests and some missing translations.

Matthew Kennedy889bfb4e4c5a
diff --git a/backend/app/views/spree/admin/menu_items/_form.html.erb b/backend/app/views/spree/admin/menu_items/_form.html.erb
index 5e1507113c..bd02bf0dd4 100644
--- a/backend/app/views/spree/admin/menu_items/_form.html.erb
+++ b/backend/app/views/spree/admin/menu_items/_form.html.erb
@@ -54,7 +54,7 @@
<%= image_tag main_app.url_for(@menu_item.image_asset) %>
<% end %>
<%= f.field_container :image_asset, class: ['form-group'] do %>
- <%= f.label :image_asset, Spree.t(:image_asset) %><br>
+ <%= f.label :image_asset, Spree.t('admin.navigation.image_asset') %><br>
<%= f.file_field :image_asset %>
<%= f.error_message_on :image_asset %>
<% end %>
@@ -85,7 +85,11 @@
<div id="alertToClickUpdate" class="d-none">
<div class="alert alert-warning mt-3">
- Click update to load your new link
+ <% if %w[new create].include? controller.action_name %>
+ <%= raw Spree.t('admin.navigation.click_create_to_load_new_link') %>
+ <% else %>
+ <%= raw Spree.t('admin.navigation.click_update_to_load_new_link') %>
+ <% end %>
</div>
</div>
</div>
diff --git a/backend/app/views/spree/admin/menus/_form.html.erb b/backend/app/views/spree/admin/menus/_form.html.erb
index 70525d6c81..227468139e 100644
--- a/backend/app/views/spree/admin/menus/_form.html.erb
+++ b/backend/app/views/spree/admin/menus/_form.html.erb
@@ -7,9 +7,10 @@
<% end %>
</div>
<div class="col-12 col-md-6">
- <div class="form-group ">
+ <div class="form-group">
<%= label_tag :menu_stores, Spree.t(:stores) %>
<%= collection_select(:menu, :store_ids, @stores, :id, :unique_name, {}, { multiple: true, class: 'select2' }) %>
+ <%= f.error_message_on :menu_stores %>
</div>
</div>
</div>
diff --git a/backend/app/views/spree/admin/menus/edit.html.erb b/backend/app/views/spree/admin/menus/edit.html.erb
index 375b423b7b..d8531ab5fb 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.menus'), spree.admin_menus_url %> / <%= @menu.name %>
+ <%= link_to Spree.t('admin.navigation.all_menus'), spree.admin_menus_url %> / <%= @menu.name %>
<% end %>
<div class="row">
diff --git a/backend/app/views/spree/admin/menus/index.html.erb b/backend/app/views/spree/admin/menus/index.html.erb
index 2738688b85..ca8e15431d 100644
--- a/backend/app/views/spree/admin/menus/index.html.erb
+++ b/backend/app/views/spree/admin/menus/index.html.erb
@@ -3,12 +3,12 @@
<% end %>
<% content_for :page_actions do %>
- <%= button_link_to Spree.t('admin.navigation.new_menu'), new_object_url, { class: "btn-success", icon: 'add.svg', id: 'new_menu' } %>
+ <%= button_link_to Spree.t('admin.navigation.add_new_menu'), new_object_url, { class: "btn-success", icon: 'add.svg', id: 'new_menu' } %>
<% end if can?(:create, Spree::Menu) %>
<% if @menus.any? %>
<div class="table-responsive">
- <table class="table">
+ <table id="menusTable" class="table">
<thead>
<th><%= Spree.t(:name) %></th>
<th data-hook="admin_menus_index_header_actions" class="actions"></th>
@@ -30,6 +30,6 @@
</div>
<% else %>
<div class="alert alert-info no-objects-found">
- <%= Spree.t(:no_resource_found, resource: plural_resource_name(Spree::Menu)) %>
+ <%= Spree.t('admin.navigation.you_have_no_menus') %>
</div>
<% end %>
diff --git a/backend/app/views/spree/admin/menus/new.html.erb b/backend/app/views/spree/admin/menus/new.html.erb
index 2eddd888fa..599924261c 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(:menus), spree.admin_menus_url %> / <%= Spree.t(:new_menu) %>
+ <%= link_to Spree.t('admin.navigation.all_menus'), spree.admin_menus_url %> / <%= 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_spec.rb b/backend/spec/features/admin/menus/edit_spec.rb
new file mode 100644
index 0000000000..79a9c4c426
--- /dev/null
+++ b/backend/spec/features/admin/menus/edit_spec.rb
@@ -0,0 +1,21 @@
+require 'spec_helper'
+
+describe 'Editing an existing menu', type: :feature do
+ stub_authorization!
+
+ let!(:main_menu) { create(:menu, name: 'Main Menu') }
+
+ context 'user can add menu items' do
+ before do
+ visit spree.edit_admin_menu_path(main_menu)
+ end
+
+ it 'shows' do
+ click_on 'Add New Item'
+
+ within('div#contentHeader') do
+ expect(page).to have_text 'New Menu Item'
+ end
+ end
+ end
+end
diff --git a/backend/spec/features/admin/menus/index_spec.rb b/backend/spec/features/admin/menus/index_spec.rb
new file mode 100644
index 0000000000..ffe7a10667
--- /dev/null
+++ b/backend/spec/features/admin/menus/index_spec.rb
@@ -0,0 +1,57 @@
+require 'spec_helper'
+
+describe 'Menu index page', type: :feature do
+ stub_authorization!
+
+ context 'when no menus 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 Spree.t('admin.navigation.you_have_no_menus')
+ end
+ end
+
+ context 'when menus are present' do
+ let!(:main_menu) { create(:menu, name: 'Main Menu') }
+ let!(:footer_menu) { create(:menu, name: 'Footer Menu') }
+
+ before do
+ visit spree.admin_menus_path
+ end
+
+ it 'lists all of the menus in the DOM' do
+ within_table('menusTable') do
+ expect(page).to have_text 'Main Menu'
+ expect(page).to have_text 'Footer Menu'
+ end
+ end
+
+ it 'does not prompt you to create your first menu' do
+ expect(page).not_to have_text Spree.t('admin.navigation.you_have_no_menus')
+ end
+
+ it 'has no missing translations' do
+ expect(page).not_to have_css('.translation_missing', visible: :all)
+ end
+ end
+
+ context 'when a user click Add New Menu' do
+ before do
+ visit spree.admin_menus_path
+ within('div#contentHeader') do
+ click_on 'Add New Menu'
+ end
+ end
+
+ it 'they are taken to the new menu page' do
+ within('h1') do
+ expect(page).to have_text Spree.t('admin.navigation.new_menu')
+ end
+
+ expect(page).to have_text Spree.t('admin.navigation.new_menu')
+ fill_in 'Name', with: 'My Super Menu'
+ end
+ end
+end
diff --git a/backend/spec/features/admin/menus/new_spec.rb b/backend/spec/features/admin/menus/new_spec.rb
new file mode 100644
index 0000000000..abd43b284c
--- /dev/null
+++ b/backend/spec/features/admin/menus/new_spec.rb
@@ -0,0 +1,74 @@
+require 'spec_helper'
+
+describe 'New Menu Page', type: :feature do
+ stub_authorization!
+
+ context 'when user visits new menu page' do
+ before do
+ visit spree.new_admin_menu_path
+ end
+
+ it 'shows in the contextual header bar the user is creating a new menu' do
+ within('h1') do
+ expect(page).to have_text Spree.t('admin.navigation.new_menu')
+ end
+ end
+
+ it 'shows the breadcrumb link back to all menus' do
+ expect(page).to have_text Spree.t('admin.navigation.all_menus')
+ 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 menu with no name' do
+ before do
+ visit spree.new_admin_menu_path
+ end
+
+ it "warns that the Name can't be blank" do
+ click_on 'Create'
+ expect(page).to have_text ("Name can't be blank")
+ end
+ end
+
+ context 'when a user tries to create a menu with no name' do
+ let!(:main_menu) { create(:menu, name: 'Main Menu') }
+
+ before do
+ visit spree.new_admin_menu_path
+ end
+
+ it 'lets the user know that the Name has already been taken' do
+ fill_in 'Name', with: 'Main Menu'
+ click_on 'Create'
+ expect(page).to have_text ('Name has already been taken')
+ end
+ end
+
+ context 'user can create a new menu', js: true do
+ let!(:store_1) { create(:store) }
+ let!(:store_2) { create(:store) }
+ let!(:store_3) { create(:store) }
+
+ before do
+ visit spree.new_admin_menu_path
+ end
+
+ it 'with stores' do
+ fill_in 'Name', with: 'Main Menu'
+
+ select2 store_1.unique_name, from: 'Stores'
+ select2 store_3.unique_name, from: 'Stores'
+ click_on 'Create'
+
+ assert_admin_flash_alert_success('Menu "Main Menu" has been successfully created!')
+ expect(page).to have_text 'Main Menu has no items. Click the Add New Item button to begin adding links to this menu.'
+ expect(page).to have_selector('a', text: Spree.t('admin.navigation.add_new_item'))
+
+ expect(page).not_to have_css('.translation_missing', visible: :all)
+ end
+ end
+end
diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml
index a29340b88d..cfdc69ce48 100644
--- a/core/config/locales/en.yml
+++ b/core/config/locales/en.yml
@@ -574,25 +574,32 @@ en:
no_store_credit: User has no Store Credit available.
available_store_credit: User has %{amount} in Store Credit available.
navigation:
- add_new_item: 'Add New Item'
- allow_this_menu_item_to_contain_nested_menu_items: Allow this Menu Item to contain nested items
- back_to_all_menus: Back To All Menus
- menu_item_type: Menu Item Type
- menu_item_basic_details: Basic Details
- link_settings: Link Settings
- link_to: Link To
- new_menu: New Menu
- new_menu_item: New Menu Item
- no_menu_items: '<b>%{menu}</b> has no items. Click the <b>Add New Item</b> button to begin adding links to this menu.'
- nested_under_info: Quickly nest your link in the menu.
- item_type: Item Type
- open_link_in_new_window: Open this link in a new window
- menu_item_type_message: "For more information about Menu Item Types and nesting Menu Items, visit the documentation by
- <a href='https://guides.spreecommerce.org/user/configuration/configuring_geography.html#zones' target='_blank' class='alert-link'>clicking here</a>."
- menus: Menus
- menu_items: '%{menu_name} Items'
- subtitle: Subtitle
- this_link_takes_you_to_your_stores_home_page: This link takes you to your stores home page.
+ all_menus: All Menus
+ add_new_menu: Add New Menu
+ add_new_item: 'Add New Item'
+ allow_this_menu_item_to_contain_nested_menu_items: Allow this Menu Item to contain nested items
+ back_to_all_menus: Back To All Menus
+ click_create_to_load_new_link: 'Click the <b>Create</b> button below to save your new Menu Item, and update the link.'
+ click_update_to_load_new_link: 'Click the <b>Update</b> button below to change the link.'
+ menu_item_type: Menu Item Type
+ menu_item_basic_details: Basic Details
+ link_settings: Link Settings
+ link_to: Link To
+ image_asset: Add a Promotion image or Link icon.
+ new_menu_item: New Menu Item
+ new_menu: New Menu
+ nested_under: Nested under
+ no_menu_items: '<b>%{menu}</b> has no items. Click the <b>Add New Item</b> button to begin adding links to this menu.'
+ nested_under_info: Quickly nest your link in the menu.
+ item_type: Item Type
+ open_link_in_new_window: Open this link in a new window
+ menu_item_type_message: "For more information about Menu Item Types and nesting Menu Items, visit the documentation by
+ <a href='https://guides.spreecommerce.org/user/configuration/configuring_geography.html#zones' target='_blank' class='alert-link'>clicking here</a>."
+ menus: Menus
+ menu_items: '%{menu_name} Items'
+ subtitle: Subtitle
+ you_have_no_menus: You have no Menus, click the Add New Menu button to create your first Menu.
+ this_link_takes_you_to_your_stores_home_page: This link takes you to your stores home page.
administration: Administration
advertise: Advertise
agree_to_privacy_policy: Agree to Privacy Policy
diff --git a/core/db/migrate/20210408092939_create_spree_menu_items.rb b/core/db/migrate/20210408092939_create_spree_menu_items.rb
index f8e5f6ff2a..12838f7475 100644
--- a/core/db/migrate/20210408092939_create_spree_menu_items.rb
+++ b/core/db/migrate/20210408092939_create_spree_menu_items.rb
@@ -21,6 +21,6 @@ class CreateSpreeMenuItems < ActiveRecord::Migration[6.0]
add_index :spree_menu_items, :rgt
add_index :spree_menu_items, :parent_id
add_index :spree_menu_items, :item_type
- add_index :spree_menu_items, [:linked_resource_type, :linked_resource_id], name: 'index_on_linked_resource_type_and_linked_resource_id'
+ add_index :spree_menu_items, [:linked_resource_type, :linked_resource_id], name: 'index_spree_menu_items_on_linked_resource'
end
end
diff --git a/core/lib/spree/testing_support/factories/menu_factory.rb b/core/lib/spree/testing_support/factories/menu_factory.rb
new file mode 100644
index 0000000000..39dbab8927
--- /dev/null
+++ b/core/lib/spree/testing_support/factories/menu_factory.rb
@@ -0,0 +1,5 @@
+FactoryBot.define do
+ factory :menu, class: Spree::Menu do
+ name { 'Main Menu' }
+ end
+end