-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Expand file tree
/
Copy pathexternal_links_in_block_note_spec.rb
More file actions
135 lines (113 loc) · 5.34 KB
/
external_links_in_block_note_spec.rb
File metadata and controls
135 lines (113 loc) · 5.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# frozen_string_literal: true
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See COPYRIGHT and LICENSE files for more details.
#++
require "rails_helper"
RSpec.describe "External links in BlockNote editor",
:js,
:selenium,
with_settings: { real_time_text_collaboration_enabled: true } do
include_context "with hocuspocus"
let(:admin) { create(:admin) }
let(:document) { create(:document, :collaborative) }
let(:editor) { FormFields::Primerized::BlockNoteEditorInput.new }
shared_examples "does not freeze when pasting multiple external links" do
it "does not freeze when pasting content with multiple external links" do
editor.paste_links(
{ text: "Link One", url: "https://example.com/one" },
{ text: "Link Two", url: "https://example.org/two" },
{ text: "Link Three", url: "https://other-site.com/three" },
{ text: "Link Four", url: "https://fourth-domain.net/four" },
{ text: "Link Five", url: "https://fifth-place.io/five" }
)
editor.fill_in(" Still typing after paste")
expect(editor.content).to include("Still typing after paste")
end
end
before do
login_as(admin)
visit document_path(document)
end
it "editor remains interactive after ProseMirrorExternalLinksController connects" do
expect(page).to have_test_selector("blocknote-document-description")
editor.fill_in("Hello from the editor")
expect(editor.content).to include("Hello from the editor")
editor.element.send_keys(:enter)
editor.fill_in("Still typing just fine")
expect(editor.content).to include("Still typing just fine")
end
it "sets target and rel attributes on external links in the shadow DOM" do
editor.paste_links(text: "Example Site", url: "https://example.com")
link = editor.shadow_root.find("a[target='_blank']", text: "Example Site", wait: 5)
expect(link[:rel]).to include("noopener")
expect(link[:rel]).to include("noreferrer")
end
it "sets aria-describedby on external links for screen reader accessibility" do
editor.paste_links(text: "Accessible Link", url: "https://example.com")
# ProseMirror inline decorations wrap the text node in a <span> with the
# attribute, rather than adding it to the <a> element (which is rendered
# by the link mark). The screen reader hint is on the link's text content.
editor.shadow_root.find(
"a[target='_blank'] [aria-describedby='open-blank-target-link-description']",
text: "Accessible Link",
wait: 5
)
end
it_behaves_like "does not freeze when pasting multiple external links"
it "does not rewrite internal links" do
editor.paste_links(text: "Internal Link", url: root_url)
link = editor.shadow_root.find("a", text: "Internal Link", wait: 5)
expect(link.native.property("href")).not_to include("/external_redirect")
end
context "with capture enabled",
with_ee: %i[capture_external_links],
with_settings: {
real_time_text_collaboration_enabled: true,
capture_external_links: true
} do
# Note: running with DevTools open (non-headless) inflates page.windows count.
# This test expects headless mode; run headless if window counts seem off.
it "intercepts clicks on external links and redirects through /external_redirect" do
editor.paste_links(text: "Captured Link", url: "https://example.com/page")
link = editor.shadow_root.find("a[target='_blank']", text: "Captured Link", wait: 5)
# href stays as original — not rewritten in the DOM
expect(link.native.property("href")).to include("example.com/page")
expect(link.native.property("href")).not_to include("/external_redirect")
original_window = page.current_window
link.click
# Wait for exactly one new window to open, verifying no double-open from TipTap + our handler
wait_for { page.windows.size }.to eq(2)
new_window = (page.windows - [original_window]).first
within_window new_window do
expect(page.current_url).to include("/external_redirect")
end
ensure
(page.windows - [original_window]).each { |w| w.close rescue nil } # rubocop:disable Style/RescueModifier
end
it_behaves_like "does not freeze when pasting multiple external links"
end
end