mirror of
https://github.com/discourse/discourse.git
synced 2025-06-02 04:08:41 +08:00

Continues the work done on https://github.com/discourse/discourse/pull/30815. Extends the ProseMirror-markdown `code-block` node by integrating our existing HighlightJS pipeline for code highlighting and adding a node view with a `<select>` to change the language of the block. We're also adding the markdown paste extension, which handles converting pasted text/plain to rich content if it contains Markdown. --------- Co-authored-by: Martin Brennan <martin@discourse.org>
75 lines
1.9 KiB
Ruby
75 lines
1.9 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(text)
|
|
page.evaluate_async_script(
|
|
"navigator.clipboard.writeText(arguments[0]).then(arguments[1])",
|
|
text,
|
|
)
|
|
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 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
|