Commit Graph

19957 Commits

Author SHA1 Message Date
Javi Martín
02825c22fe Include stat graphs JavaScript in all admin stats actions
Since the main stats index loads this JavaScript using
`"data-turbolinks-track" => "reload"`, going from the stats index to a
section that doesn't include this JavaScript did the strange effect
Turbolinks does in these situations: it first loaded the page using an
AJAX request and, after getting the contents of the page, it reloaded it
in order to apply the changes in the included JavaScript.

This behavior was a bit confusing, particularly when browsing to a
section of the admin stats, clicking the browser's back button to go
back to the stats index, the going to another section, ...

One of the admin stats tests was failing sometimes with this message:

```
  1) Stats Budget investments Supporting phase Number of users and
     supports in investment projects
     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=129.0.6668.89)
```

This was probably caused by the mentioned Turbolinks behavior that loads
the page twice. It's possible that Selenium was somehow checking the
node related to the first request when the second request had finished.

Avoiding that double request solves the issue.
2024-11-08 19:54:29 +01:00
Javi Martín
9a4aea9381 Extract method to include stat graphs JavaScript
We're going to use this method everywhere in the admin stats section.
2024-11-08 19:37:09 +01:00
Javi Martín
f8d06bcaf2 Move management investments search partial to a component
We're also moving it to the `management` subfolder, since it's only used
in the budget investments management.
2024-11-08 15:03:55 +01:00
Javi Martín
b7e9d1118e Add ARIA labels to moderation checkboxes
This way it'll be easier for people using screen readers to know which
element the checkbox is related to.

Note that we're using the `aria-label` attribute because it makes
testing with Capybara easier than using the `aria-labelledby` attribute.
The only exception are the comments, since comments don't have a title
and there isn't a proper label for them. In this case, we're using the
title of the associated commentable as the label; we might change it in
the future since there might be many comments for the same commentable.
2024-11-08 15:03:55 +01:00
Javi Martín
8213f23629 Use I18n texts for image dimensions
This way it'll be possible to customize the text in languages not using
parenthesis or not using an "x" to define dimensions.
2024-11-08 15:03:55 +01:00
Javi Martín
b82d7032ba Add a hint to the site customization image fields
This way people using screen readers will hear the required dimensions
of the images while filling in the form.
2024-11-08 15:03:55 +01:00
Javi Martín
5ca65a787f Add an ARIA label to site customization images fields
This way it'll be easier for people using screen readers to know which
field they're on.
2024-11-08 15:03:55 +01:00
Javi Martín
331228cb2a Add proper labels for site customization texts
We were rendering one label and many textarea fields for that label.
This meant that, when switching to a different language, the label
wasn't correctly associated with the textarea.

So we're now rendering one label for each textarea. We could use
`aria-label` or `aria-labelledby` instead, but using a label offers some
advantages like the fact that clicking on the label makes the textarea
take the focus.
2024-11-08 15:03:55 +01:00
Javi Martín
0f712635a4 Extract method in information text field component
This will make it easier to reuse this method.
2024-11-08 15:03:55 +01:00
Javi Martín
e1353fd865 Fix duplicate fields in information texts form
We were rendering the same hidden field, with the same HTML ID, one time
per enabled locale.
2024-11-08 15:03:55 +01:00
Javi Martín
55d81fcac7 Fix missing "for" attribute in user invitations label
Since the attribute was missing, the label wasn't correctly associated
with its field.
2024-11-08 15:03:55 +01:00
Javi Martín
431ebeda87 Fix missing "for" attribute in document number label
Since this attribute was missing, the label wasn't correctly associated
with its field.
2024-11-08 15:03:55 +01:00
Javi Martín
9f738b8d5f Fix labels in progress bar percentage selection
We were using the same label for two elements, but the label was only
assigned to one of them.
2024-11-08 15:03:55 +01:00
Javi Martín
233ba3c72f Move progress bars form partial to a component
This way we can move some of the view logic to the Ruby class. It'll
also make it easier to write tests for it.
2024-11-08 15:03:55 +01:00
Javi Martín
9c057d5695 Fix labels in color selection
We were using the same label for two elements, but the label was only
assigned to one of them.
2024-11-08 15:03:55 +01:00
Javi Martín
8aff1414c5 Move legislation process form partial to a component
This will make it easier to write tests for it.
2024-11-08 15:03:55 +01:00
Javi Martín
c1fbcb4e0f Remove obsolete resource method in controllers
This method was used by controllers using the `Translatable` concern. We
forgot to remove it in commit 71601bd3f.
2024-11-08 15:03:51 +01:00
Javi Martín
e850ae2ff9 Move banner form partial to a component
Other than simplifying the controller, this'll make it easier to write
tests for this code.
2024-11-08 14:24:57 +01:00
Javi Martín
16fc9998c4 Use labels in controls to add and select languages
The absence of labels in these controls made them hard to use,
particularly for people who use screen readers.

Note we're removing the "Choose language" prompt, since we always
automatically choose a language and not choosing a language doesn't
really make sense. The only scenario where the prompt was used took
place when all languages had been removed but, in that case, the "Choose
language" prompt was misleading because there were no languages to
choose from.
2024-11-08 14:22:44 +01:00
Javi Martín
0f10146273 Merge pull request #5740 from consuldemocracy/button_confirmations
Use buttons for actions requiring confirmation
2024-11-08 14:11:35 +01:00
Javi Martín
ef4bc6a650 Simplify accept_confirm dialog in valuation test
We were using `check "Valuation finished"` everywhere except here.

This way it's easier to realize, while reading the test, that we're
interacting with a checkbox and not a link or a button.
2024-11-08 13:35:22 +01:00
Javi Martín
87a5dd8ee5 Use a button to mark debates as featured
As mentioned in commit 5311daadf, there are several reasons to use
buttons in these situations. And, as mentioned in the previous commits,
using buttons instead of links for actions requiring confirmation will
help us test for accessibility issues.
2024-11-08 13:24:23 +01:00
Javi Martín
68744f110e Use CSS to add separators to the debates featured action
Just like we do in the moderation actions displayed next to id.
2024-11-08 13:24:23 +01:00
Javi Martín
f8faabf7d1 Extract component to mark a debate as featured
We're also moving the path argument in the `link_to` calls to a
different line, since it's what we usually do.
2024-11-08 13:24:05 +01:00
Javi Martín
d85a87a517 Use a button to delete surveys
As mentioned in commit 5311daadf, there are several reasons to use
buttons in these situations. And, as mentioned in the previous commits,
using buttons instead of links for actions requiring confirmation will
help us test for accessibility issues.
2024-11-08 13:11:02 +01:00
Javi Martín
11ef917802 Use a button to delete comments
As mentioned in commit 5311daadf, there are several reasons to use
buttons in these situations. And, as mentioned in the previous commits,
using buttons instead of links for actions requiring confirmation will
help us test for accessibility issues.
2024-11-08 13:01:01 +01:00
Javi Martín
26b24af413 Remove unused HTML class in hide recommendation button
Since the element uses `position: absolute`, the `float: right` property
set by this utility class is ignored.
2024-11-08 13:01:01 +01:00
Javi Martín
891333abed Use a button to hide recommendations
As mentioned in commit 5311daadf, there are several reasons to use
buttons in these situations. And, as mentioned in the previous commits,
using buttons instead of links for actions requiring confirmation will
help us test for accessibility issues.

Since we're adding styles for this button, we're also adding the
`font-size` property instead of using the `small` class. We'll deal with
the `float-right` property in the next commit.
2024-11-08 13:00:14 +01:00
Javi Martín
2fb8eaf6c7 Add aria-labels to user investment actions
This way it'll be easier for people using screen readers to know which
link/button they're about to click.

Note that, at least for now, we aren't reusing the code en
`Admin::ActionComponent`. We might do so in the future if we implement
similar code in more parts of the public area.
2024-11-08 12:29:37 +01:00
Javi Martín
cbdf2f7f22 Extract methods in user investment table actions 2024-11-08 12:19:39 +01:00
Javi Martín
b694ee7077 Use a button to delete an investment
Note that, since the button now generates a `form` tag, we need to
adjust the styles of this section.

As mentioned in commit 5311daadf, there are several reasons to use
buttons in these situations. And, as mentioned in the previous commits,
using buttons instead of links for actions requiring confirmation will
help us test for accessibility issues.

Note we're simplifying the `table .button` margin rules because the
`.button` class already defines `0` for all its margins except the
bottom margin. Otherwise, the margins defined by the `flex-with-gap`
mixin would be overwritten by the margins defined in the `table .button`
class.
2024-11-08 12:19:05 +01:00
Javi Martín
0e2434c094 Extract commponent to render user investment actions
This way it'll be easier to organize code related to it.
2024-11-07 15:18:37 +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
2fb8abe83f Use a button to delete documents
While testing for accessibility issues (in a development branch), we're
removing Turbolinks and monkey-patching the behavior of the `click_link`
method to check the page for accessibility issues after each request.
However, we were getting false positives when clicking links that act
like buttons.

So, for the reasons mentioned in commit 5311daadf, we're replacing the
link to delete a document with a button.
2024-11-07 15:18:37 +01:00
Javi Martín
b541fcc0fa Merge pull request #5764 from consuldemocracy/use_flex_in_executions
Use flex instead of data-equalizer in executions
2024-11-07 15:15:32 +01:00
Javi Martín
10cdfadb9b Move executions images system tests to the component
We forgot to do so in commit f0ab7bcfc. We're still leaving one system
spec to test that these images are rendered when browsing the site.

We're also changing the existing component tests to check the `alt`
attribute, just like the remaining system test does.
2024-11-07 14:21:55 +01:00
Javi Martín
75b03791b1 Extract component to render an execution
Note that, in order to be consistent with the name of the component,
we're renaming the `budget-execution` class to
`budget-executions-investment`.
2024-11-07 14:21:55 +01:00
Javi Martín
764d22f57a Use flex instead of an equalizer in executions
Just like we did in commits like f2e32b44b, a8537f7e1 and be9fc2265,
we're replacing a buggy JavaScript solution with one using just CSS.

Besides, we've had a failure in our test suite caused by an image not
being displayed on the page, with the message:

```
Failures:

1) Executions Images renders last milestone's image if investment has multiple milestones
   with images associated
   Failure/Error: expect(page).to have_css("img[alt='Second image']")
     expected to find visible css "img[alt='Second image']" but there were no matches.
     Also found "", which matched the selector but not all filters.

   # ./spec/system/budgets/executions_spec.rb:135:in `block (3 levels) in <top (required)>'
```

The text "matched the selector but not all filters" means that the
element was present on the page but wasn't visible. One possible cause
is that the equalizer was adjusting the height of the element containing
the image before the image was loaded.

Note that, after these changes, all investments on the same row will
have the same height but, unlike with Foundation's equalizer,
investments on different rows might have different heights.
2024-11-07 14:21:55 +01:00
Javi Martín
1e063e88c2 Extract component to render heading executions
Note we're adding the `budgets-executions-heading` HTML class, which is
consistent to what we do in other components.
2024-11-07 14:21:55 +01:00
Javi Martín
e3a2a42534 Move investments executions view to a component
Note that we're changing the component so it uses `polymorphic_path`;
that way we don't have to pass the `@budget` variable to the component.
We could also use `budget_investment_path investment.budget, investment`
instead.
2024-11-07 14:21:55 +01:00
Javi Martín
1057f41d61 Fix indentation in investments executions partial
We accidentally introduced the wrong indentation in commit 8376efce3.
2024-11-07 14:21:55 +01:00
Javi Martín
8c04e30d1c Merge pull request #5760 from consuldemocracy/ahoy_visits_server_side
Track ahoy visits on the server side
2024-11-07 14:08:46 +01:00
Javi Martín
6e5ef9795e Track ahoy visits on the server side
In commit 96ae69fe9, we stopped using cookies to track Ahoy visits and
started using a combination of the IP and the browser agent instead.

However, since we're still using the legacy logic from Ahoy 1.x to track
visits (which we had to add in commit b5220effd), this way of tracking
visits doesn't work and counts every page visited by a user as an
independent visit.

Maybe we could migrate existing data, which uses the `visitor_id` column
so it uses the new `visit_token` and `visitor_token` columns, but
there's no mention in the Ahoy documentation regarding how to do so.

While deciding what to do about this, we found something interesting.

For two years, we've been seeing random failures in the
`system/admin/tenants_spec.rb` tests, with messages like:

```
1) Tenants Create Tenant with subdomain
     Failure/Error:
       raise TenantNotFound, <<~EXCEPTION_MESSAGE
         Could not set search path to schemas, they may be invalid:
           "#{tenant}" #{full_search_path}.
         Original error: #{exception.class}: #{exception}
       EXCEPTION_MESSAGE

     Apartment::TenantNotFound:
       Could not set search path to schemas, they may be invalid:
         "earth" "public", "shared_extensions".
       Original error:
         ActiveRecord::StatementInvalid: Could not find schema earth
```

And we've found one of the causes: the AJAX requests done by Ahoy to
track visits. Sometimes a test that creates or updates a tenant finishes
but the Ahoy AJAX request to, say, `earth.lvh.me/ahoy/visits`, is
handled by the next test, when the `earth` schema no longer exists, thus
raising an `Apartment::TenantNotFound` exception.

So by disabling these AJAX requests and tracking the visits in the
server instead, we're killing two birds in one stone: we're fixing the
bug regarding the visits count and we're reducing the flakiness in our
test suite. It looks like we're also removing the "phantom ahoy cookie"
we were getting since the mentioned commit b5220effd: an ahoy cookie was
quickly set and unset in the browser.

Note that, even though we aren't migrating any data, we're still adding
the new fields, because some tests started to fail because, when
tracking visits in the server without cookies, Ahoy expects the Visit
model to have a `visit_token` field.
2024-11-07 12:04:46 +01:00
Javi Martín
1c10ed0ec7 Remove legacy field in the visits table
The search_keyword column was removed for new installations in Ahoy
2.1.0 and stopped being used completely in Ahoy 3.0.0.

There are other columns that we use and are no longer generated by
default by Ahoy, which are: screen_height, screen_width and postal_code.
Apparently they're still used in Ahoy if they're available, though, so
we aren't removing them, at least for now.
2024-11-07 12:04:46 +01:00
Javi Martín
df2540d483 Merge pull request #5761 from consuldemocracy/officing_voters_lock
Include voter initialization in officing voters lock
2024-11-07 11:37:25 +01:00
Javi Martín
45851c74bd Include voter initialization in officing voters lock
For reasons that might or might not affect production installations, the
test checking simultaneous requests to create poll voters in the
officing voters controller wasn't behaving as expected.

The expected behavior, since commit 9a8bfac5b, is that the second
request reaching the `with_lock` part of the code waits for the first
request to finish and so this second request raises an
`ActiveRecord::RecordInvalid` exception when trying to save a voter with
the same poll and the same user as the first one.

However, 95% of the time that wasn't the case. Instead, when entering
the `@user.with_lock` block, the second request would replace its
`@voter` object with the `@voter` object saved in the same request, so
the second call to `save!` would succeed as it would simply update the
existing record.

This is a behavior that we could accept if it were consistent and
happened 100% of the time, but that isn't the case. 5% of the time, we
do get the `ActiveRecord::RecordInvalid` exception. So 5% of the time we
got a failure in the test:

```
  1) Officing::VotersController POST create does not create two records
     with two simultaneous requests
     Failure/Error: @user.with_lock { @voter.save! }

     ActiveRecord::RecordInvalid:
       Validation failed: User User has already voted
     # ./app/controllers/officing/voters_controller.rb:25:in `block in create'
     # ./app/controllers/officing/voters_controller.rb:25:in `create'
     # ./app/controllers/application_controller.rb:50:in `switch_locale'
     # ./spec/controllers/officing/voters_controller_spec.rb:15:in `block (5 levels) in <top (required)>'
```

So we're changing the `with_lock` block so it includes the
initialization of the object. This way, we get the
`ActiveRecord::RecordInvalid` exception 100% of the time.

Note that in commit 9a8bfac5b we also rescued the
`ActionDispatch::IllegalStateError` exceptions. I'm not why we were
getting those exceptions when running the tests, and I'm not sure
whether we keep getting after these changes, but it doesn't really
matter. The reason is that in Consul Democracy 2.3.0 we're going to add
a unique index to the `poll_voters` table, which (according to the tests
done in the past) will make both the `@user.lock` block and rescuing the
`ActionDispatch::IllegalStateError` unnecessary.

So, in other words, these changes will never make it to production
because this part of the code will be changed again before releasing
version 2.3.0.
2024-11-07 11:15:15 +01:00
Javi Martín
e96171541b Merge pull request #5759 from consuldemocracy/fix_hide_public_page_test
Add missing expectation in users test
2024-11-06 16:18:46 +01:00
Javi Martín
df716c3de6 Add missing expectations in users tests
One of these tests has failed in our CI with the following message:

```
1) Users Public activity user can hide public page

   Failure/Error: expect(page).to have_content("activity list private")
     expected to find text "activity list private" in "Language: \n
     \nEnglish\nDeutsch\nEspañol\nFrançais\nNederlands\nPortuguês
     brasileiro\n中文\n       Notifications\nYou are in\nMy content\nMy
     account\nSign out\nDebates\nProposals\nVoting\nCollaborative
     legislation\nParticipatory budgeting\nSDG\nHelp\nM\nManuela124\nUser has
     no public activity\nOpen government\nThis portal uses the CONSUL
     DEMOCRACY application which is open-source
     software.\nParticipation\nDecide how to shape the city you want to live
     in.\nCONSUL DEMOCRACY, 2024 Privacy Policy Terms and conditions of use
     Accessibility"
```

Note how the text "User has no public activity" is present, which is a
message that appears when the user's activity is public.

A possible explanation is that we didn't check that the request done by
the "Save changes" button had finished before continuing with the tests.
Back when we wrote this test, submitting a form in a test would always
wait for the request to be finished before continuing, but a lot has
changed since then.

So we're adding an expectation to make sure the the changes have been
saved before making a new request.

We're also rearraging the blank lines in these tests and removing the
parenthesis in `have_content` expectations to be consistent with the
expectations we're adding.
2024-11-06 15:57:25 +01:00
Javi Martín
fbcba3afdb Merge pull request #5758 from consuldemocracy/comment_author_class_tests
Remove instance_double usage in CommentsHelper tests
2024-11-06 15:56:56 +01:00
Javi Martín
7f40029a26 Fix typo in document management verification tests 2024-11-06 15:39:10 +01:00