Commit Graph

20144 Commits

Author SHA1 Message Date
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
Javi Martín
538958de3f Simplify mailer test replying to a comment
Since we're using the `reply_to` method in a few tests on this file, we
might as well use it here for consistency.
2025-04-01 14:53:26 +02:00
Javi Martín
29ab5cebd4 Don't access the database in direct message 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.

Note that, in this case, in order to make the tests more readable, we're
adding a bit of duplication. We should probably simplify these tests by
moving most of the checks to mailer tests and then we could remove the
duplication. The alternative would be to make the
`create_direct_message` method way more complex than it is right now.
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
e29ad8b505 Remove duplicate test
We already have a test in the `level_three_verification_spec` file that
checks the exact same things and then the letter verification. And, for
the SMS step, we also have a test in the `sms_spec` file.
2025-04-01 14:53:26 +02:00
Javi Martín
2ada826f12 Move officing voters system test to controller test
As mentioned in the previous commit, checking 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 been able to test the user
experience since it looks like booths and officer assignments for voters
aren't shown anywhere.

So, since the purpose of the test was to check the database, and there
are other tests checking what happens after clicking the "Confirm vote"
button in the user interface, we're converting this test into a
controller test.
2025-04-01 14:53:26 +02:00
Javi Martín
a28967817e Split some system tests checking the database
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 these cases, however, I haven't been able to test the user
experience. For example, it looks like failed census calls for
unregistered users aren't displayed anywhere and can only be accessed by
manually checking the database. Similarly, there's no interface showing
that all the options from a poll have been deleted (which makes sense,
since we only display options in the context of their poll) or a place
showing the responsible name for a proposal.

So we're splitting the tests in two, with the controller test running
the database checks.
2025-04-01 14:53:26 +02:00
Javi Martín
990f9e9664 Merge pull request #5932 from consuldemocracy/run_apt_update_to_install_imagemagick
Run apt update to install ImageMagick in CI workflow
2025-04-01 14:53:06 +02:00
Javi Martín
a3844dcab5 Run apt update to install ImageMagick in CI workflow
We've been getting an error in our CI because some the Ubuntu 24.04
image in GitHub Actions doesn't have an updated package database:

```
E: Failed to fetch mirror+file:
   pool/main/g/ghostscript/libgs-common_10.02.1%7edfsg1-0ubuntu7.4_all.deb
   404  Not Found
E: Failed to fetch mirror+file:
   pool/main/g/ghostscript/libgs10-common_10.02.1%7edfsg1-0ubuntu7.4_all.deb
   404  Not Found
E: Failed to fetch mirror+file:
   pool/main/g/ghostscript/libgs10_10.02.1%7edfsg1-0ubuntu7.4_amd64.deb
   404  Not Found
E: Failed to fetch mirror+file:
   pool/main/g/ghostscript/ghostscript_10.02.1%7edfsg1-0ubuntu7.4_amd64.deb
   404  Not Found
E: Unable to fetch some archives, maybe run apt-get update
   or try with --fix-missing?
```

Running `sudo apt-get update` before trying to install a package solves
the issue.
2025-04-01 14:38:04 +02:00
Javi Martín
80bba21d67 Merge pull request #5927 from cyrillefr/ReplaceLinkWithButtonInInvestmentComponent
Replace link with button in ballot investment component
2025-03-30 21:31:02 +02:00
Javi Martín
c5c04cbd72 Merge pull request #5920 from consuldemocracy/dependabot/bundler/json-2.10.2
Bump json from 2.10.1 to 2.10.2
2025-03-27 19:55:55 +01:00
dependabot[bot]
1504b9dc9b Bump json from 2.10.1 to 2.10.2
Bumps [json](https://github.com/ruby/json) from 2.10.1 to 2.10.2.
- [Release notes](https://github.com/ruby/json/releases)
- [Changelog](https://github.com/ruby/json/blob/master/CHANGES.md)
- [Commits](https://github.com/ruby/json/compare/v2.10.1...v2.10.2)

---
updated-dependencies:
- dependency-name: json
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-03-27 18:19:16 +00:00
Javi Martín
d80ceada22 Merge pull request #5928 from consuldemocracy/dependabot/bundler/nokogiri-1.18.4
Bump nokogiri from 1.18.3 to 1.18.4
2025-03-27 19:17:07 +01:00
cyrillefr
03c6d9156f Fix lint/style offenses 2025-03-27 16:19:26 +01:00
cyrillefr
9d0214374b Replace link with button in ballot investment component 2025-03-27 16:19:26 +01:00
Javi Martín
f8e2a7b5ba Merge pull request #5893 from consuldemocracy/obsolete_code
Remove some obsolete code
2025-03-26 17:25:27 +01:00
Javi Martín
a72799de8d Remove redundant "let" block
An identical `let` block had already been defined inside the `describe
"Public activity"` block, so there was no need to define it again.
2025-03-26 16:42:04 +01:00
Javi Martín
71742f72b0 Remove obsolete "let" blocks in tests setup
These blocks are no longer used:

* `allowed_phase_list` isn't used since commit 04605d5d5
* `level_two_user` isn't used since commit 26d14cbd0
* `heading` in `budgets/stats_spec` was added in c2457e36a but never
  used
* `translatable` was added in 44d137a4c but it's overwritten in all the
  contexts.
* `annotation` isn't used since commit 79d00e7b9
* `admin` in `tags/budget_investments_spec` isn't used since 8a2e15980
* `budget` in `welcome_spec` was added in 87be6f302 but never used
2025-03-26 16:42:04 +01:00
Javi Martín
5ba6e7b692 Remove redeemable code
I don't think this feature it was ever used. It was introduced in commit
49dec6061 as part of a feature that was removed in commits 1cd47da9d and
c45a0bd8ac.
2025-03-26 16:42:04 +01:00
Javi Martín
6089a9249f Remove obsolete Admin::Api::BaseController class
This class isn't used since commit 14454bdd4.
2025-03-26 16:42:04 +01:00
Javi Martín
2239b8fdca Remove obsolete questions index in the admin area
We removed the link to this page in commit 83e8d6035 because poll
questions don't really make sense without a poll.

However, this page also contained information about successful
proposals, which might be interesting so administrators don't have to
navigate to the public area in order to find and create questions based
on successful proposals.

So we're keeping the part about successful proposals and linking it from
the proposals part of the admin area.

Note we're using translation keys like `successful_proposals_tab`, which
don't make sense anymore, for the successful proposals. We're doing so
because we've already got translations for these keys and, if we renamed
them, we'd lose the existing translations and our translators would have
to add them again.

Also note we're changing one poll question test a little bit so we
create the question from a successful proposal using the new page. There
are other tests checking how to create a question from the
admin/proposals#show action and other tests checking what happens when
accessing a successful proposal in the admin section, so we don't lose
any test coverage by changing an existing test instead of adding a new
one.

Finally, note that we've removing the `search` method in poll question
because we no longer use it. This currently makes the
`author_visible_name` database column useless; we aren't removing it
right now because we don't want to risk a possible data loss in a patch
release (we're about to release version 2.3.1), but we might remove it
in the future.
2025-03-26 16:42:04 +01:00
Javi Martín
cf5863b29f Move admin proposals index view to a component
This way we can use the `header` method to simplify it a bit.
2025-03-26 16:42:04 +01:00
Javi Martín
4732817360 Remove obsolete icons-related CSS
These rules aren't used since commit c5c9efee1.

Note that there's still an `icon-budget` element in the
`_investment_show` partial. The rules for this icon are already defined
inside the rules for the `.budget-investment-show` selector.

The `icon-budget` and `icon-proposals` HTML classes are still used in
the "Following" tab (the code uses the `followable_icon` method), but in
this case the `.budget-investment` or `.proposal` selectors aren't
present, so the properties weren't applied here either.

Similarly, there are elements with the `icon-debates` and
`icon-proposals` HTML classes in the dashboard area, but they aren't
inside elements matching the `.debate` or `.proposal` selectors either.

And there's an element with the `icon-debate` HTML class in the
legislation area. Once again, it isn't inside an element matching the
`.debate` selector.

So can safely remove this code.
2025-03-26 16:42:04 +01:00
Javi Martín
c5018e4a53 Remove obsolete video_url column in poll_questions table
This column isn't used since commit 4c0deb0ec because administrators can
associate videos to the answers since commit 5862eea51. The value of
this attribute isn't used in the public area since commit 8277e3cc2.
2025-03-26 16:42:04 +01: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
d18510e102 Remove unused image_default parameter
This parameter isn't used since commit b4a6f664b.

Note we're changing the tests to use proposals instead of debates
because proposals may have images attached, while debates may not.
2025-03-26 16:42:04 +01:00
Javi Martín
74a9b48076 Remove usage of obsolete with_subnavigation parameter
The layouts/header partial doesn't use this parameter since commit
488e7e081, where it was deleted while solving a merge conflict.
2025-03-26 16:42:04 +01:00
Javi Martín
26b5677d83 Merge pull request #5917 from consuldemocracy/missing_expectations
Add missing expectations in system tests
2025-03-26 16:41:35 +01:00
Javi Martín
1dcfc38e41 Add missing expectations after refreshing the page
This way we know for sure the page has finished refreshing.

Note that, for now, we aren't adding a check after every call to the
`refresh` method because sometimes the page remains identical after
refreshing. Not sure what we should do in these cases.
2025-03-26 16:27:08 +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
99932e0aaf Simplify navigation in budget executions tests
We're already testing the navigation in one test, and in some of these
tests we were checking, for instance, that the title of an investment is
present after a click, but since it is also present before that click,
that could lead to the test finishing before the request does.
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
Javi Martín
1593a150e7 Move in_browser expectations inside the same block
This way the code is easier to follow, and we avoid having simultaneous
requests on different browser sessions, which in theory shouldn't affect
the application, but the test might be a bit more robust this way.
2025-03-26 16:27:08 +01:00
Javi Martín
368cf47adf Group tests to delete a document together
This way the tests are slightly faster, and we avoid a possible flaky
spec since in one test we were checking that a certain text was not
present, which didn't guarantee that the request to delete the document
had finished.
2025-03-26 16:27:08 +01:00
Javi Martín
a39201e408 Add missing expectations in mappable tests
After clicking the "Save changes" button, we were sometimes checking
expectations that were already true before clicking the button, so it
was possible that the request generated by that button didn't finish
before the test did.

So now we're checking that the button is no longer present, which is
only true after the request has finished.
2025-03-26 16:27:08 +01:00
Javi Martín
5206708c01 Fix wrong expectation in information texts test
The expectation that there isn't a link with the text "Español" wasn't
updated in commit f7417d647, when the tests were updated after switching
the user interface from a list of links to a select field.

We're also adding an additional expectation after the `visit` to make
sure the request has finished before selecting English from the selector
(which probably doesn't make sense because it's the only option, but
changing it is out of the scope of this commit).
2025-03-26 16:27:08 +01:00
Javi Martín
2c05d7fbe7 Add an extra visit to avoid checking the same content
We were checking that, after a `visit`, we're redirected to the account
page, but, since we were already in the account page, the page doesn't
change at all. In order to be 100% that the request caused by the call
to `visit` has finished before checking the expectations, we're visiting
a different page first.
2025-03-26 16:27:08 +01:00
Javi Martín
98fec3bb2f Add missing expectation before checking metadata
We weren't checking whether the request creating the proposal had
finished before checking the document. That's probably why this test has
recently failed on our CI:

```
1) Documents Metadata download document without metadata
     Failure/Error: io = URI.parse(
                          "#{app_host}#{polymorphic_path(
                                        Document.last.attachment)}"
                        ).open

     NoMethodError:
       undefined method `attachment' for nil:NilClass
```
2025-03-26 16:27:08 +01:00
Javi Martín
f913ca75c6 Add missing expectations before opening the last email
We weren't checking that the requests had finished before checking the
last sent email. That's probably why one of these tests has recently
failed on our CI:

```
1) System Emails Preview Pending #send_pending
  Failure/Error: email = open_last_email

  RuntimeError:
    No email has been sent!
```
2025-03-26 16:27:08 +01:00