Commit Graph

6213 Commits

Author SHA1 Message Date
taitus
b7025a8135 Remove "outdated" comment
Since commit 23682fadd8, we have had the comment:
> # Review
> # Doble check why the file is stored with a name different to empty.pdf

This might be outdated.
2025-06-06 17:18:15 +02:00
taitus
afdf65dec9 Remove unnecessary tests and expectations related with loading-bar
These expectations are already covered by attach_new_file, so they are no longer needed:
>  expect(page).to have_css ".loading-bar.complete"

We can remove the tests:
> "Should update loading bar style after invalid file upload"
because the expectation:
> expect(page).to have_css ".loading-bar.errors"
It is already tested in "Should not update document cached_attachment field after invalid file upload"
2025-06-06 17:18:15 +02:00
taitus
88ba548343 Unify fill_in field in one line 2025-06-06 17:18:15 +02:00
taitus
e6089c2b63 Remove expect_document_has_title method
I think tests are now clearer by using have_field.

Note that I have remove the within ".document-fields" because there is
only one document.
2025-06-06 17:18:15 +02:00
taitus
d7581955f8 Remove duplicated code in imageable and documentable attach file methods 2025-06-06 17:18:15 +02:00
taitus
82296a33e2 Use documentable_attach_new_file method where possible
Use this commit to unify two similar specs.
2025-06-06 17:18:15 +02:00
taitus
64c1c59a7a Unify tests related with shows or hides max documents warning 2025-06-06 17:18:15 +02:00
taitus
a4e7b70227 Unify tests related with shows or hides new document link 2025-06-06 17:18:15 +02:00
taitus
82dac1225c Simplify tests by setting "max documents allowed" to 1
Note that this commit also applies a similar change to the
imageable_attach_new_file method by removing an unnecessary variable.

In order to testing with more than 1 max documents allowed we
keep one test with this value.
2025-06-06 17:18:15 +02:00
taitus
addda0c773 Unify duplicated methods in common_actions folder
Replaced the user with a level_two one in the "Default whole city" test to
bypass the full name requirement, which only applies to unverified users.
2025-06-06 17:07:50 +02:00
taitus
2cc23309b8 Unify attachables methods 2025-06-06 16:00:16 +02:00
taitus
e7c5b03d8c Extract edit proposals from shared nested documentable to system specs
We can remove shared nested documentable file because has not references.
2025-06-06 16:00:15 +02:00
taitus
979171ec45 Extract proposals from shared nested documentable to system specs
Removed the now-unused 'documentable_fill_new_valid_proposal' method
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.

Also removed the documentable_redirected_to_resource_show_or_navigate_to method,
which was only used for the :proposal factory but was not necessary.
- In the "Proposal new" case (this commit), after submitting the form we are
redirected to the "created" page, where the link "Not now, go to my proposal"
does not appear. This caused the method to always raise a
Capybara::ElementNotFound and return nil.

Instead, this "created" page already displays a preview of the proposal
and a link to publish it. Since we can verify that the proposal was created
successfully here, no redirection or click is needed.

- In the "Proposal edit" case (next commit), the user is redirected directly
to the proposal's "show" page after update, so again, the method is
unnecessary and has been removed.
2025-06-06 15:56:27 +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
taitus
b7adf760f6 Extract budget_investment from shared nested documentable spec to system specs
Make 'path', 'submit_button_text' and 'notice_text' dynamic based on
the factory.

Also adjusted the user. Budget investments require a level 2 user but do not need to be
an administrator.

Copied and renamed the 'documentable_fill_new_valid_budget_investment' method from
common actions, and introduced a 'fill_in_required_fields' method to manage multiple factories.

Added the two tests that were conditionally skipped in the shared example using
'unless: documentable_factory_name == "dashboard_action"', but omitted the call to
'documentable_redirected_to_resource_show_or_navigate_to', since it only applies to
proposals.

Note that when we create the documentable seems do not need use the user as author.
2025-06-06 15:56:25 +02:00
taitus
4d8a337e8a Extract dashboard_action from shared nested documentable spec to system specs
Removed 'documentable_path_arguments' and 'management'
parameters because they are not used by dashboard_action.

Also moved and renamed the 'documentable_fill_new_valid_dashboard_action' method
from the common actions helper to this file, since it is now only used here.

Hardcoded 'path', 'submit_button_text', and 'notice_text' for dashboard_action.
These remain fixed for now until dynamic values are required in future commits.
2025-06-06 15:48:46 +02:00
Javi Martín
cbf11c2514 Use Rails::HTML5::Sanitizer when sanitizing HTML
Since we use a version of Loofah supporting HTML5 since db2d0bb80, the
`Rails::HTML::Sanitizer.best_supported_vendor` method will return the
HTML5 sanitizer. As mentioned in the pull request introducting this
change [1], the libxml2 maintainer wrote:

> it's still a bad idea to use a 20+ years old, unmaintained HTML 4
> parser to sanitize input for the modern web

So we're going with the new default sanitizer.

Note we aren't uncommenting the `action_text.sanitizer_vendor` option
because we don't use Action Text and so it doesn't affect us , and
uncommeting it will raise an error.

Also note we need to change one test because the new sanitizer handles
whitespace slightly differently.

[1] Pull request 48293 in https://github.com/rails/rails
2025-05-20 15:38:52 +02:00
Javi Martín
0dec47c055 Use just the banner title as the banner link text
We were using an <a> tag wrapping the whole content of the banner in
order to make the whole banner clickable. However, that made the text of
the link less concise, affecting people using screen readers. So,
instead, we're using the `card` mixin, which we introduced in commit
f285dfcba.

We're making this change now because the HTML5 Sanitizer that we're
about to enable in the next commit was handling the whitespace inside
the banner differently, causing one test to fail, and we didn't find a
different way to fix it.
2025-05-20 15:38:52 +02:00
Javi Martín
8dcf66886e Fix broken tags in JavaScript injection tests
This was introduced in commit 5ecbe01d4, probably by accident while
copying a suggestion made in the pull request for that change [1]. This
broken tag introduces issues when sanitizing the HTML text with an HTML5
sanitizer, which we will start using in a couple of commits.

[1] https://github.com/consuldemocracy/consuldemocracy/pull/462#issuecomment-139309289
2025-05-20 15:38:52 +02:00
Javi Martín
321409ab0a Use fixture_paths instead of fixture_path
We were getting a warning since we upgraded to Rails 7.1:

> Rails 7.1 has deprecated the singular fixture_path in favour of an
> array.You should migrate to plural:
2025-05-20 15:38:51 +02:00
Javi Martín
24a77c6437 Remove references to ActionDispatch::IllegalStateError
We were getting a warning after upgrading to Rails 7.1:

```
DEPRECATION WARNING: ActionDispatch::IllegalStateError is deprecated
without replacement.
```
2025-05-20 15:38:51 +02:00
Javi Martín
f5221536a9 Update show_exceptions options in system tests
We were getting a deprecation warning after upgrading to Rails 7.1:

```
DEPRECATION WARNING: Setting action_dispatch.show_exceptions to true is
deprecated. Set to :all instead.
```

So we're passing `:all`.

I've checked whether we can remove the `:show_exceptions` tag completely
now that the new default option is `:rescuable`. The answer is "no" ;).
Removing the `:show_exceptions` tag makes the tests fail.
2025-05-20 15:38:51 +02:00
Javi Martín
0b1cfcd5da Upgrade to Rails 7.1
We're disabling `action_controller.raise_on_missing_callback_actions`
because sometimes we include `before_action :something, only: actions`
in concerns, and we include these concerns in controllers that don't
have all these actions.

Note that Rails 7.1 logs to STDOUT by default [1]; we're re-adding the
condition `if ENV["RAILS_LOG_TO_STDOUT"].present?` because we're still
using files and we're rotating the logs to avoid running out of space.

Also note that the GraphQL controller test (which is actually a request
test, since it's got `type: :request`) that was raising an exception no
longer does it thanks to the new default value for the
`config.action_dispatch.show_exceptions` configuration option. So we're
updating the test accordingly. This option doesn't affect regular
controller tests (without the `type: :request` option), so in other
tests we're still checking exceptions.

[1] Pull request 47138 in https://github.com/rails/rails
2025-05-20 13:12:29 +02:00
Javi Martín
3eaa40892d Extract method in GraphQL controller test
This way we remove a bit of duplication and it makes it easier to add
proper requests to other tests, which we're about to do.
2025-05-20 13:12:29 +02:00
Javi Martín
6288450ab4 Use a real browser in disabled features multitenancy test
We were using a rack browser and testing the
`FeatureFlags::FeatureDisabled` exception was raised. However, we don't
test this exception in any other system tests; we only check it in
controller tests.

So we're using a real browser for consistency and because in Rails 7.1
this test is failing when enabling the new default option
`config.action_dispatch.show_exceptions = :rescuable` in the test
environment.
2025-05-20 13:12:29 +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