Commit Graph

16076 Commits

Author SHA1 Message Date
Javi Martín
eb4ee891c4 Reduce tests timeout in GitHub Actions
Sometimes a test gets stuck and and we have to wait until it times out
in order to check which files were being tested at the time.

The default timeout is six hours. I'm reducing it to one hour which
should still be plenty of time even on repositories with no knapsack
token.
2021-04-07 14:41:06 +02:00
Javi Martín
8d38ed58c8 Reduce accesses to database after browser requests
GitHub Actions is failing to finish sometimes. Usually that happens due
to concurrency issues when the process running the test accesses the
database after the process running the browser has started.

Since these files were the ones being tested the times we had this
issue, these are the ones we are fixing right now, although there are
probably other places where we might have this issue in the future.
2021-04-07 14:41:06 +02:00
Javi Martín
03d0ffd89e Sign in manager after setting up test data
We've got quite a messy hack to sign in managers: they need to visit a
specific URL (management root path).

That means tests signing in managers start the browser to sign them in,
which might cause issues if we setup the database after that.
2021-04-07 14:41:06 +02:00
Javi Martín
efbb3bb690 Simplify setting up tests with managed users 2021-04-07 14:41:06 +02:00
Javi Martín
609d6ab9a3 Fix rubocop offense in budgets system spec
This offense was introduced in commit 28caabecdf.
2021-04-07 14:41:06 +02:00
Javi Martín
92ddcb7aef Use JavaScript in system tests by default
JavaScript is used by about 98% of web users, so by testing without it
enabled, we're only testing that the application works for a very
reduced number of users.

We proceeded this way in the past because CONSUL started using Rails 4.2
and truncating the database between JavaScript tests with database
cleaner, which made these tests terribly slow.

When we upgraded to Rails 5.1 and introduced system tests, we started
using database transactions in JavaScript tests, making these tests much
faster. So now we can use JavaScript tests everywhere without critically
slowing down our test suite.
2021-04-07 14:41:06 +02:00
Javi Martín
424fe7f5d2 Add extra expectation in emails spec
The test is failing on my machine sometimes. I thought it was because
`open_last_email` didn't wait fot the request generated by clicking the
"Registrarse" button to finish. Even if that might be the case, adding
an extra expectation showed the test was really failing because
invisible captcha reported the form was filled in too fast.

I wonder whether invisible captcha is working properly or there are
times where it doesn't start its timer when it should.

Since this might be a bug in the application, I'm not changing the test
just to make it pass.
2021-04-07 14:41:06 +02:00
Javi Martín
911640d2b2 Use JS in tests with buttons to show content 2021-04-07 14:41:06 +02:00
Javi Martín
9cfcbf2f3b Use visible texts in tests
Content like lowercase letters with `text-transform: uppercase` or
spaces after elements with `display: block` or "You're on page:" are not
seen that way by users with a browser supporting CSS.

So we're testing what most users actually experience.
2021-04-07 14:41:06 +02:00
Javi Martín
23945c2a7c Use JavaScript in tests dealing with tabs
So what we write in the tests is close to what users experience.
2021-04-07 14:41:06 +02:00
Javi Martín
baaec3a29c Use JavaScript in tests using the user menu
This way we click on the "menu" link first before clicking on any
sections, just like real users do.
2021-04-07 14:41:06 +02:00
Javi Martín
222e4c9542 Use JavaScript in tests using the admin menu
This menu requires JavaScript to open/close subnavigation menus, so
we're now testing the way users with a browser supporting JavaScript
(98%-99% of the users) deal with the menu.
2021-04-07 14:41:06 +02:00
Javi Martín
e3deff8bdc Remove redundant banners test
We're implicitly checking the link is listed on the menu by clicking it
in other tests.
2021-04-07 14:41:06 +02:00
Javi Martín
e773f72a27 Use JavaScript in test requiring to hover
Having all the text show when hovering over a cell is an
accessibility/usability issue that we now experience in the tests as
well.
2021-04-07 14:41:06 +02:00
Javi Martín
cdd70a6116 Use JavaScript in tests with flash messages
So now we feel in the tests the same usability problems users feel when
they want to click a link and the flash message is in their way.
2021-04-07 14:41:06 +02:00
Javi Martín
1bd9992890 Use JavaScripts in tests opening new windows
IMHO opening new windows is a usability issue which has been known for
twenty years since it takes control away from the user and breaks the
"back button", but for now we're keeping the same behavior as we already
had, while slightly increasing the complexity of the tests (which is a
good indicator of a usability issue).
2021-04-07 14:41:06 +02:00
Javi Martín
9d1b3a4da2 Use JavaScript in tests using the Markdown editor
The markdown editor only works with JavaScript, so in order to test it
we need a JavaScript test.
2021-04-07 14:41:06 +02:00
Javi Martín
287c488734 Use JavaScripts in tests using CKEditor
We were filling in textareas, so we were only testing how the
application behaves for about 1%-2% of our users.
2021-04-07 14:41:06 +02:00
Javi Martín
b2bc4d19f5 Use JavaScript in tests opening modal dialogs
This way we reproduce the user experience in the tests, and we can make
sure modal dialogs open when we expect it.
2021-04-07 14:41:06 +02:00
Javi Martín
fbc78984dc Fill in the right field in phases test
Before clicking the "Edit phase" link, there's already a "Name" field
present in the page (the name of the budget).

With the rack driver, there's no problem since the `fill_in` action
waits until the page is loaded.

However, the test will be a flaky spec if we use a driver supporting
JavaScript, since clicking the "Edit phase" link will cause an AJAX
request and the `fill_in` action might be executed before the AJAX
request is finished.
2021-04-07 14:41:06 +02:00
Javi Martín
919d0b8b86 Improve unfeasibility reason in valuation test
It was strange to specify the unfeasibility reason without marking the
investment as unfeasible.
2021-04-07 14:35:30 +02:00
Javi Martín
d13ef77ca5 Improve legislation process creation test
We weren't enabling phases in the test, so anything we did with the
dates didn't take any effect.
2021-04-07 14:35:30 +02:00
Javi Martín
fda61daa03 Make process creation tests more readable
We created fieldsets in commit 6172dd0a5 but forgot to simplify the
tests as well.
2021-04-07 14:35:30 +02:00
Javi Martín
2036b3d44e Add success message when creating/updating banners 2021-04-07 14:35:30 +02:00
Javi Martín
5612ada2d4 Remove unused variables 2021-04-07 14:35:30 +02:00
Javi Martín
5ab1ed57ea Simplify selector in tracking test
Using `have_selector` makes the test more robust since it matches all
the following HTML:

* <div data-track-event-category=verification>
* <div data-track-event-category='verification'>
* <div data-track-event-category="verification">

Our former expectation only matched the first one.
2021-04-07 14:35:30 +02:00
Javi Martín
0ec8878db9 Reduce number of requests in dashboard tests
Using separate tests to check every link on the page made the tests
slower. We were also adding a useless initial request on tests which
started by visiting a different URL.

This useless initial request meant in some tests the browser was started
before using factories to create data. Accessing the database in the
test after the browser starts might cause concurrency issues in
JavaScript tests.
2021-04-07 14:35:30 +02:00
Javi Martín
91b8121615 Fix typo in content types setting test
The test was creating a new "upload.images" setting instead of using
"uploads.images". It passed because it wasn't using JavaScript but was
configuring the wrong setting.
2021-04-07 14:35:30 +02:00
Javi Martín
2965e45b64 Simplify navigation in custom images tests
IMHO testing the navigation once is enough. In the rest of the tests we
can access the page directly and make the tests faster by reducing the
number of requests.
2021-04-07 14:35:30 +02:00
Javi Martín
0fcb97a78f Specify we're testing validation on the server
Testing the validation on the server side doesn't work with chromedriver
because HTML valdations result in the browser not even submitting the
form, so we're adding a `:no_js` tag to indicate we deliberately choose
to use the Rack driver.

The following test checking client side validation passes on my machine
but fails on Github Actions:

```
scenario "Validates price formats on the client side", :js do
  investment.update!(visible_to_valuators: true)

  visit edit_valuation_budget_budget_investment_path(budget, investment)

  fill_in "Price (€)", with: "12345,98"
  click_button "Save changes"

  validation_message = find_field("Price (€)").native.attribute("validationMessage")

  expect(validation_message).to be_present
end
```
2021-04-07 14:35:30 +02:00
Javi Martín
fb6e4d6c08 Mark tests checking behavior without JavaScript 2021-04-07 14:35:30 +02:00
Javi Martín
8a7555092f Explicitly use rack driver in dashboard test
There seems to be a bug in the dashboard when calculating
`accumulat_supports` because in some cases `vote_weight` is `nil`.

Besides, these tests check the database after the browser has started,
instead of checking things from a user's point of view.

Since both the tests and the code are wrong, and I'm not familiar enough
with the code in the dashboard section, for now I'm leaving things as
they were.
2021-04-07 14:35:30 +02:00
Javi Martín
56317c771a Explicitly disable JS in test deleting milestone
There's a usability issue in certain cases in browsers: when the
milestones table is at the bottom of the screen and it fills the screen
width completely, hovering over the link to delete a milestone makes the
"Delete milestone" tooltip cause a horizontal scrollbar. The scrollbar
makes it impossible for users to click the link.

We should probably fix this usuability issue; for now, I'm keeping the
test the way it was.
2021-04-07 14:35:30 +02:00
Javi Martín
1747d85c90 Explicitly disable JS with other file formats
JavaScripts drivers emulate browser behavior and browsers might download
these files instead of opening them.
2021-04-07 14:35:30 +02:00
Javi Martín
5a7298cefc Explicitly disable JS in legislation answer tests
The user experience with JavaScript enabled is actually very bad;
there's a usability issue here because it's impossible to change an
answer once a "radio button" is selected, which goes against the
standard practice on basically any HTML form.

Issue 4123 already mentions this problem. Until we fix it, we're
disabling JavaScript in these tests.
2021-04-07 14:35:30 +02:00
Javi Martín
0b7014b7d7 Explicitly disable JS when testing JS injection
CKEditor already comes with JS injection protection, so potential
attackers will most likely disable CKEditor.
2021-04-07 14:32:49 +02:00
Javi Martín
45f2abcb1c Explicitly disable JavaScript with honeypot fields
These fields are hidden for users with a browser supporting CSS and is
only there to fool bots, so we're testing the case of an attack by bots
using browsers with no CSS support.
2021-04-07 14:32:49 +02:00
Javi Martín
38edc51e3f Explicitly use rack driver in IE tests
Since we need to fake what happens to Internet Explorer users, we can't
run the test on a real browser.
2021-04-07 14:32:49 +02:00
Javi Martín
5f0c422eb3 Explicitly use rack driver in notifications spec
The filter "Mark as viewed" doesn't work properly, so here's a case
where the test would fail with JavaScript not because the test is wrong,
but due to a bug.

For now we're keeping the test as it was, but eventually we'll have to
fix the bug.
2021-04-07 14:32:49 +02:00
Javi Martín
6a509a7437 Use UTF characters in the BMP in tests
ChromeDriver only supports characters in the BMP (Basic Multilingual
Plane). One test fails with ChromeDriver because it was entering emojis.

I'm using kanji characters instead, although I must admit I'm not sure
why such an unusual login was used in the first place.
2021-04-07 14:32:49 +02:00
Javi Martín
71053fd334 Don't use localization methods in system specs
The method `formatted_heading_price` depends on the current locale. When
we make a request to `visit budgets_path locale: :es`, the request
modifies `I18n.locale` as well.

However, if we use JavaScript tests, the process running the test is
different than the process handling the request, and so the change in
`I18n.locale` does not affect the test.

Checking against the actual value we expect makes the test work with and
without JavaScript.
2021-04-07 14:32:49 +02:00
Javi Martín
f3595833fd Improve readability in some system specs
We're improving the readability of the ones we're about to modify.
Using human texts makes tests easier to read and guarantees we're
testing from the user's point of view. For instance, if we write
`fill_in banner_target_url`, the test will pass even if the field has no
label associated to it. However, `fill_in "Link"` makes sure there's a
field with an associated label.
2021-04-07 14:32:49 +02:00
Javi Martín
36e2610919 Use have_link to check for links in tests
Using `have_selector` Capybara might detect `<a>` tags which are not
links because they don't have an `href` attribute. Besides, with
`have_selector` Capybara only detects visible text, which means it won't
detect links which are icons with tooltips.
2021-04-07 14:32:49 +02:00
Javi Martín
cf4e6d2c64 Improve budget phase HTML ID
Some browsers might not recognize an ID as valid when it starts with a
number.
2021-04-07 14:32:49 +02:00
Javi Martín
b2bb0c7143 Remove unnecessary code to visit a URL
Visiting a URL before creating data in system tests might cause
concurrency issues if we start using a driver supporting JavaScript.
2021-04-07 14:32:49 +02:00
Javi Martín
7127b46d9f Use have_current_path instead of include
Using `have_current_path`, Capybara waits until the condition is true,
while using `include` the expectation is evaluated immediately and so
tests might fail when using a driver supporting JavaScript.

Besides, using `have_current_path` the error message is more readable
when the test fails.
2021-04-07 14:32:49 +02:00
Javi Martín
b7ec9bc20c Remove unnecessary code fo fill in honeypot field
This field should not be filled in when we're trying to check a
different cause for identifying a request as spam.
2021-04-07 14:32:49 +02:00
Javi Martín
5cf10a917b Avoid DB changes after a request in budget spec
When using tests with a driver supporting JavaScript, there might be
concurrency issues if both the process running the test and the process
running the browser access the database once the browser has been
started.
2021-04-07 14:32:49 +02:00
Javi Martín
8ed09adcaf Extract method to generate app host in tests
On JavaScript tests, Rails URL methods don't include the port when
invoked from a test, but they do when invoked from the browser. This was
causing some tests to fail with Selenium.
2021-04-07 14:32:49 +02:00
Javi Martín
b93f38ec11 Extract banner test to a component
Checking the `style` attribute fails in JavaScript tests because the
browser converts colors to the `rgb()` format.

So we're testing the generated HTML in a component test while
simplifying the system test.
2021-04-07 14:32:49 +02:00