Class: Repla::Test::LogHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/repla/logger/test/lib/log_helper.rb

Overview

Log helper

Constant Summary collapse

TEST_CLASS_JAVASCRIPT =
'document.body.lastChild.classList[0]'.freeze
TEST_MESSAGE_JAVASCRIPT =
'document.body.lastChild.innerText'.freeze
TEST_MESSAGE_COUNT_JAVASCRIPT =
'document.body.children.length'.freeze
TEST_JAVASCRIPT_DIRECTORY =
File.join(__dir__, '..', 'js')
TEST_JAVASCRIPT_FILE =
File.join(TEST_JAVASCRIPT_DIRECTORY,
'test_view_helper.js')

Instance Method Summary collapse

Constructor Details

#initialize(window_id, view_id = nil) ⇒ LogHelper

Returns a new instance of LogHelper.



14
15
16
17
18
19
# File 'lib/repla/logger/test/lib/log_helper.rb', line 14

def initialize(window_id, view_id = nil)
  view_id ||= Repla.split_id_in_window_last(window_id)
  @view = Repla::View.new(window_id, view_id)
  javascript = File.read(TEST_JAVASCRIPT_FILE)
  @view.do_javascript(javascript)
end

Instance Method Details

#last_log_classObject



37
38
39
# File 'lib/repla/logger/test/lib/log_helper.rb', line 37

def last_log_class
  @view.do_javascript(TEST_CLASS_JAVASCRIPT)
end

#last_log_messageObject



33
34
35
# File 'lib/repla/logger/test/lib/log_helper.rb', line 33

def last_log_message
  @view.do_javascript(TEST_MESSAGE_JAVASCRIPT)
end

#log_class_at(index) ⇒ Object



25
26
27
# File 'lib/repla/logger/test/lib/log_helper.rb', line 25

def log_class_at(index)
  @view.do_javascript_function('classOfBodyChildAtIndex', [index])
end

#log_message_at(index) ⇒ Object



21
22
23
# File 'lib/repla/logger/test/lib/log_helper.rb', line 21

def log_message_at(index)
  @view.do_javascript_function('innerTextOfBodyChildAtIndex', [index])
end

#number_of_log_messagesObject



29
30
31
# File 'lib/repla/logger/test/lib/log_helper.rb', line 29

def number_of_log_messages
  @view.do_javascript(TEST_MESSAGE_COUNT_JAVASCRIPT)
end