spree_backend 3.2.9 → 3.3.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (196) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/spree/backend/admin.js +16 -15
  3. data/app/assets/javascripts/spree/backend/checkouts/edit.js +25 -26
  4. data/app/assets/javascripts/spree/backend/general_settings.js.coffee +10 -12
  5. data/app/assets/javascripts/spree/backend/payments/edit.js.coffee +4 -6
  6. data/app/assets/javascripts/spree/backend/returns/return_item_selection.js +7 -1
  7. data/app/assets/javascripts/spree/backend/stock_transfer.js.coffee +4 -1
  8. data/app/assets/javascripts/spree/backend/user_picker.js +3 -1
  9. data/app/assets/javascripts/spree/backend.js +3 -3
  10. data/app/controllers/spree/admin/countries_controller.rb +1 -0
  11. data/app/controllers/spree/admin/log_entries_controller.rb +2 -2
  12. data/app/controllers/spree/admin/orders/customer_details_controller.rb +5 -6
  13. data/app/controllers/spree/admin/orders_controller.rb +4 -4
  14. data/app/controllers/spree/admin/payments_controller.rb +21 -10
  15. data/app/controllers/spree/admin/products_controller.rb +5 -0
  16. data/app/controllers/spree/admin/promotion_rules_controller.rb +11 -7
  17. data/app/controllers/spree/admin/stock_transfers_controller.rb +1 -1
  18. data/app/controllers/spree/admin/taxons_controller.rb +31 -23
  19. data/app/helpers/spree/admin/base_helper.rb +1 -1
  20. data/app/helpers/spree/admin/navigation_helper.rb +10 -4
  21. data/app/views/spree/admin/adjustments/_adjustments_table.html.erb +2 -2
  22. data/app/views/spree/admin/general_settings/edit.html.erb +8 -8
  23. data/app/views/spree/admin/images/_form.html.erb +2 -2
  24. data/app/views/spree/admin/images/edit.html.erb +2 -2
  25. data/app/views/spree/admin/images/new.html.erb +1 -1
  26. data/app/views/spree/admin/option_types/_form.html.erb +2 -2
  27. data/app/views/spree/admin/option_types/index.html.erb +4 -4
  28. data/app/views/spree/admin/orders/_line_items.html.erb +40 -38
  29. data/app/views/spree/admin/orders/_shipment.html.erb +77 -76
  30. data/app/views/spree/admin/orders/customer_details/_form.html.erb +5 -5
  31. data/app/views/spree/admin/orders/index.html.erb +16 -16
  32. data/app/views/spree/admin/payment_methods/_form.html.erb +2 -2
  33. data/app/views/spree/admin/payments/_list.html.erb +1 -1
  34. data/app/views/spree/admin/products/_add_stock_form.html.erb +3 -3
  35. data/app/views/spree/admin/products/_form.html.erb +16 -16
  36. data/app/views/spree/admin/products/index.html.erb +4 -4
  37. data/app/views/spree/admin/products/new.html.erb +8 -8
  38. data/app/views/spree/admin/promotion_categories/index.html.erb +3 -3
  39. data/app/views/spree/admin/promotions/_form.html.erb +3 -3
  40. data/app/views/spree/admin/promotions/_promotion_rule.html.erb +1 -1
  41. data/app/views/spree/admin/promotions/actions/_create_adjustment.html.erb +2 -2
  42. data/app/views/spree/admin/promotions/actions/_create_item_adjustments.html.erb +2 -2
  43. data/app/views/spree/admin/promotions/actions/_create_line_items.html.erb +2 -4
  44. data/app/views/spree/admin/promotions/edit.html.erb +3 -3
  45. data/app/views/spree/admin/promotions/index.html.erb +6 -6
  46. data/app/views/spree/admin/promotions/rules/_item_total.html.erb +2 -2
  47. data/app/views/spree/admin/promotions/rules/_option_value.html.erb +4 -4
  48. data/app/views/spree/admin/properties/_form.html.erb +2 -2
  49. data/app/views/spree/admin/properties/index.html.erb +6 -6
  50. data/app/views/spree/admin/prototypes/index.html.erb +4 -4
  51. data/app/views/spree/admin/reimbursement_types/_form.html.erb +4 -4
  52. data/app/views/spree/admin/reimbursements/edit.html.erb +1 -1
  53. data/app/views/spree/admin/return_authorizations/_form.html.erb +13 -1
  54. data/app/views/spree/admin/return_index/customer_returns.html.erb +2 -2
  55. data/app/views/spree/admin/return_index/return_authorizations.html.erb +5 -5
  56. data/app/views/spree/admin/shared/_content_header.html.erb +2 -2
  57. data/app/views/spree/admin/shared/_header.html.erb +2 -2
  58. data/app/views/spree/admin/shared/_index_table_options.html.erb +2 -2
  59. data/app/views/spree/admin/shared/_order_summary.html.erb +1 -1
  60. data/app/views/spree/admin/shared/_table_filter.html.erb +1 -1
  61. data/app/views/spree/admin/shared/_translations.html.erb +0 -1
  62. data/app/views/spree/admin/shared/_update_order_state.js.erb +1 -1
  63. data/app/views/spree/admin/shipping_methods/_form.html.erb +10 -10
  64. data/app/views/spree/admin/state_changes/index.html.erb +3 -3
  65. data/app/views/spree/admin/states/_form.html.erb +2 -2
  66. data/app/views/spree/admin/stock_locations/_form.html.erb +2 -2
  67. data/app/views/spree/admin/stock_locations/_transfer_stock_form.html.erb +4 -4
  68. data/app/views/spree/admin/stock_transfers/index.html.erb +3 -3
  69. data/app/views/spree/admin/stock_transfers/new.html.erb +2 -2
  70. data/app/views/spree/admin/store_credits/index.html.erb +1 -1
  71. data/app/views/spree/admin/tax_rates/_form.html.erb +2 -2
  72. data/app/views/spree/admin/taxonomies/_list.html.erb +2 -2
  73. data/app/views/spree/admin/taxonomies/{edit.erb → edit.html.erb} +0 -0
  74. data/app/views/spree/admin/taxonomies/index.html.erb +2 -2
  75. data/app/views/spree/admin/taxons/_form.html.erb +5 -5
  76. data/app/views/spree/admin/taxons/edit.html.erb +3 -0
  77. data/app/views/spree/admin/trackers/_form.html.erb +2 -2
  78. data/app/views/spree/admin/users/_addresses_form.html.erb +2 -2
  79. data/app/views/spree/admin/users/_form.html.erb +2 -2
  80. data/app/views/spree/admin/users/_user_page_actions.html.erb +1 -1
  81. data/app/views/spree/admin/users/index.html.erb +5 -5
  82. data/app/views/spree/admin/users/items.html.erb +1 -1
  83. data/app/views/spree/admin/users/orders.html.erb +1 -1
  84. data/app/views/spree/admin/variants/_form.html.erb +2 -2
  85. data/app/views/spree/admin/zones/_form.html.erb +2 -2
  86. data/app/views/spree/layouts/admin.html.erb +3 -3
  87. data/config/initializers/assets.rb +1 -1
  88. data/lib/spree/backend/engine.rb +0 -1
  89. data/spec/controllers/spree/admin/base_controller_spec.rb +46 -0
  90. data/spec/controllers/spree/admin/customer_returns_controller_spec.rb +185 -0
  91. data/spec/controllers/spree/admin/general_settings_controller_spec.rb +41 -0
  92. data/spec/controllers/spree/admin/missing_products_controller_spec.rb +18 -0
  93. data/spec/controllers/spree/admin/orders/customer_details_controller_spec.rb +199 -0
  94. data/spec/controllers/spree/admin/orders_controller_spec.rb +296 -0
  95. data/spec/controllers/spree/admin/payment_methods_controller_spec.rb +64 -0
  96. data/spec/controllers/spree/admin/payments_controller_spec.rb +97 -0
  97. data/spec/controllers/spree/admin/products_controller_spec.rb +137 -0
  98. data/spec/controllers/spree/admin/promotion_actions_controller_spec.rb +21 -0
  99. data/spec/controllers/spree/admin/promotion_rules_controller_spec.rb +21 -0
  100. data/spec/controllers/spree/admin/promotions_controller_spec.rb +44 -0
  101. data/spec/controllers/spree/admin/refunds_controller_spec.rb +32 -0
  102. data/spec/controllers/spree/admin/reimbursements_controller_spec.rb +74 -0
  103. data/spec/controllers/spree/admin/reports_controller_spec.rb +42 -0
  104. data/spec/controllers/spree/admin/resource_controller_spec.rb +252 -0
  105. data/spec/controllers/spree/admin/return_authorizations_controller_spec.rb +225 -0
  106. data/spec/controllers/spree/admin/return_index_controller_spec.rb +37 -0
  107. data/spec/controllers/spree/admin/return_items_controller_spec.rb +27 -0
  108. data/spec/controllers/spree/admin/shipping_methods_controller_spec.rb +14 -0
  109. data/spec/controllers/spree/admin/stock_items_controller_spec.rb +19 -0
  110. data/spec/controllers/spree/admin/stock_locations_controller_spec.rb +41 -0
  111. data/spec/controllers/spree/admin/stock_transfers_controller_spec.rb +41 -0
  112. data/spec/controllers/spree/admin/tax_categories_controller_spec.rb +34 -0
  113. data/spec/controllers/spree/admin/users_controller_spec.rb +161 -0
  114. data/spec/controllers/spree/admin/variants_controller_spec.rb +32 -0
  115. data/spec/features/admin/configuration/analytics_tracker_spec.rb +47 -0
  116. data/spec/features/admin/configuration/countries_spec.rb +24 -0
  117. data/spec/features/admin/configuration/general_settings_spec.rb +44 -0
  118. data/spec/features/admin/configuration/payment_methods_spec.rb +63 -0
  119. data/spec/features/admin/configuration/roles_spec.rb +47 -0
  120. data/spec/features/admin/configuration/shipping_methods_spec.rb +62 -0
  121. data/spec/features/admin/configuration/states_spec.rb +68 -0
  122. data/spec/features/admin/configuration/stock_locations_spec.rb +48 -0
  123. data/spec/features/admin/configuration/store_credit_categories_spec.rb +50 -0
  124. data/spec/features/admin/configuration/tax_categories_spec.rb +56 -0
  125. data/spec/features/admin/configuration/tax_rates_spec.rb +18 -0
  126. data/spec/features/admin/configuration/zones_spec.rb +39 -0
  127. data/spec/features/admin/homepage_spec.rb +89 -0
  128. data/spec/features/admin/locale_spec.rb +31 -0
  129. data/spec/features/admin/orders/adjustments_promotions_spec.rb +53 -0
  130. data/spec/features/admin/orders/adjustments_spec.rb +124 -0
  131. data/spec/features/admin/orders/cancelling_and_resuming_spec.rb +47 -0
  132. data/spec/features/admin/orders/customer_details_spec.rb +154 -0
  133. data/spec/features/admin/orders/line_items_spec.rb +51 -0
  134. data/spec/features/admin/orders/listing_spec.rb +224 -0
  135. data/spec/features/admin/orders/log_entries_spec.rb +55 -0
  136. data/spec/features/admin/orders/new_order_spec.rb +186 -0
  137. data/spec/features/admin/orders/order_details_spec.rb +660 -0
  138. data/spec/features/admin/orders/payments_spec.rb +244 -0
  139. data/spec/features/admin/orders/risk_analysis_spec.rb +48 -0
  140. data/spec/features/admin/orders/shipments_spec.rb +64 -0
  141. data/spec/features/admin/orders/state_changes_spec.rb +21 -0
  142. data/spec/features/admin/products/edit/images_spec.rb +86 -0
  143. data/spec/features/admin/products/edit/products_spec.rb +56 -0
  144. data/spec/features/admin/products/edit/taxons_spec.rb +41 -0
  145. data/spec/features/admin/products/edit/variants_spec.rb +56 -0
  146. data/spec/features/admin/products/option_types_spec.rb +114 -0
  147. data/spec/features/admin/products/products_spec.rb +445 -0
  148. data/spec/features/admin/products/properties_spec.rb +147 -0
  149. data/spec/features/admin/products/prototypes_spec.rb +112 -0
  150. data/spec/features/admin/products/stock_management_spec.rb +124 -0
  151. data/spec/features/admin/products/taxonomies_spec.rb +52 -0
  152. data/spec/features/admin/products/variant_spec.rb +50 -0
  153. data/spec/features/admin/promotions/adjustments_spec.rb +258 -0
  154. data/spec/features/admin/promotions/option_value_rule_spec.rb +70 -0
  155. data/spec/features/admin/promotions/tiered_calculator_spec.rb +70 -0
  156. data/spec/features/admin/refund_reasons/refund_reasons_spec.rb +57 -0
  157. data/spec/features/admin/reimbursement_type/edit_reimbursement_type_spec.rb +36 -0
  158. data/spec/features/admin/reimbursement_type/new_reimbursement_type_spec.rb +62 -0
  159. data/spec/features/admin/reports_spec.rb +61 -0
  160. data/spec/features/admin/return_authorization_reasons/return_authorization_reasons_spec.rb +63 -0
  161. data/spec/features/admin/returns/customer_returns_spec.rb +80 -0
  162. data/spec/features/admin/returns/return_authorizations_spec.rb +152 -0
  163. data/spec/features/admin/stock_transfer_spec.rb +91 -0
  164. data/spec/features/admin/store_credits_spec.rb +93 -0
  165. data/spec/features/admin/taxons_spec.rb +53 -0
  166. data/spec/features/admin/users_spec.rb +286 -0
  167. data/spec/helpers/admin/base_helper_spec.rb +30 -0
  168. data/spec/helpers/admin/navigation_helper_spec.rb +111 -0
  169. data/spec/helpers/admin/promotion_rules_helper_spec.rb +12 -0
  170. data/spec/helpers/admin/stock_movements_helper_spec.rb +30 -0
  171. data/spec/models/spree/resource_spec.rb +48 -0
  172. data/spec/routing/admin_path_spec.rb +22 -0
  173. data/spec/spec_helper.rb +144 -0
  174. data/spec/support/appear_before_matcher.rb +8 -0
  175. data/spec/support/ror_ringer.jpeg +0 -0
  176. data/spec/test_views/spree/admin/submodule/posts/edit.html.erb +1 -0
  177. data/spec/test_views/spree/admin/submodule/posts/new.html.erb +1 -0
  178. data/spec/test_views/spree/admin/widgets/edit.html.erb +1 -0
  179. data/spec/test_views/spree/admin/widgets/new.html.erb +1 -0
  180. data/spree_backend.gemspec +4 -4
  181. data/vendor/assets/javascripts/jquery.jstree/jquery.jstree.js +130 -154
  182. metadata +106 -29
  183. data/vendor/assets/images/jquery-ui/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  184. data/vendor/assets/images/jquery-ui/ui-bg_flat_0_eeeeee_40x100.png +0 -0
  185. data/vendor/assets/images/jquery-ui/ui-bg_flat_55_ffffff_40x100.png +0 -0
  186. data/vendor/assets/images/jquery-ui/ui-bg_flat_75_ffffff_40x100.png +0 -0
  187. data/vendor/assets/images/jquery-ui/ui-bg_glass_65_ffffff_1x400.png +0 -0
  188. data/vendor/assets/images/jquery-ui/ui-bg_highlight-soft_100_f6f6f6_1x100.png +0 -0
  189. data/vendor/assets/images/jquery-ui/ui-bg_highlight-soft_25_0073ea_1x100.png +0 -0
  190. data/vendor/assets/images/jquery-ui/ui-bg_highlight-soft_50_dddddd_1x100.png +0 -0
  191. data/vendor/assets/images/jquery-ui/ui-icons_0073ea_256x240.png +0 -0
  192. data/vendor/assets/images/jquery-ui/ui-icons_454545_256x240.png +0 -0
  193. data/vendor/assets/images/jquery-ui/ui-icons_666666_256x240.png +0 -0
  194. data/vendor/assets/images/jquery-ui/ui-icons_ff0084_256x240.png +0 -0
  195. data/vendor/assets/images/jquery-ui/ui-icons_ffffff_256x240.png +0 -0
  196. data/vendor/assets/stylesheets/jquery-ui.datepicker.css.erb +0 -357
@@ -0,0 +1,154 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Customer Details", type: :feature, js: true do
4
+ stub_authorization!
5
+
6
+ let!(:country) { create(:country, name: 'United States of America', iso: 'US') }
7
+ let!(:state) { create(:state, name: "Alabama", country: country, abbr: 'AL') }
8
+ let!(:shipping_method) { create(:shipping_method, display_on: "front_end") }
9
+ let!(:order) { create(:order, state: 'complete', completed_at: "2011-02-01 12:36:15") }
10
+ let!(:product) { create(:product_in_stock) }
11
+
12
+ # We need a unique name that will appear for the customer dropdown
13
+ let!(:ship_address) { create(:address, country: country, state: state, first_name: "Rumpelstiltskin") }
14
+ let!(:bill_address) { create(:address, country: country, state: state, first_name: "Rumpelstiltskin") }
15
+
16
+ let!(:user) { create(:user, email: 'foobar@example.com', ship_address: ship_address, bill_address: bill_address) }
17
+
18
+ # Value attribute is dynamically set via JS, so not observable via a CSS/XPath selector
19
+ # As the browser might take time to make the values visible in the dom we need to
20
+ # "intelligiently" wait for that event o prevent a race.
21
+ def expect_form_value(id, value)
22
+ node = page.find(id)
23
+ wait_for_condition { node.value.eql?(value) }
24
+ end
25
+
26
+ context "brand new order" do
27
+ before do
28
+ allow(Spree.user_class).to receive(:find_by).and_return(user)
29
+ visit spree.new_admin_order_path
30
+ end
31
+ # Regression test for #3335 & #5317
32
+ it "associates a user when not using guest checkout" do
33
+ select2_search product.name, from: Spree.t(:name_or_sku)
34
+ within("table.stock-levels") do
35
+ fill_in "variant_quantity", with: 1
36
+ click_icon :add
37
+ end
38
+ wait_for_ajax
39
+ click_link "Customer"
40
+ targetted_select2 "foobar@example.com", from: "#s2id_customer_search"
41
+ # 5317 - Address prefills using user's default.
42
+ expect_form_value('#order_bill_address_attributes_firstname', user.bill_address.firstname)
43
+ expect_form_value('#order_bill_address_attributes_lastname', user.bill_address.lastname)
44
+ expect_form_value('#order_bill_address_attributes_address1', user.bill_address.address1)
45
+ expect_form_value('#order_bill_address_attributes_address2', user.bill_address.address2)
46
+ expect_form_value('#order_bill_address_attributes_city', user.bill_address.city)
47
+ expect_form_value('#order_bill_address_attributes_zipcode', user.bill_address.zipcode)
48
+ expect_form_value('#order_bill_address_attributes_country_id', user.bill_address.country_id.to_s)
49
+ expect_form_value('#order_bill_address_attributes_state_id', user.bill_address.state_id.to_s)
50
+ expect_form_value('#order_bill_address_attributes_phone', user.bill_address.phone)
51
+ click_button "Update"
52
+ expect(Spree::Order.last.user).to eq(user)
53
+ end
54
+ end
55
+
56
+ context "editing an order" do
57
+ before do
58
+ configure_spree_preferences do |config|
59
+ config.default_country_id = country.id
60
+ config.company = true
61
+ end
62
+
63
+ allow(Spree.user_class).to receive(:find_by).and_return(user)
64
+ visit spree.admin_orders_path
65
+ within('table#listing_orders') { click_icon(:edit) }
66
+ end
67
+
68
+ context "selected country has no state" do
69
+ before { create(:country, iso: "BRA", name: "Brazil") }
70
+
71
+ it "changes state field to text input" do
72
+ click_link "Customer"
73
+
74
+ within("#billing") do
75
+ targetted_select2 "Brazil", from: "#s2id_order_bill_address_attributes_country_id"
76
+ fill_in "order_bill_address_attributes_state_name", with: "Piaui"
77
+ end
78
+
79
+ click_button "Update"
80
+ expect(find_field("order_bill_address_attributes_state_name").value).to eq("Piaui")
81
+ end
82
+ end
83
+
84
+ it "should be able to update customer details for an existing order" do
85
+ order.ship_address = create(:address)
86
+ order.save!
87
+
88
+ click_link "Customer"
89
+ within("#shipping") { fill_in_address "ship" }
90
+ within("#billing") { fill_in_address "bill" }
91
+
92
+ click_button "Update"
93
+ click_link "Customer"
94
+
95
+ # Regression test for #2950 + #2433
96
+ # This act should transition the state of the order as far as it will go too
97
+ within("#order_tab_summary") do
98
+ expect(find(".state").text).to eq("complete")
99
+ end
100
+ end
101
+
102
+ it "should show validation errors" do
103
+ click_link "Customer"
104
+ click_button "Update"
105
+ expect(page).to have_content("Shipping address first name can't be blank")
106
+ end
107
+
108
+ it "updates order email for an existing order with a user" do
109
+ order.update_columns(ship_address_id: ship_address.id, bill_address_id: bill_address.id, state: "confirm", completed_at: nil)
110
+ previous_user = order.user
111
+ click_link "Customer"
112
+ fill_in "order_email", with: "newemail@example.com"
113
+ expect(order.user_id).to eq previous_user.id
114
+ expect(order.user.email).to eq previous_user.email
115
+ expect { click_button "Update" }.to change { order.reload.email }.to "newemail@example.com"
116
+ end
117
+
118
+ # Regression test for #942
119
+ context "errors when no shipping methods are available" do
120
+ before do
121
+ Spree::ShippingMethod.delete_all
122
+ end
123
+
124
+ specify do
125
+ click_link "Customer"
126
+ # Need to fill in valid information so it passes validations
127
+ fill_in "order_ship_address_attributes_firstname", with: "John 99"
128
+ fill_in "order_ship_address_attributes_lastname", with: "Doe"
129
+ fill_in "order_ship_address_attributes_lastname", with: "Company"
130
+ fill_in "order_ship_address_attributes_address1", with: "100 first lane"
131
+ fill_in "order_ship_address_attributes_address2", with: "#101"
132
+ fill_in "order_ship_address_attributes_city", with: "Bethesda"
133
+ fill_in "order_ship_address_attributes_zipcode", with: "20170"
134
+
135
+ page.select('Alabama', from: 'order_ship_address_attributes_state_id')
136
+ fill_in "order_ship_address_attributes_phone", with: "123-456-7890"
137
+ expect { click_button "Update" }.not_to raise_error
138
+ end
139
+ end
140
+ end
141
+
142
+ def fill_in_address(kind = "bill")
143
+ fill_in "First Name", with: "John 99"
144
+ fill_in "Last Name", with: "Doe"
145
+ fill_in "Company", with: "Company"
146
+ fill_in "Street Address", with: "100 first lane"
147
+ fill_in "Street Address (cont'd)", with: "#101"
148
+ fill_in "City", with: "Bethesda"
149
+ fill_in "Zip", with: "20170"
150
+ targetted_select2 country.name, from: "#s2id_order_#{kind}_address_attributes_country_id"
151
+ targetted_select2 state.name, from: "#s2id_order_#{kind}_address_attributes_state_id"
152
+ fill_in "Phone", with: "123-456-7890"
153
+ end
154
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ # Tests for #3958's features
4
+ describe "Order Line Items", type: :feature, js: true do
5
+ stub_authorization!
6
+
7
+ before do
8
+ # Removing the delivery step causes the order page to render a different
9
+ # partial, called _line_items, which shows line items rather than shipments
10
+ allow(Spree::Order).to receive_messages checkout_step_names: [:address, :payment, :confirm, :complete]
11
+ end
12
+
13
+ let!(:order) do
14
+ order = create(:order_with_line_items, line_items_count: 1)
15
+ order.shipments.destroy_all
16
+ order
17
+ end
18
+
19
+ it "can edit a line item's quantity" do
20
+ visit spree.edit_admin_order_path(order)
21
+ within(".line-items") do
22
+ within_row(1) do
23
+ find(".edit-line-item").click
24
+ fill_in "quantity", with: 10
25
+ find(".save-line-item").click
26
+ within '.line-item-qty-show' do
27
+ expect(page).to have_content("10")
28
+ end
29
+ within '.line-item-total' do
30
+ expect(page).to have_content("$199.90")
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ it "can delete a line item" do
37
+ visit spree.edit_admin_order_path(order)
38
+
39
+ product_name = find(".line-items tr:nth-child(1) .line-item-name").text
40
+
41
+ within(".line-items") do
42
+ within_row(1) do
43
+ accept_alert do
44
+ find(".delete-line-item").click
45
+ end
46
+ end
47
+ end
48
+
49
+ expect(page).not_to have_content(product_name)
50
+ end
51
+ end
@@ -0,0 +1,224 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Orders Listing", type: :feature do
4
+ stub_authorization!
5
+
6
+ let(:order1) do
7
+ create :order_with_line_items,
8
+ created_at: 1.day.from_now,
9
+ completed_at: 1.day.from_now,
10
+ considered_risky: true,
11
+ number: "R100"
12
+ end
13
+
14
+ let(:order2) do
15
+ create :order,
16
+ created_at: 1.day.ago,
17
+ completed_at: 1.day.ago,
18
+ number: "R200"
19
+ end
20
+
21
+ before do
22
+ allow_any_instance_of(Spree::OrderInventory).to receive(:add_to_shipment)
23
+ # create the order instances after stubbing the `add_to_shipment` method
24
+ order1; order2
25
+ visit spree.admin_orders_path
26
+ end
27
+
28
+ describe "listing orders" do
29
+ it "should list existing orders" do
30
+ within_row(1) do
31
+ expect(column_text(2)).to eq "R100"
32
+ expect(find("td:nth-child(3)")).to have_css '.label-considered_risky'
33
+ expect(column_text(4)).to eq "cart"
34
+ end
35
+
36
+ within_row(2) do
37
+ expect(column_text(2)).to eq "R200"
38
+ expect(find("td:nth-child(3)")).to have_css '.label-considered_safe'
39
+ end
40
+ end
41
+
42
+ it "should be able to sort the orders listing" do
43
+ # default is completed_at desc
44
+ within_row(1) { expect(page).to have_content("R100") }
45
+ within_row(2) { expect(page).to have_content("R200") }
46
+
47
+ click_link "Completed At"
48
+
49
+ # Completed at desc
50
+ within_row(1) { expect(page).to have_content("R200") }
51
+ within_row(2) { expect(page).to have_content("R100") }
52
+
53
+ within('table#listing_orders thead') { click_link "Number" }
54
+
55
+ # number asc
56
+ within_row(1) { expect(page).to have_content("R100") }
57
+ within_row(2) { expect(page).to have_content("R200") }
58
+ end
59
+ end
60
+
61
+ describe "searching orders" do
62
+ it "should be able to search orders" do
63
+ fill_in "q_number_cont", with: "R200"
64
+ click_on 'Filter Results'
65
+ within_row(1) do
66
+ expect(page).to have_content("R200")
67
+ end
68
+
69
+ # Ensure that the other order doesn't show up
70
+ within("table#listing_orders") { expect(page).not_to have_content("R100") }
71
+ end
72
+
73
+ it "should return both complete and incomplete orders when only complete orders is not checked" do
74
+ Spree::Order.create! email: "incomplete@example.com", completed_at: nil, state: 'cart'
75
+ click_on 'Filter'
76
+ uncheck "q_completed_at_not_null"
77
+ click_on 'Filter Results'
78
+
79
+ expect(page).to have_content("R200")
80
+ expect(page).to have_content("incomplete@example.com")
81
+ end
82
+
83
+ it "should be able to filter risky orders" do
84
+ # Check risky and filter
85
+ check "q_considered_risky_eq"
86
+ click_on 'Filter Results'
87
+
88
+ # Insure checkbox still checked
89
+ expect(find("#q_considered_risky_eq")).to be_checked
90
+ # Insure we have the risky order, R100
91
+ within_row(1) do
92
+ expect(page).to have_content("R100")
93
+ end
94
+ # Insure the non risky order is not present
95
+ expect(page).not_to have_content("R200")
96
+ end
97
+
98
+ it "should be able to filter on variant_sku" do
99
+ click_on 'Filter'
100
+ fill_in "q_line_items_variant_sku_eq", with: order1.line_items.first.variant.sku
101
+ click_on 'Filter Results'
102
+
103
+ within_row(1) do
104
+ expect(page).to have_content(order1.number)
105
+ end
106
+
107
+ expect(page).not_to have_content(order2.number)
108
+ end
109
+
110
+ context "when pagination is really short" do
111
+ before do
112
+ @old_per_page = Spree::Config[:admin_orders_per_page]
113
+ Spree::Config[:admin_orders_per_page] = 1
114
+ end
115
+
116
+ after do
117
+ Spree::Config[:admin_orders_per_page] = @old_per_page
118
+ end
119
+
120
+ # Regression test for #4004
121
+ it "should be able to go from page to page for incomplete orders" do
122
+ Spree::Order.destroy_all
123
+ 2.times { Spree::Order.create! email: "incomplete@example.com", completed_at: nil, state: 'cart' }
124
+ click_on 'Filter'
125
+ uncheck "q_completed_at_not_null"
126
+ click_on 'Filter Results'
127
+ within(".pagination") do
128
+ click_link "2"
129
+ end
130
+ expect(page).to have_content("incomplete@example.com")
131
+ expect(find("#q_completed_at_not_null")).not_to be_checked
132
+ end
133
+ end
134
+
135
+ it "should be able to search orders using only completed at input" do
136
+ fill_in "q_created_at_gt", with: Date.current
137
+ click_on 'Filter Results'
138
+
139
+ within_row(1) { expect(page).to have_content("R100") }
140
+
141
+ # Ensure that the other order doesn't show up
142
+ within("table#listing_orders") { expect(page).not_to have_content("R200") }
143
+ end
144
+
145
+ context "filter on promotions" do
146
+ let!(:promotion) { create(:promotion_with_item_adjustment) }
147
+
148
+ before do
149
+ order1.promotions << promotion
150
+ order1.save
151
+ visit spree.admin_orders_path
152
+ end
153
+
154
+ it "only shows the orders with the selected promotion" do
155
+ select promotion.name, from: "Promotion"
156
+ click_on 'Filter Results'
157
+ within_row(1) { expect(page).to have_content("R100") }
158
+ within("table#listing_orders") { expect(page).not_to have_content("R200") }
159
+ end
160
+ end
161
+
162
+ it "should be able to apply a ransack filter by clicking a quickfilter icon", js: true do
163
+ label_pending = page.find '.label-pending'
164
+ parent_td = label_pending.find(:xpath, '..')
165
+
166
+ # Click the quick filter Pending for order #R100
167
+ within(parent_td) do
168
+ find('.js-add-filter').click
169
+ end
170
+
171
+ expect(page).to have_content("R100")
172
+ expect(page).not_to have_content("R200")
173
+ end
174
+
175
+ context "filter on shipment state" do
176
+ it "only shows the orders with the selected shipment state" do
177
+ select Spree.t("payment_states.#{order1.shipment_state}"), from: "Shipment State"
178
+ click_on 'Filter Results'
179
+ within_row(1) { expect(page).to have_content("R100") }
180
+ within("table#listing_orders") { expect(page).not_to have_content("R200") }
181
+ end
182
+ end
183
+
184
+ context "filter on payment state" do
185
+ it "only shows the orders with the selected payment state" do
186
+ select Spree.t("payment_states.#{order1.payment_state}"), from: "Payment State"
187
+ click_on 'Filter Results'
188
+ within_row(1) { expect(page).to have_content("R100") }
189
+ within("table#listing_orders") { expect(page).not_to have_content("R200") }
190
+ end
191
+ end
192
+
193
+ # regression tests for https://github.com/spree/spree/issues/6888
194
+ context "per page dropdown", js: true do
195
+ before do
196
+ select "45", from: "per_page"
197
+ wait_for_ajax
198
+ expect(page).to have_select("per_page", selected: "45")
199
+ expect(page).to have_selector(:css, "select.per-page-selected-45")
200
+ end
201
+
202
+ it "adds per_page parameter to url" do
203
+ expect(current_url).to match(/per_page\=45/)
204
+ end
205
+
206
+ it "can be used with search filtering" do
207
+ click_on 'Filter'
208
+ fill_in "q_number_cont", with: "R200"
209
+ click_on 'Filter Results'
210
+ expect(page).not_to have_content("R100")
211
+ within_row(1) { expect(page).to have_content("R200") }
212
+ expect(current_url).to match(/per_page\=45/)
213
+ expect(page).to have_select("per_page", selected: "45")
214
+ select "60", from: "per_page"
215
+ wait_for_ajax
216
+ expect(page).to have_select("per_page", selected: "60")
217
+ expect(page).to have_selector(:css, "select.per-page-selected-60")
218
+ expect(page).not_to have_content("R100")
219
+ within_row(1) { expect(page).to have_content("R200") }
220
+ expect(current_url).to match(/per_page\=60/)
221
+ end
222
+ end
223
+ end
224
+ end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Log entries", type: :feature do
4
+ stub_authorization!
5
+
6
+ let!(:payment) { create(:payment) }
7
+
8
+ context "with a successful log entry" do
9
+ before do
10
+ response = ActiveMerchant::Billing::Response.new(
11
+ true,
12
+ "Transaction successful",
13
+ transid: "ABCD1234"
14
+ )
15
+
16
+ payment.log_entries.create(
17
+ source: payment.source,
18
+ details: response.to_yaml
19
+ )
20
+ end
21
+
22
+ it "shows a successful attempt" do
23
+ visit spree.admin_order_payments_path(payment.order)
24
+ find("#payment_#{payment.id} a").click
25
+ click_link "Logs"
26
+ within("#listing_log_entries") do
27
+ expect(page).to have_content("Transaction successful")
28
+ end
29
+ end
30
+ end
31
+
32
+ context "with a failed log entry" do
33
+ before do
34
+ response = ActiveMerchant::Billing::Response.new(
35
+ false,
36
+ "Transaction failed",
37
+ transid: "ABCD1234"
38
+ )
39
+
40
+ payment.log_entries.create(
41
+ source: payment.source,
42
+ details: response.to_yaml
43
+ )
44
+ end
45
+
46
+ it "shows a failed attempt" do
47
+ visit spree.admin_order_payments_path(payment.order)
48
+ find("#payment_#{payment.id} a").click
49
+ click_link "Logs"
50
+ within("#listing_log_entries") do
51
+ expect(page).to have_content("Transaction failed")
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,186 @@
1
+ require 'spec_helper'
2
+
3
+ describe "New Order", type: :feature do
4
+ let!(:product) { create(:product_in_stock) }
5
+ let!(:state) { create(:state) }
6
+ let!(:user) { create(:user, ship_address: create(:address), bill_address: create(:address)) }
7
+ let!(:payment_method) { create(:check_payment_method) }
8
+ let!(:shipping_method) { create(:shipping_method) }
9
+
10
+ stub_authorization!
11
+
12
+ before do
13
+ # create default store
14
+ allow(Spree.user_class).to receive(:find_by).and_return(user)
15
+ create(:store)
16
+ visit spree.new_admin_order_path
17
+ end
18
+
19
+ it "does check if you have a billing address before letting you add shipments" do
20
+ click_on "Shipments"
21
+ expect(page).to have_content 'Please fill in customer info'
22
+ expect(current_path).to eql(spree.edit_admin_order_customer_path(Spree::Order.last))
23
+ end
24
+
25
+ it "completes new order successfully without using the cart", js: true do
26
+ select2_search product.name, from: Spree.t(:name_or_sku)
27
+ click_icon :add
28
+ wait_for_ajax
29
+ click_on "Customer"
30
+ select_customer
31
+
32
+ check "order_use_billing"
33
+ fill_in_address
34
+ click_on "Update"
35
+
36
+ click_on "Payments"
37
+ click_on "Update"
38
+
39
+ expect(current_path).to eql(spree.admin_order_payments_path(Spree::Order.last))
40
+ click_icon "capture"
41
+
42
+ click_on "Shipments"
43
+ click_on "Ship"
44
+ wait_for_ajax
45
+
46
+ expect(page).to have_content("shipped")
47
+ end
48
+
49
+ context "adding new item to the order", js: true do
50
+ it "inventory items show up just fine and are also registered as shipments" do
51
+ select2_search product.name, from: Spree.t(:name_or_sku)
52
+
53
+ within("table.stock-levels") do
54
+ fill_in "variant_quantity", with: 2
55
+ click_icon :add
56
+ end
57
+
58
+ within(".line-items") do
59
+ expect(page).to have_content(product.name)
60
+ end
61
+
62
+ click_on "Customer"
63
+ select_customer
64
+
65
+ check "order_use_billing"
66
+ fill_in_address
67
+ click_on "Update"
68
+
69
+ click_on "Shipments"
70
+
71
+ within(".stock-contents") do
72
+ expect(page).to have_content(product.name)
73
+ end
74
+ end
75
+ end
76
+
77
+ context "adding new item to the order which isn't available", js: true do
78
+ before do
79
+ product.update(available_on: nil)
80
+ select2_search product.name, from: Spree.t(:name_or_sku)
81
+ end
82
+
83
+ it "inventory items is displayed" do
84
+ expect(page).to have_content(product.name)
85
+ expect(page).to have_css('#stock_details')
86
+ end
87
+
88
+ context 'on increase in quantity the product should be removed from order', js: true do
89
+ before do
90
+ accept_alert do
91
+ within("table.stock-levels") do
92
+ fill_in "variant_quantity", with: 2
93
+ click_icon :add
94
+ wait_for_ajax
95
+ end
96
+ end
97
+ end
98
+
99
+ it { expect(page).not_to have_css('#stock_details') }
100
+ end
101
+ end
102
+
103
+ # Regression test for #3958
104
+ context "without a delivery step", js: true do
105
+ before do
106
+ allow(Spree::Order).to receive_messages checkout_step_names: [:address, :payment, :confirm, :complete]
107
+ end
108
+
109
+ it "can still see line items" do
110
+ select2_search product.name, from: Spree.t(:name_or_sku)
111
+ click_icon :add
112
+ within(".line-items") do
113
+ within(".line-item-name") do
114
+ expect(page).to have_content(product.name)
115
+ end
116
+ within(".line-item-qty-show") do
117
+ expect(page).to have_content("1")
118
+ end
119
+ within(".line-item-price") do
120
+ expect(page).to have_content(product.price)
121
+ end
122
+ end
123
+ end
124
+ end
125
+
126
+ # Regression test for #3336
127
+ context "start by customer address" do
128
+ it "completes order fine", js: true do
129
+ click_on "Customer"
130
+ select_customer
131
+
132
+ check "order_use_billing"
133
+ fill_in_address
134
+ click_on "Update"
135
+
136
+ click_on "Shipments"
137
+ select2_search product.name, from: Spree.t(:name_or_sku)
138
+ click_icon :add
139
+ wait_for_ajax
140
+
141
+ click_on "Payments"
142
+ click_on "Continue"
143
+
144
+ within(".additional-info .state") do
145
+ expect(page).to have_content("complete")
146
+ end
147
+ end
148
+ end
149
+
150
+ # Regression test for #5327
151
+ context "customer with default credit card", js: true do
152
+ before do
153
+ allow(Spree.user_class).to receive(:find_by).and_return(user)
154
+ create(:credit_card, default: true, user: user)
155
+ end
156
+ it "transitions to delivery not to complete" do
157
+ select2_search product.name, from: Spree.t(:name_or_sku)
158
+ within("table.stock-levels") do
159
+ fill_in "variant_quantity", with: 1
160
+ click_icon :add
161
+ end
162
+ wait_for_ajax
163
+ click_link "Customer"
164
+ select_customer
165
+ click_button "Update"
166
+ expect(Spree::Order.last.state).to eq 'delivery'
167
+ end
168
+ end
169
+
170
+ def fill_in_address(kind = "bill")
171
+ fill_in "First Name", with: "John 99"
172
+ fill_in "Last Name", with: "Doe"
173
+ fill_in "Street Address", with: "100 first lane"
174
+ fill_in "Street Address (cont'd)", with: "#101"
175
+ fill_in "City", with: "Bethesda"
176
+ fill_in "Zip", with: "20170"
177
+ targetted_select2_search state.name, from: "#s2id_order_#{kind}_address_attributes_state_id"
178
+ fill_in "Phone", with: "123-456-7890"
179
+ end
180
+
181
+ def select_customer
182
+ within "div#select-customer" do
183
+ targetted_select2_search user.email, from: "#s2id_customer_search"
184
+ end
185
+ end
186
+ end