From afb30556bdbc90c39ad0d4e8327e87a41a9770c5 Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Mon, 2 Dec 2013 07:38:02 +0100 Subject: [PATCH] Working user order flow spec --- Gemfile | 2 +- Gemfile.lock | 4 +-- app/assets/javascripts/user/quser.js.coffee | 2 +- .../_products_category_for_order.mustache | 2 +- spec/acceptance/users/order_a_product.feature | 21 ++++++++++++ .../users/sign_up_with_facebook.feature | 4 +-- spec/acceptance_steps/global_section_steps.rb | 3 ++ spec/acceptance_steps/global_table_steps.rb | 9 +++++ spec/acceptance_steps/global_user_steps.rb | 12 +++++++ spec/acceptance_steps/list_steps.rb | 4 +++ spec/acceptance_steps/order_steps.rb | 30 +++++++++++++++++ spec/acceptance_steps/supplier_steps.rb | 10 ++++++ .../users/order_products_steps.rb | 17 ++++++++++ spec/spec_helper.rb | 33 +++++++++++++++++++ spec/support/route_helpers.rb | 15 +++++++++ 15 files changed, 161 insertions(+), 7 deletions(-) create mode 100644 spec/acceptance/users/order_a_product.feature create mode 100644 spec/acceptance_steps/global_section_steps.rb create mode 100644 spec/acceptance_steps/global_table_steps.rb create mode 100644 spec/acceptance_steps/global_user_steps.rb create mode 100644 spec/acceptance_steps/supplier_steps.rb create mode 100644 spec/acceptance_steps/users/order_products_steps.rb create mode 100644 spec/support/route_helpers.rb diff --git a/Gemfile b/Gemfile index da60935f..93efed1e 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ -source :rubygems +source 'https://rubygems.org' gem 'rails', '3.2.13' gem 'rack-cors', :require => 'rack/cors' diff --git a/Gemfile.lock b/Gemfile.lock index 0f4019cd..76a9d611 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -47,7 +47,7 @@ PATH tinymce-rails GEM - remote: http://rubygems.org/ + remote: https://rubygems.org/ specs: actionmailer (3.2.13) actionpack (= 3.2.13) @@ -213,7 +213,7 @@ GEM railties (>= 3.1.0) js-routes (0.9.0) rails (>= 3.2) - json (1.8.0) + json (1.8.1) jwt (0.1.8) multi_json (>= 1.5) kaminari (0.14.1) diff --git a/app/assets/javascripts/user/quser.js.coffee b/app/assets/javascripts/user/quser.js.coffee index 3225dfb8..93345241 100644 --- a/app/assets/javascripts/user/quser.js.coffee +++ b/app/assets/javascripts/user/quser.js.coffee @@ -294,7 +294,7 @@ class Quser data ||= {} $.getJSON(data_host + src, $.extend(@authentication_object, data), (res) => include_order_buttons = res.my_list || !res.table_occupied - + $('.table-number').text(res.table_number) if res.table_number $('.supplier-name').text(res.supplier_name) if res.supplier_name diff --git a/app/templates/user/_products_category_for_order.mustache b/app/templates/user/_products_category_for_order.mustache index fb7cf3ff..8ab6425f 100644 --- a/app/templates/user/_products_category_for_order.mustache +++ b/app/templates/user/_products_category_for_order.mustache @@ -8,6 +8,6 @@ + {{#currency}}{{price}}{{/currency}} - + {{/products}} diff --git a/spec/acceptance/users/order_a_product.feature b/spec/acceptance/users/order_a_product.feature new file mode 100644 index 00000000..f61dc45d --- /dev/null +++ b/spec/acceptance/users/order_a_product.feature @@ -0,0 +1,21 @@ +Feature: Ordering a product as a user + + @javascript + Scenario: Happy flow + 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 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 + Then the user order should get feedback of being in process + When the user order gets marked as being delivered + Then the user order should get feedback of being delivered + When the user orders list gets closed + Then the user should be redirected to the archived list path + + Scenario: Resetting an active order diff --git a/spec/acceptance/users/sign_up_with_facebook.feature b/spec/acceptance/users/sign_up_with_facebook.feature index d88370da..1a43b06f 100644 --- a/spec/acceptance/users/sign_up_with_facebook.feature +++ b/spec/acceptance/users/sign_up_with_facebook.feature @@ -1,6 +1,6 @@ Feature: Sign up as user using facebook - @javascript @broken + @javascript Scenario: Happy flow Given There is no user information stored in the local storage When I visit the user obtain token path @@ -9,7 +9,7 @@ Feature: Sign up as user using facebook And I should be redirected to the user home And the newly created user info should be stored in the local storage - @javascript @broken + @javascript Scenario: Already signed in user visits obtain token path Given I am signed in as a user When I visit '/user' diff --git a/spec/acceptance_steps/global_section_steps.rb b/spec/acceptance_steps/global_section_steps.rb new file mode 100644 index 00000000..df8da35b --- /dev/null +++ b/spec/acceptance_steps/global_section_steps.rb @@ -0,0 +1,3 @@ +step 'there is a section' do + @section ||= create :section, supplier: @supplier +end diff --git a/spec/acceptance_steps/global_table_steps.rb b/spec/acceptance_steps/global_table_steps.rb new file mode 100644 index 00000000..ab8d87ee --- /dev/null +++ b/spec/acceptance_steps/global_table_steps.rb @@ -0,0 +1,9 @@ +step "the user scans a table QR code" do + step 'there is a table' + page.execute_script "Quser.actions_for_table({table_id: '#{@table.id}'})" +end + +step 'there is a table' do + step 'there is a section' + @table ||= create :table, section: @section, supplier: @supplier +end diff --git a/spec/acceptance_steps/global_user_steps.rb b/spec/acceptance_steps/global_user_steps.rb new file mode 100644 index 00000000..84584e07 --- /dev/null +++ b/spec/acceptance_steps/global_user_steps.rb @@ -0,0 +1,12 @@ +step "I am on the user homepage" do + visit user_root_path +end + +step "the user should be redirected to the user order overview page" do + route_should_be 'user#active_list' +end + +step "the user should be redirected to the archived list path" do + route_should_be 'user#history_list' + page.should have_selector ".order-row-#{@order.id}" +end diff --git a/spec/acceptance_steps/list_steps.rb b/spec/acceptance_steps/list_steps.rb index 3c22bc1f..63a81fd3 100644 --- a/spec/acceptance_steps/list_steps.rb +++ b/spec/acceptance_steps/list_steps.rb @@ -18,3 +18,7 @@ step 'a new order on a table in another section is created' do @new_list = create :list, section: @new_section, table: @new_table, supplier: @supplier, user_ids: [@user.id] @new_order = @new_list.place_order @user, {@product.id => 3} end + +step "I am signed in as a user" do + step "I visit the user obtain token path" +end diff --git a/spec/acceptance_steps/order_steps.rb b/spec/acceptance_steps/order_steps.rb index 359ce9a0..d897ef1c 100644 --- a/spec/acceptance_steps/order_steps.rb +++ b/spec/acceptance_steps/order_steps.rb @@ -11,3 +11,33 @@ end step "another order is placed" do @new_order = @list.place_order @user, {@product.id => 5} end + +step "the user order should be created as a new order" do + @order = Order.last + row = find(".order-row-#{@order.id}") + row['class'].should include 'placed' + page.should have_content 'Apple pie (1), Heineken beer (2)' + page.should have_content '€ 8.96' +end + +step "the user order gets marked as being in process" do + @order.is_being_processed! +end + +step "the user order should get feedback of being in process" do + row = find(".order-row-#{@order.id}") + row['class'].should include 'active' +end + +step "the user order gets marked as being delivered" do + @order.is_delivered! +end + +step "the user order should get feedback of being delivered" do + row = find(".order-row-#{@order.id}") + row['class'].should include 'delivered' +end + +step "the user orders list gets closed" do + @order.list.close! +end diff --git a/spec/acceptance_steps/supplier_steps.rb b/spec/acceptance_steps/supplier_steps.rb new file mode 100644 index 00000000..5167918c --- /dev/null +++ b/spec/acceptance_steps/supplier_steps.rb @@ -0,0 +1,10 @@ +step "There is an open supplier with a menu" do + step 'there is a confirmed and open supplier' + @category_beer = create :product_category, name: 'Beer', supplier: @supplier + @category_lunch = create :product_category, name: 'Lunch', supplier: @supplier + @heineken_beer = create :product, name: 'Heineken beer', supplier: @supplier, price: 2.34 + @apple_pie= create :product, name: 'Apple pie', supplier: @supplier, price: 4.28 + @heineken_beer.add_product_category @category_beer + @apple_pie.add_product_category @category_lunch +end + diff --git a/spec/acceptance_steps/users/order_products_steps.rb b/spec/acceptance_steps/users/order_products_steps.rb new file mode 100644 index 00000000..ae63459d --- /dev/null +++ b/spec/acceptance_steps/users/order_products_steps.rb @@ -0,0 +1,17 @@ + +step "the user clicks on the order :product_name twice" do |product_name| + @last_product = instance_variable_get product_name.underscore.gsub(/\s/, '_').prepend('@') + button = find ".order-product-#{@last_product.id}" + 2.times { button.click } +end + +step "the user clicks on the order product button :product_name" do |product_name| + @last_product = instance_variable_get product_name.underscore.gsub(/\s/, '_').prepend('@') + button = find ".order-product-#{@last_product.id}" + button.click +end + +step "the user clicks on the user order button" do + find('#active-order-table .btn-primary').click + sleep 1 +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 893caf5f..9a352d18 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -22,6 +22,38 @@ module FactoryAttributesFor super(obj, options).merge(build(obj).attributes.select{|k,v| k =~ /_id$/}).symbolize_keys end end +module SpecSelectorHelpers + def top_navigation + '.navbar-fixed-top' + end + + # allows tests like: + # route_should_be 'agama_groups#index' + def route_should_be(route_def) + route_hash = case route_def + when String + controller_name, action_name = route_def.split('#') + #action_name = 'index' unless action_name.present? + {controller: controller_name, action: action_name} + else + route_def + end + Rails.application.routes.recognize_path(page.current_path).should include route_hash + end + + # Uses the click_on method for capybara + def click_on_translation(key) + text = I18n.t(key) + text.should_not =~ /missing/ + click_on text + end + + # same as save_and_open_page but with styling + def show_page + save_page Rails.root.join( 'public', 'capybara.html' ) + %x(launchy http://localhost:3000/capybara.html) + end +end RSpec.configure do |config| # == Mock Framework # @@ -36,6 +68,7 @@ RSpec.configure do |config| config.include Devise::TestHelpers, type: :controller config.include EndWithMatcher config.include Features::BasicHelpers, type: :feature + config.include SpecRouteHelpers, type: :feature #config.use_transactional_fixtures = true config.infer_base_class_for_anonymous_controllers = true config.filter_run_excluding broken: true diff --git a/spec/support/route_helpers.rb b/spec/support/route_helpers.rb new file mode 100644 index 00000000..30453f30 --- /dev/null +++ b/spec/support/route_helpers.rb @@ -0,0 +1,15 @@ +module SpecRouteHelpers + # allows tests like: + # route_should_be 'agama_groups#index' + def route_should_be(route_def) + route_hash = case route_def + when String + controller_name, action_name = route_def.split('#') + #action_name = 'index' unless action_name.present? + {controller: controller_name, action: action_name} + else + route_def + end + Rails.application.routes.recognize_path(page.current_path).should include route_hash + end +end