discourse/spec/system/page_objects/components/select_kit.rb
Joffrey JAFFEUX 9392bd0f79
DEV: fix tag synonyms flakey specs (#21787)
The fix use the SelectKit component in the spec and improves reliability of SelectKit component to ensure expanded/collapsed state effectively set/present.

Multiple lines have also been removed as they are not necessary, eg: 

- check button is present
- click button

The check is un-necesssary as we won't find the button on click if not present. This kind of checks are only necessary when another element has to be present before the button is show, eg:

- check modal is displayed
- click button

FInally this commit changes the way the SelectKit component initializes component and now uses a css selector instead of a finder, it ensures we are always getting fresh object and allows to build complete selectors: ".context[data-id=1].foo:enabled"
2023-05-28 15:35:55 +02: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)")
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