mirror of
https://github.com/discourse/discourse.git
synced 2024-12-02 04:03:44 +08:00
56524f4bdf
Very similar to move up/down flag problem fixed here - https://github.com/discourse/discourse/pull/28272 Those are the steps to toggle the flag: 1. click toggle - `saving` CSS class is added; 2. request to backend; 3. `saving` CSS class is removed. And check if the flag was toggle was: ```ruby def has_saved_flag?(key) has_css?(".admin-flag-item.#{key}.saving") has_no_css?(".admin-flag-item.#{key}.saving") end ``` If the save action is very fast, then the saving class is removed before the first check. Therefore I decided to invert it, and once action is finished add `saved` CSS class. Then we can have a quick positive check: ```ruby def has_saved_flag?(key) has_css?(".admin-flag-item.#{key}.saved") end ```
111 lines
2.5 KiB
Ruby
111 lines
2.5 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module PageObjects
|
|
module Pages
|
|
class AdminFlags < PageObjects::Pages::Base
|
|
def visit
|
|
page.visit("/admin/config/flags")
|
|
self
|
|
end
|
|
|
|
def toggle(key)
|
|
PageObjects::Components::DToggleSwitch.new(".admin-flag-item__toggle.#{key}").toggle
|
|
has_saved_flag?(key)
|
|
self
|
|
end
|
|
|
|
def open_flag_menu(key)
|
|
find(".#{key} .flag-menu-trigger").click
|
|
self
|
|
end
|
|
|
|
def has_action_for_flag?(flag)
|
|
has_selector?(".#{flag} .flag-menu-trigger")
|
|
end
|
|
|
|
def has_no_action_for_flag?(flag)
|
|
has_no_selector?(".#{flag} .flag-menu-trigger")
|
|
end
|
|
|
|
def has_disabled_edit_for_flag?(flag)
|
|
has_selector?(".#{flag} .admin-flag-item__edit[disabled]")
|
|
end
|
|
|
|
def has_disabled_item_action?(action)
|
|
has_selector?(".admin-flag-item__#{action}[disabled]")
|
|
end
|
|
|
|
def has_item_action?(action)
|
|
has_selector?(".admin-flag-item__#{action}")
|
|
end
|
|
|
|
def has_no_item_action?(action)
|
|
has_no_selector?(".admin-flag-item__#{action}")
|
|
end
|
|
|
|
def has_flags?(*flags)
|
|
all(".admin-flag-item__name").map(&:text) == flags
|
|
end
|
|
|
|
def has_add_flag_button_enabled?
|
|
has_css?(".admin-flags__header-add-flag:not([disabled])")
|
|
end
|
|
|
|
def has_add_flag_button_disabled?
|
|
has_no_css?(".admin-flags__header-add-flag[disabled]")
|
|
end
|
|
|
|
def has_flag?(flag)
|
|
has_css?(".admin-flag-item.#{flag}")
|
|
end
|
|
|
|
def has_no_flag?(flag)
|
|
has_no_css?(".admin-flag-item.#{flag}")
|
|
end
|
|
|
|
def has_saved_flag?(key)
|
|
has_css?(".admin-flag-item.#{key}.saved")
|
|
end
|
|
|
|
def has_closed_flag_menu?
|
|
has_no_css?(".flag-menu-content")
|
|
end
|
|
|
|
def move_down(key)
|
|
open_flag_menu(key)
|
|
find(".admin-flag-item__move-down").click
|
|
has_closed_flag_menu?
|
|
self
|
|
end
|
|
|
|
def move_up(key)
|
|
open_flag_menu(key)
|
|
find(".admin-flag-item__move-up").click
|
|
has_closed_flag_menu?
|
|
self
|
|
end
|
|
|
|
def click_add_flag
|
|
find(".admin-flags__header-add-flag").click
|
|
self
|
|
end
|
|
|
|
def click_edit_flag(key)
|
|
find(".#{key} .admin-flag-item__edit").click
|
|
self
|
|
end
|
|
|
|
def click_delete_flag(key)
|
|
find(".#{key} .flag-menu-trigger").click
|
|
find(".admin-flag-item__delete").click
|
|
self
|
|
end
|
|
|
|
def confirm_delete
|
|
find(".dialog-footer .btn-primary").click
|
|
self
|
|
end
|
|
end
|
|
end
|
|
end
|