Skip to content

Commit 6694683

Browse files
committed
Do not test Rails disable-with behavior
We can just test that the buttons have the necessary attribute for the behaviour. These tests had become flaky.
1 parent dc5c7d3 commit 6694683

File tree

5 files changed

+11
-41
lines changed

5 files changed

+11
-41
lines changed

backend/spec/features/admin/orders/customer_returns_spec.rb

+3-14
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,14 @@ def expect_order_state_label_to_eq(text)
3333
end
3434
end
3535

36-
it 'disables the button at submit', :js do
37-
page.execute_script "$('form').submit(function(e) { e.preventDefault()})"
38-
39-
create_customer_return('receive')
40-
41-
expect(page).to have_button("Create", disabled: true)
36+
it 'disables the button at submit' do
37+
expect(page).to have_css('input[type="submit"][data-disable-with="Create"]')
4238
end
4339

4440
context 'when creating a return with state "In Transit" and then marking it as "Received"' do
4541
it 'disables the "Receive" button at submit', :js do
4642
create_customer_return('in_transit')
47-
48-
page.execute_script "$('form').submit(function(e) { e.preventDefault()})"
49-
50-
within('[data-hook="rejected_return_items"] tbody tr:nth-child(1)') do
51-
click_button('Receive')
52-
53-
expect(page).to have_button("Receive", disabled: true, wait: 5)
54-
end
43+
expect(page).to have_css('input[type="submit"][data-disable-with="Receive"]')
5544
end
5645

5746
it 'marks the order as returned', :js do

backend/spec/features/admin/orders/return_payment_state_spec.rb

+2-7
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,9 @@ def create_customer_return
6767
)
6868
end
6969

70-
it 'disables the "Create Reimbursement" button at submit', :js do
70+
it 'disables the "Create Reimbursement" button at submit' do
7171
create_customer_return
7272

73-
page.execute_script "$('form').submit(function(e) { e.preventDefault()})"
74-
75-
# Create reimbursement
76-
click_on 'Create reimbursement'
77-
78-
expect(page).to have_button("Create reimbursement", disabled: true)
73+
expect(page).to have_css("input[type='submit'][data-disable-with='Create reimbursement']")
7974
end
8075
end

legacy_promotions/spec/features/backend/promotion_adjustments_spec.rb

+2-7
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,8 @@
167167
expect(promotion.actions.first).to be_a(Spree::Promotion::Actions::FreeShipping)
168168
end
169169

170-
it "disables the button at submit", :js do
171-
page.execute_script "$('form').submit(function(e) { e.preventDefault()})"
172-
fill_in "Name", with: "SAVE SAVE SAVE"
173-
choose "Apply to all orders"
174-
click_button "Create"
175-
176-
expect(page).to have_button("Create", disabled: true)
170+
it "disables the button at submit" do
171+
expect(page).to have_css("input[type='submit'][data-disable-with='Create']")
177172
end
178173

179174
it "should allow an admin to create an automatic promotion" do

legacy_promotions/spec/features/backend/promotions/promotion_code_batches_spec.rb

+2-6
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,14 @@ def create_code_batch
2323
expect(page).to_not have_field("promotion_per_code_usage_limit")
2424
end
2525

26-
it "creates a new promotion code batch and disables the submit button", :js do
26+
it "creates a new promotion code batch and disables the submit button" do
2727
create_code_batch
2828

2929
expect(page).to have_content "Promotion Code Batch has been successfully created!"
3030

3131
visit spree.new_admin_promotion_promotion_code_batch_path(promotion)
3232

33-
page.execute_script "$('form').submit(function(e) { e.preventDefault()})"
34-
35-
create_code_batch
36-
37-
expect(page).to have_button("Create", disabled: true)
33+
expect(page).to have_css("input[type='submit'][data-disable-with='Create']")
3834
end
3935
end
4036
end

legacy_promotions/spec/features/backend/promotions/promotion_code_spec.rb

+2-7
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,8 @@
1919
expect(page).to have_content "Promotion Code has been successfully created!"
2020
end
2121

22-
it "disables the button at submit", :js do
23-
page.execute_script "$('form').submit(function(e) { e.preventDefault()})"
24-
25-
fill_in "Value", with: "XYZ"
26-
click_button "Create"
27-
28-
expect(page).to have_button("Create", disabled: true)
22+
it "disables the button at submit" do
23+
expect(page).to have_css("input[type='submit'][data-disable-with='Create']")
2924
end
3025
end
3126
end

0 commit comments

Comments
 (0)