Module: Capybara::ScopesPicker

Includes:
DataPicker
Defined in:
decidim-dev/lib/decidim/dev/test/rspec_support/capybara_scopes_picker.rb

Instance Method Summary collapse

Methods included from DataPicker

#data_picker_choose_value, #data_picker_close, #data_picker_pick_current, #find_data_picker, #select_data_picker

Instance Method Details

#scope_pick(scope_picker, scope) ⇒ Object


28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'decidim-dev/lib/decidim/dev/test/rspec_support/capybara_scopes_picker.rb', line 28

def scope_pick(scope_picker, scope)
  data_picker = scope_picker.data_picker
  # use scope_repick to change single scope picker selected scope
  expect(data_picker).to have_selector(".picker-values:empty", visible: :all) if data_picker.has_css?(".picker-single")

  expect(data_picker).to have_selector(".picker-prompt")
  data_picker.find(".picker-prompt").click

  scope_picker_browse_scopes(scope.part_of_scopes) if scope
  data_picker_pick_current

  expect(scope_picker).to have_scope_picked(scope)
end

#scope_repick(element_id, old_scope, new_scope) ⇒ Object


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'decidim-dev/lib/decidim/dev/test/rspec_support/capybara_scopes_picker.rb', line 42

def scope_repick(element_id, old_scope, new_scope)
  scope_picker = select_data_picker(element_id)

  data_picker = scope_picker.data_picker

  expect(data_picker).to have_selector(".picker-values div input[value='#{old_scope&.id || scope_picker.global_value}']", visible: :all)
  data_picker.find(:xpath, "//div[contains(@class,'picker-values')]/div/input[@value='#{old_scope&.id || scope_picker.global_value}']/../a").click

  # browse to lowest common parent between old and new scope
  parent_scope = (old_scope.part_of_scopes & new_scope.part_of_scopes).last

  scope_picker_browse_scope(parent_scope, back: true)
  scope_picker_browse_scopes(new_scope.part_of_scopes - old_scope.part_of_scopes)
  data_picker_pick_current

  scope_picker = select_data_picker(element_id)

  expect(scope_picker).to have_scope_picked(new_scope)
end

#scope_unpick(scope_picker, scope) ⇒ Object


62
63
64
65
66
67
68
69
# File 'decidim-dev/lib/decidim/dev/test/rspec_support/capybara_scopes_picker.rb', line 62

def scope_unpick(scope_picker, scope)
  data_picker = scope_picker.data_picker

  expect(data_picker).to have_selector(".picker-values div input[value='#{scope&.id || scope_picker.global_value}']", visible: :all)
  data_picker.find(".picker-values div input[value='#{scope&.id || scope_picker.global_value}']").click

  expect(scope_picker).to have_scope_not_picked(scope)
end