effective_test_bot 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5f5f5c2542da07000f1d5a44c7f221e8c21445bc
4
- data.tar.gz: 3304a80e911d3d33c3bb8ba53425ddad434c7a3c
3
+ metadata.gz: 974ef4a9d6b759cc434619a082215a74c9823904
4
+ data.tar.gz: 224d534f49202c588dc33d98284358dcdc249c99
5
5
  SHA512:
6
- metadata.gz: 732e7628a607983ae21eb7b06a3cb4391252d2685152c3263c3f7c518183f7eb4cbb8d12ce9935d5f99e3790a1880a0e9abb1066d99e5614768751e7801a5194
7
- data.tar.gz: a846a8e053b03809e4b267282d38ca27832cf0b36b4136f3ba771f2627f8e8bf1fc88c8f282bbb99c8f502f6d19a4f69200bfb613582fefd2caf40b372c7b37c
6
+ metadata.gz: 4fbbc8bee9fcfc819818edafe8dd8e6c1fc9aa33242e3e5137dcbd6e9f06d657fbfb9ee200fc102f1594882c714fb66a537c6b2b650b009fbee273611b170ee1
7
+ data.tar.gz: e186e7db807007b73033ad7b254b9961617f450aea119f754d77f505bc772425b75ff3d460722ed758dfc34262e3045aa2c5b92b57d63ef5c06b3c97970421ea
data/README.md CHANGED
@@ -114,7 +114,7 @@ The following assertions are added for use in any integration test:
114
114
 
115
115
  - `assert_assigns` asserts a given rails view_assigns object is present.
116
116
  - `assert_assigns_errors` use after an intentionally invalid form submit to make sure your assigned rails object has errors, or a specific error.
117
- - `assert_authorization` checks for a 403 Access Denied error. For this to work, please add `assign_test_bot_access_denied_exception(exception) if defined?(EffectiveTestBot)` to your ApplicationController's `rescue_from` block to generate more information.
117
+ - `assert_authorization` checks for a 403 Access Denied error. For this to work, please add `assign_test_bot_access_denied_exception(exception) if defined?(EffectiveTestBot)` to the bottom of your ApplicationController's `rescue_from` block, after the respond_to, to generate more information.
118
118
  - `assert_no_assigns_errors` should be used after any form submit to make sure your assigned rails object has no errors. Prints out any errors if they exist.
119
119
  - `assert_current_path(path)` asserts the current page path.
120
120
  - `assert_email(action)` asserts an email with the given action name was sent. Also supports `assert_email(to: email)` type syntax with to, from, subject, body.
@@ -1,7 +1,18 @@
1
1
  require 'test_helper'
2
2
 
3
+ require 'capybara'
4
+ require 'selenium-webdriver'
5
+
6
+ Capybara.register_driver :effective_headless do |app|
7
+ options = Selenium::WebDriver::Chrome::Options.new
8
+
9
+ ['headless', 'disable-gpu', 'window-size=1366x1366'].each { |arg| options.add_argument(arg) }
10
+
11
+ Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
12
+ end
13
+
3
14
  class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
4
- driven_by :selenium_chrome_headless, screen_size: [1366, 768]
15
+ driven_by :effective_headless
5
16
 
6
17
  include Warden::Test::Helpers if defined?(Devise)
7
18
  include EffectiveTestBot::DSL
@@ -29,5 +29,10 @@ module EffectiveTestBot
29
29
  include TestBotable::RedirectDsl
30
30
  include TestBotable::WizardDsl
31
31
  end
32
+
33
+ def absolute_image_path
34
+ Rails.root.join("tmp/screenshots/#{image_name.gsub('/', '-')}.png")
35
+ end
36
+
32
37
  end
33
38
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveTestBot
2
- VERSION = '1.0.2'.freeze
2
+ VERSION = '1.0.3'.freeze
3
3
  end
@@ -208,9 +208,9 @@ module EffectiveTestBotFormFiller
208
208
 
209
209
  when 'input_file'
210
210
  if field['class'].to_s.include?('asset-box-uploader-fileinput')
211
- "#{File.dirname(__FILE__)}/../fixtures/documents._test"
211
+ "#{File.dirname(__FILE__).sub('test/support', 'test/fixtures')}/documents._test"
212
212
  else
213
- "#{File.dirname(__FILE__)}/../fixtures/logo.png"
213
+ "#{File.dirname(__FILE__).sub('test/support', 'test/fixtures')}/logo.png"
214
214
  end
215
215
 
216
216
  when 'input_number'
@@ -392,6 +392,10 @@ module EffectiveTestBotFormFiller
392
392
  end
393
393
  end
394
394
 
395
+ def clear_effective_select(field)
396
+ page.execute_script("try { $('select##{field['id']}').val('').trigger('change.select2'); } catch(e) {};")
397
+ end
398
+
395
399
  def close_effective_date_time_picker(field)
396
400
  page.execute_script("try { $('input##{field['id']}').data('DateTimePicker').hide(); } catch(e) {};")
397
401
  end
@@ -46,11 +46,11 @@ module EffectiveTestBotFormHelper
46
46
  def clear_form
47
47
  all('input,select,textarea').each do |field|
48
48
  if field.tag_name == 'select' && field['class'].to_s.include?('select2') # effective_select
49
- within(field.query_scope) { first(:css, '.select2-selection__clear').try(:click) }
49
+ clear_effective_select(field)
50
50
  end
51
51
 
52
52
  begin
53
- field.set('');
53
+ field.set('')
54
54
  close_effective_date_time_picker(field) if field['class'].to_s.include?('effective_date')
55
55
  save_test_bot_screenshot if EffectiveTestBot.tour_mode_extreme?
56
56
  rescue => e; end
@@ -63,7 +63,7 @@ module EffectiveTestBotFormHelper
63
63
  # This kind of sucks, as we want to simulate mouse movements with the tour
64
64
  # Instead we manually trigger submit buttons and use the data-disable-with to
65
65
  # make the 'submit form' step look nice
66
- def click_submit(label, last: false, debug: false)
66
+ def click_submit(label = nil, last: false, debug: false)
67
67
  submit = find_submit(label, last: last)
68
68
 
69
69
  if EffectiveTestBot.screenshots?
@@ -85,7 +85,7 @@ module EffectiveTestBotFormHelper
85
85
  end
86
86
 
87
87
  # Keys are :value, should be one of :count, :minimum, :maximum, :between, :text, :id, :class, :visible, :exact, :exact_text, :match, :wait, :filter_se
88
- def find_submit(label, last: false)
88
+ def find_submit(label = nil, last: false)
89
89
  submit = nil
90
90
 
91
91
  if label.present?
@@ -80,18 +80,10 @@ module BaseTest
80
80
  # Try to find a link_to_delete already on this page
81
81
  # Otherwise create one
82
82
  # Returns the link element
83
- def find_or_create_rails_ujs_link_to_delete(resource)
84
- selector = "a[href='#{resource_path(resource)}'][data-method='delete']"
85
- link_to_delete = page.document.all(selector, visible: false).first # could be nil, but this is a non-blocking selector
86
-
87
- if link_to_delete.present? # Take excessive efforts to ensure it's visible and clickable
88
- page.execute_script("$('body').prepend($(\"#{selector}\").first().clone().show().removeProp('disabled').html('Delete'));")
89
- else # Create our own link
90
- page.execute_script("$('body').prepend($('<a>').attr({href: '#{resource_path(resource)}', 'data-method': 'delete', 'data-confirm': 'Are you sure?'}).html('Delete'));")
91
- end
83
+ def create_rails_ujs_link_to_delete(resource)
84
+ selector = "a[href='#{destroy_resource_path(resource)}'][data-method='delete']"
92
85
 
93
- # capybara-webkit doesn't seem to stop on the alert 'Are you sure?'.
94
- # Otherwise we'd want to take a screenshot of it
86
+ page.execute_script("$('body').prepend($('<a>').attr({href: '#{destroy_resource_path(resource)}', 'data-method': 'delete'}).html('Delete'));")
95
87
 
96
88
  (page.document.first(:css, selector) rescue nil)
97
89
  end
@@ -115,4 +107,9 @@ module BaseTest
115
107
  def edit_resource_path(resource) # edit
116
108
  effective_resource.action_path(:edit, resource)
117
109
  end
110
+
111
+ def destroy_resource_path(resource)
112
+ effective_resource.action_path(:destroy, resource)
113
+ end
114
+
118
115
  end
@@ -67,7 +67,10 @@ module CrudTest
67
67
  assert_assigns_errors(resource_name) unless test_bot_skip?(:assigns_errors)
68
68
 
69
69
  assert_equal(before[:count], after[:count], "Expected #{resource_class}.count to be unchanged") if resource_class.respond_to?(:count)
70
- assert_equal(resources_path, page.current_path, "(path) Expected current_path to match resource #create path #{resources_path}") unless test_bot_skip?(:path)
70
+
71
+ if resources_path.present? && !test_bot_skip?(:path)
72
+ assert_equal(resources_path, page.current_path, "(path) Expected current_path to match resource #create path #{resources_path}")
73
+ end
71
74
 
72
75
  assert_flash(:danger) unless test_bot_skip?(:flash)
73
76
  end
@@ -150,13 +153,14 @@ module CrudTest
150
153
  assert_assigns(resource_name) unless test_bot_skip?(:assigns)
151
154
  assert_assigns_errors(resource_name) unless test_bot_skip?(:assigns_errors)
152
155
 
153
- assert_equal(resource_path(resource), page.current_path, "(path) Expected current_path to match resource #update path") unless test_bot_skip?(:path)
156
+ if effective_resource.action_path(:update, resource) && !test_bot_skip?(:path)
157
+ assert_equal(effective_resource.action_path(:update, resource), page.current_path, "(path) Expected current_path to match resource #update path") unless test_bot_skip?(:path)
158
+ end
154
159
 
155
160
  assert_equal before[:count], after[:count], "Expected: #{resource_class}.count to be unchanged"
156
161
  assert_equal(before[:updated_at], after[:updated_at], "(updated_at) Expected @#{resource_name}.updated_at to be unchanged") if (resource.respond_to?(:updated_at) && !test_bot_skip?(:updated_at))
157
162
 
158
163
  assert_flash(:danger) unless test_bot_skip?(:flash)
159
-
160
164
  end
161
165
 
162
166
  def test_bot_update_valid_test
@@ -203,7 +207,7 @@ module CrudTest
203
207
  visit(resources_path)
204
208
  save_test_bot_screenshot
205
209
 
206
- link_to_delete = find_or_create_rails_ujs_link_to_delete(resource)
210
+ link_to_delete = create_rails_ujs_link_to_delete(resource)
207
211
 
208
212
  if link_to_delete.present? && (link_to_delete.click() rescue false)
209
213
  synchronize!
@@ -217,7 +221,7 @@ module CrudTest
217
221
  # So we just assert the 200 status code, and page title present manually
218
222
  # Javascript errors cannot be detected
219
223
 
220
- visit_delete(resource_path(resource), user)
224
+ visit_delete(destroy_resource_path(resource), user)
221
225
  assert_equal(200, @visit_delete_page.try(:status_code), '(page_status) Expected 200 HTTP status code') unless test_bot_skip?(:page_status)
222
226
  assert((@visit_delete_page.find(:xpath, '//title', visible: false) rescue nil).present?, '(page_title) Expected page title to be present') unless test_bot_skip?(:page_title)
223
227
  end
@@ -57,9 +57,10 @@ module DeviseTest
57
57
 
58
58
  within_if('form#new_user', !test_bot_skip?(:form)) do
59
59
  fill_form(email: email, password: 'not-correct-password')
60
- submit_form
60
+ submit_novalidate_form
61
61
  end
62
62
 
63
+ assert_assigns_errors(:user)
63
64
  assert_page_normal
64
65
 
65
66
  assert_signed_out
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_test_bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-25 00:00:00.000000000 Z
11
+ date: 2018-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails