Files
discourse/spec/system/page_objects/components/ace_editor.rb
Alan Guo Xiang Tan f9bedc76f2 DEV: Rename fill_input -> set_input in AceEditor page object (#31825)
Follow up to dd015af0b8e9528eaabd690299cde12a0fdbe7de
2025-03-14 22:16:53 +08:00

37 lines
864 B
Ruby

# frozen_string_literal: true
module PageObjects
module Components
class AceEditor < PageObjects::Components::Base
def type_input(content)
editor_input.send_keys(content)
self
end
def set_input(content)
# Can't rely on capybara here because ace editor is not a normal input.
page.evaluate_script(
"ace.edit(document.getElementsByClassName('ace')[0]).setValue(#{content.to_json})",
)
self
end
def clear_input
set_input("")
end
def editor_input
find(".ace-wrapper .ace:not(.hidden)", visible: true).find(
".ace_text-input",
visible: false,
)
end
def has_content?(content)
editor_content = all(".ace_line").map(&:text).join("\n")
editor_content == content
end
end
end
end