New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Ship Order menu choice not working #12376
Fix Ship Order menu choice not working #12376
Conversation
@@ -19,3 +21,6 @@ | |||
%span=link[:name] | |||
|
|||
= render 'spree/admin/shared/custom-confirm' | |||
- if shipment_ready |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am wondering if we could move the shipment_ready
logic in an helper ? so we could do if order_shipment_ready?(@order)
I am not a big fan of setting variable in the view, in this case it's not quite clear what's why shipment_ready
is set to true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's a good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, I might have been a bit hurry. I have put the logic in the order_helpers.rb
@@ -19,3 +21,6 @@ | |||
%span=link[:name] | |||
|
|||
= render 'spree/admin/shared/custom-confirm' | |||
- if shipment_ready |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's a good idea.
Hey @cyrillefr , I've submitted a PR (here) with a spec reproducing this regression (it's currently in code review). In case you find it useful, please feel free to cherry pick it, for this PR 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good now !
Hello @filipefurtad0 , Thanks for the offer, I think your PR will be complementary to mine. Coverage will be top. |
Thanks @cyrillefr - that's perfect as well: after merging, I can remove the |
Oh, I just merged the other PR. So we have to resolve it here now. |
Hm, the new specs seem to be failing. I shouldn't have merged them without testing against the solution. |
ee1a806
to
4260047
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I rebased the branch to resolve the conflict on the spec. I also changed Filipe's spec with bits from @cyrillefr's spec but I think that there's a bug.
Can you have another look?
spec/system/admin/order_spec.rb
Outdated
|
||
# the best & easiest way to close the modal without calling all the JS | ||
find_button("Cancel").click |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be a bug that needs to be resolved. Testing locally, the modal didn't close for me in dev environment either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I deleted this part to work with the shared examples. In the new version, it closes well after running examples dozens of time. Hope it will be the same in your local and dev.
spec/system/admin/order_spec.rb
Outdated
context 'when not on the Order Details sub section' do | ||
before do | ||
click_link 'Customer Details' | ||
end | ||
it 'can ship order too' do | ||
find('.ofn-drop-down').click | ||
click_link 'Ship Order' | ||
|
||
within ".reveal-modal" do | ||
expect(page).to have_checked_field('Send a shipment/pick up ' \ | ||
'notification email to the customer.') | ||
# no test of enqueued job since it can cause failures | ||
# if the remainder of the spec is too fasr | ||
find_button('Confirm').click | ||
end | ||
|
||
# the best & easiest way to close the modal without calling all the JS | ||
find_button("Cancel").click | ||
expect(order.reload.shipped?).to be true | ||
click_link('Order Details') | ||
expect(page).to have_text 'SHIPPED' | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that this is now covered by the above shared examples. I just left it here for reference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is now included in the shared examples, so I deleted this part. Also I modified a bit the shared examples, see below.
4260047
to
320b551
Compare
Hello @mkllnk , some words about my last changes. I have added a click to the 'Order Details' part to check for the shipped status (it only writes there). I then had a problem, from time to time: the mailing job was not enqueued. But it is not a good practice, so I have looked for another solution. |
But that's a bug, right? Shouldn't the modal close when you choose an action? @filipefurtad0 |
I've staged the PR, and I think you mean the confirmation modal - right? The dropdown closes when clicked, but the confirmation modal indeed requires a click/action from the user. Is this what you refer to @cyrillefr ? If so I think it is the correct behavior. |
Hello @filipefurtad0 , Yes the modal I am referring to is the one on the screenshot, when you edit an order. |
Ok, I see it now. I've pulled the code from this PR and compared it with master: indeed, in master the confirmation modal closes after selecting an option; this is not the case within this PR. I agree with @mkllnk: we should keep the current behavior (in master), i.e., the modal should close after selecting one of the options. |
Hello @filipefurtad0 , I have checked and here are the details:
Which means this modal is dependent of the subpage. @mkllnk , I 'll go check and update as soon as possible. |
dceea4e
to
37616c6
Compare
Hello @mkllnk , Now there is no need to close the modal manually in the specs. But because there is a redirection to a classical Rails controller, the page is reloaded and the reload make the modal go away. Also , I would need a rerun of the checks since the specs in error works fine locally. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, good. Page reload is fine.
app/reflexes/admin/orders_reflex.rb
Outdated
module Constants | ||
PATHS = %w[edit customer payments adjustments invoices return_authorizations].freeze | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that you need an additional module just to declare a constant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with you, but there is a 100 lines limit for Class size, so I had to do this not to raise the rubocop offense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, this is a good example for style rules producing worse code. Rubocop is supposed to help us. If its recommendation is stupid, we need to do something else.
I agree with Rubocop that the class is getting too big. Adding a module doesn't help though. We could move some code into other files like an InvoiceReflex, for example. But since we are going to shift away from reflexes, we can just add it to the rubocop todo file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, I added a new line on the rubocop todo file :)
- Front End ShipOrderComponent was missed for the menu to work - updated spec to test for a specific case
- deletes local variables in view - factor logic in helper
- removes the pending - add the click to go to the 'Order Details' page to check for the 'shipped' status - from enqueued to have_been_enqueued so the spec is flaky-free
- returns to the same processing for customer, invoices etc. that edit - need a bit of sleep in spec bc 2 tasks are asynchroneous
- bypass rubocop class lines limit
9447b95
to
6575ad7
Compare
Hey @cyrillefr , Awesome, thanks so much for your work on this and the thorough description. I've tested both as superadmin and hub admin, selecting the Ship Order from the Actions drop down, on the order edit page, for several orders in
In all cases, the shipping state changed to Great to finally have this one through 👏 👏 👏 |
59e04cc
into
openfoodfoundation:master
It looks like this fixes a user-facing bug, so I'm updating the label. Please correct me if wrong! |
What? Why?
Error when trying to ship an order when everywhere in
admin/orders/RXX/customer
,admin/orders/RXXX/payments
,admin/orders/RXXXX/adjustments
,admin/orders/RXXXXX/return_authorizations
Reason: there were not the
ShipOrderComponent
which enables a modal for shipping order. The same component this present when in theadmin/orders/R52384XXX/edit
page_order_links.html.haml
)What should we test?
admin/orders
.admin/orders/R52384XXX/edit
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