2023-03-14 18:46:05 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module PageObjects
|
|
|
|
module Components
|
|
|
|
class SelectKit < PageObjects::Components::Base
|
2023-05-28 21:35:55 +08:00
|
|
|
attr_reader :context
|
2023-03-14 18:46:05 +08:00
|
|
|
|
2023-05-28 21:35:55 +08:00
|
|
|
def initialize(context)
|
|
|
|
@context = context
|
|
|
|
end
|
|
|
|
|
|
|
|
def component
|
|
|
|
find(@context)
|
|
|
|
end
|
|
|
|
|
2023-08-09 05:45:04 +08:00
|
|
|
def visible?
|
|
|
|
has_css?(@context)
|
|
|
|
end
|
|
|
|
|
|
|
|
def hidden?
|
|
|
|
has_no_css?(@context)
|
|
|
|
end
|
|
|
|
|
2023-05-28 21:35:55 +08:00
|
|
|
def expanded_component
|
|
|
|
expand_if_needed
|
|
|
|
find(@context + ".is-expanded")
|
|
|
|
end
|
|
|
|
|
|
|
|
def collapsed_component
|
|
|
|
find(@context + ":not(.is-expanded)")
|
2023-03-14 18:46:05 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def is_expanded?
|
2023-05-28 21:35:55 +08:00
|
|
|
has_css?(context + ".is-expanded")
|
2023-03-14 18:46:05 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def is_collapsed?
|
2023-05-29 13:31:02 +08:00
|
|
|
has_css?(context + ":not(.is-expanded)", wait: 0)
|
2023-03-14 18:46:05 +08:00
|
|
|
end
|
|
|
|
|
2023-10-23 08:35:40 +08:00
|
|
|
def is_not_disabled?
|
|
|
|
has_css?(@context + ":not(.disabled)", wait: 0)
|
|
|
|
end
|
|
|
|
|
2023-03-14 18:46:05 +08:00
|
|
|
def has_selected_value?(value)
|
2023-05-28 21:35:55 +08:00
|
|
|
component.find(".select-kit-header[data-value='#{value}']")
|
2023-03-14 18:46:05 +08:00
|
|
|
end
|
|
|
|
|
2023-05-30 05:47:18 +08:00
|
|
|
def has_selected_name?(name)
|
|
|
|
component.find(".select-kit-header[data-name='#{name}']")
|
|
|
|
end
|
|
|
|
|
|
|
|
def has_selected_choice_name?(name)
|
|
|
|
component.find(".selected-choice[data-name='#{name}']")
|
|
|
|
end
|
|
|
|
|
|
|
|
def has_option_name?(name)
|
|
|
|
component.find(".select-kit-collection li[data-name='#{name}']")
|
2023-03-14 18:46:05 +08:00
|
|
|
end
|
|
|
|
|
2024-03-06 07:04:05 +08:00
|
|
|
def has_option_value?(value)
|
|
|
|
component.find(".select-kit-collection li[data-value='#{value}']")
|
|
|
|
end
|
|
|
|
|
2023-03-14 18:46:05 +08:00
|
|
|
def expand
|
2023-05-29 16:48:59 +08:00
|
|
|
collapsed_component.find(":not(.is-expanded) .select-kit-header", visible: :all).click
|
2023-05-28 21:35:55 +08:00
|
|
|
expanded_component
|
2023-03-14 18:46:05 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def collapse
|
2023-05-28 21:35:55 +08:00
|
|
|
expanded_component.find(".is-expanded .select-kit-header").click
|
|
|
|
collapsed_component
|
|
|
|
end
|
|
|
|
|
|
|
|
def search(value = nil)
|
|
|
|
expanded_component.find(".select-kit-filter .filter-input").fill_in(with: value)
|
2023-03-14 18:46:05 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def select_row_by_value(value)
|
2023-05-28 21:35:55 +08:00
|
|
|
expanded_component.find(".select-kit-row[data-value='#{value}']").click
|
2023-03-14 18:46:05 +08:00
|
|
|
end
|
2023-04-17 16:48:41 +08:00
|
|
|
|
|
|
|
def select_row_by_name(name)
|
2023-05-28 21:35:55 +08:00
|
|
|
expanded_component.find(".select-kit-row[data-name='#{name}']").click
|
|
|
|
end
|
|
|
|
|
|
|
|
def select_row_by_index(index)
|
|
|
|
expanded_component.find(".select-kit-row[data-index='#{index}']").click
|
|
|
|
end
|
|
|
|
|
|
|
|
def expand_if_needed
|
|
|
|
expand if is_collapsed?
|
2023-04-17 16:48:41 +08:00
|
|
|
end
|
2023-03-14 18:46:05 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|