-
Notifications
You must be signed in to change notification settings - Fork 1.9k
UI test for Translation Function #9856
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Looks like the error is: |
|
@imajit, I'm playing around with this right now in GitPod. I don't know very much about the areas you're working on. I'm doing a lot of catch-up to try and understand what this test is supposed to do. It looks like I'm not familiar with this I'm guessing that this line is looking up the Is there an equivalent of |
I wrote this test to check if UI breaks for Translation team members. It is able to fetch the |
Ah, okay, so this line does work: That means the page and element are rendering correctly, and you can search for the Why don't you just |
I don't think there is. Integration tests are the closest thing to system tests but still don't run in a "real" browser. They're still simulated just by parsing the response from the application in text, rather than actually rendering it. But good thought... we could alternatively try a system test if that's going to be easier, though it "costs" a little more compute time. |
|
I do recall that the parsing and matching in integration tests is notoriously fickle, one reason why it made sense to move to system tests where it really is just a browser. :-//// |
|
Hey @imajit @jywarren @noi5e I tried this locally by hitting the |
Hi! This is only visible to users having plots2/app/views/layouts/_header.html.erb Line 20 in 3d3de3f
To reproduce the error you need to add translation-helper tag and remove the false parameter. You can see the UI error in /change_locale/es
|
|
I put a console log into the test:
Which has this output:
Looks like the In the original comment's screenshot, it looks like |
Yes, that is true, we do not want the I also tried to write a system test for this based on changes in #9878 , it works with |
|
|
@imajit Nice! Does that system test work? As to why the integration test wasn't able to find it... |
No even this doesn't seem to work 😞 , it needs changes made in #9878 so won't work for now in local dev. |
|
I too think as the |
|
@imajit, I was thinking about this today, and I remembered there are some system tests that run JavaScript within the headless browser. Check out: plots2/test/system/comment_test.rb Lines 222 to 265 in b73594f
Basically I think you would be able to get this test to work if you did that, and used JS methods that look through the DOM for the value you want. Something like |
test/integration/I18n_test.rb
Outdated
| get '/dashboard' | ||
| follow_redirect! | ||
| #assert_select '#searchform_input:match("placeholder",?)',I18n.t('layout._header.search') | ||
| assert_select '#searchform_input:match("placeholder",?)',/span/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now that #9878 is merged did you want to rebase this? Just linking relevant lines here:
Line 631 in b73594f
| search: "Search on Public Lab" |
plots2/app/views/layouts/_header.html.erb
Line 20 in b73594f
| <input aria-label="Enter Search Query" type="text" id="searchform_input" class="form-control search-query typeahead" role="search" qryType="tags" placeholder="<%= translation('layout._header.search',{},false) %>" value="<%= params[:query] %>" required> |
So since we don't have a spanish equivalent, you're looking for the helper now:
https://github.com/publiclab/plots2/blob/main/config/locales/es.yml
Is it inserting this via JavaScript after the page is rendered, or in Ruby before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're passing html = false, it should show line 167, which is just the translated string if it exists, or the English if it doesn't, right? This is all in Ruby so the only JS needed is when the placeholder is built in JavaScript. That said, are we sure the Bootstrap UI scripts (which build the placeholder) run in the limited "simulation" of a browser in integration tests? If not, best move this over to a system test as you've discussed.
b1abd50 to
4ebec79
Compare
|
In my previous commits, I was not writing the I'm not sure but can this be a possibility that the tests are running before the helper function renders the HTML ? |
|
I think having this as a system test definitely is the way to go. I also agree that maybe the test is not finding elements because the page isn't fully loaded. Maybe inserting more Regarding JS in system tests, I also want to point out this code which inserts a new HTML element onto the page after it's loaded: plots2/test/application_system_test_case.rb Lines 9 to 20 in f41f8e7
Then the system test uses it to simulate someone drag & dropping an image for upload: plots2/test/system/comment_test.rb Lines 666 to 671 in f41f8e7
I know it's unrelated, but it's just a for-example showing that it's possible for system tests to manipulate the DOM, and get the true and current attributes of HTML elements, like the Definitely try |
|
So the key here i THINK is not that the helper won't have rendered yet, since that's all on the server side in ruby, but that the key markup is within a Bootstrap "popover" - https://getbootstrap.com/docs/4.4/components/popovers/ - which is created after Bootstrap JavaScript executes - it pulls out the After that you may still have some timing issues and can try other techniques that @noi5e suggested. But I hope simply running this in system tests will fix most of it! |
4ebec79 to
1dd2aac
Compare
|
Code Climate has analyzed commit 1dd2aac and detected 0 issues on this pull request. View more on Code Climate. |
|
This test will fail when the translation function fails to render UI correctly. |
| visit '/dashboard' | ||
| uid = users(:bob).id | ||
| visit '/profile/tags/create/'+uid.to_s+'?translationswitch=yes&name=translation-helper' | ||
| assert_selector(:xpath, './/input[@id="searchform_input"][contains(@placeholder,"Search")]') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice!!!
|
Well done, @imajit !!! |
|
Nice @imajit!!! |
* Tests not working * Changing integration test to system test * Yaay it works Co-authored-by: imajit <[email protected]>
* Tests not working * Changing integration test to system test * Yaay it works Co-authored-by: imajit <[email protected]>



Part of #9686

I'm trying to check if
<span>occurs in placeholder but it doesn't seem to work, when I try to search the wordSearchthen the test works.Not able to figure out what is the mistake in this 😕 @jywarren can you please help me out with this one ?