Sha256: a5facbb4448685f8a62ff79b2b30176ddfd24b57997bb8354048f9861da6d51a
Contents?: true
Size: 1.16 KB
Versions: 42
Compression:
Stored size: 1.16 KB
Contents
module Coco module TestHelpers NESTED_TAG_ATTRS = %w[data test_data x] def create_class(name, parent) klass = Class.new(parent) Object.const_set(name, klass) klass end def assert_component_selector(name, text: nil, visible: nil, **) assert_selector(component_selector(name, **), text: text, visible: visible) end def component_selector(name, **opts) attr_selector = build_attr_selector(opts.except(:append, :tag)) "#{opts[:tag]}[data-component='#{name}']#{attr_selector}#{opts[:append]}".strip end def build_attr_selector(attrs) tag_attrs = attrs.except(*NESTED_TAG_ATTRS) NESTED_TAG_ATTRS.each do |key| subattrs = attrs.fetch(key, {}) tag_attrs.merge!(prefix_keys(subattrs, key)) end attrs.reduce("") do |str, (key, value)| if value.is_a?(Hash) value.each do |k, v| str += "[#{key}-#{k}='#{v}']" end else str += "[#{key}='#{value}']" end str end end def prefix_keys(attrs, prefix) attrs.transform_keys! { [prefix, _1].map(&:to_s).join("-").tr("_", "-") } end end end
Version data entries
42 entries across 42 versions & 1 rubygems