Show actions dropdown on edit order page only when there are actions available#13760
Show actions dropdown on edit order page only when there are actions available#13760drummer83 wants to merge 2 commits intoopenfoodfoundation:masterfrom
Conversation
|
Hi @filipefurtad0, |
|
Hey @drummer83 , |
| render | ||
|
|
||
| expect(rendered).to have_content("Actions") | ||
| end |
There was a problem hiding this comment.
Hey @drummer83,
I believe this assertion will pass, if you run it within the file ./spec/views/spree/admin/orders/index.html.haml_spec.rb, instead of this one here (.spec/views/spree/admin/orders/edit.html.haml_spec.rb - this deals with the edit variants section of the edit orders page).
There was a problem hiding this comment.
...Hum, not quite. It passes, because it deals with the bulk orders page. You're looking at the right file @drummer83 👍 But the view is not generating that menu. Will investigate further.
There was a problem hiding this comment.
Ok, so I think I was close 😅
So, we need to run that test on the right component, which is spree/admin/shared/_order_links.html.haml which is the one you change in this PR. However, view specs test one component at a time, system specs test them all. So, to test the component in a granular way 💪 I'd say you need to create a specific test for this component, as I've found none.
So, I'd suggest creating this view test, on a separate file and commit (code suggestion below), and then create a context in which the actions menu is hidden (e.g., cancelled):
| end | |
| # frozen_string_literal: true | |
| require "spec_helper" | |
| RSpec.describe "spree/admin/shared/_order_links.html.haml" do | |
| helper Spree::Admin::OrdersHelper | |
| around do |example| | |
| original_config = Spree::Config[:enable_invoices?] | |
| example.run | |
| Spree::Config[:enable_invoices?] = original_config | |
| end | |
| let(:current_test_user) { create(:admin_user) } | |
| before do | |
| controller.singleton_class.class_eval do | |
| attr_accessor :current_test_user | |
| def current_ability | |
| Spree::Ability.new(current_test_user) | |
| end | |
| end | |
| controller.current_test_user = current_test_user | |
| allow(view).to receive_messages spree_current_user: current_test_user | |
| end | |
| context "when order is complete" do | |
| let(:order) { create(:completed_order_with_fees) } | |
| before do | |
| order.distributor = create(:distributor_enterprise) | |
| assign(:order, order) | |
| assign(:shops, [order.distributor]) | |
| assign(:order_cycles, []) | |
| end | |
| it "displays the order_links dropdown" do | |
| render | |
| expect(rendered).to have_content("Actions") | |
| end | |
| end | |
| end | |
What do you think @drummer83 ?
(PS: this comment looks weird as it suggests to replace the end line; the idea I'm proposing is rather replacing this commit with another one, in which you create a new spec file, with the code in green above. Please let me know if this clarifies.)
What? Why?
On cancelled orders there are no actions that can be taken, like ship order, cancel order, send invoice, print invoice etc. So the actions dropdown is empty. Instead of showing the empty dropdown we should simply hide it.
This PR makes sure that the actions dropdown is only rendered when there are actions available.
Before
Dropdown open and no actions available:

After
No dropdown:

Before and after (unchanged)
Dropdown is shown when actions are available:

What should we test?
Release notes
Changelog Category (reviewers may add a label for the release notes):
The title of the pull request will be included in the release notes.
Dependencies
Documentation updates