Commit Graph

6089 Commits

Author SHA1 Message Date
cyrillefr
31ceb31256 Replace link with button in Dashboard show 2025-07-03 11:14:53 +02:00
cyrillefr
c7827136cd Replace link with button in mailing options 2025-04-10 15:54:46 +02:00
cyrillefr
30979b2e96 Replace link with button in author_actions
- modified corresponding spec
2025-04-10 12:41:02 +02:00
cyrillefr
c6f0a3761b Replace link with button in login items component
- modified related specs
- modified scss to keep new button same style as previous link
2025-04-10 12:41:02 +02:00
cyrillefr
bc912b53da Replace link with button in OmniAuth form component
- and modified spec
2025-04-10 12:40:34 +02:00
Javi Martín
c6f1974c45 Use labels in nested option fields
We were using a placeholder, which is way less accessible than a label.

One issue here (which also happened before, but is now more obvious) is
that, when adding several options, there will be many fields with the
same label.

Another issue is that, for some languages, we're using texts like "Add a
closed answer", which might be confusing because we might be editing an
existing answer. The proper solution would probably be using the text
"Option 1", "Option 2", ... I'm not doing so right now because I'm not
sure that's a good option and because changing the text would mean
losing the existing translations.
2025-04-03 15:01:01 +02:00
Javi Martín
9308189a00 Use number fields to enter number of votes
This way the fields are easier to use, and we can get rid of the
placeholders.

Note we're simplifying the `answer_result_value` in order to make it
easier to return `0` instead of `nil` when the field is empty.

Also note there's a small change of behavior here; previously, these
fields were empty by default, and now their value is `0` by default, so
blindly clicking the "Save" button would send `0` instead of an empty
value. I don't think it's a big deal, though, but we need to keep that
in mind.
2025-04-03 15:01:01 +02:00
Javi Martín
ff3ada780d Use fieldsets and legends in officing results form
We were using <h3> tags instead of a combination of <fieldset> and
<legend> tags to group fields together.
2025-04-03 15:01:01 +02:00
Javi Martín
31f413de61 Use labels in officing results form
Back when we added all the missing labels (changes that we merged in
commit c34cab282), we forgot about fields which had placeholdes, since
Axe doesn't report an error when there are placeholders but there aren't
labels.

In this case, we were using an invalid <label> tag for the question
options, and <h3> tags as labels for the votes.

Using standard labels solves the issue.
2025-04-03 15:00:46 +02:00
Javi Martín
4b3f58cf4c Don't create content after a visit in notifications test
We forgot to apply this change in commit f5f96ba86.

Note that, in this case, executing `proposal_notification.author.email`
in the middle of a test would also result in a database query. For some
reason (probably the same reason why the code that explicitly created
the author was added in this test but not in other moderation tests),
that doesn't seem to happen in other moderation tests, so for now we
aren't changing those ones.
2025-04-02 21:03:38 +02:00
Javi Martín
42bfd2fce2 Add missing expectations in hidden content tests
We were checking that we still were on the same page, which was true
even before finishing the request to restore the content.
2025-04-02 17:31:54 +02:00
Javi Martín
b08c279c31 Make links to annotation comments accessible
The link to the comments page was an "expand" icon, which was confusing
because it wasn't really expanding the contents of the sidebar but going
to an entirely different page. Furthermore, it didn't have any text for
people using screen readers, which is why 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: #annotation-link > a
  HTML: <a href="/legislation/processes/75/draft_versions/30/annotations/8?sub_annotation_ids=">
          <span class="icon-expand" aria-hidden="true"></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
```

So we're removing the icon and turning the "N comments" text into a
link, so it's easier to guess that the link takes us to the page showing
all the comments for this annotation.
2025-04-02 16:03:07 +02:00
Javi Martín
2f667a6225 Add missing expectation to annotations test
This expectations in this test were true both before and after clicking
on the `.icon-expand` link, so it was possible that the test finished
before the request generated by that click did.

So we're adding an extra expectation to make sure we're testing what we
want to test: the content of the page after the request has finished.
2025-04-02 16:03:07 +02:00
Javi Martín
da53a6acae Validate result publication enabled processes have a date
Just like we do with the rest of the phases.

The reason why we're making this change right now is that we were
getting an accessibility error with processes with no result publication
date:

```
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: p:nth-child(6) > a
  HTML: <a href="/legislation/processes/39/result_publication">
          <strong></strong>
        </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 16:03:07 +02:00
Javi Martín
6c3e7391d4 Use buttons to execute/unexecute dashboard actions
As mentioned in commit 5311daadf, using buttons for non-GET requests has
several advantages over using links.
2025-04-02 16:03:07 +02:00
Javi Martín
4e08f3f147 Add a text to the links to execute dashboard actions
People using screen readers had no idea what these links were about (not
that the icons are very usable for people seeing them either... but
that's a different topic). Axe was reporting this 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: #dashboard_action_2_execute
  HTML: <a id="dashboard_action_2_execute" class="unchecked-link"
           rel="nofollow" data-method="post"
           href="/proposals/16-proposal-6-title/dashboard/actions/2/execute">
          <span class="unchecked"></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 16:02:55 +02:00
Javi Martín
942ccf6674 Group similar dashboard progress tests together
All these tests were basically checking the same things. Since system
tests are slow, we're grouping them together so executing them is
slightly faster.
2025-04-02 15:58:23 +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
75ef3e0a51 Avoid empty links in banners without content
This happened when previewing banners in the "new banner form", which
might cause accessibility issues when people access the list of links on
the page.

We were getting the following accessibility error:

```
link-name: Links must have discernible text (serious)
https://dequeuniversity.com/rules/axe/4.9/link-name?application=axeAPI

The following node violate this rule:

  Selector: a[href$="new"]
  HTML: <a href="/admin/banners/new"><h2></h2><h3></h3></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
  - Element has no title attribute
```
2025-04-02 15:57:23 +02:00
Javi Martín
45c74681c4 Add ARIA labels to progressbars
People using screen readers might have a hard time knowing what a
progressbar is about unless we provide a label for it. Axe was reporting
failures like:

```
aria-progressbar-name: ARIA progressbar nodes must have an accessible
name (serious)
https://dequeuniversity.com/rules/axe/4.10/aria-progressbar-name?application=axeAPI
The following 1 node violate this rule:

  Selector: .progress
  HTML: <div class="progress" role="progressbar" tabindex="0"
             aria-valuenow="0.0" aria-valuemin="0" aria-valuemax="100">
          <div class="progress-meter" style="width: 0.0%"></div>
        </div>
  Fix any of the following:
  - 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
```

Note that, in the case of the ballot progressbar, it's easier to use
`aria-labelledby`, while in other place it's easier to use `aria-label`,
so we using the easier solution in each scenario.
2025-04-02 15:00:06 +02:00
Javi Martín
48593a19ea Remove redundant test to vote an investment
This is already tested in the "Add an investment" test.
2025-04-02 14:58:48 +02:00
Javi Martín
ee03712df0 Move milestones progress bars partial to a component 2025-04-02 14:44:01 +02:00
Javi Martín
932d4cd698 Fix wrong ARIA attribute in dashboard actions form
Using a `data-toggle` attribute, which we do since commit 07fd5084f,
made Foundation generate an `aria-expanded` attribute to a radio button,
but this attribute can't be present in radio buttons. This makes sense,
since the main purpose of a radio button in a form is to choose an
option, not to show/hide content.

This resulted in the following error when checking the page with Axe:

```
Found 1 accessibility violation:

aria-allowed-attr: Elements must only use supported ARIA attributes
(critical)
https://dequeuniversity.com/rules/axe/4.10/aria-allowed-attr?application=axeAPI
The following 2 nodes violate this rule:

  Selector: #dashboard_action_action_type_proposed_action
  HTML: <input data-toggle="request_to_administrators short_description"
               type="radio" value="proposed_action" checked="checked"
               name="dashboard_action[action_type]"
               id="dashboard_action_action_type_proposed_action"
               aria-expanded="true"
               aria-controls="request_to_administrators">
  Fix all of the following:
    - ARIA attribute is not allowed: aria-expanded="true"

  Selector: #dashboard_action_action_type_resource
  HTML: <input data-toggle="request_to_administrators short_description"
               type="radio" value="resource"
               name="dashboard_action[action_type]"
               id="dashboard_action_action_type_resource"
               aria-expanded="true"
               aria-controls="request_to_administrators">
  Fix all of the following:
    - ARIA attribute is not allowed: aria-expanded="true"
```

So we're using custom JavaScript instead. We're also making the
`short_description` field act as intended; since the changes in commit
07fd5084f it was never shown because it had the `hide` HTML class and it
didn't have a `data-toggler` attribute.
2025-04-02 13:43:29 +02:00
Javi Martín
f3fcee430e Use labels to find fields in dashboard actions tests
In the tests for the edit/update action, we were using field names, but
using labels is a better approach because it tests that the label is
correctly associated with the field.

We aren't changing the tests for the new/create action because we were
already using labels there.
2025-04-02 13:40:45 +02:00
Javi Martín
5b5571bb54 Create records before a visit in dashboard actions tests
This way we avoid possible database corruption in our CI, which has
happened in the past when the process running the test accesses the
database after the process running the browser has started.
2025-04-02 13:40:45 +02:00
Javi Martín
3484c6b7b8 Use a list of links to change group in budgets wizard
The original implementation (which was never merged) had a `<select>`
field for the switch, which offered accessibility issues. So I came up
with a very bad idea, which was emulating the look and feel of a select
field while making it more accessible for keyboard users.

This approach is inconvenient because we were using a bunch of ARIA
roles to do the same thing that can be done with a list of links, going
against the first rule of ARIA, which is:

> "Don’t use ARIA if you can achieve the same semantics with a native
> HTML element or attribute

Not only that, but the control was confusing for people using mobile
phones (select fields don't behave the same way), and we were using
*invalid* ARIA roles in this situation, leading Axe to report a critical
accessibility error:

```
aria-required-children: Certain ARIA roles must contain particular
children (critical)
https://dequeuniversity.com/rules/axe/4.10/aria-required-children?application=axeAPI
The following 1 node violate this rule:

  Selector: ul[data-dropdown-menu="edw1i2-dropdown-menu"]
  HTML: <ul class="dropdown menu" wnenu="edw1i2-dropdown-menu"
            data-disable-hover="true" op="true" role="menubar">
  Fix any of the following:
  - Element has children which are not allowed: button[tabindex]
```

So, at least for now, we're using a simple list of links. We might style
it in the future if we find ways to make usability improvements, but,
for now, it does the job, and it does it better than the custom control
we were using.
2025-04-02 13:40:04 +02:00
Javi Martín
90ae03795d Send an empty CSV file for invalid user segments
We were getting an exception in this case, which was OK I guess since
this shouldn't happen if the application is used in a normal way, but we
can simplify the code a little bit if we make the `recipients` code
return an empty list of users.

Note that the behavior of the `AdminNotification#list_of_recipients` and
`Newsletter#list_of_recipient_emails` methods is now slightly different;
previously they returned `nil` when given an invalid segment recipient,
while now they return an empty array. I haven't found a place where this
change is relevant. For example, in both of these models, the `deliver`
method used to raise an exception when given an invalid segment while
now it doesn't, but we always check the user segment is valid before
calling the `deliver` method anyway, so it doesn't really affect the
application.
2025-04-02 13:21:45 +02:00
Javi Martín
41ca271fcf Add a controller test for the generate_csv action
While we've already got a system test for the same purpose, we're going
to add another controller test for this action, so we're now writing a
test for the "happy path" scenario.
2025-04-01 16:13:17 +02:00
Javi Martín
ad995f5a7c Check for valid segments before returning recipients
We were getting a warning by CodeQL regarding a possible code injection
in the `send(segment)` code.

In practice, this wasn't a big deal because the `self.recipients` method
is only called in the admin section, meaning only admin users could try
to take advantage of the code injection, and because this code is rarely
called with an invalid segment due to several conditions in the code
checking that the user segment is valid, with the only exception being
the `generate_csv` action in the `Admin::EmailsDownloadController`.

In any case, now we're checking that the segment is valid before calling
the `send` method. Since now we're making sure that the segment is valid
in the `recipients` method itself, we can remove this check from methods
calling it.
2025-04-01 16:13:17 +02:00
Javi Martín
985d3da032 Move officing menu partial to a component
This way we can move some system tests to component tests and stop
creating records after starting the browser with a `visit`.

We could also split the system test in two, but since these tests
aren't checking any user interactions, moving the to component tests we
check the same things while making the tests faster.

Since the partial was using an instance variable, we're passing it to
the component. We're naming it `voter_user` instead of `user` because
passing something named `user` could make us think that we're passing
the `current_user`. I wasn't sure about naming it `voter` because it's a
`User` record and not a `Poll::Voter` record, but naming it `voter`
would definitely be an option.
2025-04-01 15:08:55 +02:00
Javi Martín
4c4aa210a1 Remove redundant whitespace in consecutive let blocks 2025-04-01 14:53:27 +02:00
Javi Martín
420ae41153 Avoid calls to let after starting the browser
In some places, we were accidentally creating records after the browser
started because we weren't executing a `let` block before starting the
browser with a `visit`, but were executing the `let` block after that.
2025-04-01 14:53:27 +02:00
Javi Martín
f5f96ba86e Don't create records during a system test
In the officing tests, we were accessing `admin.user` after starting the
browser with a `visit`. However, since `admin` is a method with a `let`
block, the administrator isn't created in the database until we
referenced the variable, meaning we were creating the database record in
the middle of the test. Referencing the variable at the beginning of the
test solves the issue.

We were also creating records to call the `login_as` method in the users
tests, so we're moving the code to create them before the first call to
`visit`.

In the notifiable test, we were doing a loop consisting of "create()" ->
"visit" -> "create()" -> "visit!" -> (...), meaning we were creating the
second user after the first `visit`. Creating every user before the
first `visit` solves the issue.
2025-04-01 14:53:27 +02:00
Javi Martín
9a7681b75f Don't hide records during a system test
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.

In this case, we were hiding a proposal after starting the process
running the browser to check what happens when accessing a notification
for a hidden proposal. We can avoid database access in the middle of the
test by hidding a proposal before starting the browser. The process to
create a notification using the browser is already tested in other
specs, so we don't need to do it here as well.

Note that, to simplify the test, we're extracting the `notify_users`
method. I wonder whether this method should be called in an
`after_create` callback instead... That's a topic for another time,
though.
2025-04-01 14:53:27 +02:00
Javi Martín
92fc45cbb4 Don't destroy records during a system test
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.

In this case, however, I haven't found a way to destroy the VerifiedUser
record using the interface, so we're stubbing `VerifiedUser` instead.
Note we can't stub it since the beginning of the test because we're
testing what happens when clicking the "Send code" button doesn't work,
and we wouldn't be able to access the page containing the "Send code" if
we stubbed `VerifiedUser` since the beginning of the test.
2025-04-01 14:53:27 +02:00
Javi Martín
a6d470ded6 Setup the database before a visit in investments test
This way we avoid possible issues that might be caused by calling the
`update!` method after the browser had already started.
2025-04-01 14:53:27 +02:00
Javi Martín
2fbba71ffc Don't loop over budget phases in system tests
We've already got model tests for that, and we were modifying the
database after a `visit`, since we were doing a loop consisting of
"update!" -> "visit" -> "update!" -> "visit!" -> (...).

Besides, note that the `.kind_or_later("publishing_prices").each` block
wasn't modifying the budget, so it always visited the page under the
same conditions.

So we're simply randomly checking one phase to test that the user
interface works as expected.
2025-04-01 14:53:27 +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
be4cf23a5c Don't check the database for voters 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.

In these cases, there's no need to check the database; we're already
checking the application behavior that shows that the voters have been
correctly created.
2025-04-01 14:53:27 +02:00
Javi Martín
2575fb316b Simplify test checking multiple officing sessions
We can reuse the `officing_verify_residence` method to make the test
easier to read.

We're also removing the final visit to final_officing_polls_path because
it doesn't really add anything to the test.
2025-04-01 14:53:27 +02:00
Javi Martín
7b6d6266e5 Remove redundant expectations in officing test
We were checking that a field exists before interacting with it.
However, the methods that interact with fields already check whether the
field exists, so there's no need for us to check that.
2025-04-01 14:53:27 +02:00
Javi Martín
8e1c6f6db5 Re-use methods to login through the form in tests
We were calling these methods in some places, so, for consistency, we're
now calling them when possible.
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
fa9ab61f72 Simplify login through form as user in tests
The logic was almost the same as the method to login with an email and a
password.
2025-04-01 14:53:26 +02:00
Javi Martín
55a5cef783 Simplify login through form as officer in tests
We were always passing `officer.user` to this method, so we might as
well pass the officer (since the "officer" is in the name of the method)
and call `officer.user` inside the method.

We're also calling `login_through_form_as` in order to remove the
duplication between these two methods.
2025-04-01 14:53:26 +02:00
Javi Martín
f15991dd3e Simplify tests replying to a comment
We were using the `reply_to` method in some places, but not in others.
2025-04-01 14:53:26 +02:00
Javi Martín
1c2ec3f37e Don't access the database in comment replies 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.

In this case, we're avoiding the usage of `user.subscriptions_token` and
`Comment.last`. In the future, we should probably simplify these tests
by moving most of the checks to a mailer test.
2025-04-01 14:53:26 +02:00