65 Commits

Author SHA1 Message Date
Sebastia
f4189365ea Merge pull request #5955 from cyrillefr/ReplaceLinkWithButtonInVariousComponentsPartI
Replace link with button in various components part i
2025-07-09 15:26:38 +02:00
cyrillefr
267dd931d8 Replace link with button in change user link 2025-07-09 13:48:58 +02:00
taitus
12c1d77061 Extract management_budget_investment from shared nested documentable spec to system specs
Replaced 'login_as' with 'do_login_for' using 'management: management_section?' to
handle login requirements correctly for each context.

Also removed the now-unused 'documentable_fill_new_valid_budget_investment' helper
from common actions.

Note that it does not seem necessary to create an administrator with the user, as was
done in the original shared example. Also, as in the previous commit, it appears that
we do not need to set the user as the author when creating the documentable.

While reviewing this, we also noticed that the create(:administrator, user: user) call
was unnecessarily included in the nested_imageable system spec in commit cdfaec5217 when
the path is a management section. So we use this commit to remove the unnecessary condition.
2025-06-06 15:56:27 +02:00
Javi Martín
573f0e62cc Use a button to show/hide password in the management area
When using a link, people using screen readers might think they're going
to a new page where the password is going to be shown. With a button,
they get a better idea about what to expect.

Furthermore, with a button, we can use the `aria-pressed` attribute to
indicate whether the password is currently being shown.
2025-04-02 15:58:11 +02:00
Javi Martín
a1bdaf6e8f Add a text to the show password link in management area
We were using an icon for this link, but people who can't see the icon
couldn't know what the link was about. Axe was reporting the following
accessibility error:

```
link-name: Links must have discernible text (serious)
https://dequeuniversity.com/rules/axe/4.10/link-name?application=axeAPI
The following 1 node violate this rule:

  Selector: .show-password
  HTML: <a href="#" class="show-password">
          <span class="icon-eye"></span>
        </a>
  Fix all of the following:
  - Element is in tab order and does not have accessible text
  Fix any of the following:
  - Element does not have text that is visible to screen readers
  - aria-label attribute does not exist or is empty
  - aria-labelledby attribute does not exist, references elements
    that do not exist or references elements that are empty
  - Element has no title attribute
```
2025-04-02 15:57:23 +02:00
Javi Martín
248b826f20 Merge reset password tests together
Since system tests are slow, and these tests were almost identical,
we're merging them into one to make them faster.
2025-04-02 15:57:23 +02:00
Javi Martín
db9b849d82 Use labels to fill in fields in management account tests
This way we're testing that the label is correctly associated with the
field.
2025-04-02 15:57:23 +02:00
Javi Martín
f93c85bd2e Don't check the database during system tests
As mentioned in commits like a586ba806, a7664ad81, 006128da5, b41fbfa52
and c480cdd91, accessing the database after starting the browser with
the `visit` method sometimes results in database corruption and failing
tests on our CI due to the process running the test accessing the
database after the process running the browser has started.

IMHO this is also a bad practice for system tests, since these tests
should be checking what users experience.

So, just like we did a few commits ago with tests that reloaded records,
we're modifying the tests to check the results of user interactions from
the point of view of the users.

Also note we aren't changing tests with the `:no_js` tag, since these
tests don't run a real browser in a separate process. In the future, we
should also change most of these tests so they don't access the database
and they use a real browser.

Finally, note that one of the tests we're changing in the shared
`notifiable_in_app` file did not check the database content, but we're
also changing it for consistency.
2025-04-01 14:53:27 +02:00
Javi Martín
8774488650 Make login through form in tests more readable
We're removing the word "email" from the method name because the method
was accepting either an email or a username, and we're using the name of
the label to fill in fields, which is better because it checks that the
label is correctly associated with the field , as shown for instance in
commit 431ebeda8.
2025-04-01 14:53:26 +02:00
Javi Martín
1b8a079727 Don't reload records in system tests
As mentioned in commits like a586ba806, a7664ad81, 006128da5, b41fbfa52
and c480cdd91, accessing the database after starting the browser with
the `visit` method sometimes results in database corruption and failing
tests on our CI due to the process running the test accessing the
database after the process running the browser has started.

For example, one of these tests has recently failed on our CI:

```
3) Users Create a level 3 user with email from scratch
   Failure/Error: expect(user.reload).to be_confirmed
     expected `#<User id: 2060, email: "pepe@gmail.com", created_at:
     "2025-03-12 19:51:03.688867000 +0100", updated_...d_debates: true,
     recommended_proposals: true, subscriptions_token: nil,
     registering_from_web: false>.confirmed?` to be truthy, got false
```

IMHO this is also a bad practice for system tests, since these tests
should be checking what users experience.

So we're modifying the tests to check the results of users interaction
from the point of view of the users. For example, instead of checking
that a user is now level 3 verified in the database, we're checking that
the user interface states that the user is level 3 verified.

Note we're adding an offset when editing the map marker by clicking on
`map-location` with `.click(x: 30, y: 30)`. This way we make sure that
both the latitude and longitude change from the original values; we used
to clicking in the middle (no offset), which didn't change the longitude
and changed the latitude just by coincidence.

Also note we aren't changing tests with the `:no_js` tag, since these
tests don't run a real browser in a separate process. In the future, we
should also change most of these tests so they don't access the database
and they use a real browser.
2025-04-01 14:53:26 +02:00
Javi Martín
e70732a47f Don't create records after starting the browser in user test
I accidentally made this mistake while trying to avoid the exact same
issue back in commit 73992b2c8. Accessing the database in a test after
starting the process running the browser has caused database corruption
in our CI multiple times.
2025-03-26 16:42:04 +01:00
Javi Martín
f63be041c1 Add missing expectations to confirm the page has changed
After a `visit`, we were checking for content or filling in fields that
were already there before the `visit`, so we weren't 100% sure that the
request had finished before the test continued.

In the case of the verification tests, we were clicking the submit
buttons over and over without and then checking or interacting with
elements that were already there. Even though the button was disabled
between requests, meaning there wouldn't be simultaneous requests, it
was possible to interact with a form field before waiting for the
request to finish.

Some of these tests have recently failed on our CI, and it might be
because of that:

```
1) Admin budgets Edit Changing name for current locale will update the
   slug if budget is in draft phase
   Failure/Error: raise ex, cause: cause

   Selenium::WebDriver::Error::UnknownError:
     unknown error: unhandled inspector error: {"code":-32000,
     "message":"Node with given id does not belong to the document"}
       (Session info: chrome=134.0.6998.35)

1) Budgets creation wizard Creation of a multiple-headings budget by
   steps
   Failure/Error: expect(page).to have_content "Heading created
   successfully!"

   Selenium::WebDriver::Error::UnknownError:
     unknown error: unhandled inspector error: {"code":-32000,
     "message":"Node with given id does not belong to the document"}
       (Session info: chrome=134.0.6998.35)

1) Custom information texts Show custom texts instead of default ones
   Failure/Error: raise ex, cause: cause

   Selenium::WebDriver::Error::UnknownError:
     unknown error: unhandled inspector error: {"code":-32000,
     "message":"Node with given id does not belong to the document"}
       (Session info: chrome=134.0.6998.35)

1) Users Regular authentication Sign in Avoid username-email collisions
   Failure/Error: raise ex, cause: cause

   Selenium::WebDriver::Error::UnknownError:
     unknown error: unhandled inspector error: {"code":-32000,
     "message":"Node with given id does not belong to the document"}
       (Session info: chrome=134.0.6998.35)

2) Verify Letter Code verification 6 tries allowed
   Failure/Error: raise ex, cause: cause

   Selenium::WebDriver::Error::UnknownError:
     unknown error: unhandled inspector error: {"code":-32000,
     "message":"Node with given id does not belong to the document"}
       (Session info: chrome=134.0.6998.35)

2) Valuation budget investments Valuate Finish valuation
   Failure/Error: raise ex, cause: cause

   Selenium::WebDriver::Error::UnknownError:
     unknown error: unhandled inspector error: {"code":-32000,
     "message":"Node with given id does not belong to the document"}
       (Session info: chrome=134.0.6998.35)

1) Users Delete a level 2 user account from document verification page
   Failure/Error: raise ex, cause: cause

   Selenium::WebDriver::Error::UnknownError:
     unknown error: unhandled inspector error: {"code":-32000,
     "message":"Node with given id does not belong to the document"}
       (Session info: chrome=134.0.6998.35)
```
2025-03-26 16:27:08 +01:00
Javi Martín
533d2198ee Use refresh instead of visiting the current page
This way it's more obvious what's going on.

Note that, in this case, the expectations were **not** true before
visiting the page, so we aren't fixing a flaky test.
2025-03-26 16:27:08 +01:00
taitus
cdfaec5217 Extract management budget investment from shared nested imageable specs to system specs 2024-11-26 17:58:10 +01:00
taitus
9d7fa9d0f8 Unify notice responders for budget investments create action 2024-11-26 17:58:10 +01:00
Javi Martín
3b7948a139 Use a date field to select the date of birth
The default `date_select` used in fields presents an accessibility
issue, because in generates three select controls but only one label.
That means that there are two controls without a label.

So we're using a date field instead. This type is field is supported by
about 99% of the browsers, and we've already got JavaScript code
converting this field to a jQuery UI datepicker in case the browser
doesn't support date fields.

Note that, since we no longer need to parse the three date fields into
one, we can simplify the code in both the models and the tests.

Another slight improvement is that, previously, we couldn't restrict the
month and day controls in order to set the minimum date, so the maximum
selectable date was always the 31st of December of the year set by the
minimum age setting. As seen in the component test, now that we use only
one field, we can set a specific date as the maximum one.
2024-11-12 15:15:34 +01:00
Javi Martín
1cefc040a7 Add labels to the search form in the management area
The text for the unfeasible checkbox wasn't correctly defined as a
label, while the fields to search investments and select the heading
weren't intuitive since their purpose wasn't obvious.
2024-11-11 15:04:35 +01:00
Javi Martín
58cba2316a Use a button to erase an account in the management area
As mentioned in commit 5311daadf, there are several reasons to use
buttons in these situations. And, as mentioned in the previous commit,
using buttons instead of links for actions requiring confirmation will
help us test for accessibility issues.
2024-11-07 15:18:37 +01:00
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
f52a86b465 Apply (but don't add) Capybara/SpecificMatcher rule
This rule was added in rubocop-rspec 2.12.0, and we were already
following it most of the time.

However, the rule isn't working correctly in some cases, such as input
selectors, so we aren't enabling it.
2023-09-06 19:00:56 +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
03fa5fc8d6 Simplify long test titles 2023-08-30 14:46:35 +02:00
Javi Martín
5b6de96241 Add and apply MultilineMethodCallIndentation rule 2023-08-18 14:56:16 +02:00
Javi Martín
09c63e354c Add and apply Layout/DotPosition rule
Since IRB has improved its support for multiline, the main argument
towars using a trailing dot no longer affects most people.

It still affects me, though, since I use Pry :), but I agree
leading dots are more readable, so I'm enabling the rule anyway.
2023-08-18 14:56:16 +02:00
Javi Martín
7dfbf772e2 Use the new name in default settings 2023-07-12 16:05:33 +02:00
Senén Rodero
e147408ebd Merge pull request #5064 from consul/managment_print_budgets
Allow printing investments from any budget in the management interface
2023-02-03 15:46:27 +01:00
Senén Rodero Rodríguez
96f584c4f7 Allow printing investments from any budget in the management interface 2023-02-03 12:18:13 +01: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
cd3b196a04 Make it clear what verified users can vote for
"Participate in the final voting" was a concept which was hard to
understand since many people would think it was related to the
voting/polls section and that somehow there was going to be a "final"
poll.

So we use "Vote for budget projects" instead.

Thanks Pomerange for the suggestion.
2022-06-01 14:27:33 +02:00
Javi Martín
92b1e53fc3 Unify user permission texts
We had the same texts four times, with slight variations in the case of
the management section.

We're unifying them under the "verification" i18n namespace, since the
texts are about actions which can be done depending on whether users are
verified or not.

Note the names of the i18n keys aren't very consistent, since we use
"debates" in plural but "proposal" in singular. We're leaving it like
this so existing translations aren't affected.
2022-06-01 14:27:33 +02:00
Javi Martín
88004a5e8a Replace support proposal link with a button
As mentioned in commits 5311daadf and bb958daf0, using links combined
with JavaScript to generate POST requests to the server has a few
issues.
2022-02-21 18:47:37 +01:00
decabeza
9979b53994 Add setting to allow remove investments supports 2021-11-08 01:37:41 +01: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
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
ff0f2215ea Extract component for locale switcher
Note that in order to simplify the component tests (which for some
reason seem to be whitespace-sensitive), we have to omit whitespace
characters inside the `<option>` tags.

Also note we're simplifying the test with a missing language name; since
a component test doesn't involve a whole request, we don't need a
complex setup (I'm not sure we even need it in system tests).
2021-07-05 22:27:39 +02:00
Javi Martín
93c521bd29 Use labels in language selector tests
This way the test verifies there's a label associated to that form
field.
2021-07-05 22:27:39 +02:00
Javi Martín
14d8bef0d8 Use order links in print proposals management
A `<select>` tag here might make more sense than in other similar places
since there are 5 options to choose among, and using links might take
too much screen space.

However, as mentioned in the previous commits, `<select>` tags which
automatically submit a form have many accessibility and usability
issues.

An alternative would be to create a dropdown menu with a button and a
list of links (similar to what Foundation does). I'm keeping the links
for simplicity and because the interface looks a bit more consistent
with the rest of the sections. Before these changes, we had a heading,
then a `<select>` field to choose the filter, and then a button to print
the page. We never use a similar interface, and some people might think
the "Print" button is related to the same form as the `<select>` field.

Now that we don't use the `order_selector` partial anywhere anymore, we
can remove it.
2021-06-28 00:15:08 +02:00
decabeza
a851048d56 Allow users to remove their support on investments
Note we don't cast negative votes when users remove their support. That
way we provide compatibility for institutions who have implemented real
negative votes (in case there are / will be any), and we also keep the
database meaningful: it's not that users downvoted something; they
simply removed their upvote.

Co-Authored-By: Javi Martín <javim@elretirao.net>
Co-Authored-By: Julian Nicolas Herrero <microweb10@gmail.com>
2021-06-14 14:46:54 +02:00
Javi Martín
071da81be6 Add notice when supporting an investment
It was hard to notice what was going on when supporting one investment
which was at the bottom of the investment index page.

I wonder whether we should add the title of the investment to this text;
I'm not doing so because we don't do that anywhere else.
2021-06-14 14:42:03 +02:00
Javi Martín
bb958daf05 Replace support investment link with a button
Using links combined with JavaScript to generate POST requests to the
browser has a few issues.

An obvious one is that it doesn't work for users without JavaScript
enabled (which lately I've noticed are more common than I thought, even
though I've been one of them for years). These users will reach a 404
page.

Since CONSUL isn't currently designed to work without JavaScript
enabled, let's ignore this one for now.

A not so obvious issue is screen reader users might expect the link to
take them somewhere instead of performing an action (in this case,
sending a form to the server).

There might be more issues I'm unaware of. Quoting DHH [1]:

"Turning ahrefs into POSTs is a bit of an anti-pattern, especially for
a11y reasons. Better to use button_to with a styling."

So we're using a button instead. This way we can also simplify the code
and make the button disabled for unidentified users, which automatically
makes it impossible to focus it using the keyboard.

A possible disadvantage of using `button_to` is it will create a form
tag which will be announced to screen readers as a form landmark. I've
tested it with my screen reader and everything worked fine for me, but
some screen reader users might interact with these forms in a different
way and find it confusing, particularly in the case where the button is
disabled.

With this change, we're only changing links for buttons in one place.
There are other places where we should do similar changes.

[1] See issue 33 in https://github.com/hotwired/turbo-rails/
2021-06-14 12:51:41 +02:00
Javi Martín
e4ad70fd82 Revert "Adds .js-class for specs"
The `js-` prefix (which I admit I'm not fond of) is usually used to
indicate the class is used by JavaScript files, not for using it in test
files. And in all the other similar tests, we're using the `in-favor`
class instead of the `js-in-favor` class.

This reverts commit 83fe74d53.
2021-06-14 12:51:41 +02:00
Javi Martín
d983443ecc Fix investment support in management section
When supporting an investment in the management section through the
investment view, we were accessing an action in the public investments
controller. This meant the manager was the one supporting the investment
(as they'd be the `current_user` in this controller) and not the managed
user.

In the case of groups with many headings, voting the first time requires
a confirmation and then a regular (non-AJAX) request takes place. In
this case, users were redirected to the public area instead of remaining
in the management area.

Using the proper URL to vote solves the problem.

Note there was a comment about one of these tests failing in Travis.
Most probably the test failed because there was no expectation after
clicking the link with the investment title, so the "Support" button
(which is also present in the index page) was clicked before the
investment view was loaded.
2021-06-14 12:37:40 +02:00
decabeza
88ad711330 Hide group name only on budgets with one group
In the form of creating a new investment was hiding the name of the
group if it had only one heading, but could be confusing to users if
there are, for example, five different groups of one heading.

The solution:

- If the budget has one group and one heading, the heading selector is
  hidden.
- If the budget has one group and more than one heading, the group name
  is hidden.
- If the budget has more than one group, the group name appears
  regardless of the number of headings.
2021-06-11 14:43:18 +02:00
decabeza
0488b3735f Hide single heading select on new budget investment form 2021-06-11 12:37:56 +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
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
73992b2c82 Test erased reason from the user's point of view
What users care about isn't the database; they care about that reason
being displayed when administrators check the reason.

This way we also avoid accessing the database after the process running
the browser has been started.
2021-04-16 14:25:34 +02:00
Javi Martín
c8df5e3af2 Remove redundant delete account test
This scenario is already tested in the management users spec: ""Delete a
level 2 user account from document verification page".
2021-04-16 14:25:34 +02:00