From 961da0c0991896bb264e6b71e0448a0871eafb70 Mon Sep 17 00:00:00 2001 From: Andrzej Krzywda Date: Tue, 28 Nov 2023 21:35:18 +0100 Subject: [PATCH] Display "cancel" button only for submitted orders We have a duplication of state machine between the Ordering aggregate and this view file (which is more error prone) --- rails_application/app/views/orders/show.html.erb | 2 +- .../test/integration/orders_test.rb | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/rails_application/app/views/orders/show.html.erb b/rails_application/app/views/orders/show.html.erb index 99ea19fb5..8d4188222 100644 --- a/rails_application/app/views/orders/show.html.erb +++ b/rails_application/app/views/orders/show.html.erb @@ -23,7 +23,7 @@ <%= button_to("Pay", pay_order_path(@order.uid), class: "mr-3 ml-3 inline-flex items-center px-4 py-2 border rounded-md shadow-sm text-sm font-medium focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 border-transparent text-white bg-blue-600 hover:bg-blue-700") %> <% end %> - <% if (@order.state != "Cancelled" && @order.state != "Paid") %> + <% if (@order.state == "Submitted") %> <%= button_to("Cancel Order", cancel_order_path(@order.uid), class: "inline-flex items-center px-4 py-2 border rounded-md shadow-sm text-sm font-medium focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-50 border-gray-300 text-gray-700 bg-white hover:bg-gray-50") %> <% end %> <% end %> diff --git a/rails_application/test/integration/orders_test.rb b/rails_application/test/integration/orders_test.rb index a21cce4d7..610a49b9d 100644 --- a/rails_application/test/integration/orders_test.rb +++ b/rails_application/test/integration/orders_test.rb @@ -135,6 +135,12 @@ def test_confirmed_order_doesnt_show_cancel_button get "/" get "/orders/new" post "/orders/#{order_id}/add_item?product_id=#{async_remote_id}" + Sidekiq::Job.drain_all + + get "/orders/#{order_id}" + + assert_select("button", text: "Cancel Order", count: 0) + post "/orders", params: { "authenticity_token" => "[FILTERED]", @@ -142,12 +148,20 @@ def test_confirmed_order_doesnt_show_cancel_button "customer_id" => shopify_id, "commit" => "Submit order" } + Sidekiq::Job.drain_all + + get "/orders/#{order_id}" + assert_select("button", text: "History") + #assert_select("button", text: "Cancel Order", count: 1) + + post "/orders/#{order_id}/pay" Shipments::MarkOrderSubmitted.drain follow_redirect! assert_select("td", text: "Paid") get "/orders/#{order_id}" - assert_select("button", 2) + assert_select("button", text: "History") + assert_select("button", text: "Cancel Order", count: 0) end def test_order_value_doesnt_change_after_changing_price