Module: TramwayHelpers

Defined in:
lib/tramway/spec/helpers/tramway_helpers.rb

Instance Method Summary collapse

Instance Method Details

#click_on_association_delete_button(object) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/tramway/spec/helpers/tramway_helpers.rb', line 4

def click_on_association_delete_button(object)
  delete_path = ::Tramway::Engine.routes.url_helpers.record_path(
    object.id,
    model: object.class
  )
  row = find("td[colspan='2'] td a[href='#{delete_path}']").parent_node(level: 2)
  row.find('td button.delete[type="submit"]').click
end

#click_on_delete_button(object) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/tramway/spec/helpers/tramway_helpers.rb', line 21

def click_on_delete_button(object)
  delete_path = ::Tramway::Engine.routes.url_helpers.record_path(
    object.id,
    model: object.class
  )
  form = find("form[action='#{delete_path}']")
  form.find('button[type="submit"]').click
end

#click_on_tab(text) ⇒ Object



13
14
15
# File 'lib/tramway/spec/helpers/tramway_helpers.rb', line 13

def click_on_tab(text)
  find('li.nav-item a.nav-link', text: text).click
end

#click_on_table_item(text) ⇒ Object



17
18
19
# File 'lib/tramway/spec/helpers/tramway_helpers.rb', line 17

def click_on_table_item(text)
  find('table td a', text: text).click
end

#fill_in_ckeditor(name, with:) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/tramway/spec/helpers/tramway_helpers.rb', line 30

def fill_in_ckeditor(name, with:)
  id = name.gsub(']', '').split('[').join('_')
  content = with.to_json # convert to a safe javascript string
  page.execute_script "    CKEDITOR.instances['\#{id}'].setData(\#{content});\n    $('textarea#\#{id}').text(\#{content});\n  SCRIPT\nend\n"

#fill_in_datepicker(name, with:) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/tramway/spec/helpers/tramway_helpers.rb', line 39

def fill_in_datepicker(name, with:)
  return unless with.present?

  input = find("input[name=#{name.gsub('[', '\[').gsub(']', '\]')}]")
  input.click

  find('td.day', text: /^#{with.day}$/, match: :first).click
end