Commit Graph

816 Commits

Author SHA1 Message Date
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
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
Javi Martín
74089d1feb Add "Go back" link in admin verifications
It isn't very intuitive that this link points to the stats page, but
since it's the only page linking to it and there's no link pointing to
it in the admin navigation, I guess it's better than offering no clue at
all of the current whereabouts.
2021-04-02 20:56:09 +02:00
Javi Martín
5831f190ba Fix "Go back" link in stat graphs
The link appeared twice when visiting stats for a budget's supporting
phase.
2021-04-02 20:56:09 +02:00
Javi Martín
02981324ab Move exception tests to controller specs
System tests are used to test the application from the user's point of
view. To test for specific exceptions, particularly regarding
authorization permissions, controller tests fit better.

Another option would be to test the page displayed shows a certain text,
like "Internal server error". I'm choosing controller tests because
they're faster and we're basically testing the same scenario many times
and we've already got a test checking what happens when users access a
page raising an exception.
2021-03-31 14:42:20 +02:00
Javi Martín
abd6a1971f Move redirection test to controller specs
We make the test faster and avoid a strange issue with `current_path` in
JavaScript tests.

We should probably have done this in commit ec1874325.
2021-03-31 14:42:20 +02:00
Javi Martín
81295abd8c Move custom page 404 test to controller specs
So it's similar to the other custom page 404 tests.

Note we're explicitely marking the page as a draft so it's more obvious
what's going on in the test.
2021-03-31 14:42:20 +02:00
Javi Martín
489e012e1b Test 500 Internal server error page in system spec
We were testing what happens when users disable features in the admin
panel, so it makes sense to test what happens from the user's point of
view when trying to access a disabled feature: they see a page with the
test "Internal server error".

Whether we should responde with 500 Internal server error page or a 404
Not Found is up to debate; personally I find the latter more
appropriate.

Code based on the article "Changing Rails consider_all_requests_local in
RSpec fails" [1].

[1] http://atodorov.org/blog/2016/04/27/changing-rails-consider_all_requests_local-in-rspec-fails/
2021-03-31 14:42:20 +02:00
Javi Martín
0c95ababdf Use dates to fill in admin date input fields
Tests are easier to read now. Besides, since we changed the inputs in
the admin section so they don't use jQuery but an HTML date field,
formatting with %d/%m/%Y might not work depending on the browser's
locale.
2021-03-31 14:09:13 +02:00
Javi Martín
24a66f16f2 Close datepicker in tests after filling in dates
Some tests were failing depending on the window resolution due to the
datepicker making it impossible to click the "Filter" button. They were
also failing if using `clear: :backspace` to fill in those fields.

So we're focusing on a different field in order to hide the datepicker
and click the "Filter" button.
2021-03-31 14:09:13 +02:00
Javi Martín
863f70044b Fix test trying to set a wrong date
The line `fill_in "advanced_search_date_max", with: "wrong date"`
doesn't work because the jQuery UI datepicker prevents users from
entering that value.
2021-03-31 14:09:13 +02:00
Javi Martín
52e0d45ff7 Fix filling in dates in advanced search tests
We were filling in dates with times, which is not what users would do.
2021-03-31 14:09:13 +02:00
Javi Martín
d7563be8b3 Fix admin notification with relative URLs
The test was passing because it was using the rack driver, but on real
browsers it wasn't generating the expected URL.
2021-03-31 14:03:26 +02:00
Javi Martín
6ea9383743 Allow toggling elements with the keyboard
Using `<a>` tags with no `href` means these elements cannot be activated
by keyboard users, so we're replacing them with buttons.

In the future we probably want to add more consistency so all toggle
buttons use the same code. We might also add styles depending on the
`aria-expanded` property.
2021-03-31 13:38:38 +02:00
Alberto
048ca61207 Improve styles for budgets voting phase 2021-03-24 15:50:25 +01:00
Alberto
f79edf6ba4 Improve message to submit ballot 2021-03-24 15:48:24 +01:00