lib/et_test_helpers/common.rb
# Helper to provide the correct component class for use as the second parameter to the section method in site prism
# @param [String,Symbol] type - The type of component eg :text_field
# @return [::EtTestHelpers::Components::GovUKTextField] - This can be many types
Helper to provide the correct component class for use as the second parameter to the section method in site prism
Helper to provide the correct component class for use as the second parameter to the section method in site prism
def govuk_component(type, scope: nil)
        component_classname = "GovUK#{type.to_s.camelize}"
        klass_name = "::EtTestHelpers::Components::#{component_classname}"
        klass      = klass_name.safe_constantize
        raise "Unknown govuk_component with a type of '#{type}' - it should be defined as '#{klass_name}'" if klass.nil?
        if scope.nil?
          klass
        else
          wrapper_classname = "#{component_classname}Wrapper#{(Time.now.to_f * 1000000).to_i}"
          class_eval <<-CODE, __FILE__, __LINE__ + 1
            class ::EtTestHelpers::Components::#{wrapper_classname} < #{klass_name}
              cattr_accessor :govuk_component_args
              self.govuk_component_args = ['#{type}', :'#{scope}']
              def inspect
                "govuk_component('#{type}', :'#{scope}'}) #{klass_name} \#{super}"
              end
              def i18n_scope
                t(govuk_component_args.second)
              end
              def root_scope
                i18n_scope.tap do |value|
                  unless value.is_a?(Hash)
                    raise "#{scope} must contain at least label in the i18n file"
                  end
                end
              end
            end
          CODE
          ::EtTestHelpers::Components.const_get(wrapper_classname)
        end
      end
def govuk_component ( type , scope : nil ) component_classname = "GovUK#{type.to_s.camelize}" klass_name = "::EtTestHelpers::Components::#{component_classname}" klass = klass_name . safe_constantize raise "Unknown govuk_component with a type of '#{type}' - it should be defined as '#{klass_name}'" if klass . nil? if scope . nil? klass else wrapper_classname = "#{component_classname}Wrapper#{(Time.now.to_f * 1000000).to_i}" class_eval <<-CODE , __FILE__ , __LINE__ + 1 
            class ::EtTestHelpers::Components:: #{ wrapper_classname }  <  #{ klass_name } 
              cattr_accessor :govuk_component_args
              self.govuk_component_args = [' #{ type } ', :' #{ scope } ']

              def inspect
                "govuk_component(' #{ type } ', :' #{ scope } '})  #{ klass_name } \# {super}"
              end

              def i18n_scope
                t(govuk_component_args.second)
              end

              def root_scope
                i18n_scope.tap do |value|
                  unless value.is_a?(Hash)
                    raise " #{ scope }  must contain at least label in the i18n file"
                  end
                end
              end
            end
           CODE :: EtTestHelpers :: Components . const_get ( wrapper_classname ) end end
Helper to provide the correct component class for use as the second parameter to the section method in site prism
Helper to provide the correct component class for use as the second parameter to the section method in site prism
This can be many types
This can be many types
::EtTestHelpers::Components::GovUKTextField
type
<not_specific>
scope
<not_specific>
<not_specific>
The type of component eg :text_field
The type of component eg : text_field