Files
nairobi/spec/system/comments/legislation_annotations_spec.rb
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

111 lines
3.7 KiB
Ruby

require "rails_helper"
describe "Commenting legislation annotations" do
let(:user) { create(:user) }
describe "Merged comment threads" do
let!(:draft_version) { create(:legislation_draft_version, :published) }
let!(:annotation1) do
create(:legislation_annotation,
draft_version: draft_version,
text: "my annotation",
ranges: [{ "start" => "/p[1]", "startOffset" => 1, "end" => "/p[1]", "endOffset" => 5 }])
end
let!(:annotation2) do
create(:legislation_annotation,
draft_version: draft_version,
text: "my other annotation",
ranges: [{ "start" => "/p[1]", "startOffset" => 1, "end" => "/p[1]", "endOffset" => 10 }])
end
let!(:comment1) { annotation1.comments.first }
let!(:comment2) { annotation2.comments.first }
before do
login_as user
visit legislation_process_draft_version_path(draft_version.process, draft_version)
expect(page).to have_css ".annotator-hl"
first(:css, ".annotator-hl").click
within(".comment-box") do
expect(page).to have_content "my annotation"
expect(page).to have_content "my other annotation"
end
end
scenario "View comments of annotations in an included range" do
click_link "2 comment"
expect(page).to have_content "Comments about"
expect(page).to have_css ".comment", count: 2
expect(page).to have_content "my annotation"
expect(page).to have_content "my other annotation"
end
scenario "Reply on a single annotation thread and display it in the merged annotation thread" do
within(".comment-box #annotation-#{annotation1.id}-comments") do
first(:link, "0 replies").click
end
click_link "Reply"
within "#js-comment-form-comment_#{comment1.id}" do
fill_in "Leave your comment", with: "replying in single annotation thread"
click_button "Publish reply"
end
within "#comment_#{comment1.id}" do
expect(page).to have_content "replying in single annotation thread"
end
visit legislation_process_draft_version_path(draft_version.process, draft_version)
expect(page).to have_css ".annotator-hl"
first(:css, ".annotator-hl").click
within(".comment-box") do
expect(page).to have_content "my annotation"
expect(page).to have_content "my other annotation"
end
click_link "2 comment"
expect(page).to have_css ".comment", count: 3
expect(page).to have_content "my annotation"
expect(page).to have_content "my other annotation"
expect(page).to have_content "replying in single annotation thread"
end
scenario "Reply on a multiple annotation thread and display it in the single annotation thread" do
click_link "2 comment"
within("#comment_#{comment2.id}") do
click_link "Reply"
end
within "#js-comment-form-comment_#{comment2.id}" do
fill_in "Leave your comment", with: "replying in multiple annotation thread"
click_button "Publish reply"
end
within "#comment_#{comment2.id}" do
expect(page).to have_content "replying in multiple annotation thread"
end
visit legislation_process_draft_version_path(draft_version.process, draft_version)
expect(page).to have_css ".annotator-hl"
first(:css, ".annotator-hl").click
within(".comment-box #annotation-#{annotation2.id}-comments") do
first(:link, "1 reply").click
end
expect(page).to have_css(".comment", count: 2)
expect(page).to have_content("my other annotation")
expect(page).to have_content("replying in multiple annotation thread")
end
end
end