Class: Interfacets::Test::UiSimulator

Inherits:
Object
  • Object
show all
Defined in:
lib/interfacets/test/ui_simulator.rb

Constant Summary collapse

TYPES =
{
  inline: Js::InlineBus,
  nodo: Js::NodoBus,
  mruby_wasm: Js::NodoBus,
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, bus:, router:, contract_path: nil, validation: :strict) ⇒ UiSimulator

Returns a new instance of UiSimulator.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/interfacets/test/ui_simulator.rb', line 12

def initialize(type:, bus:, router:, contract_path: nil, validation: :strict)
  unless TYPES.keys.include?(type)
    raise ArgumentError.new(
      "type: #{type.inspect} not allowed. Must be one of #{TYPES.keys}"
    )
  end

  @type = type
  # Serialize and deserialize to ensure proper data structure for JS
  @system_json = JSON.parse(bus.client_system_json(only_facets: type == :inline).to_json)
  @router = router
  @contract_path = contract_path
  @validation = validation
end

Instance Attribute Details

#contract_path ⇒ Object (readonly)

Returns the value of attribute contract_path.



11
12
13
# File 'lib/interfacets/test/ui_simulator.rb', line 11

def contract_path
  @contract_path
end

#router ⇒ Object (readonly)

Returns the value of attribute router.



11
12
13
# File 'lib/interfacets/test/ui_simulator.rb', line 11

def router
  @router
end

#system_json ⇒ Object (readonly)

Returns the value of attribute system_json.



11
12
13
# File 'lib/interfacets/test/ui_simulator.rb', line 11

def system_json
  @system_json
end

#type ⇒ Object (readonly)

Returns the value of attribute type.



11
12
13
# File 'lib/interfacets/test/ui_simulator.rb', line 11

def type
  @type
end

#validation ⇒ Object (readonly)

Returns the value of attribute validation.



11
12
13
# File 'lib/interfacets/test/ui_simulator.rb', line 11

def validation
  @validation
end

Instance Method Details

#c(channel_id) ⇒ Object



33
34
35
# File 'lib/interfacets/test/ui_simulator.rb', line 33

def c(channel_id)
  js.handler(channel_id)
end

#dispatch(channel_id, event) ⇒ Object



37
38
39
# File 'lib/interfacets/test/ui_simulator.rb', line 37

def dispatch(channel_id, event)
  js.dispatch(channel_id, event)
end

#dom ⇒ Object



45
46
47
# File 'lib/interfacets/test/ui_simulator.rb', line 45

def dom
  c("dom")
end

#timers ⇒ Object



49
50
51
# File 'lib/interfacets/test/ui_simulator.rb', line 49

def timers
  c("timer")
end

#url ⇒ Object



41
42
43
# File 'lib/interfacets/test/ui_simulator.rb', line 41

def url
  c("url")
end

#visit(path) ⇒ Object



27
28
29
30
31
# File 'lib/interfacets/test/ui_simulator.rb', line 27

def visit(path)
  js.init(
    hydrated_facet: router.call(path).render
  )
end