From 2ed75dbaf6617a69eefaacca1b194e30b063a068 Mon Sep 17 00:00:00 2001 From: Martin Brennan Date: Thu, 12 Jan 2023 13:54:26 +1000 Subject: [PATCH] DEV: DRY up PageObject::Topic and PageObject::Components::Composer (#19841) The latter can be called directly from the Topic page object, so we can remove some duplication between the two. There are levels of page objects (e.g. entire page, component, complete flow) and its perfectly valid to call one from another. --- .../page_objects/components/composer.rb | 25 ++++++++++---- spec/system/page_objects/pages/base.rb | 4 --- spec/system/page_objects/pages/topic.rb | 33 ++++++++++--------- 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/spec/system/page_objects/components/composer.rb b/spec/system/page_objects/components/composer.rb index 28dd6b88a2..1ac5ebfb6a 100644 --- a/spec/system/page_objects/components/composer.rb +++ b/spec/system/page_objects/components/composer.rb @@ -3,12 +3,6 @@ module PageObjects module Components class Composer < PageObjects::Components::Base - def open_new_topic - visit("/latest") - find("button#create-topic").click - self - end - def open_composer_actions find(".composer-action-title .btn").click self @@ -20,10 +14,23 @@ module PageObjects end def fill_content(content) - find("#reply-control .d-editor-input").fill_in(with: content) + composer_input.fill_in(with: content) self end + def type_content(content) + composer_input.send_keys(content) + self + end + + def clear_content + fill_content("") + end + + def has_content?(content) + composer_input.value == content + end + def select_action(action) find(action(action)).click self @@ -40,6 +47,10 @@ module PageObjects def button_label find("#reply-control .btn-primary .d-button-label") end + + def composer_input + find("#reply-control .d-editor .d-editor-input") + end end end end diff --git a/spec/system/page_objects/pages/base.rb b/spec/system/page_objects/pages/base.rb index 60c2ffb24f..48b005fc1c 100644 --- a/spec/system/page_objects/pages/base.rb +++ b/spec/system/page_objects/pages/base.rb @@ -4,10 +4,6 @@ module PageObjects module Pages class Base include Capybara::DSL - - def setup_component_classes!(component_classes) - @component_classes = component_classes - end end end end diff --git a/spec/system/page_objects/pages/topic.rb b/spec/system/page_objects/pages/topic.rb index efe278d05c..f863315468 100644 --- a/spec/system/page_objects/pages/topic.rb +++ b/spec/system/page_objects/pages/topic.rb @@ -4,13 +4,7 @@ module PageObjects module Pages class Topic < PageObjects::Pages::Base def initialize - setup_component_classes!( - post_show_more_actions: ".show-more-actions", - post_action_button_bookmark: ".bookmark.with-reminder", - reply_button: ".topic-footer-main-buttons > .create", - composer: "#reply-control", - composer_textarea: "#reply-control .d-editor .d-editor-input", - ) + @composer_component = PageObjects::Components::Composer.new end def visit_topic(topic) @@ -18,6 +12,17 @@ module PageObjects self end + def open_new_topic + page.visit "/" + find("button#create-topic").click + self + end + + def open_new_message + page.visit "/new-message" + self + end + def visit_topic_and_open_composer(topic) visit_topic(topic) click_reply_button @@ -85,24 +90,20 @@ module PageObjects has_css?("#reply-control.open") end - def find_composer - find("#reply-control .d-editor .d-editor-input") - end - def type_in_composer(input) - find_composer.send_keys(input) + @composer_component.type_content(input) end def fill_in_composer(input) - find_composer.fill_in(with: input) + @composer_component.fill_content(input) end def clear_composer - fill_in_composer("") + @composer_component.clear_content end def has_composer_content?(content) - find_composer.value == content + @composer_component.has_content?(content) end def send_reply @@ -110,7 +111,7 @@ module PageObjects end def fill_in_composer_title(title) - find("#reply-title").fill_in(with: title) + @composer_component.fill_title(title) end private