Alan Guo Xiang Tan 7fdede9f0f
DEV: Speed up slow system tests (#21803)
What is the problem?

Prior to this change, we had a `has_css?(context + ":not(.is-expanded)"`
check when using the select-kit component page object. The problem here
is that this check will end up waiting the full capybara default wait
time if the select-kit has already been expanded. It turns out that we
were calling this check alot of times when the select-kit has already
been expanded resulting in many tests waiting the full default wait
time.

What is the fix?

The fix here is to specify the `wait: 0` option such that we do not wait
and fundamentally, there is no need for us to wait at all here.
2023-05-29 13:31:02 +08:00

73 lines
1.7 KiB
Ruby

# frozen_string_literal: true
module PageObjects
module Components
class SelectKit < PageObjects::Components::Base
attr_reader :context
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)")
end
def is_expanded?
has_css?(context + ".is-expanded")
end
def is_collapsed?
has_css?(context + ":not(.is-expanded)", wait: 0)
end
def has_selected_value?(value)
component.find(".select-kit-header[data-value='#{value}']")
end
def has_selected_name?(value)
component.find(".select-kit-header[data-name='#{value}']")
end
def expand
collapsed_component.find(":not(.is-expanded) .select-kit-header").click
expanded_component
end
def collapse
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)
end
def select_row_by_value(value)
expanded_component.find(".select-kit-row[data-value='#{value}']").click
end
def select_row_by_name(name)
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?
end
end
end
end