discourse/spec/system/page_objects/pages/form_template.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

90 lines
2.3 KiB
Ruby
Raw Normal View History

2023-02-09 03:21:39 +08:00
# frozen_string_literal: true
module PageObjects
module Pages
class FormTemplate < PageObjects::Pages::Base
def visit
page.visit("/admin/customize/form-templates")
self
end
def visit_new
page.visit("/admin/customize/form-templates/new")
self
end
2023-02-09 03:21:39 +08:00
# Form Template Index
def has_form_template_table?
page.has_selector?("table.form-templates__table")
2023-02-09 03:21:39 +08:00
end
def click_view_form_template
find(".form-templates__table tr:first-child .btn-view-template").click
end
def click_toggle_preview
find(".d-toggle-switch .d-toggle-switch__checkbox-slider", visible: false).click
self
2023-02-09 03:21:39 +08:00
end
def has_form_template?(name)
find(".form-templates__table tbody tr td", text: name).present?
2023-02-09 03:21:39 +08:00
end
def has_category_in_template_row?(category_name)
find(".form-templates__table .categories .category-name", text: category_name).present?
end
2023-02-09 03:21:39 +08:00
def has_template_structure?(structure)
find("code", text: structure).present?
end
# Form Template new/edit form related
def type_in_template_name(input)
find(".form-templates__form-name-input").fill_in(with: input)
2023-02-09 03:21:39 +08:00
self
end
def click_save_button
DEV: ensures save button is visible and enabled (#21781) In tests we could attempt to click the button before it was enabled and it could also not be visible on screen. This commits attempts to solve both problems. It should solve this failure: ``` Failures: 1) Admin Customize Form Templates when visiting the page to create a new form template should allow admin to create a new form template Failure/Error: find(".form-templates__table tbody tr td", text: name).present? Capybara::ElementNotFound: Unable to find css ".form-templates__table tbody tr td" [Screenshot Image]: /__w/discourse/discourse/tmp/capybara/failures_r_spec_example_groups_admin_customize_form_templates_when_visiting_the_page_to_create_a_new_form_template_should_allow_admin_to_create_a_new_form_template_911.png ~~~~~~~ JS LOGS ~~~~~~~ http://localhost:31339/favicon.ico - Failed to load resource: the server responded with a status of 404 (Not Found) ~~~~~ END JS LOGS ~~~~~ # ./vendor/bundle/ruby/3.2.0/gems/capybara-3.39.1/lib/capybara/node/finders.rb:312:in `block in synced_resolve' # ./vendor/bundle/ruby/3.2.0/gems/capybara-3.39.1/lib/capybara/node/base.rb:84:in `synchronize' # ./vendor/bundle/ruby/3.2.0/gems/capybara-3.39.1/lib/capybara/node/finders.rb:301:in `synced_resolve' # ./vendor/bundle/ruby/3.2.0/gems/capybara-3.39.1/lib/capybara/node/finders.rb:60:in `find' # ./vendor/bundle/ruby/3.2.0/gems/capybara-3.39.1/lib/capybara/session.rb:773:in `find' # ./vendor/bundle/ruby/3.2.0/gems/capybara-3.39.1/lib/capybara/dsl.rb:52:in `call' # ./vendor/bundle/ruby/3.2.0/gems/capybara-3.39.1/lib/capybara/dsl.rb:52:in `find' # ./spec/system/page_objects/pages/form_template.rb:21:in `has_form_template?' # ./spec/system/admin_customize_form_templates_spec.rb:71:in `block (3 levels) in <main>' # ./spec/rails_helper.rb:381:in `block (3 levels) in <top (required)>' # ./vendor/bundle/ruby/3.2.0/gems/timeout-0.3.2/lib/timeout.rb:189:in `block in timeout' # ./vendor/bundle/ruby/3.2.0/gems/timeout-0.3.2/lib/timeout.rb:36:in `block in catch' # ./vendor/bundle/ruby/3.2.0/gems/timeout-0.3.2/lib/timeout.rb:36:in `catch' # ./vendor/bundle/ruby/3.2.0/gems/timeout-0.3.2/lib/timeout.rb:36:in `catch' # ./vendor/bundle/ruby/3.2.0/gems/timeout-0.3.2/lib/timeout.rb:198:in `timeout' # ./spec/rails_helper.rb:377:in `block (2 levels) in <top (required)>' # ./spec/rails_helper.rb:369:in `block (2 levels) in <top (required)>' # ./vendor/bundle/ruby/3.2.0/gems/webmock-3.18.1/lib/webmock/rspec.rb:37:in `block (2 levels) in <top (required)>' ```
2023-05-28 20:14:25 +08:00
find(".form-templates__form .footer-buttons .btn-primary:enabled", visible: :all).click
2023-02-09 03:21:39 +08:00
end
def click_quick_insert(field_type)
find(".form-templates__form .quick-insert-#{field_type}").click
end
def click_validations_button
find(".form-templates__validations-modal-button").click
end
def click_preview_button
DEV: ensures preview button is enabled (#21780) In tests we could attempt to click the preview button when it was not enabled yet, causing a noop and a future failure. This fix ensures we try to find (and wait) for an enabled button. This should help with this specific flakey: ``` Failures: 1) Admin Customize Form Templates when visiting the page to create a new form template should render all the input field types in the preview Failure/Error: find(".form-template-field__#{type}").present? Capybara::ElementNotFound: Unable to find css ".form-template-field__input" [Screenshot Image]: /__w/discourse/discourse/tmp/capybara/failures_r_spec_example_groups_admin_customize_form_templates_when_visiting_the_page_to_create_a_new_form_template_should_render_all_the_input_field_types_in_the_preview_277.png ~~~~~~~ JS LOGS ~~~~~~~ http://localhost:31339/favicon.ico - Failed to load resource: the server responded with a status of 404 (Not Found) ~~~~~ END JS LOGS ~~~~~ # ./vendor/bundle/ruby/3.2.0/gems/capybara-3.39.1/lib/capybara/node/finders.rb:312:in `block in synced_resolve' # ./vendor/bundle/ruby/3.2.0/gems/capybara-3.39.1/lib/capybara/node/base.rb:84:in `synchronize' # ./vendor/bundle/ruby/3.2.0/gems/capybara-3.39.1/lib/capybara/node/finders.rb:301:in `synced_resolve' # ./vendor/bundle/ruby/3.2.0/gems/capybara-3.39.1/lib/capybara/node/finders.rb:60:in `find' # ./vendor/bundle/ruby/3.2.0/gems/capybara-3.39.1/lib/capybara/session.rb:773:in `find' # ./vendor/bundle/ruby/3.2.0/gems/capybara-3.39.1/lib/capybara/dsl.rb:52:in `call' # ./vendor/bundle/ruby/3.2.0/gems/capybara-3.39.1/lib/capybara/dsl.rb:52:in `find' # ./spec/system/page_objects/pages/form_template.rb:55:in `has_input_field?' # ./spec/system/admin_customize_form_templates_spec.rb:114:in `block (3 levels) in <main>' # ./spec/rails_helper.rb:368:in `block (3 levels) in <top (required)>' # ./vendor/bundle/ruby/3.2.0/gems/timeout-0.3.2/lib/timeout.rb:189:in `block in timeout' # ./vendor/bundle/ruby/3.2.0/gems/timeout-0.3.2/lib/timeout.rb:36:in `block in catch' # ./vendor/bundle/ruby/3.2.0/gems/timeout-0.3.2/lib/timeout.rb:36:in `catch' # ./vendor/bundle/ruby/3.2.0/gems/timeout-0.3.2/lib/timeout.rb:36:in `catch' # ./vendor/bundle/ruby/3.2.0/gems/timeout-0.3.2/lib/timeout.rb:198:in `timeout' # ./spec/rails_helper.rb:364:in `block (2 levels) in <top (required)>' # ./spec/rails_helper.rb:356:in `block (2 levels) in <top (required)>' # ./vendor/bundle/ruby/3.2.0/gems/webmock-3.18.1/lib/webmock/rspec.rb:37:in `block (2 levels) in <top (required)>' ```
2023-05-28 20:15:02 +08:00
find(".form-templates__preview-button:enabled").click
end
def has_input_field?(type)
find(".form-template-field__#{type}").present?
end
def has_preview_modal?
find(".form-template-form-preview-modal").present?
end
def has_validations_modal?
find(".admin-form-template-validation-options-modal").present?
2023-02-09 03:21:39 +08:00
end
def has_name_value?(name)
find(".form-templates__form-name-input").value == name
end
def has_save_button_with_state?(disabled:)
find_button("Save", disabled:)
end
def has_preview_button_with_state?(disabled:)
find_button("Preview", disabled:)
2023-02-09 03:21:39 +08:00
end
end
end
end