Commit Graph

420 Commits

Author SHA1 Message Date
Javi Martín
bab5cbf03a Merge pull request #4215 from consul/dependabot/bundler/rubocop-0.93.1
Bump rubocop from 0.91.1 to 0.93.1
2021-08-10 13:15:52 +02:00
decabeza
4a9aae9806 Add groups index page
When render the investment list component with the link "see all
investments", now we redirect to groups index page when a budget has
multiple headings.
2021-08-09 21:45:29 +02:00
Javi Martín
469b39ffa3 Add and apply Style/RedundantInterpolation rule
Somehow I thought we already had this rule; must have forgotten to
actually add it.
2021-08-09 21:37:04 +02:00
taitus
c6b23bb6fa Render investments list in all budgets types
We make this change to unify the index/show budget pages.

This way both single and multiple budgets will render the investments
list component.
2021-08-09 20:07:51 +02:00
Javi Martín
f92796c7fa Move list of investments tests to component tests
In general, slow system tests requiring no interaction from the user are
good candidates to be moved to component tests because component tests
are much faster.

In this case, the system tests were also updating the database after
starting the browser, which might cause concurrency issues. We could
split the test and have one system test per phase, but IMHO there's no
need.

We're still having a couple of system tests for the happy path, in order
to make sure users actually see the list of investments.
2021-08-09 20:07:50 +02:00
Javi Martín
9328c72aaa Simplify link to see all investments test 2021-08-09 19:46:40 +02:00
Javi Martín
afb660f82c Fix rubocop convention offenses
While we use Pronto to detect offenses in the lines changed in our pull
request, sometimes our changes introduce offenses in other lines, and we
don't detect them.

In commit 0488b3735, we removed the only usage of the `heading` method
in a test, which caused a `RSpec/LetSetup` offense.

In commit 287c48873, we changed some lines from `fill_in` to
`fill_in_ckeditor`. Some of these lines were aligned with the following
ones, which after that change had extra spacing for no reason.

Finally, in commit 8d38ed58c we added a line before two lines which had
their equals signs aligned. Since, after adding this line, the block was
no longer aligned, there was no reason for the extra space in one of the
lines.
2021-08-09 16:23:40 +02:00
Javi Martín
b3104fae68 Merge pull request #4586 from consul/attach_with_keyboard
Allow attaching files using the keyboard
2021-07-15 00:19:27 +02:00
decabeza
e42db48f2b Do not show confirm message if user can vote in all headings 2021-07-14 16:14:29 +02:00
Javi Martín
cc6f9391fc Fix attaching files using the keyboard
We were hiding the file input and styling the label as a button instead.
Since clicking on a label has the same effect as clicking on the input,
the input worked properly for mouse and touch screen users.

However, hiding the input makes it inaccessible for keyboard users,
since labels don't get keyboard focus, but inputs do.

So we must not hide the input but make it invisible instead. But we
still need to hide the input (alongside the label) after a file has been
attached.

We could add some extra JavaScript to hide the input when we hide the
label. Since the JavaScript is already quite complex and my first few
attempts at changing it failed, I've opted to assume that the input (and
its label) must be hidden whenever there's already a file name, and
implement that rule with CSS.

Note we're using the `:focus-within` pseudoclass to style a label when
focus is on the input. This rule (at the time of writing) is only
supported by 93.5% of the browsers. Keyboard users without a screen
reader and using the other 6.5% of the browsers will still be able to
focus on the field but might not notice the field has received focus.
Since the percentage of affected users will decrease over time and until
now 100% of keyboard users were completely unable to focus on these
fields, for now we think this is a good-enough solution.
2021-07-13 17:09:05 +02:00
decabeza
909fd00714 Update styles and layout for new debates form 2021-07-13 15:27:14 +02:00
Javi Martín
62ca762587 Only show terms acceptance on new investment form
No need to accept the terms when updating the investment.
2021-07-09 14:25:18 +02:00
Javi Martín
a4eff3aa19 Simplify subnavigation layout
Using `flex` instead of a fixed width for the navigation, the elements
take all the available space when the search form isn't present. That
wasn't the case before and produced a strange effect on medium-sized
screens.

This way we also align the search to the right.
2021-07-08 18:57:21 +02:00
Javi Martín
ff0f2215ea Extract component for locale switcher
Note that in order to simplify the component tests (which for some
reason seem to be whitespace-sensitive), we have to omit whitespace
characters inside the `<option>` tags.

Also note we're simplifying the test with a missing language name; since
a component test doesn't involve a whole request, we don't need a
complex setup (I'm not sure we even need it in system tests).
2021-07-05 22:27:39 +02:00
Javi Martín
93c521bd29 Use labels in language selector tests
This way the test verifies there's a label associated to that form
field.
2021-07-05 22:27:39 +02:00
decabeza
3762421247 Do not show SDG columns if disabled 2021-07-02 14:59:31 +02:00
Javi Martín
58d123ad51 Merge pull request #4552 from consul/table_icons_with_text
Use icons with text in admin table actions
2021-06-30 16:31:18 +02:00
Javi Martín
db4a262a0d Merge pull request #4571 from consul/campaigns_specs
Make campaign specs more robust
2021-06-30 16:16:28 +02:00
Javi Martín
28e720a1ec Make sure we use non-existent IDs in campaign test
Previously, depending on the database status, it could be possible that
the ID of the campaign2 record was exactly 999 and this test could fail.
2021-06-30 16:00:07 +02:00
Javi Martín
855f47f386 Create campaings before running campaigns tests
We were defining campaigns with `let`. That meant they weren't created
until these methods were used in the tests.

For the test "Do not track erroneous track_ids", that meant the line
`expect(page).not_to have_content campaign2.name.to_s` wasn't really
testing anything, since before this line is executed, the campaign2
wasn't in the database at all, and so obviously its name wouldn't be on
the stats page.

For the test "Track email templates", it meant we were creating the
campaign2 record after visiting the campaign1 page with the browser.
Creating records in the tests after starting the browser might be the
reason why this test has recenty failed in our CI [1]:

 1) Email campaigns Track email templates
     Failure/Error: ds.add params[:event].titleize, Ahoy::Event.where(
                    name: params[:event]).group_by_day(:time).count
     ActiveRecord::StatementInvalid:
       PG::ProtocolViolation: ERROR:  bind message supplies 0
       parameters, but prepared statement "" requires 1
     # ./app/controllers/admin/api/stats_controller.rb:13:in `show'

Using `let!` to create the campaings before the browser starts improves
the situation.

[1] https://github.com/consul/consul/runs/2952333023
2021-06-30 16:00:00 +02:00
Javi Martín
5531a0b2bc Simplify action links in budgets table
The word "budget" in the "Preview budget" link is redundant.

On the other hand, the words "Manage", Edit" and "Admin" are not
really necessary in my humble opinion. Just like in the admin
navigation menu we use "Participatory budgets" instead of "Manage
Participatory budgets", the fact that we're going to manage or
admin or edit something can be deduced from the fact that we're in
the admin section.

Besides, it isn't clear to me why we use "Manage" for projects,
"Edit" for heading groups and "Admin" for ballots. The differences
between these three concepts might be too subtle for me.

The previous paragraphs haven't been corroborated with real users,
though, so I might be mistaken and we might need to revisit these
links in the future.

These actions still take quite a lot of space. Maybe in the future we
could remove the "delete" icon, at least on budgets which cannot be
deleted.
2021-06-30 14:33:37 +02:00
Javi Martín
6f04c8f057 Use conventions in page actions texts
We use the words "Manage" and "View" in other places; we don't use the
word "See" as often.
2021-06-30 14:33:37 +02:00
Javi Martín
7d590031f5 Remove redundant words in edit and destroy links
When we see a list of, let's say, banners, and each one has a link to
edit them, the word "banner" in the text "edit banner" is redundant and
adds noise; even for users with cognitive disabilities, it's obvious
that the "edit" link refers to the banner.
2021-06-30 14:33:37 +02:00
Javi Martín
614e6da92b Use a submit button in budget executions filters
As mentioned in commit 5214d89c8, there are several issues with
submitting a form when a `<select>` tag changes. In particular, keyboard
users might accidentally fire the event while browsing the options, and
screen reader users will find a form with no obvious way to submit it.

In this case, there's an extra problem: in commit be8a0dbe8 we added a
second `<select>` field to this form, which also submitted on change.
Sometimes users changed one of the values and wanted to change the other
value as well before submitting the form. However, it wasn't possible,
because we would submit it before they had a chance to change the second
value.

So now we don't submit the form on change and add a submit button. This
is similar to what we do in the "Advanced filters" we use in several
places.
2021-06-30 14:14:43 +02:00
Javi Martín
ee4ef8d3a5 Use labels to select filters in executions tests
This way we check there's a label associated to these fields.
2021-06-29 20:07:55 +02:00
Javi Martín
626af63a42 Merge pull request #4565 from consul/improve-home-cards
Improve home cards
2021-06-29 17:07:07 +02:00
taitus
db23d536dd Do not show link content section when links fields are not defined. 2021-06-29 16:53:37 +02:00
Javi Martín
a2f6e03516 Move advanced search toggle button inside the form
Since forms are landmarks, screen reader users might navigate to the
form. But then they were going to find an empty form with no way to
toggle it.

Moving the button inside the form means screen reader users navigating
to the form will find the button to toggle it.

It also helps us simplifying the code; there's no need to use
data-attributes to communicate whether the form should be visible since
now we can easily use the button `aria-expanded` attribute.

We could further simplify the JavaScript if we used a CSS rule to
show/hide the form fields based on the toggle button `aria-expanded`
attribute. However, implementing the "slide" animation we use when
toggling the form with CSS is difficult and unreliable.
2021-06-29 14:13:54 +02:00
Javi Martín
6dcdf5c843 Use a button to toggle the advanced search form
Users (particularly, screen reader users) usually identify links with
things that take you somewhere, and buttons with things that either send
forms or change things on the page.

Using a button we can also use the `aria-expanded` attribute, meaning
screen reader users will know that the button has two states ("expanded"
and "collapsed"), the current state of the button, and will get
immediate feedback when clicking the button because the new state of the
button will be announced.

Thanks to this change, we can also slightly simplify the code; we
obviously have to remove the (useless) `href` attribute, and we don't
have to prevent the default event in JavaScript since there's no default
event for buttons with `type="button"`.
2021-06-29 13:58:32 +02:00
taitus
1d47a5c079 Add link_url validation for cards when are not header cards
Currently it is not necessary to include the link_url field.

When we display these cards without link_url, they create an empty link that
redirects to the same page. I understand that this is not a desired behavior, so I
think it is better to add a validation in this case and force administrators to add a
link_url when creating a card.
2021-06-28 15:57:39 +02:00
Javi Martín
bc0f040758 Use order links in legislation proposals admin
As mentioned in the previous commits, a `<select>` field which submits
its form on change causes many accessibility and usability issues, so
we're replacing it with the order links we use everywhere else.

Since the links "Id" and "Title" by themselves don't have enough
information to let users know they're used to sort by ID or title, we
have to update them somehow. We could add a "Sort by:" prefix before the
list of links (and associate it with the `aria-labelledby` attribute);
however, we don't do this anywhere else and might look weird depending
on the screen size.

So we're simply adding "Sort by" before each link.

Now that we don't use the `wide_order_selector` partial anymore, we can
remove it alongside the styles for the `select-order` class.
2021-06-28 01:20:39 +02:00
Javi Martín
14d8bef0d8 Use order links in print proposals management
A `<select>` tag here might make more sense than in other similar places
since there are 5 options to choose among, and using links might take
too much screen space.

However, as mentioned in the previous commits, `<select>` tags which
automatically submit a form have many accessibility and usability
issues.

An alternative would be to create a dropdown menu with a button and a
list of links (similar to what Foundation does). I'm keeping the links
for simplicity and because the interface looks a bit more consistent
with the rest of the sections. Before these changes, we had a heading,
then a `<select>` field to choose the filter, and then a button to print
the page. We never use a similar interface, and some people might think
the "Print" button is related to the same form as the `<select>` field.

Now that we don't use the `order_selector` partial anywhere anymore, we
can remove it.
2021-06-28 00:15:08 +02:00
Javi Martín
227a5868b8 Use order links in moderation section
Using order links in this case causes an unusual interface, where we
show filter links, then information about the number of results, and
then order links.

Whether or not this makes sense needs to be confirmed with usability
tests. In any case, this is still way better than using `<select>`
fields which automatically change to a new page, since they cause
problems to keyboard users, are harder to select for touchscreen users,
might confuse screen reader users who will notice a form but no way to
submit it, and are not elements we generally use to let users choose the
order of the records.

For a more detailed explanation of these issues, check the commit
message in the commit "Use order links to sort comments and topics"
(just a few commits ago).
2021-06-28 00:15:08 +02:00
Javi Martín
55cf502e8f Fix typo in proposal notifications moderation test 2021-06-28 00:15:08 +02:00
Javi Martín
93f3411a30 Use anchors in comments order and pagination links
It was a bit frustrating to click on one of the order elements or the
link to the next page and having to scroll down again until reaching the
comments.
2021-06-28 00:15:06 +02:00
Javi Martín
5214d89c88 Use order links to sort comments and topics
We use order links in many places in the web. However, in the comments
section and the list of community topics, we were displaying a
`<select>` element, and changing the location when users select an
option.

This has several disadvantages.

First, and most important, it's terrible for keyboard users. `<select>`
fields allow using the arrow keys to navigate through their options, and
typing a letter will select the first option starting with that letter.
This will trigger the "change" event and so users will navigate through
a new page while they were probably just checking the available options
[1]. For these reasons, WCAG Success Criterion 3.2.2 [2] states:

> Changing the setting of any user interface component does not
> automatically cause a change of context unless the user has been
> advised of the behavior before using the component.

Second, the form didn't have a submit button. This might confuse screen
reader users, who might not know how that form is supposed to be
submitted.

Finally, dropdowns have usability issues of their own [3], particularly
on mobile phones [4]

The easiest solution is to use the same links we generally use to allow
users select an order, so using them here we make the user experience
more consistent. They offer one disadvantage, though; on small screens
and certain languages, these links might take too much space and not
look that great. This issue affects pretty much every place where we use
order or filter links, so we might revisit it in the future.

Note we're moving the links to order comments after the form to add a
new comment. In my opinion, having an element such as a form to add a
new comment between the element to select the desired order of the
comments and the comments themselves is a bit confusing.

[1] https://webaim.org/techniques/forms/controls#javascript
[2] https://www.w3.org/WAI/WCAG21/Understanding/on-input.html
[3] https://www.youtube.com/watch?v=CUkMCQR4TpY
[4] https://www.lukew.com/ff/entry.asp?1950
2021-06-28 00:08:18 +02:00
Javi Martín
1632540984 Remove redundant placeholders in forms
Using placeholders having similar (or identical) text as already present
as a label has a few issues.

First, it's a distraction. Reading the same information twice is
useless, requires an extra effort, and might even frustrate users.

Second, if users start typing before reading the placeholder and see it
disappear, they might think they're missing relevant information,
delete what they typed, and read the placeholder. That will get them
nowhere.

Finally, we display placeholders using a text offering very low contrast
against the background, so users don't think the placeholder is an
actual value entered in the field. Using such low contrast makes the
text hard to read, particularly for users with visual impairments.

So we're removing these placeholders.

This commit only deals with placeholder texts with similar (or
identical) texts as the label text. There might be other places where we
should replace placeholder texts with labels, but that's a different
topic.
2021-06-23 19:52:45 +02:00
Javi Martín
918276ec70 Merge pull request #4555 from consul/flaky_recount_spec
Fix flaky poll recount spec
2021-06-22 18:30:14 +02:00
Javi Martín
c6a459c115 Merge pull request #4558 from consul/featured_disabled
Respond with 403 when features are disabled
2021-06-17 15:39:12 +02:00
Javi Martín
59518846a8 Merge pull request #4554 from consul/flaky_hidden_spec
Fix flaky hidden budget investments spec
2021-06-17 15:34:22 +02:00
Javi Martín
5f747122c5 Don't assign IDs to user records in tests
This test will fail if the ID of the created record is the same as the
ID of the first user we create in the test. The chance is very low due
to the `rand(9999999)` which causes the test to fail just once every ten
million times. However, why assigning the ID in the first place? Without
it, the test will never fail due to conflicting IDs.
2021-06-17 01:46:48 +02:00
Javi Martín
7bb7548d00 Respond with 403 when features are disabled
When administrators disabled features and users tried to access them
with the browser, we were responding with a 500 "Internal Server Error"
page, which in my humble opinion was incorrect. There was no error at
all; the server worked exactly as expected.

I think a 403 "Forbidden" code is better; since that feature is
disabled, we're refusing to let users access it.

We could also respond with a 404 "Not found", although I wonder whether
that'll be confusing when administrators temporarily or accidentally
disable a feature.

A similar thing might happen if we responded with a 410 "Gone" code.
Actually this case might be more confusing since users aren't that
familiar with this code.

In any case, all these options are better than the 500 error.
2021-06-16 20:45:15 +02:00
decabeza
a851048d56 Allow users to remove their support on investments
Note we don't cast negative votes when users remove their support. That
way we provide compatibility for institutions who have implemented real
negative votes (in case there are / will be any), and we also keep the
database meaningful: it's not that users downvoted something; they
simply removed their upvote.

Co-Authored-By: Javi Martín <javim@elretirao.net>
Co-Authored-By: Julian Nicolas Herrero <microweb10@gmail.com>
2021-06-14 14:46:54 +02:00
Javi Martín
071da81be6 Add notice when supporting an investment
It was hard to notice what was going on when supporting one investment
which was at the bottom of the investment index page.

I wonder whether we should add the title of the investment to this text;
I'm not doing so because we don't do that anywhere else.
2021-06-14 14:42:03 +02:00
decabeza
b23fe300f5 Add supports info section on budgets index page 2021-06-14 13:48:44 +02:00
Javi Martín
bb958daf05 Replace support investment link with a button
Using links combined with JavaScript to generate POST requests to the
browser has a few issues.

An obvious one is that it doesn't work for users without JavaScript
enabled (which lately I've noticed are more common than I thought, even
though I've been one of them for years). These users will reach a 404
page.

Since CONSUL isn't currently designed to work without JavaScript
enabled, let's ignore this one for now.

A not so obvious issue is screen reader users might expect the link to
take them somewhere instead of performing an action (in this case,
sending a form to the server).

There might be more issues I'm unaware of. Quoting DHH [1]:

"Turning ahrefs into POSTs is a bit of an anti-pattern, especially for
a11y reasons. Better to use button_to with a styling."

So we're using a button instead. This way we can also simplify the code
and make the button disabled for unidentified users, which automatically
makes it impossible to focus it using the keyboard.

A possible disadvantage of using `button_to` is it will create a form
tag which will be announced to screen readers as a form landmark. I've
tested it with my screen reader and everything worked fine for me, but
some screen reader users might interact with these forms in a different
way and find it confusing, particularly in the case where the button is
disabled.

With this change, we're only changing links for buttons in one place.
There are other places where we should do similar changes.

[1] See issue 33 in https://github.com/hotwired/turbo-rails/
2021-06-14 12:51:41 +02:00
Javi Martín
0b287e4a78 Fix test checking same group investment support
We meant to check that the link to support a different investment didn't
have an alert dialog. However, we were testing by trying to support the
same investment twice, and here there was no link at all, so the
assertion "there's no link with a dialog" always passed even when the
application didn't behave properly.

Now we check there's a link there, and that link doesn't have an
associated alert dialog.
2021-06-14 12:51:41 +02:00
Javi Martín
de436e33a4 Use a component test to check a link title
In regular system tests, we prefer testing against the text of the link
because it's easier to recognize which link we're talking about.

I was wondering whether we should remove the `title` attribute
completely and use just the `aria-label` attribute. Quoting The Paciello
Group blog [1]:

"If you want to hide content from mobile and tablet users as well as
assistive tech users and keyboard only users, use the title attribute."

However, there's a case where mouse users might find the title attribute
useful. When visiting an investment page, the connection between the
"Support" link and the investment is not as clear as it is in the
investments index page, so it might not be clear what you're supporting.

As mentioned, though, this information will only be relevant for mouse
users, who nowadays represent less than half of our users.

[1] https://www.tpgi.com/using-the-html-title-attribute-updated/
2021-06-14 12:51:41 +02:00
Javi Martín
e4ad70fd82 Revert "Adds .js-class for specs"
The `js-` prefix (which I admit I'm not fond of) is usually used to
indicate the class is used by JavaScript files, not for using it in test
files. And in all the other similar tests, we're using the `in-favor`
class instead of the `js-in-favor` class.

This reverts commit 83fe74d53.
2021-06-14 12:51:41 +02:00
Javi Martín
d983443ecc Fix investment support in management section
When supporting an investment in the management section through the
investment view, we were accessing an action in the public investments
controller. This meant the manager was the one supporting the investment
(as they'd be the `current_user` in this controller) and not the managed
user.

In the case of groups with many headings, voting the first time requires
a confirmation and then a regular (non-AJAX) request takes place. In
this case, users were redirected to the public area instead of remaining
in the management area.

Using the proper URL to vote solves the problem.

Note there was a comment about one of these tests failing in Travis.
Most probably the test failed because there was no expectation after
clicking the link with the investment title, so the "Support" button
(which is also present in the index page) was clicked before the
investment view was loaded.
2021-06-14 12:37:40 +02:00