-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathfeature_helpers.rb
More file actions
71 lines (60 loc) · 2.06 KB
/
feature_helpers.rb
File metadata and controls
71 lines (60 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# frozen_string_literal: true
module SolidusAdmin
module TestingSupport
module FeatureHelpers
def sign_in(user)
allow_any_instance_of(SolidusAdmin::BaseController).to receive(:spree_current_user).and_return(user)
end
def stub_authorization!(user)
ability = Spree::Ability.new(user)
if block_given?
yield ability
else
ability.can :manage, :all
end
allow_any_instance_of(SolidusAdmin::BaseController).to receive(:current_ability).and_return(ability)
allow_any_instance_of(Spree::Admin::BaseController).to receive(:current_ability).and_return(ability)
end
def find_row(text)
find('table tbody tr td', text:)
end
def find_row_checkbox(text)
find('table tbody tr', text:).find('td:first-child input[type="checkbox"]')
end
def select_row(text)
find_row_checkbox(text).tap do |checkbox|
checkbox.check
checkbox.synchronize { checkbox.checked? }
end
end
# Select options from a "solidus-select" field
#
# @param value [String, Array<String>] which option(s) to select
# @param from [String] label of the select box
def solidus_select(value, from:)
input = find_field(from, visible: :all)
control = input.ancestor(".control")
dropdown = control.sibling(".dropdown", visible: :all)
# Make sure options are loaded
control.click
within(dropdown) { expect(first(".option", visible: :all)).to be }
Array.wrap(value).each do |val|
input.fill_in(with: val).send_keys(:return)
expect(control).to have_text(val)
end
end
def checkbox(locator)
find(:checkbox, locator)
end
def clear_search
within('div[role="search"]') do
find('button[aria-label="Clear"]').click
end
end
def switch(locator, on: true)
checkbox = find(:label, text: locator).find(:checkbox)
on ? checkbox.check : checkbox.uncheck
end
end
end
end