unabridged / motion

Reactive frontend UI components for Rails in pure Ruby
https://github.com/unabridged/motion
MIT License
697 stars 19 forks source link

Fix intermittent system test failure #81

Closed Gmfholley closed 3 years ago

Gmfholley commented 3 years ago

Description

Attempts to fix intermittent system test failure: https://travis-ci.com/github/unabridged/motion/jobs/490209306 https://travis-ci.com/github/unabridged/motion/jobs/490205207

The stale element error from Selenium tells me motion re-renders between selenium finding an element and filling it in. The failure of the 'Taken' test with a 'Name cannot be blank' error shows that a motion is getting triggered too soon or is not registering the fill_in of Taken. When I added some logging to that test, I could see below that motion was getting triggered on the 'T' of 'Taken', but the formdata showed a dog_name of empty and T, such that it re-rendered for the first time as nil.

validate: 
#<Motion::Event:0x00000000022ae2a0
  @raw={
    "type"=>"change", "details"=>{}, "extraData"=>nil,
    "target"=>{"tagName"=>"INPUT", "value"=>"T", "attributes"=>{"type"=>"text", "name"=>"dog[name]", "id"=>"dog_name"}, 
    "formData"=>"utf8=%E2%9C%93&authenticity_token=D29EbbCr98xLYlzttbok%2BqZ%2BWUwIEH0zgVqDU4RSMC9SapAuVIRw2UGbcPQz7V5%2BnPu%2Bn29zAxNGeKndhHRE%2FA%3D%3D&dog%5Bname%5D=T&dog%5Bname%5D="
   }
...
>

I tried a few solutions, including changing the input to map a motion on blur, instead of the form on change, but I decided we wanted to be able to write a system test like this, on change.

In the end the solution for these errors seems to be:

I tested this fix four times, and it appears to be working.