Commit Graph

19 Commits

Author SHA1 Message Date
Javi Martín
3fe65bafd1 Use keyword arguments in mappable specs
We were getting a warning with Ruby 2.7 due to the change in the way
keyword arguments are handled in Ruby 3.0.

```
ruby/gems/2.7.0/gems/rspec-support-3.11.0/lib/rspec/support/with_keywords_when_needed.rb:18:
warning: Passing the keyword argument as the last hash parameter is
deprecated
```

As hinted by the warning, this code crashes with Ruby 3.0:

```
ArgumentError:
  unknown keyword: :budget_id
```

I'm not sure why this is the case, though, since we were already
explicitely passing a hash first before passing the keyword parameters.
I guess there are some cases in this whole keyword VS hash parameters
incompatibility that I haven't completely understood.
2023-01-26 17:19:15 +01:00
Javi Martín
2d693328dc Simplify checking map longitude and latitude
We were doing a `mappable.map_location` call in an `expect` which might
result in a database queries. Doing database queries in a test after the
process running the browser has started might result in exceptions while
running our test suite.
2022-06-02 19:25:14 +02:00
Javi Martín
e49c32638d Use if instead of skip to skip tests
This way the tests won't appear as "pending" when running the test
suite, and so we get rid of a lot of noise in the test results. There
doesn't seem to be a way to call `skip` without the test being marked as
"pending".

Note that in the globalizable tests we need to build a factory before
deciding whether an atribute is required or not (particularly for the
milestone factory, since milestone attributes are required depending on
the presence of other attributes). This isn't possible before we're
inside the test, so we can't add an `if:` condition to the test. So
we're adding the condition inside the test instead. A minor
inconvenience of this method is the test still runs even when the
condition is `false`.
2022-04-07 15:34:10 +02:00
Javi Martín
42b8729cd8 Remove duplicate map test
We were skipping the test, but there's an identical test right below it.
2022-04-07 15:34:09 +02:00
Senén Rodero Rodríguez
c086308b6f Call new common actions modules methods explicitly 2022-04-06 16:06:44 +02:00
Senén Rodero Rodríguez
b26a7528df Move mappable helper methods to a new common actions module
So we can use the same customization technique overriding
the methods we need.
2022-04-06 11:15:23 +02:00
Javi Martín
f638e50174 Wait for suggestions to finish loading in tests
Sometimes tests were hanging indefinitely. Debugging shows that in some
cases it's due to submitting a form before the AJAX request to get
proposals, debates or investments suggestions is finished, since having
an AJAX and a non-AJAX request at the same time when running the test
sometimes leads to unexpected results.

In our case, we were having many timeouts in Github Actions in the
branches where we use both ActiveStorage and Paperclip to store files
(based on pull request 4598). I can reproduce it in those branches
running the following test ("Should show new image after successful
creation with one uploaded file"), although only when my laptop isn't
plugged (!!):

```
rspec './spec/system/proposals_spec.rb[1:33:1:14]'
```

Since we didn't have a proper way to know the AJAX request had finished,
we're adding a `suggest-success` class to the element showing the
suggestions when that happens. Then in the tests we can look for that
class after filling in the title of a proposal, debate or investments.
Just for clarity's sake, we're also adding the `suggest-loading` class
when the suggestions are loading.

In order not to have expectations everywhere about the suggestions,
we're extracting methods to fill in those titles in the tests. Note we
aren't using these methods in the "edit" actions (suggestions are not
showing when editing) or in tests with the `no_js` tag (since
suggestions only work with JavaScript).
2021-09-22 18:29:23 +02:00
decabeza
0488b3735f Hide single heading select on new budget investment form 2021-06-11 12:37:56 +02:00
Melvin Lammerts
c34aa54122 Remove skip map checkbox 2021-06-03 11:13:52 +02:00
taitus
fa12528581 Make the do_login_for method accessible to other shared specs 2021-04-09 16:20:59 +02:00
taitus
7a34a338f4 Allow to create an investment with a geolocation.
In the Management section when creating an investment we were not passing the
map attributes, so we were never able to associate a geolocation.
2021-04-09 16:20:59 +02:00
Javi Martín
03d0ffd89e Sign in manager after setting up test data
We've got quite a messy hack to sign in managers: they need to visit a
specific URL (management root path).

That means tests signing in managers start the browser to sign them in,
which might cause issues if we setup the database after that.
2021-04-07 14:41:06 +02:00
Javi Martín
92ddcb7aef Use JavaScript in system tests by default
JavaScript is used by about 98% of web users, so by testing without it
enabled, we're only testing that the application works for a very
reduced number of users.

We proceeded this way in the past because CONSUL started using Rails 4.2
and truncating the database between JavaScript tests with database
cleaner, which made these tests terribly slow.

When we upgraded to Rails 5.1 and introduced system tests, we started
using database transactions in JavaScript tests, making these tests much
faster. So now we can use JavaScript tests everywhere without critically
slowing down our test suite.
2021-04-07 14:41:06 +02:00
taitus
1a58fcf2a2 Make tests independent of Setting["org_name"]
So tests won't fail when an institution changes the default organization
name.

The tests are also easier to understand now, since it's more obvious
where the "CONSUL" text is coming from.
2020-12-08 18:56:33 +01:00
Senén Rodero Rodríguez
a986028794 Get map center longitude from correct place 2020-09-14 14:54:30 +02:00
Senén Rodero Rodríguez
b9ce68bc82 Set marker coordinates as map center when map location fields has valid coordinates
When a user recovers a page from browser history where placed a
marker in different map pane (visible map layer) marker was
successfully added to the map but the map center is the one
defined at Settings map properties so the marker was not visible
to the user.

Now when map_location form has valid coordinates we use them
instead of default map center settings. This will avoid the user to
have to rellocate the marker (or find the correct pane where the
marker was added) if already placed.
2020-08-12 10:10:58 +02:00
Senén Rodero Rodríguez
6aa94a787c Use map location form latitude, longitude and zoom when valid
When using an editable map is better to load marker latitude, longitude and
map zoom from form fields so we can show the marker at latest position defined
by user when the page was restored from browser history.

To reproduce this behavior:
0. Undo this commit
1. Go to new proposal page
2. Place the proposal map marker
3. Go away to any other page
4. Restore new proposal page from browser history.

At this point you should not see the recently placed marker.

The same thing happens when editing a proposal.
2020-08-12 10:10:58 +02:00
Senén Rodero Rodríguez
289426c1c3 Destroy maps before leaving the current page
If we do not do this a map could be initialized twice times or more
when restoring a page with a map causing weird UI effects and
loading some map layers also twice times or more.

Need to add a maps array to be able to store all initialized
(visible) maps so we can destroy them when needed. Notice that
we are destroying maps also when admin settings tabs changes
(only visible ones), this is again to avoid to re-initialize map more
than once when users navigate through settings tabs, another
option to the settings issue could be to detect if the map was
already initialized to skip uneeded initialization.
2020-08-12 10:10:58 +02:00
Javi Martín
9427f01442 Use system specs instead of feature specs
We get rid of database cleaner, and JavaScript tests are faster because
between tests we now rollback transactions instead of truncating the
database.
2020-04-24 15:43:54 +02:00