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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
def has_selected_name?(value)
|
2023-05-28 21:35:55 +08:00
|
|
|
component.find(".select-kit-header[data-name='#{value}']")
|
2023-03-14 18:46:05 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def expand
|
2023-05-28 21:35:55 +08:00
|
|
|
collapsed_component.find(":not(.is-expanded) .select-kit-header").click
|
|
|
|
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
|