Commit Graph

46 Commits

Author SHA1 Message Date
Javi Martín
ea913f9332 Use Capybara methods to find/click/check links
We applied the Capybara/SpecificMatcher in commit f52a86b46.  However,
this rule doesn't convert methods finding <a> tags to methods finding
links because <a> tags only count as links when they've got the `href`
attribute. For instance, in the `xss_spec.rb` file we check what happens
when clicking on an anchor tag because we're testing that the `href`
attribute has been removed and so we can't use `click_link`.

So, basically, we can't enable a rule to automatically detect when we're
using `have_css` instead of `have_link`, but we should still do it
because `have_link` adds an extra check which affects accessibility
since it makes sure the tag has the `href` attribute and so it's
recognizable as a link by screen readers.
2023-09-11 14:10:41 +02:00
Javi Martín
daa35845da Add and apply Style/RedundantStringEscape rule
This rule was added in rubocop 1.37.0. It's particularly useful in the
background image spec, since now there's one less backslash to decipher
when reading the code :).
2023-09-07 13:09:11 +02:00
Javi Martín
a1439d0790 Apply Layout/LineLength rubocop rule
Note we're excluding a few files:

* Configuration files that weren't generated by us
* Migration files that weren't generated by us
* The Gemfile, since it includes an important comment that must be on
  the same line as the gem declaration
* The Budget::Stats class, since the heading statistics are a mess and
  having shorter lines would require a lot of refactoring
2023-08-30 14:46:35 +02:00
Javi Martín
629e208e9d Add and apply ArgumentAlignment rubocop rule
We're choosing the default `with_first_argument` style because it's the
one we use the most.
2023-08-18 14:56:16 +02:00
Senén Rodero Rodríguez
1bc2a68856 Do not show the geozone selector where there are no geozones defined 2023-06-14 14:32:08 +02:00
Senén Rodero Rodríguez
9003c460d5 Do not render the geozone link where there are no geozones defined 2023-06-14 14:32:07 +02:00
Javi Martín
3fe65bafd1 Use keyword arguments in mappable specs
We were getting a warning with Ruby 2.7 due to the change in the way
keyword arguments are handled in Ruby 3.0.

```
ruby/gems/2.7.0/gems/rspec-support-3.11.0/lib/rspec/support/with_keywords_when_needed.rb:18:
warning: Passing the keyword argument as the last hash parameter is
deprecated
```

As hinted by the warning, this code crashes with Ruby 3.0:

```
ArgumentError:
  unknown keyword: :budget_id
```

I'm not sure why this is the case, though, since we were already
explicitely passing a hash first before passing the keyword parameters.
I guess there are some cases in this whole keyword VS hash parameters
incompatibility that I haven't completely understood.
2023-01-26 17:19:15 +01:00
Javi Martín
c8270d58bd Add and apply Rails/DurationArithmetic rubocop rule
This rule was added in rubocop-rails 2.13.0. We were already applying it
most of the time.
2022-08-24 23:24:36 +02:00
Javi Martín
d776923ffe Use "withdraw" instead of "retire"
We used "retire" because we translated it literally from the Spanish
verb "retirar" which can mean both "retire" and "withdraw".

Note we're still using "retire" in database fields and method names;
changing that might make it harder to upgrade from a previous version of
CONSUL.
2022-06-01 14:27:33 +02:00
Javi Martín
f638e50174 Wait for suggestions to finish loading in tests
Sometimes tests were hanging indefinitely. Debugging shows that in some
cases it's due to submitting a form before the AJAX request to get
proposals, debates or investments suggestions is finished, since having
an AJAX and a non-AJAX request at the same time when running the test
sometimes leads to unexpected results.

In our case, we were having many timeouts in Github Actions in the
branches where we use both ActiveStorage and Paperclip to store files
(based on pull request 4598). I can reproduce it in those branches
running the following test ("Should show new image after successful
creation with one uploaded file"), although only when my laptop isn't
plugged (!!):

```
rspec './spec/system/proposals_spec.rb[1:33:1:14]'
```

Since we didn't have a proper way to know the AJAX request had finished,
we're adding a `suggest-success` class to the element showing the
suggestions when that happens. Then in the tests we can look for that
class after filling in the title of a proposal, debate or investments.
Just for clarity's sake, we're also adding the `suggest-loading` class
when the suggestions are loading.

In order not to have expectations everywhere about the suggestions,
we're extracting methods to fill in those titles in the tests. Note we
aren't using these methods in the "edit" actions (suggestions are not
showing when editing) or in tests with the `no_js` tag (since
suggestions only work with JavaScript).
2021-09-22 18:29:23 +02:00
Javi Martín
65c9786db7 Apply Layout/RedundantLineBreak rule to short lines
We're not adding the rule because it would apply the current line length
rule of 110 characters per line. We still haven't decided whether we'll
keep that rule or make lines shorter so they're easier to read,
particularly when vertically splitting the editor window.

So, for now, I'm applying the rule to lines which are about 90
characters long.
2021-09-03 11:49:53 +02:00
Javi Martín
41a9d17c76 Add and apply Lint/SymbolConversion rubocop rule
This rule was added in Rubocop 1.9.0.

We're excluding the Setting model in order to keep the settings
consistent.
2021-09-03 11:49:53 +02:00
Javi Martín
a4eff3aa19 Simplify subnavigation layout
Using `flex` instead of a fixed width for the navigation, the elements
take all the available space when the search form isn't present. That
wasn't the case before and produced a strange effect on medium-sized
screens.

This way we also align the search to the right.
2021-07-08 18:57:21 +02:00
Javi Martín
f92008e91e Simplify system tests using a small window 2021-06-02 17:06:40 +02:00
Javi Martín
2732c08f3d Simplify calls to have_current_path
In general, we shold check the contents of the page instead of the
current path, since the contents of the page are what users experience.

In one test, the only reason we check the current path additionally to
the contents of the page is to make sure we're still in the management
section.

Checking just that we avoid querying the database after starting the
browser.
2021-04-16 14:33:26 +02:00
Javi Martín
994745839b Simplify tests checking dates are present
When we create a record like a debate or an event and we check the page
content, we want to make sure that today's date is present, since it's
the date where the record is supposed to have been created.

This way we avoid querying the database after the browser has been
started.
2021-04-16 14:33:26 +02:00
Javi Martín
fc32c767dd Split independent blocks of tests
This way we avoid modifying the database in the middle of a system test
(after we've started the browser), which can lead to database
inconsistencies.

In the case of the reclassification specs we're simply removing part of
the test because that part is already tested by other specs.
2021-04-16 14:33:26 +02:00
Javi Martín
405c6e6d14 Test data introduced from the user's point of view
Users don't care about database content; they care about what they see
on the screen.

Writing tests this way we also avoid potencial database inconsistencies
due to accessing the database after starting the browser.
2021-04-16 14:33:26 +02:00
Javi Martín
7b15cc290d Use human labels to fill in proposal form in tests
This way we make sure the label is correctly associated with a field.
2021-04-16 14:33:26 +02:00
Javi Martín
386771f2df Remove duplicate line 2021-04-16 14:33:26 +02:00
Javi Martín
907c0fc679 Remove redundant database checks in system tests
These tests check what happens from the user's point of view. For
instance, we check that after disabling recommendations, they are not
shown. What happens in the database is not related to the user
experience.

Furthermore, checking the database after the browser has started is
proving to be a major source for inconsistent data in specs.
2021-04-16 14:25:21 +02:00
Javi Martín
804e513c7f Remove redundant setting resets in after blocks
We forgot to remove these lines in commit da121ebc53.
2021-04-13 21:54:26 +02:00
taitus
ea8ce24a2a Only make suggestions for related titles for new records
Avoid show suggestions for :edit and :update actions.
2021-04-12 11:05:51 +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
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
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
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
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
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
0d8119a1e3 Use social-share-button whatsapp icon
We were using a custom icon because in the past social-share-button
didn't have support for whatsapp. But now that it does, we can remove
our custom icon.

Note we're using the `_app` suffix because that's the name of the icon
meant for mobile devices.
2021-02-08 16:31:26 +01:00
Javi Martín
a6714be6b8 Group advanced search tests together
We were doing the same tests three times to test the advanced search
feature. I'm grouping them in one place and shuffling the sections
around to remove duplication and make the test suite faster.
2021-01-28 13:42:44 +01:00
Javi Martín
3ec628a63b Add SDG target filter to advanced search 2021-01-26 19:30:58 +01:00
taitus
95c1f36bdd Add SDG::RelatedListSelectorComponent to Proposals
Allow to relate SDG and Targets to Proposals
2021-01-22 16:05:16 +01:00
taitus
1a58fcf2a2 Make tests independent of Setting["org_name"]
So tests won't fail when an institution changes the default organization
name.

The tests are also easier to understand now, since it's more obvious
where the "CONSUL" text is coming from.
2020-12-08 18:56:33 +01:00
Javi Martín
3da4ee00b8 Simplify tests requiring admin login
We were repeating the same code over and over (with a few variants) to
setup tests which require an administrator. We can use a tag and
simplify the code.
2020-12-02 15:33:19 +01:00
Javi Martín
dd7d6440ec Add and apply Capybara/VisibilityMatcher rule
This rule was added in rubocop-rspec 1.39.0. The `visible: false` option
is equivalent to `visible: :all`, but we generally use it meaning
`visible: :hidden` for positive expectations and `visible: :all` for
negative expectations.

The only exceptations are tests where we count the number of map icons
present. I'm assuming in this case we care about the number of map icons
independently on whether they are currently shown in the map, so I'm
keeping the `visible: :all` behavior in this case.
2020-10-25 14:23:53 +01:00
Senén Rodero Rodríguez
b2196561e2 Override proposal sticky top property when anchored
It's known that Foundation Sticky causes some renderization problems
when rendering sticky elements in anchored position.

The problem seems to be that Foundation Sticky is showing the
support box on medium and up devices overlapped with "Share" and
"Community" sidebar boxes when loading proposal page through
Turbolinks and when restoring the page from brwoser history.
Foundation seems to be doing some top property dynamic calculation
(javascript) and is setting top property to `206px` when it should be
`0px`. Notice that this do not happen on page first load (without
Turbolinks). Check foundation/foundation-sites issue 11098.

Another workaround could be to remove sticky feature for bigger that
small devices (medium large xlarge xxlarge).
Check foundation/foundation-sites issue 9892.
2020-08-24 19:41:14 +02:00
Senén Rodero Rodríguez
137e0f5a64 Remove description for screen readers
It was being duplicated when restoring a page by using browser
history. With this solution we will avoid to have screen readers
descriptions more than once inside any sociual share button.
2020-08-12 10:07:35 +02:00
Javi Martín
7b96180a76 Upgrade Turbolinks to version 5.2.1
We didn't upgrade Turbolinks when we upgraded to Rails 5 so we didn't
upgrade too many things at the same time, and postponed it... until now
:).

Note upgrading Turbolinks fixes an issue with foundation's sticky when
using the browser's back and forward buttons. We're adding tests for
these scenarios.

Co-authored-by: Senén Rodero Rodríguez <senenrodero@gmail.com>
2020-08-05 14:10:22 +02:00
Javi Martín
983bf49b38 Simplify code related to Foundation's sticky
In the past we had huge problems trying to make it work with Turbolinks.
However, after updating foundation-rails in commit 58071fd6, these hacks
aren't necessary anymore.

We're adding a test for the scenario of visiting a page using
Turbolinks, which was missing, so we're sure we aren't breaking
anything.

Note the sticky will still not work after using the browser back button.
We haven't been able to make it work with turbolinks-classic; we'll fix
this issue when upgrading turbolinks.
2020-08-05 11:34:57 +02:00
decabeza
e3539544a8 Remove google plus share button 2020-07-17 16:24:20 +02:00
Javi Martín
d9eeb1ad15 Improve test checking order by relevance
The test wasn't working when postgres used the English dictionary
because in English the word "what" was ignored (or, at least, not given
enough relevance) while searching. When we wrote the test, it passed
because back then we always used the Spanish dictionary. However, when
we switched to a dictionary based on the default locale (in commit
d99875cd), we had to force this test to keep using the Spanish
dictionary.

Using the Spanish dictionary in a test where all texts are in English is
strange to say the least ;). So here we're making the test a bit easier
to understand.

Since now we're only using the `:spanish_search` tag in one test, I've
decided to remove it and simply add it to that test's setup.
2020-07-14 14:49:39 +02:00
Javi Martín
91da038b27 Extract shared tests to flag/unflag a record 2020-07-07 22:56:17 +02:00
Javi Martín
7563b7f4d1 Simplify polymorphic routes in shared specs
Now we get rid of the "hierarchy" methods and use standard Rails methods
except in the routes definitions themselves.
2020-06-15 11:54:05 +02:00
Javi Martín
9427f01442 Use system specs instead of feature specs
We get rid of database cleaner, and JavaScript tests are faster because
between tests we now rollback transactions instead of truncating the
database.
2020-04-24 15:43:54 +02:00