Class: WithForm::ScopeForm

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::TranslationHelper, TranslationHelpers
Defined in:
lib/with_form/scope_form.rb

Instance Method Summary collapse

Constructor Details

#initialize(scope:, page:) ⇒ ScopeForm

Returns a new instance of ScopeForm.



10
11
12
13
# File 'lib/with_form/scope_form.rb', line 10

def initialize(scope:, page:)
  @page = page
  @scope = scope
end

Instance Method Details

#attach_file(attribute, path, **options) ⇒ Object



60
61
62
# File 'lib/with_form/scope_form.rb', line 60

def attach_file(attribute, path, **options)
  @page.attach_file label(attribute), path, **options
end

#check(attribute, **options) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/with_form/scope_form.rb', line 15

def check(attribute, **options)
  case attribute
  when Symbol
    value = label(attribute)
  else
    value = attribute
  end

  @page.check value, **options
end

#click_button(action = nil, **options) ⇒ Object



64
65
66
# File 'lib/with_form/scope_form.rb', line 64

def click_button(action = nil, **options)
  @page.click_button submit(action), **options
end

#fill_in(attribute, with:, **options) ⇒ Object



37
38
39
# File 'lib/with_form/scope_form.rb', line 37

def fill_in(attribute, with:, **options)
  @page.fill_in label(attribute), with: with, **options
end

#fill_in_rich_text_area(locator = nil, with:) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/with_form/scope_form.rb', line 41

def fill_in_rich_text_area(locator = nil, with:)
  fill_in_script = <<~JS
    this.editor.loadHTML(arguments[0])
  JS

  @page.find(:rich_text_area, label(locator)).execute_script(
    fill_in_script,
    with.to_s,
  )
end

#label(attribute) ⇒ Object



72
73
74
# File 'lib/with_form/scope_form.rb', line 72

def label(attribute)
  super(@scope, attribute)
end

#select(value, from:, **options) ⇒ Object



52
53
54
# File 'lib/with_form/scope_form.rb', line 52

def select(value, from:, **options)
  @page.select value, from: label(from), **options
end

#submit(action = nil) ⇒ Object



68
69
70
# File 'lib/with_form/scope_form.rb', line 68

def submit(action = nil)
  super(@scope, action || :submit)
end

#uncheck(attribute, **options) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/with_form/scope_form.rb', line 26

def uncheck(attribute, **options)
  case attribute
  when Symbol
    value = label(attribute)
  else
    value = attribute
  end

  @page.uncheck value, **options
end

#unselect(value, from:, **options) ⇒ Object



56
57
58
# File 'lib/with_form/scope_form.rb', line 56

def unselect(value, from:, **options)
  @page.unselect value, from: label(from), **options
end