Files
discourse/spec/system/page_objects/cdp.rb
Renato Atilio 29ca0ae0b1 FEATURE: add footnote (plugin) rich editor extension (#31719)
Continues the work done on
https://github.com/discourse/discourse/pull/30815.

Adds a `footnote` node, parser, `^[inline]` input rule, toolbar button
item, and serializer.

Also adds a NodeView with an internal ProseMirror editor to edit the
footnote content.
2025-04-14 14:25:36 -03:00

97 lines
2.4 KiB
Ruby

# frozen_string_literal: true
module PageObjects
class CDP
include Capybara::DSL
include SystemHelpers
include RSpec::Matchers
def allow_clipboard
cdp_params = {
origin: page.server_url,
permission: {
name: "clipboard-read",
},
setting: "granted",
}
page.driver.browser.execute_cdp("Browser.setPermission", **cdp_params)
cdp_params = {
origin: page.server_url,
permission: {
name: "clipboard-write",
},
setting: "granted",
}
page.driver.browser.execute_cdp("Browser.setPermission", **cdp_params)
end
def read_clipboard
page.evaluate_async_script("navigator.clipboard.readText().then(arguments[0])")
end
def write_clipboard(content, html: false)
if html
page.evaluate_async_script(
"navigator.clipboard.write([
new ClipboardItem({
'text/html': new Blob([arguments[0]], { type: 'text/html' }),
'text/plain': new Blob([arguments[0]], { type: 'text/plain' })
})
]).then(arguments[1])",
content,
)
else
page.evaluate_async_script(
"navigator.clipboard.writeText(arguments[0]).then(arguments[1])",
content,
)
end
end
def clipboard_has_text?(text, chomp: false, strict: true)
try_until_success do
clipboard_text = chomp ? read_clipboard.chomp : read_clipboard
expect(clipboard_text).to strict ? eq(text) : include(text)
end
end
def copy_paste(text, html: false)
allow_clipboard
write_clipboard(text, html: html)
paste
end
def paste
page.send_keys([PLATFORM_KEY_MODIFIER, "v"])
end
def with_network_disconnected
begin
page.driver.browser.network_conditions = { offline: true }
yield
ensure
page.driver.browser.network_conditions = { offline: false }
end
end
def with_slow_download
begin
page.driver.browser.network_conditions = { latency: 20_000, download_throughput: 1 }
yield
ensure
page.driver.browser.network_conditions = { latency: 0 }
end
end
def with_slow_upload
begin
page.driver.browser.network_conditions = { latency: 20_000, upload_throughput: 1 }
yield
ensure
page.driver.browser.network_conditions = { latency: 0 }
end
end
end
end