diff --git a/app/assets/javascripts/user/app/controllers/table_controller.js.coffee b/app/assets/javascripts/user/app/controllers/table_controller.js.coffee index e4ef3e39..b09bb81f 100644 --- a/app/assets/javascripts/user/app/controllers/table_controller.js.coffee +++ b/app/assets/javascripts/user/app/controllers/table_controller.js.coffee @@ -21,7 +21,7 @@ App.TableController = Ember.ObjectController.extend if existing = @store.all('product_order').find((po)-> po.get('product') == product and not po.get('order')) existing.increment() else - @store.createRecord 'product_order', product: product + @store.createRecord 'product_order', product: product, price: product.get('price') joinOccupiedTable: -> #@secured => Ember.$.post('/user/join_occupied_table.json', table_id: @get('model.id')) diff --git a/app/assets/javascripts/user/app/templates/product_orders.emblem b/app/assets/javascripts/user/app/templates/product_orders.emblem index af30c606..3b469229 100644 --- a/app/assets/javascripts/user/app/templates/product_orders.emblem +++ b/app/assets/javascripts/user/app/templates/product_orders.emblem @@ -1,15 +1,15 @@ hr.hide-for-medium-up if modelDisabled - a.tiny.button.right{action clearProductOrders} href="#" × + a.tiny.button.right{action "clearProductOrders"} href="#" × .clearfix .panel ul.product-orders each product_order in product_orders - li.product_order + li.product-order = product_order.quantity - | x + | x = product_order.product.name - button.product_order-remove.right{action removeProductOrder product_order} + button.product-order-remove.right{action "removeProductOrder" product_order} span.icon span.currency=currency product_order.total else @@ -19,4 +19,4 @@ if modelDisabled = t 'product_orders.total' span.right.currency=currency orderTotal if product_orders - a.order-selected-products-button{action orderProducts} href="#"= t 'product_orders.order_button' + a.order-selected-products-button{action "orderProducts"} href="#"= t 'product_orders.order_button' diff --git a/app/assets/stylesheets/user/foundation/_qproduct_orders.css.sass b/app/assets/stylesheets/user/foundation/_qproduct_orders.css.sass index 8fb6536f..bb5e9abb 100644 --- a/app/assets/stylesheets/user/foundation/_qproduct_orders.css.sass +++ b/app/assets/stylesheets/user/foundation/_qproduct_orders.css.sass @@ -7,7 +7,7 @@ ul.product-orders border-bottom: none border-top: 4px solid #333 font-weight: bold - .product_order-remove + .product-order-remove +button-style($bg:$secondary-color) +button-icon-only //+button-size($padding:$button-tny) diff --git a/app/templates/user/_active_order.mustache b/app/templates/user/_active_order.mustache index 2168eac5..b637fcd4 100644 --- a/app/templates/user/_active_order.mustache +++ b/app/templates/user/_active_order.mustache @@ -13,7 +13,7 @@ {{number}} {{#currency}}{{product_total}}{{/currency}} - + {{/products}} diff --git a/spec/acceptance/users/order_a_product.feature b/spec/acceptance/users/order_a_product.feature index f61dc45d..f094eeff 100644 --- a/spec/acceptance/users/order_a_product.feature +++ b/spec/acceptance/users/order_a_product.feature @@ -7,8 +7,11 @@ Feature: Ordering a product as a user And I am on the user homepage When the user scans a table QR code And the user clicks on the order 'Heineken beer' twice - And the user clicks on the order product button 'Apple Pie' - And the user clicks on the user order button + Then the user order 'Heineken beer' should be in the order list with price + And the user order total should not be visible for only one order + When the user clicks on the order product button 'Apple pie' + Then the user order total should be visible with the correct total price + When the user clicks on the user order button Then the user should be redirected to the user order overview page And the user order should be created as a new order When the user order gets marked as being in process @@ -18,4 +21,18 @@ Feature: Ordering a product as a user When the user orders list gets closed Then the user should be redirected to the archived list path + @javascript Scenario: Resetting an active order + Given There is an open supplier with a menu + And I am signed in as a user + And I am on the user homepage + When the user scans a table QR code + And the user clicks on the order 'Heineken beer' twice + And the user clicks on the order product button 'Apple pie' + And the user clicks on the clear order for the last order button + And the user clicks on the clear order for the last order button + Then the user should see an empty active order panel + And the user clicks on the order 'Heineken beer' twice + And the user clicks on the user order button + Then an order with 2 products 'Heineken beer' should have been created + And no order for the product 'Apple pie' should have been created diff --git a/spec/acceptance_steps/global_order_steps.rb b/spec/acceptance_steps/global_order_steps.rb index 359696a7..0a39e2b4 100644 --- a/spec/acceptance_steps/global_order_steps.rb +++ b/spec/acceptance_steps/global_order_steps.rb @@ -3,3 +3,13 @@ step "A new order is placed" do @list = create :list, state: 'active', supplier: @supplier, table: @table, section: @section, user_ids: [@user.id] @order = @list.place_order products: {@product.id => 2}, user: @user end + +step "an order with :quantity products :product_name should have been created" do |quantity, product_name| + concerning_product = Product.find_by_name(product_name) + ProductOrder.find_by_quantity_and_product_id(quantity.to_i, concerning_product.id).should be_present +end + +step "no order for the product :product_name should have been created" do |product_name| + concerning_product = Product.find_by_name(product_name) + ProductOrder.find_by_product_id(concerning_product.id).should_not be_present +end diff --git a/spec/acceptance_steps/users/order_products_steps.rb b/spec/acceptance_steps/users/order_products_steps.rb index 18a9ffbb..056f8455 100644 --- a/spec/acceptance_steps/users/order_products_steps.rb +++ b/spec/acceptance_steps/users/order_products_steps.rb @@ -45,3 +45,38 @@ end step "the user page should have product information :product_description" do |product_description| page.should have_content product_description end + +step "the user order :product_name should be in the order list with price" do |product_name| + concerning_product = Product.find_by_name(product_name) + ember_order = ember_store['product_orders'].find{|po| po['product_id'] == concerning_product.id} + quantity = ember_order['quantity'] + order_price = quantity * concerning_product.price + within '.product-orders .product-order' do + page.should have_content product_name + if quantity > 1 + page.should have_content "#{quantity} x" + end + page.should have_content order_price + end +end + +step "the user order total should not be visible for only one order" do + page.should_not have_selector ".product-orders .total" +end + +step "the user order total should be visible with the correct total price" do + within ".product-orders .total" do + page.should have_content "8.96" # more dynamic in the future if needed + end +end + +step "the user clicks on the clear order for the last order button" do + within page.all('.product-orders .product-order').last do + find('.product-order-remove').click + end +end + +step "the user should see an empty active order panel" do + no_orders_message = page.evaluate_script(%|t('product_orders.no_orders')|) + page.find('.product-orders').text.should == no_orders_message +end