Last active
April 24, 2017 13:18
-
-
Save mttdffy/77d924435958a547834e to your computer and use it in GitHub Desktop.
Revisions
-
mttdffy revised this gist
Jun 4, 2014 . 1 changed file with 14 additions and 18 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,11 +18,11 @@ module JQueryUI # @return nil # def autocomplete(field, options = {}) fill_in(field, with: options.delete(:with)) expect(page).not_to have_selector 'html.loading' page.execute_script(%{ $('##{field}').trigger('focus') }) page.execute_script(%{ $('##{field}').trigger('keydown') }) if text = options.delete(:select) selector = %{ ul.ui-autocomplete li.ui-menu-item a:contains('#{text}') } @@ -31,7 +31,7 @@ def autocomplete(field, options = {}) end page.should have_selector('ul.ui-autocomplete li.ui-menu-item a') page.execute_script(%{ $("#{selector}").trigger('mouseenter').click() }) end # find a datetimepicker field and set the datetime @@ -40,13 +40,13 @@ def autocomplete(field, options = {}) # @param [Hash] options options for setting the value # @param options [String] :from the id of the field to set datetime on # # @example # datetimepick(2.days.from_now, from: 'event_start_datetime') # # @return nil # def datetimepick(datetime, options = {}) set_datetimepicker_value(datetime, "##{options.delete(:from)}", 'datetimepicker') end # find a datepicker field and set the date @@ -55,13 +55,13 @@ def datetimepick(datetime, options = {}) # @param [Hash] options options for setting the value # @param options [String] :from the id of the field to set date on # # @example # datepick(Date.tomorrow, from: 'event_start_date') # # @return nil # def datepick(date, options = {}) set_datetimepicker_value(date, "##{options.delete(:from)}", 'datepicker') end # find a timepicker field and set the time @@ -70,25 +70,21 @@ def datepick(date, options = {}) # @param [Hash] options options for setting the value # @param options [String] :from the id of the field to set time on # # @example # timepick(12.hours.from_now, from: 'event_start_time') # # @return nil # def timepick(time, options = {}) set_datetimepicker_value(time, "##{options.delete(:from)}", 'timepicker') end private def set_datetimepicker_value(datetime, selector, widget) js_date_object = "new Date(#{datetime.to_i * 1000})" page.execute_script(%{ $("#{selector}").#{widget}("setDate", #{js_date_object})}) end end end -
mttdffy revised this gist
Jun 4, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -79,7 +79,7 @@ def timepick(time, options = {}) date_and_or_time_pick(time, "##{options.delete(:from)}", 'timepicker', options) end private def date_and_or_time_pick(date_and_or_time, selector, widget, options = {}) js_value = if date_and_or_time.is_a? Date or date_and_or_time.is_a? Time -
mttdffy revised this gist
Jun 4, 2014 . 1 changed file with 15 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,6 +9,12 @@ module JQueryUI # @param options [String] :select the text value of the autocomplete resuilt you # want to pick. If this option is not present, the first result will be picked. # # @example Auto-select first result # autocomplete('product_search', with: 'example') # # @example Select specific result # autocomplete('product_search', with: 'example', select: 'example product 12') # # @return nil # def autocomplete(field, options = {}) @@ -34,6 +40,9 @@ def autocomplete(field, options = {}) # @param [Hash] options options for setting the value # @param options [String] :from the id of the field to set datetime on # # @example Using ActiveSupport syntax # datetimepick(2.days.from_now, from: 'event_start_datetime') # # @return nil # def datetimepick(datetime, options = {}) @@ -46,6 +55,9 @@ def datetimepick(datetime, options = {}) # @param [Hash] options options for setting the value # @param options [String] :from the id of the field to set date on # # @example Using ActiveSupport syntax # datepick(Date.tomorrow, from: 'event_start_date') # # @return nil # def datepick(date, options = {}) @@ -58,6 +70,9 @@ def datepick(date, options = {}) # @param [Hash] options options for setting the value # @param options [String] :from the id of the field to set time on # # @example Using ActiveSupport syntax # timepick(12.hours.from_now, from: 'event_start_time') # # @return nil # def timepick(time, options = {}) @@ -77,4 +92,3 @@ def date_and_or_time_pick(date_and_or_time, selector, widget, options = {}) end end end -
mttdffy revised this gist
Jun 4, 2014 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ # adds helpers to rspec whenever test is run with js: true flag RSpec.configure do |config| config.include(JSHelpers::JQueryUI, js: true) end -
mttdffy created this gist
Jun 4, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,80 @@ module JSHelpers module JQueryUI # type inside an autocomplete field and pick a value. # # @param [String] field selector of the autocomplete field # @param [Hash] options details about what to search and what to select # @param options [String] :with the text to type in the autocomplete field # @param options [String] :select the text value of the autocomplete resuilt you # want to pick. If this option is not present, the first result will be picked. # # @return nil # def autocomplete(field, options = {}) fill_in field, with: options.delete(:with) expect(page).not_to have_selector 'html.loading' page.execute_script %{ $('##{field}').trigger('focus') } page.execute_script %{ $('##{field}').trigger('keydown') } if text = options.delete(:select) selector = %{ ul.ui-autocomplete li.ui-menu-item a:contains('#{text}') } else selector = %{ ul.ui-autocomplete li.ui-menu-item:first-child a } end page.should have_selector('ul.ui-autocomplete li.ui-menu-item a') page.execute_script %{ $("#{selector}").trigger('mouseenter').click() } end # find a datetimepicker field and set the datetime # # @param [DateTime] datetime datetime to set to # @param [Hash] options options for setting the value # @param options [String] :from the id of the field to set datetime on # # @return nil # def datetimepick(datetime, options = {}) date_and_or_time_pick(datetime, "##{options.delete(:from)}", 'datetimepicker', options) end # find a datepicker field and set the date # # @param [Date] date date to set to # @param [Hash] options options for setting the value # @param options [String] :from the id of the field to set date on # # @return nil # def datepick(date, options = {}) date_and_or_time_pick(date, "##{options.delete(:from)}", 'datepicker', options) end # find a timepicker field and set the time # # @param [Time] time time to set to # @param [Hash] options options for setting the value # @param options [String] :from the id of the field to set time on # # @return nil # def timepick(time, options = {}) date_and_or_time_pick(time, "##{options.delete(:from)}", 'timepicker', options) end private def date_and_or_time_pick(date_and_or_time, selector, widget, options = {}) js_value = if date_and_or_time.is_a? Date or date_and_or_time.is_a? Time "new Date(#{date_and_or_time.to_i * 1000})" else date_and_or_time.to_json end page.execute_script(%{ $("#{selector}").#{widget}("setDate", #{js_value})}) end end end