Module: Ontra::React::Common::Capybara::Helpers

Defined in:
lib/ontra/react/common/capybara/helpers.rb,
lib/ontra/react/common/capybara/helpers/version.rb

Overview

Helpers for capybara tests to intereact and assert ontra-react-common components.

Defined Under Namespace

Classes: Error

Constant Summary collapse

VERSION =
"0.1.3"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.clear_table_filter(filter_id, drawer: false) ⇒ Object



88
89
90
91
92
# File 'lib/ontra/react/common/capybara/helpers.rb', line 88

def clear_table_filter(filter_id, drawer: false)
  open_table_filter(filter_id, drawer: drawer)
  page.find("[data-testid=#{filter_id}-options] li", exact_text: "Any").click
  click_button("View Results") if drawer
end

.open_table_filter(filter_id, drawer: false) ⇒ Object



83
84
85
86
# File 'lib/ontra/react/common/capybara/helpers.rb', line 83

def open_table_filter(filter_id, drawer: false)
  click_button("More Filter") if drawer
  page.find("[data-testid=#{filter_id}] > button").click
end

.select_option_in_table_filter(filter_id, option, drawer: false) ⇒ Object



102
103
104
105
106
107
# File 'lib/ontra/react/common/capybara/helpers.rb', line 102

def select_option_in_table_filter(filter_id, option, drawer: false)
  open_table_filter(filter_id, drawer: drawer)
  expect(option).not_to be == "Any"
  page.find("[data-testid=#{filter_id}-options] li p", exact_text: option).click
  click_button("View Results") if drawer
end

.sort_table_by(header) ⇒ Object



113
114
115
# File 'lib/ontra/react/common/capybara/helpers.rb', line 113

def sort_table_by(header)
  within("table thead") { click_button(header) }
end

.table_filter_have_selected_value(filter_id, option, drawer: false) ⇒ Object



94
95
96
97
98
99
100
# File 'lib/ontra/react/common/capybara/helpers.rb', line 94

def table_filter_have_selected_value(filter_id, option, drawer: false)
  click_button("More Filter") if drawer
  within(page.find("[data-testid=#{filter_id}]")) do
    expect(page).to have_content(option)
  end
  click_button("View Results") if drawer
end

.table_next_pageObject



109
110
111
# File 'lib/ontra/react/common/capybara/helpers.rb', line 109

def table_next_page
  page.all("[data-testid=filters-pagination] [data-testid=chevronRight-icon]")[0].click
end

Instance Method Details

#react_all(component_name, **props) ⇒ Object



27
28
29
# File 'lib/ontra/react/common/capybara/helpers.rb', line 27

def react_all(component_name, **props)
  all(react_selector(component_name, **props))
end

#react_assert_checked(component_name, **props) ⇒ Object



67
68
69
# File 'lib/ontra/react/common/capybara/helpers.rb', line 67

def react_assert_checked(component_name, **props)
  expect(react_find(component_name, **props)).to be_checked
end

#react_assert_disabled(component_name, **props) ⇒ Object



75
76
77
# File 'lib/ontra/react/common/capybara/helpers.rb', line 75

def react_assert_disabled(component_name, **props)
  expect(react_find(component_name, **props)).to be_disabled
end

#react_assert_no_text(component_name, text:, **props) ⇒ Object



55
56
57
# File 'lib/ontra/react/common/capybara/helpers.rb', line 55

def react_assert_no_text(component_name, text:, **props)
  expect(react_find(component_name, **props)).not_to have_text(text)
end

#react_assert_not_checked(component_name, **props) ⇒ Object



71
72
73
# File 'lib/ontra/react/common/capybara/helpers.rb', line 71

def react_assert_not_checked(component_name, **props)
  expect(react_find(component_name, **props)).not_to be_checked
end

#react_assert_not_disabled(component_name, **props) ⇒ Object



79
80
81
# File 'lib/ontra/react/common/capybara/helpers.rb', line 79

def react_assert_not_disabled(component_name, **props)
  expect(react_find(component_name, **props)).not_to be_disabled
end

#react_assert_not_visible(component_name, **props) ⇒ Object



63
64
65
# File 'lib/ontra/react/common/capybara/helpers.rb', line 63

def react_assert_not_visible(component_name, **props)
  expect(react_find(component_name, **props)).not_to be_visible
end

#react_assert_text(component_name, text:, **props) ⇒ Object



51
52
53
# File 'lib/ontra/react/common/capybara/helpers.rb', line 51

def react_assert_text(component_name, text:, **props)
  expect(react_find(component_name, **props)).to have_text(text)
end

#react_assert_visible(component_name, **props) ⇒ Object



59
60
61
# File 'lib/ontra/react/common/capybara/helpers.rb', line 59

def react_assert_visible(component_name, **props)
  expect(react_find(component_name, **props)).to be_visible
end

#react_check(component_name, **props) ⇒ Object



43
44
45
# File 'lib/ontra/react/common/capybara/helpers.rb', line 43

def react_check(component_name, **props)
  react_find(component_name, **props).check
end

#react_click(component_name, **props) ⇒ Object



31
32
33
# File 'lib/ontra/react/common/capybara/helpers.rb', line 31

def react_click(component_name, **props)
  react_find(component_name, **props).click
end

#react_component(component_name, **props) ⇒ Object



14
15
16
17
# File 'lib/ontra/react/common/capybara/helpers.rb', line 14

def react_component(component_name, **props)
  data = { component: component_name, props: props }
  "data-react-component=#{data.to_json}"
end

#react_fill_in(component_name, with:, **props) ⇒ Object



35
36
37
# File 'lib/ontra/react/common/capybara/helpers.rb', line 35

def react_fill_in(component_name, with:, **props)
  react_find(component_name, **props).fill_in(with: with)
end

#react_find(component_name, **props) ⇒ Object



23
24
25
# File 'lib/ontra/react/common/capybara/helpers.rb', line 23

def react_find(component_name, **props)
  find(react_selector(component_name, **props))
end

#react_select(component_name, option:, **props) ⇒ Object



39
40
41
# File 'lib/ontra/react/common/capybara/helpers.rb', line 39

def react_select(component_name, option:, **props)
  react_find(component_name, **props).select(option)
end

#react_selector(component_name, **props) ⇒ Object



19
20
21
# File 'lib/ontra/react/common/capybara/helpers.rb', line 19

def react_selector(component_name, **props)
  "[#{react_component(component_name, **props)}]"
end

#react_uncheck(component_name, **props) ⇒ Object



47
48
49
# File 'lib/ontra/react/common/capybara/helpers.rb', line 47

def react_uncheck(component_name, **props)
  react_find(component_name, **props).uncheck
end