Files
discourse/spec/system/page_objects/components/ace_editor.rb
Alan Guo Xiang Tan dd015af0b8 DEV: Fix flaky system test (#31820)
The "Admin editing objects type theme setting when editing a theme
setting of objects type allows an admin to edit a theme setting of
objects type via the settings editor"
system test was flaky because of the way we were filling in content into
AceEditor. It is not a normal input and does not seem to function like a
normal input. Using Capybara's `fill_in` method was not reliable so we
will just use AceEditor's API directly to update its input.
2025-03-14 15:33:09 +08:00

37 lines
866 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 fill_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
fill_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