Skip to content

Commit

Permalink
Fix spec to remove reliance on browser's message
Browse files Browse the repository at this point in the history
Client side validation messages depend on the browser's locale, which
we have no controll over. Now we just check a message is set.
  • Loading branch information
rioug committed Aug 27, 2024
1 parent f3bfcdf commit 4ad89f6
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions spec/system/admin/products_v3/update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@
# have to use below method to trigger the +change+ event,
# +fill_in "Unit value", with: ""+ does not trigger +change+ event
find_field('Unit value').send_keys(:control, 'a', :backspace) # empty the field
# In CI we get "Please fill out this field." and locally we get
# "Please fill in this field."
expect_browser_validation('input[aria-label="Unit value"]',
/Please fill (in|out) this field./)
expect_browser_validation('input[aria-label="Unit value"]')

fill_in "Unit value", with: "500.1"
fill_in "Price", with: "10.25"
Expand Down Expand Up @@ -513,8 +510,7 @@
# Client side validation
click_button "Save changes"
within new_variant_row do
expect_browser_validation('select[aria-label="Unit scale"]',
"Please select an item in the list.")
expect_browser_validation('select[aria-label="Unit scale"]')
end

# Fix error
Expand All @@ -527,8 +523,7 @@
within new_variant_row do
# In CI we get "Please fill out this field." and locally we get
# "Please fill in this field."
expect_browser_validation('input[aria-label="Unit value"]',
/Please fill (in|out) this field./)
expect_browser_validation('input[aria-label="Unit value"]')
end

# Fix error
Expand Down Expand Up @@ -745,8 +740,10 @@
end
end

def expect_browser_validation(selector, message)
# Check a validation message is set, we don't check the message itself because the value is based
# on the browser's locale.
def expect_browser_validation(selector)
browser_message = page.find(selector)["validationMessage"]
expect(browser_message).to match message
expect(browser_message.present?).to be(true)
end
end

0 comments on commit 4ad89f6

Please sign in to comment.