capybara_active_admin 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 16668060b6810df687cbcfd8757396b2ff13c9f98519090928308f872609017f
4
- data.tar.gz: 6f005ee3bcf21792abf5246d284802aa1ae52544c1547cd9f1ca0ece36ef6e99
3
+ metadata.gz: 4da4f63c41b38a64d538b7b68481643e46b1889fbe0872aed20f382e141a0775
4
+ data.tar.gz: 84731f3fc29c973dec00c1def2f2796de9635850012f99f7bcd5788f0425ffd6
5
5
  SHA512:
6
- metadata.gz: 9488c08a71f94b535a4723fce444cb5a4bbf804c34c3e9593e10849925476e7294a47db30420669fbe87aa38bc2e8bfb249f0b7312e67c6c9057678eea82eea8
7
- data.tar.gz: 3bdf50dc809f1515e64bc73a46d622cb540342ef8da2e587ff9627f9018eee75565b5402c692eb23ad97030f07c7e47249535b961de2e0f3173e85627a003f8a
6
+ metadata.gz: 98c30e82888cee2fd037151143fe0123427d322a8953bcc62d662654d98424a98bfe936ed7bc9ec0b4d0dbcb26ceae55f07c710b6ecb8fbee34368ddd88e1d7a
7
+ data.tar.gz: 6afe3d0d6568155abb51806a61fbbba2aa161a05d42b91faedec5690d5bda399024a9e3b865078bc65cb5501ecd2f825764d2cdc010388f5b2c973b2e4287408
data/CHANGELOG.md CHANGED
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.3.0] - 2020-04-15
10
+ ### Added
11
+ - implement DSL for tabs, batch actions, modal dialog, attributes table, panel, sidebar, footer
12
+ - improve form DSL
13
+
9
14
  ## [0.2.1] - 2020-04-14
10
15
  ### Fixed
11
16
  - `table_selector`, `within_table_for` incorrect resource name
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'capybara/active_admin/version'
4
+ require 'capybara/active_admin/util'
4
5
  require 'capybara/active_admin/selectors'
5
6
  require 'capybara/active_admin/finders'
6
7
  require 'capybara/active_admin/matchers'
@@ -9,6 +9,23 @@ module Capybara
9
9
  click_link(title, options)
10
10
  end
11
11
  end
12
+
13
+ def switch_tab(tab_name, options = {})
14
+ opts = Util.options_with_text(tab_name, options)
15
+ find(tab_header_link_selector, opts).click
16
+ end
17
+
18
+ def click_batch_action(title)
19
+ find(batch_actions_button_selector).click
20
+ within(dropdown_list_selector) do
21
+ selector = batch_action_selector(title)
22
+ find(selector).click
23
+ end
24
+ end
25
+
26
+ def confirm_modal_dialog
27
+ within_modal_dialog { click_button 'OK' }
28
+ end
12
29
  end
13
30
  end
14
31
  end
@@ -4,7 +4,13 @@ module Capybara
4
4
  module ActiveAdmin
5
5
  module Finders
6
6
  module AttributesTable
7
- # todo
7
+ # @param model_name [Class<Object>, nil] model name or class.
8
+ # @param record_id [String, Numeric, nil]
9
+ # @yield within attributes table
10
+ def within_attributes_table_for(model_name, record_id = nil)
11
+ selector = attributes_table_selector(model_name, record_id)
12
+ within(selector) { yield }
13
+ end
8
14
  end
9
15
  end
10
16
  end
@@ -5,6 +5,7 @@ module Capybara
5
5
  module Finders
6
6
  module Form
7
7
  # @param name [Class<Object>, String] form record class or model name
8
+ # @yield within form
8
9
  def within_form_for(name)
9
10
  name = name.model_name.singular if name.is_a?(Class)
10
11
  selector = form_selector(name)
@@ -20,6 +21,20 @@ module Capybara
20
21
 
21
22
  within(fieldset) { yield }
22
23
  end
24
+
25
+ def find_input(label, options = {})
26
+ label_opts = Util.options_with_text label, options.slice(:exact)
27
+ label_node = find(label_selector, label_opts)
28
+
29
+ input_id = label_node[:for]
30
+ opts = options.except(:exact)
31
+ find("##{input_id}", opts)
32
+ end
33
+
34
+ def within_filters
35
+ selector = filter_form_selector
36
+ within(selector) { yield }
37
+ end
23
38
  end
24
39
  end
25
40
  end
@@ -4,7 +4,36 @@ module Capybara
4
4
  module ActiveAdmin
5
5
  module Finders
6
6
  module Layout
7
- # todo
7
+ def find_footer(options = {})
8
+ selector = footer_selector
9
+ have_selector(selector, options)
10
+ end
11
+
12
+ def within_tab_body
13
+ selector = tab_content_selector
14
+ within(selector) { yield }
15
+ end
16
+
17
+ def within_sidebar(title, exact: nil)
18
+ selector = sidebar_selector
19
+
20
+ within(selector) do
21
+ within_panel(title, exact: exact) { yield }
22
+ end
23
+ end
24
+
25
+ def within_panel(title, exact: nil)
26
+ title_selector = "#{panel_selector} > #{panel_title_selector}"
27
+ title_opts = Util.options_with_text(title, exact: exact)
28
+ panel_title = find(title_selector, title_opts)
29
+ panel_content = panel_title.sibling(panel_content_selector)
30
+
31
+ within(panel_content) { yield }
32
+ end
33
+
34
+ def within_modal_dialog
35
+ within(modal_dialog_selector) { yield }
36
+ end
8
37
  end
9
38
  end
10
39
  end
@@ -10,7 +10,7 @@ module Capybara
10
10
 
11
11
  # @param model_name [Class<#model_name>, String] records class or model name to match rows.
12
12
  # @param resource_name [String, nil] resource name of index page.
13
- # @yield within table.
13
+ # @yield within table
14
14
  def within_table_for(model_name, resource_name = nil)
15
15
  selector = table_selector(resource_name)
16
16
 
@@ -25,6 +25,9 @@ module Capybara
25
25
  end
26
26
  end
27
27
 
28
+ # id [String, Integer, nil] record ID.
29
+ # index [Integer] row index in table (starts with 0).
30
+ # @yield within table>tbody>tr
28
31
  def within_table_row(id: nil, index: nil)
29
32
  row = find_table_row(id: id, index: index)
30
33
  within(row) { yield }
@@ -43,6 +46,7 @@ module Capybara
43
46
  find_all(selector, minimum: index + 1)[index]
44
47
  end
45
48
 
49
+ # @yield within table>tbody>tr>td
46
50
  def within_table_cell(name)
47
51
  cell = find_table_cell(name)
48
52
  within(cell) { yield }
@@ -4,7 +4,17 @@ module Capybara
4
4
  module ActiveAdmin
5
5
  module Matchers
6
6
  module AttributesTable
7
- # todo
7
+ def have_attributes_table(options = {})
8
+ model_name = options.delete(:model)
9
+ record_id = options.delete(:id)
10
+ selector = attributes_table_selector(model_name, record_id)
11
+ have_selector(selector, options)
12
+ end
13
+
14
+ def have_attribute_row(label, options = {})
15
+ selector = attributes_row_selector(label)
16
+ have_selector(selector, options)
17
+ end
8
18
  end
9
19
  end
10
20
  end
@@ -4,27 +4,23 @@ module Capybara
4
4
  module ActiveAdmin
5
5
  module Matchers
6
6
  module Form
7
- def have_form_error(error, options = {})
7
+ def have_form_error(text, options = {})
8
8
  field = options.delete(:field)
9
- opts = options.merge(text: error)
10
- return have_selector("li #{inline_error_selector}", opts) if field.nil?
9
+ opts = Util.options_with_text(text, options)
10
+ li_selector = input_container_selector field, options.slice(:exact)
11
11
 
12
- label = find(label_selector, text: field)
13
- li_id = label.ancestor('li')[:id]
14
- have_selector("li##{li_id} #{inline_error_selector}", opts)
12
+ have_selector("#{li_selector} #{inline_error_selector}", opts)
15
13
  end
16
14
 
17
15
  def have_no_form_errors(options = {})
18
16
  field = options.delete(:field)
19
- return have_none_of_selectors(:css, "li #{inline_error_selector}", options) if field.nil?
17
+ li_selector = input_container_selector field, options.slice(:exact)
20
18
 
21
- label = find(label_selector, text: field)
22
- li_id = label.ancestor('li')[:id]
23
- have_none_of_selectors(:css, "li##{li_id} #{inline_error_selector}", options)
19
+ have_none_of_selectors(:css, "#{li_selector} #{inline_error_selector}", options)
24
20
  end
25
21
 
26
- def have_semantic_error(error, options = {})
27
- opts = options.merge(text: error)
22
+ def have_semantic_error(text, options = {})
23
+ opts = Util.options_with_text(text, options)
28
24
  have_selector(semantic_error_selector, opts)
29
25
  end
30
26
 
@@ -32,8 +28,8 @@ module Capybara
32
28
  have_selector(semantic_error_selector, options)
33
29
  end
34
30
 
35
- def have_no_input(label, options = {})
36
- opts = options.merge(text: label)
31
+ def have_no_input(text, options = {})
32
+ opts = Util.options_with_text(text, options)
37
33
  have_none_of_selectors(:css, label_selector, opts)
38
34
  end
39
35
 
@@ -42,8 +38,8 @@ module Capybara
42
38
  have_selector(selector, options)
43
39
  end
44
40
 
45
- def have_input(label, options = {})
46
- selector = input_selector label, options.slice(:type, :text)
41
+ def have_input(text, options = {})
42
+ selector = input_selector text, options.slice(:type, :text)
47
43
  opts = options.except(:type, :text)
48
44
  have_selector(selector, opts)
49
45
  end
@@ -5,21 +5,38 @@ module Capybara
5
5
  module Matchers
6
6
  module Layout
7
7
  def have_action_item(text, options = {})
8
- opts = options.merge(text: text)
8
+ opts = Util.options_with_text(text, options)
9
9
  have_selector(action_item_selector, opts)
10
10
  end
11
11
 
12
12
  def have_page_title(text, options = {})
13
- opts = options.merge(text: text)
13
+ opts = Util.options_with_text(text, options)
14
14
  have_selector(page_title_selector, opts)
15
15
  end
16
16
 
17
17
  def have_flash_message(text, options = {})
18
18
  type = options.delete(:type)
19
- opts = options.merge(text: text)
19
+ opts = Util.options_with_text(text, options)
20
20
  selector = flash_message_selector(type)
21
21
  have_selector(selector, opts)
22
22
  end
23
+
24
+ def have_footer(options = {})
25
+ selector = footer_selector
26
+ have_selector(selector, options)
27
+ end
28
+
29
+ def have_panel(title, options = {})
30
+ title_selector = "#{panel_selector} > #{panel_title_selector}"
31
+ opts = Util.options_with_text(title, options)
32
+ have_selector(title_selector, opts)
33
+ end
34
+
35
+ def have_sidebar(title, options = {})
36
+ title_selector = "#{sidebar_selector} #{panel_selector} > #{panel_title_selector}"
37
+ opts = Util.options_with_text(title, options)
38
+ have_selector(title_selector, opts)
39
+ end
23
40
  end
24
41
  end
25
42
  end
@@ -19,6 +19,7 @@ module Capybara
19
19
 
20
20
  # @param options [Hash]
21
21
  # :text [String, nil] cell content
22
+ # :exact_text [String, nil] cell content exact matching
22
23
  # :id [String, Number, nil] record ID
23
24
  # for other options @see Capybara::RSpecMatchers#have_selector
24
25
  # @example
@@ -33,7 +34,8 @@ module Capybara
33
34
  end
34
35
 
35
36
  # @param options [Hash]
36
- # :text [String, nil] cell content
37
+ # :text [String, nil] cell content include matching
38
+ # :exact_text [String, nil] cell content exact matching
37
39
  # :column [String, nil] cell header name
38
40
  # for other options @see Capybara::RSpecMatchers#have_selector
39
41
  # @example
@@ -4,7 +4,21 @@ module Capybara
4
4
  module ActiveAdmin
5
5
  module Selectors
6
6
  module AttributesTable
7
- # todo
7
+ def attributes_table_selector(model_name, record_id = nil)
8
+ return 'div.attributes_table' if model_name.nil?
9
+
10
+ model_name = Util.parse_model_name(model_name)
11
+ selector = "div.attributes_table.#{model_name}"
12
+ selector += "#attributes_table_#{model_name}_#{record_id}" if record_id
13
+ selector
14
+ end
15
+
16
+ def attributes_row_selector(label)
17
+ return 'tr.row > td' if label.nil?
18
+
19
+ label = label.to_s.gsub(' ', '_').downcase
20
+ "tr.row.row-#{label} > td"
21
+ end
8
22
  end
9
23
  end
10
24
  end
@@ -44,6 +44,19 @@ module Capybara
44
44
  selector = %(#{selector}[value="#{text}"]) unless text.nil?
45
45
  selector
46
46
  end
47
+
48
+ def input_container_selector(label, exact: nil)
49
+ return 'li' if label.nil?
50
+
51
+ label_opts = Util.options_with_text(label, exact: exact)
52
+ label_node = find(label_selector, label_opts)
53
+ li_id = label_node.ancestor('li')[:id]
54
+ "li##{li_id}"
55
+ end
56
+
57
+ def filter_form_selector
58
+ '.filter_form'
59
+ end
47
60
  end
48
61
  end
49
62
  end
@@ -21,6 +21,50 @@ module Capybara
21
21
 
22
22
  '.flashes .flash'
23
23
  end
24
+
25
+ def footer_selector
26
+ 'div.footer#footer'
27
+ end
28
+
29
+ def tab_header_link_selector
30
+ '.tabs.ui-tabs li.ui-tabs-tab a'
31
+ end
32
+
33
+ def tab_content_selector
34
+ '.tab-content'
35
+ end
36
+
37
+ def sidebar_selector
38
+ '#sidebar'
39
+ end
40
+
41
+ def panel_selector
42
+ '.panel'
43
+ end
44
+
45
+ def panel_title_selector
46
+ 'h3'
47
+ end
48
+
49
+ def panel_content_selector
50
+ '.panel_contents'
51
+ end
52
+
53
+ def batch_actions_button_selector
54
+ 'div.batch_actions_selector'
55
+ end
56
+
57
+ def dropdown_list_selector
58
+ 'ul.dropdown_menu_list'
59
+ end
60
+
61
+ def batch_action_selector(title)
62
+ "li a[data-action='#{title}']"
63
+ end
64
+
65
+ def modal_dialog_selector
66
+ '.active_admin_dialog'
67
+ end
24
68
  end
25
69
  end
26
70
  end
@@ -14,8 +14,7 @@ module Capybara
14
14
  def table_row_selector(model_name, record_id)
15
15
  return 'tbody > tr' if record_id.nil?
16
16
 
17
- model_name = model_name.model_name.singular if model_name.is_a?(Class)
18
- model_name = model_name.to_s.gsub(' ', '_').singularize.downcase
17
+ model_name = Util.parse_model_name(model_name)
19
18
  "tbody > tr##{model_name}_#{record_id}"
20
19
  end
21
20
 
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Capybara
4
+ module ActiveAdmin
5
+ module Util
6
+ # Common pure utility functions
7
+
8
+ def parse_model_name(model_name, singular: true)
9
+ return if model_name.nil?
10
+
11
+ model_name = model_name.model_name.singular if model_name.is_a?(Class)
12
+ model_name = model_name.to_s.gsub(' ', '_').downcase
13
+ singular ? model_name.singularize : model_name.pluralize
14
+ end
15
+
16
+ def options_with_text(text, options = {})
17
+ key = options[:exact] ? :exact_text : :text
18
+
19
+ options.except(:exact).merge(key => text)
20
+ end
21
+
22
+ module_function :parse_model_name, :options_with_text
23
+ end
24
+ end
25
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Capybara
4
4
  module ActiveAdmin
5
- VERSION = '0.2.1'
5
+ VERSION = '0.3.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capybara_active_admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Talakevich
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-14 00:00:00.000000000 Z
11
+ date: 2020-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeadmin
@@ -81,6 +81,7 @@ files:
81
81
  - lib/capybara/active_admin/selectors/layout.rb
82
82
  - lib/capybara/active_admin/selectors/table.rb
83
83
  - lib/capybara/active_admin/test_helpers.rb
84
+ - lib/capybara/active_admin/util.rb
84
85
  - lib/capybara/active_admin/version.rb
85
86
  - lib/capybara_active_admin.rb
86
87
  homepage: https://github.com/active_admin_plugins/capybara_active_admin