spree_backend 3.0.5 → 3.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1 -0
  3. data/Gemfile +6 -0
  4. data/Rakefile +29 -0
  5. data/app/assets/javascripts/spree/backend/admin.js +26 -0
  6. data/app/controllers/spree/admin/resource_controller.rb +4 -2
  7. data/app/helpers/spree/admin/navigation_helper.rb +10 -1
  8. data/app/views/spree/admin/images/new.html.erb +1 -1
  9. data/app/views/spree/admin/payments/_list.html.erb +1 -1
  10. data/app/views/spree/admin/products/_form.html.erb +1 -1
  11. data/app/views/spree/admin/shared/_index_table_options.html.erb +1 -11
  12. data/app/views/spree/admin/shared/sub_menu/_product.html.erb +1 -1
  13. data/script/rails +9 -0
  14. data/spec/controllers/spree/admin/base_controller_spec.rb +46 -0
  15. data/spec/controllers/spree/admin/customer_returns_controller_spec.rb +185 -0
  16. data/spec/controllers/spree/admin/general_settings_controller_spec.rb +41 -0
  17. data/spec/controllers/spree/admin/missing_products_controller_spec.rb +18 -0
  18. data/spec/controllers/spree/admin/orders/customer_details_controller_spec.rb +42 -0
  19. data/spec/controllers/spree/admin/orders_controller_spec.rb +247 -0
  20. data/spec/controllers/spree/admin/payment_methods_controller_spec.rb +49 -0
  21. data/spec/controllers/spree/admin/payments_controller_spec.rb +97 -0
  22. data/spec/controllers/spree/admin/products_controller_spec.rb +53 -0
  23. data/spec/controllers/spree/admin/promotion_actions_controller_spec.rb +21 -0
  24. data/spec/controllers/spree/admin/promotion_rules_controller_spec.rb +21 -0
  25. data/spec/controllers/spree/admin/promotions_controller_spec.rb +44 -0
  26. data/spec/controllers/spree/admin/refunds_controller_spec.rb +32 -0
  27. data/spec/controllers/spree/admin/reimbursements_controller_spec.rb +74 -0
  28. data/spec/controllers/spree/admin/reports_controller_spec.rb +42 -0
  29. data/spec/controllers/spree/admin/resource_controller_spec.rb +276 -0
  30. data/spec/controllers/spree/admin/return_authorizations_controller_spec.rb +225 -0
  31. data/spec/controllers/spree/admin/return_items_controller_spec.rb +27 -0
  32. data/spec/controllers/spree/admin/root_controller_spec.rb +35 -0
  33. data/spec/controllers/spree/admin/search_controller_spec.rb +56 -0
  34. data/spec/controllers/spree/admin/shipping_methods_controller_spec.rb +14 -0
  35. data/spec/controllers/spree/admin/stock_items_controller_spec.rb +19 -0
  36. data/spec/controllers/spree/admin/stock_locations_controller_spec.rb +41 -0
  37. data/spec/controllers/spree/admin/stock_transfers_controller_spec.rb +41 -0
  38. data/spec/controllers/spree/admin/tax_categories_controller_spec.rb +34 -0
  39. data/spec/controllers/spree/admin/users_controller_spec.rb +161 -0
  40. data/spec/controllers/spree/admin/variants_controller_spec.rb +32 -0
  41. data/spec/features/admin/configuration/analytics_tracker_spec.rb +46 -0
  42. data/spec/features/admin/configuration/countries_spec.rb +24 -0
  43. data/spec/features/admin/configuration/general_settings_spec.rb +43 -0
  44. data/spec/features/admin/configuration/payment_methods_spec.rb +63 -0
  45. data/spec/features/admin/configuration/roles_spec.rb +47 -0
  46. data/spec/features/admin/configuration/shipping_methods_spec.rb +62 -0
  47. data/spec/features/admin/configuration/states_spec.rb +68 -0
  48. data/spec/features/admin/configuration/stock_locations_spec.rb +48 -0
  49. data/spec/features/admin/configuration/tax_categories_spec.rb +56 -0
  50. data/spec/features/admin/configuration/tax_rates_spec.rb +18 -0
  51. data/spec/features/admin/configuration/zones_spec.rb +39 -0
  52. data/spec/features/admin/homepage_spec.rb +81 -0
  53. data/spec/features/admin/locale_spec.rb +31 -0
  54. data/spec/features/admin/orders/adjustments_promotions_spec.rb +53 -0
  55. data/spec/features/admin/orders/adjustments_spec.rb +129 -0
  56. data/spec/features/admin/orders/cancelling_and_resuming_spec.rb +47 -0
  57. data/spec/features/admin/orders/customer_details_spec.rb +182 -0
  58. data/spec/features/admin/orders/line_items_spec.rb +51 -0
  59. data/spec/features/admin/orders/listing_spec.rb +225 -0
  60. data/spec/features/admin/orders/log_entries_spec.rb +55 -0
  61. data/spec/features/admin/orders/new_order_spec.rb +161 -0
  62. data/spec/features/admin/orders/order_details_spec.rb +620 -0
  63. data/spec/features/admin/orders/payments_spec.rb +229 -0
  64. data/spec/features/admin/orders/risk_analysis_spec.rb +48 -0
  65. data/spec/features/admin/orders/shipments_spec.rb +64 -0
  66. data/spec/features/admin/orders/state_changes_spec.rb +21 -0
  67. data/spec/features/admin/products/edit/images_spec.rb +86 -0
  68. data/spec/features/admin/products/edit/products_spec.rb +64 -0
  69. data/spec/features/admin/products/edit/taxons_spec.rb +41 -0
  70. data/spec/features/admin/products/edit/variants_spec.rb +56 -0
  71. data/spec/features/admin/products/option_types_spec.rb +113 -0
  72. data/spec/features/admin/products/products_spec.rb +394 -0
  73. data/spec/features/admin/products/properties_spec.rb +140 -0
  74. data/spec/features/admin/products/prototypes_spec.rb +112 -0
  75. data/spec/features/admin/products/stock_management_spec.rb +123 -0
  76. data/spec/features/admin/products/taxonomies_spec.rb +52 -0
  77. data/spec/features/admin/products/variant_spec.rb +50 -0
  78. data/spec/features/admin/promotions/adjustments_spec.rb +255 -0
  79. data/spec/features/admin/promotions/option_value_rule_spec.rb +70 -0
  80. data/spec/features/admin/promotions/tiered_calculator_spec.rb +70 -0
  81. data/spec/features/admin/reports_spec.rb +61 -0
  82. data/spec/features/admin/stock_transfer_spec.rb +75 -0
  83. data/spec/features/admin/taxons_spec.rb +47 -0
  84. data/spec/features/admin/users_spec.rb +284 -0
  85. data/spec/helpers/admin/base_helper_spec.rb +24 -0
  86. data/spec/helpers/admin/navigation_helper_spec.rb +106 -0
  87. data/spec/helpers/admin/stock_movements_helper_spec.rb +30 -0
  88. data/spec/helpers/promotion_rules_helper_spec.rb +12 -0
  89. data/spec/models/spree/resource_spec.rb +48 -0
  90. data/spec/spec_helper.rb +133 -0
  91. data/spec/support/appear_before_matcher.rb +8 -0
  92. data/spec/support/ror_ringer.jpeg +0 -0
  93. data/spec/test_views/spree/admin/submodule/posts/edit.html.erb +1 -0
  94. data/spec/test_views/spree/admin/submodule/posts/new.html.erb +1 -0
  95. data/spec/test_views/spree/admin/widgets/edit.html.erb +1 -0
  96. data/spec/test_views/spree/admin/widgets/new.html.erb +1 -0
  97. data/spree_backend.gemspec +29 -0
  98. metadata +101 -14
@@ -0,0 +1,129 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Adjustments", type: :feature do
4
+ stub_authorization!
5
+
6
+ let!(:order) { create(:completed_order_with_totals, line_items_count: 5) }
7
+ let!(:line_item) do
8
+ line_item = order.line_items.first
9
+ # so we can be sure of a determinate price in our assertions
10
+ line_item.update_column(:price, 10)
11
+ line_item
12
+ end
13
+
14
+ let!(:tax_adjustment) do
15
+ create(:tax_adjustment,
16
+ :adjustable => line_item,
17
+ :state => 'closed',
18
+ :order => order,
19
+ :label => "VAT 5%",
20
+ :amount => 10)
21
+ end
22
+
23
+ let!(:adjustment) { order.adjustments.create!(order: order, label: 'Rebate', amount: 10) }
24
+
25
+ before(:each) do
26
+ # To ensure the order totals are correct
27
+ order.update_totals
28
+ order.persist_totals
29
+
30
+ visit spree.admin_orders_path
31
+ within_row(1) { click_on order.number }
32
+ click_on "Adjustments"
33
+ end
34
+
35
+ after :each do
36
+ order.reload.all_adjustments.each do |adjustment|
37
+ expect(adjustment.order_id).to equal(order.id)
38
+ end
39
+ end
40
+
41
+ context "admin managing adjustments" do
42
+ it "should display the correct values for existing order adjustments" do
43
+ within_row(1) do
44
+ expect(column_text(2)).to eq("VAT 5%")
45
+ expect(column_text(3)).to eq("$10.00")
46
+ end
47
+ end
48
+
49
+ it "only shows eligible adjustments" do
50
+ expect(page).not_to have_content("ineligible")
51
+ end
52
+ end
53
+
54
+ context "admin creating a new adjustment" do
55
+ before(:each) do
56
+ click_link "New Adjustment"
57
+ end
58
+
59
+ context "successfully" do
60
+ it "should create a new adjustment" do
61
+ fill_in "adjustment_amount", with: "10"
62
+ fill_in "adjustment_label", with: "rebate"
63
+ click_button "Continue"
64
+ expect(page).to have_content("successfully created!")
65
+ expect(page).to have_content("Total: $180.00")
66
+ end
67
+ end
68
+
69
+ context "with validation errors" do
70
+ it "should not create a new adjustment" do
71
+ fill_in "adjustment_amount", with: ""
72
+ fill_in "adjustment_label", with: ""
73
+ click_button "Continue"
74
+ expect(page).to have_content("Label can't be blank")
75
+ expect(page).to have_content("Amount is not a number")
76
+ end
77
+ end
78
+ end
79
+
80
+ context "admin editing an adjustment", js: true do
81
+
82
+ before(:each) do
83
+ within_row(2) { click_icon :edit }
84
+ end
85
+
86
+ context "successfully" do
87
+ it "should update the adjustment" do
88
+ fill_in "adjustment_amount", with: "99"
89
+ fill_in "adjustment_label", with: "rebate 99"
90
+ click_button "Continue"
91
+ expect(page).to have_content("successfully updated!")
92
+ expect(page).to have_content("rebate 99")
93
+ within(".adjustments") do
94
+ expect(page).to have_content("$99.00")
95
+ end
96
+
97
+ expect(page).to have_content("Total: $259.00")
98
+ end
99
+ end
100
+
101
+ context "with validation errors" do
102
+ it "should not update the adjustment" do
103
+ fill_in "adjustment_amount", with: ""
104
+ fill_in "adjustment_label", with: ""
105
+ click_button "Continue"
106
+ expect(page).to have_content("Label can't be blank")
107
+ expect(page).to have_content("Amount is not a number")
108
+ end
109
+ end
110
+ end
111
+
112
+ context "deleting an adjustment" do
113
+ it "should not be possible if adjustment is closed" do
114
+ within_row(1) do
115
+ expect(page).not_to have_css('.fa-delete')
116
+ end
117
+ end
118
+
119
+ it "should update the total", js: true do
120
+ accept_alert do
121
+ within_row(2) do
122
+ click_icon(:delete)
123
+ end
124
+ end
125
+
126
+ expect(page).to have_content(/Total: ?\$170\.00/)
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Cancelling + Resuming", :type => :feature do
4
+
5
+ stub_authorization!
6
+
7
+ let(:user) { double(id: 123, has_spree_role?: true, spree_api_key: 'fake') }
8
+
9
+ before do
10
+ allow_any_instance_of(Spree::Admin::BaseController).to receive(:try_spree_current_user).and_return(user)
11
+ end
12
+
13
+ let(:order) do
14
+ order = create(:order)
15
+ order.update_columns({
16
+ :state => 'complete',
17
+ :completed_at => Time.now
18
+ })
19
+ order
20
+ end
21
+
22
+ it "can cancel an order" do
23
+ visit spree.edit_admin_order_path(order.number)
24
+ click_button 'Cancel'
25
+ within(".additional-info") do
26
+ within(".state") do
27
+ expect(page).to have_content("canceled")
28
+ end
29
+ end
30
+ end
31
+
32
+ context "with a cancelled order" do
33
+ before do
34
+ order.update_column(:state, 'canceled')
35
+ end
36
+
37
+ it "can resume an order" do
38
+ visit spree.edit_admin_order_path(order.number)
39
+ click_button 'Resume'
40
+ within(".additional-info") do
41
+ within(".state") do
42
+ expect(page).to have_content("resumed")
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,182 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Customer Details", type: :feature, js: true do
4
+ stub_authorization!
5
+
6
+ let(:country) { create(:country, name: "Kangaland") }
7
+ let(:state) { create(:state, name: "Alabama", country: country) }
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
+ # "Intelligiently" wait on condition
19
+ #
20
+ # Much better than a random sleep "here and there"
21
+ # it will not cause any delay in case the condition is fullfilled on first cycle.
22
+ def wait_for_condition
23
+ time = Capybara.default_max_wait_time
24
+ step = 0.1
25
+ while time > 0
26
+ return if yield
27
+ sleep(step)
28
+ time -= 0.1
29
+ end
30
+ fail "Could not achieve condition within #{Capybara.default_max_wait_time} seconds."
31
+ end
32
+
33
+ # Value attribute is dynamically set via JS, so not observable via a CSS/XPath selector
34
+ # As the browser might take time to make the values visible in the dom we need to
35
+ # "intelligiently" wait for that event o prevent a race.
36
+ def expect_form_value(id, value)
37
+ node = page.find(id)
38
+ wait_for_condition { node.value.eql?(value) }
39
+ end
40
+
41
+ context "brand new order" do
42
+ before do
43
+ visit spree.new_admin_order_path
44
+ end
45
+ # Regression test for #3335 & #5317
46
+ it "associates a user when not using guest checkout" do
47
+ select2_search product.name, from: Spree.t(:name_or_sku)
48
+ within("table.stock-levels") do
49
+ fill_in "variant_quantity", with: 1
50
+ click_icon :add
51
+ end
52
+ wait_for_ajax
53
+ click_link "Customer"
54
+ targetted_select2 "foobar@example.com", from: "#s2id_customer_search"
55
+ # 5317 - Address prefills using user's default.
56
+ expect_form_value('#order_bill_address_attributes_firstname', user.bill_address.firstname)
57
+ expect_form_value('#order_bill_address_attributes_lastname', user.bill_address.lastname)
58
+ expect_form_value('#order_bill_address_attributes_address1', user.bill_address.address1)
59
+ expect_form_value('#order_bill_address_attributes_address2', user.bill_address.address2)
60
+ expect_form_value('#order_bill_address_attributes_city', user.bill_address.city)
61
+ expect_form_value('#order_bill_address_attributes_zipcode', user.bill_address.zipcode)
62
+ expect_form_value('#order_bill_address_attributes_country_id', user.bill_address.country_id.to_s)
63
+ expect_form_value('#order_bill_address_attributes_state_id', user.bill_address.state_id.to_s)
64
+ expect_form_value('#order_bill_address_attributes_phone', user.bill_address.phone)
65
+ click_button "Update"
66
+ expect(Spree::Order.last.user).not_to be_nil
67
+ end
68
+ end
69
+
70
+ context "editing an order" do
71
+ before do
72
+ configure_spree_preferences do |config|
73
+ config.default_country_id = country.id
74
+ config.company = true
75
+ end
76
+
77
+ visit spree.admin_orders_path
78
+ within('table#listing_orders') { click_icon(:edit) }
79
+ end
80
+
81
+ context "selected country has no state" do
82
+ before { create(:country, iso: "BRA", name: "Brazil") }
83
+
84
+ it "changes state field to text input" do
85
+ click_link "Customer"
86
+
87
+ within("#billing") do
88
+ targetted_select2 "Brazil", from: "#s2id_order_bill_address_attributes_country_id"
89
+ fill_in "order_bill_address_attributes_state_name", with: "Piaui"
90
+ end
91
+
92
+ click_button "Update"
93
+ expect(find_field("order_bill_address_attributes_state_name").value).to eq("Piaui")
94
+ end
95
+ end
96
+
97
+ it "should be able to update customer details for an existing order" do
98
+ order.ship_address = create(:address)
99
+ order.save!
100
+
101
+ click_link "Customer"
102
+ within("#shipping") { fill_in_address "ship" }
103
+ within("#billing") { fill_in_address "bill" }
104
+
105
+ click_button "Update"
106
+ click_link "Customer"
107
+
108
+ # Regression test for #2950 + #2433
109
+ # This act should transition the state of the order as far as it will go too
110
+ within("#order_tab_summary") do
111
+ expect(find(".state").text).to eq("complete")
112
+ end
113
+ end
114
+
115
+ it "should show validation errors" do
116
+ click_link "Customer"
117
+ click_button "Update"
118
+ expect(page).to have_content("Shipping address first name can't be blank")
119
+ end
120
+
121
+ it "updates order email for an existing order with a user" do
122
+ order.update_columns(ship_address_id: ship_address.id, bill_address_id: bill_address.id, state: "confirm", completed_at: nil)
123
+ previous_user = order.user
124
+ click_link "Customer"
125
+ fill_in "order_email", with: "newemail@example.com"
126
+ expect { click_button "Update" }.to change { order.reload.email }.to "newemail@example.com"
127
+ expect(order.user_id).to eq previous_user.id
128
+ expect(order.user.email).to eq previous_user.email
129
+ end
130
+
131
+ context "country associated was removed" do
132
+ let(:brazil) { create(:country, iso: "BRA", name: "Brazil") }
133
+
134
+ before do
135
+ order.bill_address.country.destroy
136
+ configure_spree_preferences do |config|
137
+ config.default_country_id = brazil.id
138
+ end
139
+ end
140
+
141
+ it "sets default country when displaying form" do
142
+ click_link "Customer"
143
+ expect(find_field("order_bill_address_attributes_country_id").value.to_i).to eq brazil.id
144
+ end
145
+ end
146
+
147
+ # Regression test for #942
148
+ context "errors when no shipping methods are available" do
149
+ before do
150
+ Spree::ShippingMethod.delete_all
151
+ end
152
+
153
+ specify do
154
+ click_link "Customer"
155
+ # Need to fill in valid information so it passes validations
156
+ fill_in "order_ship_address_attributes_firstname", with: "John 99"
157
+ fill_in "order_ship_address_attributes_lastname", with: "Doe"
158
+ fill_in "order_ship_address_attributes_lastname", with: "Company"
159
+ fill_in "order_ship_address_attributes_address1", with: "100 first lane"
160
+ fill_in "order_ship_address_attributes_address2", with: "#101"
161
+ fill_in "order_ship_address_attributes_city", with: "Bethesda"
162
+ fill_in "order_ship_address_attributes_zipcode", with: "20170"
163
+
164
+ page.select('Alabama', from: 'order_ship_address_attributes_state_id')
165
+ fill_in "order_ship_address_attributes_phone", with: "123-456-7890"
166
+ expect { click_button "Update" }.not_to raise_error
167
+ end
168
+ end
169
+ end
170
+
171
+ def fill_in_address(kind = "bill")
172
+ fill_in "First Name", with: "John 99"
173
+ fill_in "Last Name", with: "Doe"
174
+ fill_in "Company", with: "Company"
175
+ fill_in "Street Address", with: "100 first lane"
176
+ fill_in "Street Address (cont'd)", with: "#101"
177
+ fill_in "City", with: "Bethesda"
178
+ fill_in "Zip", with: "20170"
179
+ targetted_select2 "Alabama", from: "#s2id_order_#{kind}_address_attributes_state_id"
180
+ fill_in "Phone", with: "123-456-7890"
181
+ end
182
+ 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("$100.00")
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,225 @@
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_id" do
99
+ # Insure we have the SKU in the options
100
+ expect(find('#q_line_items_variant_id_in').all('option').collect(&:text)).to include(order1.line_items.first.variant.sku)
101
+
102
+ # Select and filter
103
+ find('#q_line_items_variant_id_in').find(:xpath, 'option[2]').select_option
104
+ click_on 'Filter Results'
105
+
106
+ within_row(1) do
107
+ expect(page).to have_content(order1.number)
108
+ end
109
+
110
+ expect(page).not_to have_content(order2.number)
111
+ end
112
+
113
+ context "when pagination is really short" do
114
+ before do
115
+ @old_per_page = Spree::Config[:orders_per_page]
116
+ Spree::Config[:orders_per_page] = 1
117
+ end
118
+
119
+ after do
120
+ Spree::Config[:orders_per_page] = @old_per_page
121
+ end
122
+
123
+ # Regression test for #4004
124
+ it "should be able to go from page to page for incomplete orders" do
125
+ Spree::Order.destroy_all
126
+ 2.times { Spree::Order.create! email: "incomplete@example.com", completed_at: nil, state: 'cart' }
127
+ click_on 'Filter'
128
+ uncheck "q_completed_at_not_null"
129
+ click_on 'Filter Results'
130
+ within(".pagination") do
131
+ click_link "2"
132
+ end
133
+ expect(page).to have_content("incomplete@example.com")
134
+ expect(find("#q_completed_at_not_null")).not_to be_checked
135
+ end
136
+ end
137
+
138
+ it "should be able to search orders using only completed at input" do
139
+ fill_in "q_created_at_gt", with: Date.current
140
+ click_on 'Filter Results'
141
+
142
+ within_row(1) { expect(page).to have_content("R100") }
143
+
144
+ # Ensure that the other order doesn't show up
145
+ within("table#listing_orders") { expect(page).not_to have_content("R200") }
146
+ end
147
+
148
+ context "filter on promotions" do
149
+ let!(:promotion) { create(:promotion_with_item_adjustment) }
150
+
151
+ before do
152
+ order1.promotions << promotion
153
+ order1.save
154
+ visit spree.admin_orders_path
155
+ end
156
+
157
+ it "only shows the orders with the selected promotion" do
158
+ select promotion.name, from: "Promotion"
159
+ click_on 'Filter Results'
160
+ within_row(1) { expect(page).to have_content("R100") }
161
+ within("table#listing_orders") { expect(page).not_to have_content("R200") }
162
+ end
163
+ end
164
+
165
+ it "should be able to apply a ransack filter by clicking a quickfilter icon", js: true do
166
+ label_pending = page.find '.label-pending'
167
+ parent_td = label_pending.find(:xpath, '..')
168
+
169
+ # Click the quick filter Pending for order #R100
170
+ within(parent_td) do
171
+ find('.js-add-filter').click
172
+ end
173
+
174
+ expect(page).to have_content("R100")
175
+ expect(page).not_to have_content("R200")
176
+ end
177
+
178
+ context "filter on shipment state" do
179
+ it "only shows the orders with the selected shipment state" do
180
+ select Spree.t("payment_states.#{order1.shipment_state}"), from: "Shipment State"
181
+ click_on 'Filter Results'
182
+ within_row(1) { expect(page).to have_content("R100") }
183
+ within("table#listing_orders") { expect(page).not_to have_content("R200") }
184
+ end
185
+ end
186
+
187
+ context "filter on payment state" do
188
+ it "only shows the orders with the selected payment state" do
189
+ select Spree.t("payment_states.#{order1.payment_state}"), from: "Payment State"
190
+ click_on 'Filter Results'
191
+ within_row(1) { expect(page).to have_content("R100") }
192
+ within("table#listing_orders") { expect(page).not_to have_content("R200") }
193
+ end
194
+ end
195
+
196
+ # regression tests for https://github.com/spree/spree/issues/6888
197
+ context "per page dropdown", js: true do
198
+ before do
199
+ select "45", from: "per_page"
200
+ sleep(1)
201
+ expect(page).to have_select("per_page", selected: "45")
202
+ end
203
+
204
+ it "adds per_page parameter to url" do
205
+ expect(current_url).to match(/per_page\=45/)
206
+ end
207
+
208
+ it "can be used with search filtering" do
209
+ click_on 'Filter'
210
+ fill_in "q_number_cont", with: "R200"
211
+ click_on 'Filter Results'
212
+ expect(page).not_to have_content("R100")
213
+ within_row(1) { expect(page).to have_content("R200") }
214
+ expect(current_url).to match(/per_page\=45/)
215
+ expect(page).to have_select("per_page", selected: "45")
216
+ select "60", from: "per_page"
217
+ sleep(1)
218
+ expect(page).to have_select("per_page", selected: "60")
219
+ expect(page).not_to have_content("R100")
220
+ within_row(1) { expect(page).to have_content("R200") }
221
+ expect(current_url).to match(/per_page\=60/)
222
+ end
223
+ end
224
+ end
225
+ end