Skip to content
This repository has been archived by the owner on Aug 10, 2021. It is now read-only.

Commit

Permalink
Adjust spec and add select2 helper for spec
Browse files Browse the repository at this point in the history
  • Loading branch information
przemosk committed Oct 20, 2020
1 parent 064377e commit ba07480
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
12 changes: 9 additions & 3 deletions spec/features/admin/editor_settings_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
RSpec.feature 'Rich Editor Settings', :js do
RSpec.feature 'Rich Editor Settings', js: true do
include ::Select2Helper

stub_authorization!

context '#edit' do
Expand Down Expand Up @@ -26,9 +28,11 @@
scenario 'will be applied when used' do
visit spree.edit_admin_editor_settings_path

select2 'TinyMCE', from: 'Rich Editor engine'
select2_choose('current_editor', choose: 'TinyMCE')
click_button 'Update'

expect(page).to have_content('successfully updated!')

visit spree.edit_admin_product_path(product)
expect(page).to have_css '.mce-tinymce', match: :one
end
Expand All @@ -38,9 +42,11 @@
scenario 'will be applied when used' do
visit spree.edit_admin_editor_settings_path

select2 'CKEditor', from: 'Rich Editor engine'
select2_choose('current_editor', choose: 'CKEditor')
click_button 'Update'

expect(page).to have_content('successfully updated!')

visit spree.edit_admin_product_path(product)
expect(page).to have_css '.cke_editor_product_description', match: :one
end
Expand Down
18 changes: 18 additions & 0 deletions spec/support/select2_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Select2Helper
def select2_choose(id, options)
options[:query] ||= options[:choose]

page.execute_script %Q{
$('#s2id_#{id} .select2-offscreen')
.trigger('keydown')
.val('#{options[:query]}')
.trigger('keyup');
}

if options[:first]
find('.select2-highlighted .select2-match').click
else
find('.select2-result-label', text: options[:choose]).click
end
end
end

0 comments on commit ba07480

Please sign in to comment.