unpoly-rails 0.61.0 → 2.0.0.pre.rc3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of unpoly-rails might be problematic. Click here for more details.

Files changed (340) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -1
  3. data/CHANGELOG.md +94 -1
  4. data/README.md +3 -11
  5. data/README_RAILS.md +295 -14
  6. data/dist/unpoly-bootstrap3.css +9 -14
  7. data/dist/unpoly-bootstrap3.js +4 -18
  8. data/dist/unpoly-bootstrap3.min.css +1 -1
  9. data/dist/unpoly-bootstrap3.min.js +1 -1
  10. data/dist/unpoly-bootstrap4.css +9 -0
  11. data/dist/unpoly-bootstrap4.js +16 -0
  12. data/dist/unpoly-bootstrap4.min.css +1 -0
  13. data/dist/unpoly-bootstrap4.min.js +1 -0
  14. data/dist/unpoly-bootstrap5.css +9 -0
  15. data/dist/unpoly-bootstrap5.js +14 -0
  16. data/dist/unpoly-bootstrap5.min.css +1 -0
  17. data/dist/unpoly-bootstrap5.min.js +1 -0
  18. data/dist/unpoly-migrate.js +1213 -0
  19. data/dist/unpoly-migrate.min.js +1 -0
  20. data/dist/unpoly.css +109 -140
  21. data/dist/unpoly.js +15439 -10434
  22. data/dist/unpoly.min.css +1 -1
  23. data/dist/unpoly.min.js +6 -4
  24. data/lib/unpoly-rails.rb +9 -3
  25. data/lib/unpoly/rails/change.rb +372 -0
  26. data/lib/unpoly/rails/change/cache.rb +26 -0
  27. data/lib/unpoly/rails/change/context.rb +80 -0
  28. data/lib/unpoly/rails/change/field.rb +117 -0
  29. data/lib/unpoly/rails/change/field_definition.rb +74 -0
  30. data/lib/unpoly/rails/change/layer.rb +60 -0
  31. data/lib/unpoly/rails/controller.rb +47 -0
  32. data/lib/unpoly/rails/error.rb +5 -0
  33. data/lib/unpoly/rails/request_echo_headers.rb +2 -2
  34. data/lib/unpoly/rails/version.rb +1 -1
  35. data/lib/unpoly/tasks.rb +45 -0
  36. metadata +43 -314
  37. data/.gitignore +0 -10
  38. data/.ruby-version +0 -2
  39. data/Gemfile +0 -8
  40. data/Gemfile.lock +0 -45
  41. data/Rakefile +0 -144
  42. data/bower.json +0 -27
  43. data/design/animation-ghosting.txt +0 -72
  44. data/design/design.txt +0 -34
  45. data/design/draft.html.erb +0 -48
  46. data/design/draft.rb +0 -9
  47. data/design/es6.js +0 -32
  48. data/design/ghost-debugging.txt +0 -118
  49. data/design/homepage.txt +0 -236
  50. data/design/ie11.txt +0 -9
  51. data/design/measure_import_node.js +0 -330
  52. data/design/measure_jquery/element_list.js +0 -41
  53. data/design/measure_jquery/up.on_vs_addEventListener.js +0 -56
  54. data/design/positioning.txt +0 -28
  55. data/design/query-params-in-form-actions/cases.html +0 -125
  56. data/design/rename.txt +0 -0
  57. data/design/test_rejected_promise.txt +0 -5
  58. data/design/unpoly errors.txt +0 -19
  59. data/lib/assets/javascripts/unpoly-bootstrap3.coffee +0 -2
  60. data/lib/assets/javascripts/unpoly-bootstrap3/feedback-ext.coffee +0 -5
  61. data/lib/assets/javascripts/unpoly-bootstrap3/form-ext.coffee +0 -1
  62. data/lib/assets/javascripts/unpoly-bootstrap3/modal-ext.coffee +0 -14
  63. data/lib/assets/javascripts/unpoly-bootstrap3/viewport-ext.coffee +0 -5
  64. data/lib/assets/javascripts/unpoly.coffee +0 -28
  65. data/lib/assets/javascripts/unpoly/browser.coffee.erb +0 -236
  66. data/lib/assets/javascripts/unpoly/classes/body_shifter.coffee +0 -36
  67. data/lib/assets/javascripts/unpoly/classes/cache.coffee +0 -127
  68. data/lib/assets/javascripts/unpoly/classes/compile_pass.coffee +0 -93
  69. data/lib/assets/javascripts/unpoly/classes/config.coffee +0 -9
  70. data/lib/assets/javascripts/unpoly/classes/css_transition.coffee +0 -118
  71. data/lib/assets/javascripts/unpoly/classes/divertible_chain.coffee +0 -39
  72. data/lib/assets/javascripts/unpoly/classes/event_listener.coffee +0 -116
  73. data/lib/assets/javascripts/unpoly/classes/extract_cascade.coffee +0 -86
  74. data/lib/assets/javascripts/unpoly/classes/extract_plan.coffee +0 -111
  75. data/lib/assets/javascripts/unpoly/classes/field_observer.coffee +0 -80
  76. data/lib/assets/javascripts/unpoly/classes/focus_follower.coffee +0 -29
  77. data/lib/assets/javascripts/unpoly/classes/follow_variant.coffee +0 -56
  78. data/lib/assets/javascripts/unpoly/classes/html_parser.coffee +0 -46
  79. data/lib/assets/javascripts/unpoly/classes/motion_controller.coffee +0 -157
  80. data/lib/assets/javascripts/unpoly/classes/params.coffee.erb +0 -543
  81. data/lib/assets/javascripts/unpoly/classes/record.coffee +0 -22
  82. data/lib/assets/javascripts/unpoly/classes/rect.js +0 -21
  83. data/lib/assets/javascripts/unpoly/classes/request.coffee +0 -246
  84. data/lib/assets/javascripts/unpoly/classes/response.coffee +0 -157
  85. data/lib/assets/javascripts/unpoly/classes/reveal_motion.coffee +0 -102
  86. data/lib/assets/javascripts/unpoly/classes/scroll_motion.coffee +0 -67
  87. data/lib/assets/javascripts/unpoly/classes/selector.coffee +0 -60
  88. data/lib/assets/javascripts/unpoly/classes/store/memory.coffee +0 -26
  89. data/lib/assets/javascripts/unpoly/classes/store/session.coffee +0 -59
  90. data/lib/assets/javascripts/unpoly/classes/tether.coffee +0 -105
  91. data/lib/assets/javascripts/unpoly/classes/url_set.coffee +0 -32
  92. data/lib/assets/javascripts/unpoly/cookie.coffee +0 -56
  93. data/lib/assets/javascripts/unpoly/element.coffee.erb +0 -1126
  94. data/lib/assets/javascripts/unpoly/event.coffee.erb +0 -438
  95. data/lib/assets/javascripts/unpoly/feedback.coffee +0 -353
  96. data/lib/assets/javascripts/unpoly/form.coffee.erb +0 -1032
  97. data/lib/assets/javascripts/unpoly/fragment.coffee.erb +0 -924
  98. data/lib/assets/javascripts/unpoly/framework.coffee +0 -67
  99. data/lib/assets/javascripts/unpoly/history.coffee +0 -268
  100. data/lib/assets/javascripts/unpoly/legacy.coffee +0 -60
  101. data/lib/assets/javascripts/unpoly/link.coffee.erb +0 -622
  102. data/lib/assets/javascripts/unpoly/log.coffee +0 -248
  103. data/lib/assets/javascripts/unpoly/modal.coffee.erb +0 -825
  104. data/lib/assets/javascripts/unpoly/motion.coffee.erb +0 -668
  105. data/lib/assets/javascripts/unpoly/namespace.coffee.erb +0 -5
  106. data/lib/assets/javascripts/unpoly/popup.coffee.erb +0 -515
  107. data/lib/assets/javascripts/unpoly/protocol.coffee +0 -298
  108. data/lib/assets/javascripts/unpoly/proxy.coffee +0 -672
  109. data/lib/assets/javascripts/unpoly/radio.coffee +0 -60
  110. data/lib/assets/javascripts/unpoly/rails.coffee +0 -24
  111. data/lib/assets/javascripts/unpoly/syntax.coffee.erb +0 -477
  112. data/lib/assets/javascripts/unpoly/toast.coffee +0 -67
  113. data/lib/assets/javascripts/unpoly/tooltip.coffee +0 -276
  114. data/lib/assets/javascripts/unpoly/util.coffee.erb +0 -1676
  115. data/lib/assets/javascripts/unpoly/viewport.coffee.erb +0 -806
  116. data/lib/assets/stylesheets/unpoly-bootstrap3.sass +0 -1
  117. data/lib/assets/stylesheets/unpoly-bootstrap3/modal-ext.sass +0 -27
  118. data/lib/assets/stylesheets/unpoly.sass +0 -1
  119. data/lib/assets/stylesheets/unpoly/close.sass +0 -2
  120. data/lib/assets/stylesheets/unpoly/dom.sass +0 -5
  121. data/lib/assets/stylesheets/unpoly/layout.sass +0 -2
  122. data/lib/assets/stylesheets/unpoly/link.sass +0 -2
  123. data/lib/assets/stylesheets/unpoly/modal.sass +0 -116
  124. data/lib/assets/stylesheets/unpoly/popup.sass +0 -7
  125. data/lib/assets/stylesheets/unpoly/toast.sass +0 -33
  126. data/lib/assets/stylesheets/unpoly/tooltip.sass +0 -62
  127. data/lib/unpoly/rails/inspector.rb +0 -149
  128. data/lib/unpoly/rails/inspector_accessor.rb +0 -30
  129. data/package.json +0 -38
  130. data/spec_app/.firefox-version +0 -1
  131. data/spec_app/.gitignore +0 -17
  132. data/spec_app/.rspec +0 -2
  133. data/spec_app/Gemfile +0 -32
  134. data/spec_app/Gemfile.lock +0 -233
  135. data/spec_app/README.rdoc +0 -28
  136. data/spec_app/Rakefile +0 -6
  137. data/spec_app/app/assets/images/.keep +0 -0
  138. data/spec_app/app/assets/images/favicon.png +0 -0
  139. data/spec_app/app/assets/images/grid.png +0 -0
  140. data/spec_app/app/assets/javascripts/bootstrap_manifest.coffee +0 -6
  141. data/spec_app/app/assets/javascripts/integration_test.coffee +0 -6
  142. data/spec_app/app/assets/javascripts/jasmine_specs.coffee +0 -6
  143. data/spec_app/app/assets/stylesheets/_helpers.sass +0 -5
  144. data/spec_app/app/assets/stylesheets/bootstrap_manifest.sass +0 -2
  145. data/spec_app/app/assets/stylesheets/integration_test.sass +0 -88
  146. data/spec_app/app/assets/stylesheets/jasmine_specs.sass +0 -20
  147. data/spec_app/app/controllers/application_controller.rb +0 -14
  148. data/spec_app/app/controllers/binding_test_controller.rb +0 -51
  149. data/spec_app/app/controllers/compiler_test_controller.rb +0 -5
  150. data/spec_app/app/controllers/css_test_controller.rb +0 -5
  151. data/spec_app/app/controllers/error_test_controller.rb +0 -5
  152. data/spec_app/app/controllers/form_test/basics_controller.rb +0 -14
  153. data/spec_app/app/controllers/form_test/redirects_controller.rb +0 -17
  154. data/spec_app/app/controllers/form_test/uploads_controller.rb +0 -15
  155. data/spec_app/app/controllers/hash_test_controller.rb +0 -5
  156. data/spec_app/app/controllers/method_test_controller.rb +0 -16
  157. data/spec_app/app/controllers/motion_test_controller.rb +0 -5
  158. data/spec_app/app/controllers/pages_controller.rb +0 -9
  159. data/spec_app/app/controllers/replace_test_controller.rb +0 -5
  160. data/spec_app/app/controllers/reveal_test_controller.rb +0 -5
  161. data/spec_app/app/controllers/scroll_test_controller.rb +0 -5
  162. data/spec_app/app/helpers/application_helper.rb +0 -2
  163. data/spec_app/app/mailers/.keep +0 -0
  164. data/spec_app/app/models/concerns/.keep +0 -0
  165. data/spec_app/app/views/compiler_test/timestamp.erb +0 -9
  166. data/spec_app/app/views/css_test/modal.erb +0 -47
  167. data/spec_app/app/views/css_test/modal_contents.erb +0 -5
  168. data/spec_app/app/views/css_test/modal_contents_wide.erb +0 -5
  169. data/spec_app/app/views/css_test/popup.erb +0 -81
  170. data/spec_app/app/views/css_test/popup_contents.erb +0 -5
  171. data/spec_app/app/views/css_test/tooltip.erb +0 -48
  172. data/spec_app/app/views/error_test/trigger.erb +0 -80
  173. data/spec_app/app/views/error_test/unexpected_response.erb +0 -3
  174. data/spec_app/app/views/form_test/basics/new.erb +0 -60
  175. data/spec_app/app/views/form_test/redirects/new.erb +0 -27
  176. data/spec_app/app/views/form_test/redirects/target.erb +0 -4
  177. data/spec_app/app/views/form_test/submission_result.erb +0 -30
  178. data/spec_app/app/views/form_test/uploads/new.erb +0 -44
  179. data/spec_app/app/views/hash_test/unpoly.erb +0 -30
  180. data/spec_app/app/views/hash_test/vanilla.erb +0 -13
  181. data/spec_app/app/views/layouts/integration_test.erb +0 -22
  182. data/spec_app/app/views/layouts/jasmine_rails/spec_runner.html.erb +0 -20
  183. data/spec_app/app/views/method_test/form_target.erb +0 -17
  184. data/spec_app/app/views/method_test/page1.erb +0 -11
  185. data/spec_app/app/views/method_test/page2.erb +0 -6
  186. data/spec_app/app/views/motion_test/animations.erb +0 -16
  187. data/spec_app/app/views/motion_test/transitions.erb +0 -13
  188. data/spec_app/app/views/pages/start.erb +0 -79
  189. data/spec_app/app/views/replace_test/_nav.erb +0 -6
  190. data/spec_app/app/views/replace_test/page1.erb +0 -14
  191. data/spec_app/app/views/replace_test/page2.erb +0 -14
  192. data/spec_app/app/views/replace_test/table.erb +0 -16
  193. data/spec_app/app/views/reveal_test/long1.erb +0 -17
  194. data/spec_app/app/views/reveal_test/long2.erb +0 -17
  195. data/spec_app/app/views/reveal_test/within_document_viewport.erb +0 -24
  196. data/spec_app/app/views/reveal_test/within_overflowing_div_viewport.erb +0 -28
  197. data/spec_app/app/views/scroll_test/long1.erb +0 -30
  198. data/spec_app/bin/bundle +0 -3
  199. data/spec_app/bin/rails +0 -8
  200. data/spec_app/bin/rake +0 -8
  201. data/spec_app/bin/setup +0 -29
  202. data/spec_app/bin/spring +0 -18
  203. data/spec_app/config.ru +0 -4
  204. data/spec_app/config/application.rb +0 -28
  205. data/spec_app/config/boot.rb +0 -3
  206. data/spec_app/config/database.yml +0 -25
  207. data/spec_app/config/environment.rb +0 -5
  208. data/spec_app/config/environments/development.rb +0 -41
  209. data/spec_app/config/environments/production.rb +0 -79
  210. data/spec_app/config/environments/test.rb +0 -42
  211. data/spec_app/config/initializers/assets.rb +0 -19
  212. data/spec_app/config/initializers/backtrace_silencers.rb +0 -7
  213. data/spec_app/config/initializers/bower_rails.rb +0 -16
  214. data/spec_app/config/initializers/cookies_serializer.rb +0 -3
  215. data/spec_app/config/initializers/filter_parameter_logging.rb +0 -4
  216. data/spec_app/config/initializers/inflections.rb +0 -16
  217. data/spec_app/config/initializers/mime_types.rb +0 -4
  218. data/spec_app/config/initializers/session_store.rb +0 -3
  219. data/spec_app/config/initializers/wrap_parameters.rb +0 -14
  220. data/spec_app/config/locales/en.yml +0 -23
  221. data/spec_app/config/routes.rb +0 -30
  222. data/spec_app/config/secrets.yml +0 -22
  223. data/spec_app/db/schema.rb +0 -23
  224. data/spec_app/db/seeds.rb +0 -7
  225. data/spec_app/lib/assets/.keep +0 -0
  226. data/spec_app/lib/tasks/.keep +0 -0
  227. data/spec_app/lib/tasks/cucumber.rake +0 -65
  228. data/spec_app/log/.keep +0 -0
  229. data/spec_app/public/404.html +0 -67
  230. data/spec_app/public/422.html +0 -67
  231. data/spec_app/public/500.html +0 -66
  232. data/spec_app/public/favicon.ico +0 -0
  233. data/spec_app/public/robots.txt +0 -5
  234. data/spec_app/script/cucumber +0 -10
  235. data/spec_app/spec/controllers/binding_test_controller_spec.rb +0 -248
  236. data/spec_app/spec/javascripts/helpers/agent_detector.coffee +0 -20
  237. data/spec_app/spec/javascripts/helpers/async_sequence.js.coffee +0 -103
  238. data/spec_app/spec/javascripts/helpers/browser_switches.js.coffee +0 -21
  239. data/spec_app/spec/javascripts/helpers/enable_logging.js.coffee +0 -2
  240. data/spec_app/spec/javascripts/helpers/fixture.js.coffee +0 -25
  241. data/spec_app/spec/javascripts/helpers/index.js.coffee +0 -1
  242. data/spec_app/spec/javascripts/helpers/jquery_no_conflict.js +0 -1
  243. data/spec_app/spec/javascripts/helpers/knife.js.coffee +0 -69
  244. data/spec_app/spec/javascripts/helpers/last_request.js.coffee +0 -25
  245. data/spec_app/spec/javascripts/helpers/mock_ajax.js.coffee +0 -8
  246. data/spec_app/spec/javascripts/helpers/mock_clock.js.coffee +0 -2
  247. data/spec_app/spec/javascripts/helpers/parse_form_data.js.coffee +0 -24
  248. data/spec_app/spec/javascripts/helpers/promise_state.js +0 -18
  249. data/spec_app/spec/javascripts/helpers/protect_jasmine_runner.coffee +0 -12
  250. data/spec_app/spec/javascripts/helpers/remove_body_margin.js.coffee +0 -8
  251. data/spec_app/spec/javascripts/helpers/reset_history.js.coffee +0 -23
  252. data/spec_app/spec/javascripts/helpers/reset_knife.js.coffee +0 -2
  253. data/spec_app/spec/javascripts/helpers/reset_up.js.coffee +0 -25
  254. data/spec_app/spec/javascripts/helpers/restore_body_scroll.js.coffee +0 -5
  255. data/spec_app/spec/javascripts/helpers/show_lib_versions.coffee +0 -12
  256. data/spec_app/spec/javascripts/helpers/spec_util.coffee +0 -47
  257. data/spec_app/spec/javascripts/helpers/to_be_around.js.coffee +0 -8
  258. data/spec_app/spec/javascripts/helpers/to_be_array.coffee +0 -5
  259. data/spec_app/spec/javascripts/helpers/to_be_attached.coffee +0 -9
  260. data/spec_app/spec/javascripts/helpers/to_be_blank.js.coffee +0 -8
  261. data/spec_app/spec/javascripts/helpers/to_be_detached.coffee +0 -9
  262. data/spec_app/spec/javascripts/helpers/to_be_element.js.coffee +0 -8
  263. data/spec_app/spec/javascripts/helpers/to_be_error.coffee +0 -8
  264. data/spec_app/spec/javascripts/helpers/to_be_given.js.coffee +0 -8
  265. data/spec_app/spec/javascripts/helpers/to_be_hidden.js.coffee +0 -8
  266. data/spec_app/spec/javascripts/helpers/to_be_jquery.js.coffee +0 -5
  267. data/spec_app/spec/javascripts/helpers/to_be_missing.js.coffee +0 -8
  268. data/spec_app/spec/javascripts/helpers/to_be_present.js.coffee +0 -8
  269. data/spec_app/spec/javascripts/helpers/to_be_scrolled_to.coffee +0 -11
  270. data/spec_app/spec/javascripts/helpers/to_be_visible.js.coffee +0 -9
  271. data/spec_app/spec/javascripts/helpers/to_contain.js.coffee +0 -8
  272. data/spec_app/spec/javascripts/helpers/to_end_with.js.coffee +0 -11
  273. data/spec_app/spec/javascripts/helpers/to_equal_jquery.js.coffee +0 -8
  274. data/spec_app/spec/javascripts/helpers/to_equal_node_list.coffee +0 -7
  275. data/spec_app/spec/javascripts/helpers/to_equal_via_is_equal.js.coffee +0 -7
  276. data/spec_app/spec/javascripts/helpers/to_have_class.js.coffee +0 -10
  277. data/spec_app/spec/javascripts/helpers/to_have_descendant.js.coffee +0 -10
  278. data/spec_app/spec/javascripts/helpers/to_have_length.js.coffee +0 -8
  279. data/spec_app/spec/javascripts/helpers/to_have_opacity.coffee +0 -15
  280. data/spec_app/spec/javascripts/helpers/to_have_own_property.js.coffee +0 -8
  281. data/spec_app/spec/javascripts/helpers/to_have_request_method.js.coffee +0 -16
  282. data/spec_app/spec/javascripts/helpers/to_have_text.js.coffee +0 -9
  283. data/spec_app/spec/javascripts/helpers/to_have_unhandled_rejections.coffee +0 -18
  284. data/spec_app/spec/javascripts/helpers/to_match_list.coffee +0 -14
  285. data/spec_app/spec/javascripts/helpers/to_match_selector.coffee +0 -8
  286. data/spec_app/spec/javascripts/helpers/to_match_text.js.coffee +0 -13
  287. data/spec_app/spec/javascripts/helpers/to_match_url.coffee +0 -14
  288. data/spec_app/spec/javascripts/helpers/trigger.js.coffee +0 -200
  289. data/spec_app/spec/javascripts/helpers/wait_until_dom_ready.js.coffee +0 -5
  290. data/spec_app/spec/javascripts/support/jasmine.yml +0 -51
  291. data/spec_app/spec/javascripts/up/browser_spec.js.coffee +0 -150
  292. data/spec_app/spec/javascripts/up/classes/cache_spec.js.coffee +0 -82
  293. data/spec_app/spec/javascripts/up/classes/config_spec.coffee +0 -24
  294. data/spec_app/spec/javascripts/up/classes/divertible_chain_spec.coffee +0 -45
  295. data/spec_app/spec/javascripts/up/classes/focus_tracker_spec.coffee +0 -34
  296. data/spec_app/spec/javascripts/up/classes/params_spec.coffee +0 -557
  297. data/spec_app/spec/javascripts/up/classes/request_spec.coffee +0 -50
  298. data/spec_app/spec/javascripts/up/classes/scroll_motion_spec.js.coffee +0 -51
  299. data/spec_app/spec/javascripts/up/classes/store/memory_spec.js.coffee +0 -70
  300. data/spec_app/spec/javascripts/up/classes/store/session_spec.js.coffee +0 -114
  301. data/spec_app/spec/javascripts/up/element_spec.coffee +0 -897
  302. data/spec_app/spec/javascripts/up/event_spec.js.coffee +0 -530
  303. data/spec_app/spec/javascripts/up/feedback_spec.js.coffee +0 -401
  304. data/spec_app/spec/javascripts/up/form_spec.js.coffee +0 -1488
  305. data/spec_app/spec/javascripts/up/fragment_spec.js.coffee +0 -2589
  306. data/spec_app/spec/javascripts/up/history_spec.js.coffee +0 -340
  307. data/spec_app/spec/javascripts/up/jquery_spec.js.coffee +0 -4
  308. data/spec_app/spec/javascripts/up/legacy_spec.js.coffee +0 -27
  309. data/spec_app/spec/javascripts/up/link_spec.js.coffee +0 -1093
  310. data/spec_app/spec/javascripts/up/log_spec.js.coffee +0 -119
  311. data/spec_app/spec/javascripts/up/modal_spec.js.coffee +0 -917
  312. data/spec_app/spec/javascripts/up/motion_spec.js.coffee +0 -582
  313. data/spec_app/spec/javascripts/up/popup_spec.js.coffee +0 -507
  314. data/spec_app/spec/javascripts/up/protocol_spec.js.coffee +0 -39
  315. data/spec_app/spec/javascripts/up/proxy_spec.js.coffee +0 -1137
  316. data/spec_app/spec/javascripts/up/radio_spec.js.coffee +0 -212
  317. data/spec_app/spec/javascripts/up/rails_spec.js.coffee +0 -118
  318. data/spec_app/spec/javascripts/up/spec_spec.js.coffee +0 -9
  319. data/spec_app/spec/javascripts/up/syntax_spec.js.coffee +0 -304
  320. data/spec_app/spec/javascripts/up/toast_spec.js.coffee +0 -37
  321. data/spec_app/spec/javascripts/up/tooltip_spec.js.coffee +0 -163
  322. data/spec_app/spec/javascripts/up/util_spec.js.coffee +0 -1420
  323. data/spec_app/spec/javascripts/up/viewport_spec.js.coffee +0 -655
  324. data/spec_app/spec/spec_helper.rb +0 -62
  325. data/spec_app/test/controllers/.keep +0 -0
  326. data/spec_app/test/fixtures/.keep +0 -0
  327. data/spec_app/test/helpers/.keep +0 -0
  328. data/spec_app/test/integration/.keep +0 -0
  329. data/spec_app/test/mailers/.keep +0 -0
  330. data/spec_app/test/models/.keep +0 -0
  331. data/spec_app/test/test_helper.rb +0 -10
  332. data/spec_app/vendor/asset-libs/es6-promise-4.1.6/es6-promise.auto.js +0 -1159
  333. data/spec_app/vendor/asset-libs/jasmine-ajax-3.3.1/.bower.json +0 -43
  334. data/spec_app/vendor/asset-libs/jasmine-ajax-3.3.1/.gitignore +0 -6
  335. data/spec_app/vendor/asset-libs/jasmine-ajax-3.3.1/.npmignore +0 -10
  336. data/spec_app/vendor/asset-libs/jasmine-ajax-3.3.1/.pairs +0 -6
  337. data/spec_app/vendor/asset-libs/jasmine-ajax-3.3.1/.travis.yml +0 -56
  338. data/spec_app/vendor/asset-libs/jasmine-ajax-3.3.1/jasmine-ajax.js +0 -790
  339. data/spec_app/vendor/assets/.keep +0 -0
  340. data/unpoly-rails.gemspec +0 -24
@@ -1,401 +0,0 @@
1
- u = up.util
2
- $ = jQuery
3
-
4
- describe 'up.feedback', ->
5
-
6
- beforeEach ->
7
- up.history.config.enabled = true
8
- up.modal.config.openAnimation = 'none'
9
- up.modal.config.closeAnimation = 'none'
10
- up.popup.config.openAnimation = 'none'
11
- up.popup.config.closeAnimation = 'none'
12
-
13
- describe 'unobtrusive behavior', ->
14
-
15
- describe '[up-nav]', ->
16
-
17
- it 'marks a child link as .up-current if it links to the current URL', ->
18
- up.history.replace('/foo')
19
- $nav = $fixture('div[up-nav]')
20
- $currentLink = $nav.affix('a[href="/foo"]')
21
- $otherLink = $nav.affix('a[href="/bar"]')
22
- up.hello($nav)
23
- expect($currentLink).toHaveClass('up-current')
24
- expect($otherLink).not.toHaveClass('up-current')
25
-
26
- it 'marks the element as .up-current if it is also a link to the current URL', ->
27
- up.history.replace('/foo')
28
- $currentLink = $fixture('a[href="/foo"][up-nav]')
29
- $otherLink = $fixture('a[href="/bar"][up-nav]')
30
- up.hello($currentLink)
31
- up.hello($otherLink)
32
- expect($currentLink).toHaveClass('up-current')
33
- expect($otherLink).not.toHaveClass('up-current')
34
-
35
- it 'does not mark a link as .up-current if the link is outside an [up-nav]', ->
36
- up.history.replace('/foo')
37
- $nav = $fixture('div[up-nav]')
38
- $currentLinkInNav = $nav.affix('a[href="/foo"]')
39
- $currentLinkOutsideNav = $fixture('a[href="/foo"]')
40
- up.hello($nav)
41
- expect($currentLinkInNav).toHaveClass('up-current')
42
- expect($currentLinkOutsideNav).not.toHaveClass('up-current')
43
-
44
- it 'marks a replaced child link as .up-current if it links to the current URL', asyncSpec (next) ->
45
- up.history.replace('/foo')
46
- $nav = $fixture('div[up-nav]')
47
- $nav.affix('a.link[href="/bar"]').text('old link')
48
- up.hello($nav)
49
-
50
- expect('.link').toHaveText('old link')
51
- expect('.link').not.toHaveClass('up-current')
52
-
53
- up.replace('.link', '/src', history: false)
54
-
55
- next =>
56
- @respondWith """
57
- <a class="link" href="/foo">
58
- new link
59
- </a>
60
- """
61
-
62
- next =>
63
- expect('.link').toHaveText('new link')
64
- expect('.link').toHaveClass('up-current')
65
-
66
- it 'marks any link as .up-current if its up-href attribute matches the current URL', ->
67
- up.history.replace('/foo')
68
- $nav = $fixture('div[up-nav]')
69
- $currentLink = $nav.affix('span[up-href="/foo"]')
70
- $otherLink = $nav.affix('span[up-href="/bar"]')
71
- up.hello($nav)
72
- expect($currentLink).toHaveClass('up-current')
73
- expect($otherLink).not.toHaveClass('up-current')
74
-
75
- it 'matches the current and destination URLs if they only differ by a trailing slash', ->
76
- up.history.replace('/foo')
77
- $nav = $fixture('div[up-nav]')
78
- $currentLink = $nav.affix('span[up-href="/foo/"]')
79
- up.hello($nav)
80
- expect($currentLink).toHaveClass('up-current')
81
-
82
- it 'does not match the current and destination URLs if they differ in the search', ->
83
- up.history.replace('/foo?q=1')
84
- $nav = $fixture('div[up-nav]')
85
- $currentLink = $nav.affix('span[up-href="/foo?q=2"]')
86
- up.hello($nav)
87
- expect($currentLink).not.toHaveClass('up-current')
88
-
89
- it 'marks any link as .up-current if any of its space-separated up-alias values matches the current URL', ->
90
- up.history.replace('/foo')
91
- $nav = $fixture('div[up-nav]')
92
- $currentLink = $nav.affix('a[href="/x"][up-alias="/aaa /foo /bbb"]')
93
- $otherLink = $nav.affix('a[href="/y"][up-alias="/bar"]')
94
- up.hello($nav)
95
- expect($currentLink).toHaveClass('up-current')
96
- expect($otherLink).not.toHaveClass('up-current')
97
-
98
- it 'does not throw if the current location does not match an up-alias wildcard (bugfix)', ->
99
- inserter = -> up.hello(fixture('a[up-nav][up-alias="/qqqq*"]'))
100
- expect(inserter).not.toThrow()
101
-
102
- it 'does not highlight a link to "#" (commonly used for JS-only buttons)', ->
103
- $nav = $fixture('div[up-nav]')
104
- $link = $nav.affix('a[href="#"]')
105
- up.hello($nav)
106
- expect($link).not.toHaveClass('up-current')
107
-
108
- it 'does not highlight links with unsafe methods', ->
109
- up.history.replace('/foo')
110
- $nav = $fixture('div[up-nav]')
111
- $defaultLink = $nav.affix('a[href="/foo"]')
112
- $getLink = $nav.affix('a[href="/foo"][up-method="get"]')
113
- $putLink = $nav.affix('a[href="/foo"][up-method="put"]')
114
- $patchLink = $nav.affix('a[href="/foo"][up-method="patch"]')
115
- $postLink = $nav.affix('a[href="/foo"][up-method="post"]')
116
- $deleteLink = $nav.affix('a[href="/foo"][up-method="delete"]')
117
- up.hello($nav)
118
-
119
- expect($defaultLink).toHaveClass('up-current')
120
- expect($getLink).toHaveClass('up-current')
121
- expect($putLink).not.toHaveClass('up-current')
122
- expect($patchLink).not.toHaveClass('up-current')
123
- expect($postLink).not.toHaveClass('up-current')
124
- expect($deleteLink).not.toHaveClass('up-current')
125
-
126
- it 'marks URL prefixes as .up-current if an up-alias value ends in *', ->
127
- up.history.replace('/foo/123')
128
-
129
- $nav = $fixture('div[up-nav]')
130
- $currentLink = $nav.affix('a[href="/x"][up-alias="/aaa /foo/* /bbb"]')
131
- $otherLink = $nav.affix('a[href="/y"][up-alias="/bar"]')
132
- up.hello($nav)
133
-
134
- expect($currentLink).toHaveClass('up-current')
135
- expect($otherLink).not.toHaveClass('up-current')
136
-
137
- it 'marks URL prefixes as .up-current if an up-alias has multiple * placeholders', ->
138
- up.history.replace('/a-foo-b-bar-c')
139
-
140
- $nav = $fixture('div[up-nav]')
141
- $currentLink = $nav.affix('a[href="/x"][up-alias="*-foo-*-bar-*"]')
142
- $otherLink1 = $nav.affix('a[href="/y"][up-alias="/foo-bar"]')
143
- $otherLink2 = $nav.affix('a[href="/y"][up-alias="/foo-b-bar"]')
144
- $otherLink3 = $nav.affix('a[href="/y"][up-alias="/a-foo-b-bar"]')
145
- $otherLink4 = $nav.affix('a[href="/y"][up-alias="/foo-b-bar-c"]')
146
- $otherLink5 = $nav.affix('a[href="/y"][up-alias="/a-foo-b-bar-c-d"]')
147
- up.hello($nav)
148
-
149
- expect($currentLink).toHaveClass('up-current')
150
- expect($otherLink1).not.toHaveClass('up-current')
151
- expect($otherLink2).not.toHaveClass('up-current')
152
- expect($otherLink3).not.toHaveClass('up-current')
153
- expect($otherLink4).not.toHaveClass('up-current')
154
- expect($otherLink5).not.toHaveClass('up-current')
155
-
156
-
157
- it 'allows to configure a custom "current" class in addition to .up-current', ->
158
- up.feedback.config.currentClasses.push('highlight')
159
- up.history.replace('/foo')
160
- $nav = $fixture('div[up-nav]')
161
- $currentLink = $nav.affix('a[href="/foo"]')
162
- up.hello($nav)
163
-
164
- expect($currentLink).toHaveClass('highlight')
165
- expect($currentLink).toHaveClass('up-current')
166
-
167
- it 'allows to configure multiple additional "current" classes', ->
168
- up.feedback.config.currentClasses.push('highlight1')
169
- up.feedback.config.currentClasses.push('highlight2')
170
- up.history.replace('/foo')
171
- $nav = $fixture('div[up-nav]')
172
- $currentLink = $nav.affix('a[href="/foo"]')
173
- up.hello($nav)
174
-
175
- expect($currentLink).toHaveClass('highlight1')
176
- expect($currentLink).toHaveClass('highlight2')
177
- expect($currentLink).toHaveClass('up-current')
178
-
179
- it 'allows to configure additional nav selectors', ->
180
- up.history.replace('/foo')
181
- up.feedback.config.navs.push('.navi')
182
- $nav = $fixture('div.navi')
183
- $currentLink = $nav.affix('a[href="/foo"]')
184
- $otherLink = $nav.affix('a[href="/bar"]')
185
- up.hello($nav)
186
- expect($currentLink).toHaveClass('up-current')
187
- expect($otherLink).not.toHaveClass('up-current')
188
-
189
- describeCapability 'canPushState', ->
190
-
191
- describe 'updating .up-current marks wen the URL changes', ->
192
-
193
- it 'marks a link as .up-current if it links to the current URL, but is missing a trailing slash', asyncSpec (next) ->
194
- $nav = $fixture('div[up-nav]')
195
- $link = $nav.affix('a[href="/foo"][up-target=".main"]')
196
- up.hello($nav)
197
-
198
- fixture('.main')
199
- Trigger.clickSequence($link)
200
-
201
- next =>
202
- @respondWith
203
- responseHeaders: { 'X-Up-Location': '/foo/' }
204
- responseText: '<div class="main">new-text</div>'
205
-
206
- next =>
207
- expect($link).toHaveClass('up-current')
208
-
209
- it 'marks a link as .up-current if it links to the current URL, but has an extra trailing slash', asyncSpec (next) ->
210
- $nav = $fixture('div[up-nav]')
211
- $link = $nav.affix('a[href="/foo/"][up-target=".main"]')
212
- up.hello($nav)
213
-
214
- fixture('.main')
215
- Trigger.clickSequence($link)
216
-
217
- next =>
218
- @respondWith
219
- responseHeaders: { 'X-Up-Location': '/foo' }
220
- responseText: '<div class="main">new-text</div>'
221
-
222
- next =>
223
- expect($link).toHaveClass('up-current')
224
-
225
- it 'marks a link as .up-current if it links to an URL currently shown either within or below the modal', asyncSpec (next) ->
226
- up.history.replace('/foo')
227
-
228
- $nav = $fixture('div[up-nav]')
229
- $backgroundLink = $nav.affix('a[href="/foo"]')
230
- $modalLink = $nav.affix('a[href="/bar"][up-modal=".main"]')
231
- $unrelatedLink = $nav.affix('a[href="/baz"]')
232
- up.hello($nav)
233
-
234
- Trigger.clickSequence($modalLink)
235
-
236
- next =>
237
- @respondWith('<div class="main">new-text</div>')
238
-
239
- next =>
240
- expect($backgroundLink).toHaveClass('up-current')
241
- expect($modalLink).toHaveClass('up-current')
242
- expect($unrelatedLink).not.toHaveClass('up-current')
243
- next.await up.modal.close()
244
-
245
- next =>
246
- expect($backgroundLink).toHaveClass('up-current')
247
- expect($modalLink).not.toHaveClass('up-current')
248
- expect($unrelatedLink).not.toHaveClass('up-current')
249
-
250
- it "marks a link as .up-current if it links to the URL currently either within or below the popup, even if the popup doesn't change history", asyncSpec (next) ->
251
- up.history.replace('/foo')
252
-
253
- # This is actually the default. Popups don't change the address bar by default,
254
- # but we still want to cause their URL to mark links as current.
255
- up.popup.config.history = false
256
-
257
- $nav = $fixture('div[up-nav]')
258
- $backgroundLink = $nav.affix('a[href="/foo"]')
259
- $popupLink = $nav.affix('a[href="/bar"][up-popup=".main"]')
260
- $unrelatedLink = $nav.affix('a[href="/baz"]')
261
- up.hello($nav)
262
-
263
- expect(up.browser.url()).toMatchUrl('/foo')
264
- expect(up.popup.coveredUrl()).toBeMissing()
265
-
266
- next =>
267
- Trigger.clickSequence($popupLink)
268
-
269
- next =>
270
- @respondWith('<div class="main">new-text</div>')
271
-
272
- next =>
273
- expect(up.browser.url()).toMatchUrl('/foo') # popup did not change history
274
- expect(up.popup.url()).toMatchUrl('/bar') # popup still knows which URL it is displaying
275
- expect($backgroundLink).toHaveClass('up-current')
276
- expect($popupLink).toHaveClass('up-current')
277
- expect($unrelatedLink).not.toHaveClass('up-current')
278
-
279
- next.await up.popup.close()
280
-
281
- next =>
282
- expect($backgroundLink).toHaveClass('up-current')
283
- expect($popupLink).not.toHaveClass('up-current')
284
- expect($unrelatedLink).not.toHaveClass('up-current')
285
-
286
- it "respects links that are added to an existing [up-nav] by a fragment update", asyncSpec (next) ->
287
- $nav = $fixture('.nav[up-nav]')
288
- $link = $nav.affix('a[href="/foo"][up-target=".main"]')
289
- $more = $nav.affix('.more')
290
- up.hello($nav)
291
-
292
- up.extract '.more', '<div class="more"><a href="/bar"></div>', history: '/bar'
293
-
294
- next =>
295
- $moreLink = $('.more').find('a')
296
- expect($moreLink).toBeAttached()
297
- expect($moreLink).toHaveClass('up-current')
298
-
299
-
300
- describe '.up-active', ->
301
-
302
- describeCapability 'canPushState', ->
303
-
304
- it 'marks clicked links as .up-active until the request finishes', asyncSpec (next) ->
305
- $link = $fixture('a[href="/foo"][up-target=".main"]')
306
- fixture('.main')
307
- Trigger.clickSequence($link)
308
-
309
- next =>
310
- expect($link).toHaveClass('up-active')
311
- @respondWith('<div class="main">new-text</div>')
312
-
313
- next =>
314
- expect($link).not.toHaveClass('up-active')
315
-
316
- it 'does not mark a link as .up-active while it is preloading', asyncSpec (next) ->
317
- $link = $fixture('a[href="/foo"][up-target=".main"]')
318
- fixture('.main')
319
-
320
- up.proxy.preload($link)
321
-
322
- next =>
323
- expect(jasmine.Ajax.requests.count()).toEqual(1)
324
- expect($link).not.toHaveClass('up-active')
325
-
326
- it 'marks links with [up-instant] on mousedown as .up-active until the request finishes', asyncSpec (next) ->
327
- $link = $fixture('a[href="/foo"][up-instant][up-target=".main"]')
328
- fixture('.main')
329
- Trigger.mousedown($link)
330
-
331
- next => expect($link).toHaveClass('up-active')
332
- next => @respondWith('<div class="main">new-text</div>')
333
- next => expect($link).not.toHaveClass('up-active')
334
-
335
- it 'prefers to mark an enclosing [up-expand] click area', asyncSpec (next) ->
336
- $area = $fixture('div[up-expand] a[href="/foo"][up-target=".main"]')
337
- up.hello($area)
338
- $link = $area.find('a')
339
- fixture('.main')
340
- Trigger.clickSequence($link)
341
-
342
- next =>
343
- expect($link).not.toHaveClass('up-active')
344
- expect($area).toHaveClass('up-active')
345
- next =>
346
- @respondWith('<div class="main">new-text</div>')
347
- next =>
348
- expect($area).not.toHaveClass('up-active')
349
-
350
- it 'removes .up-active when a link with [up-confirm] was not confirmed', asyncSpec (next) ->
351
- $link = $fixture('a[href="/foo"][up-modal=".main"][up-confirm="Really follow?"]')
352
- spyOn(up.browser, 'whenConfirmed').and.returnValue(Promise.reject('User aborted'))
353
-
354
- Trigger.clickSequence($link)
355
-
356
- next =>
357
- expect($link).not.toHaveClass('up-active')
358
-
359
- it 'marks clicked modal openers as .up-active while the modal is loading', asyncSpec (next) ->
360
- $link = $fixture('a[href="/foo"][up-modal=".main"]')
361
- fixture('.main')
362
- Trigger.clickSequence($link)
363
-
364
- next => expect($link).toHaveClass('up-active')
365
- next => @respondWith('<div class="main">new-text</div>')
366
- next => expect($link).not.toHaveClass('up-active')
367
-
368
- it 'removes .up-active from a clicked modal opener if the target is already preloaded (bugfix)', asyncSpec (next) ->
369
- $link = $fixture('a[href="/foo"][up-modal=".main"]')
370
- up.proxy.preload($link)
371
-
372
- next => @respondWith('<div class="main">new-text</div>')
373
- next => Trigger.clickSequence($link)
374
- next =>
375
- expect('.up-modal .main').toHaveText('new-text')
376
- expect($link).not.toHaveClass('up-active')
377
-
378
- it 'removes .up-active from a clicked link if the target is already preloaded (bugfix)', asyncSpec (next) ->
379
- $link = $fixture('a[href="/foo"][up-target=".main"]')
380
- fixture('.main')
381
- up.proxy.preload($link)
382
-
383
- next => @respondWith('<div class="main">new-text</div>')
384
- next => Trigger.clickSequence($link)
385
- next =>
386
- expect('.main').toHaveText('new-text')
387
- expect($link).not.toHaveClass('up-active')
388
-
389
- it 'removes .up-active from a clicked link if the request fails (bugfix)', asyncSpec (next) ->
390
- $link = $fixture('a[href="/foo"][up-target=".main"]')
391
- fixture('.main')
392
- Trigger.clickSequence($link)
393
-
394
- next =>
395
- expect($link).toHaveClass('up-active')
396
- # @respondWith
397
- # responseText: '<div class="main">failed</div>'
398
- # status: 400
399
- #
400
- # next =>
401
- # expect($link).not.toHaveClass('up-active')
@@ -1,1488 +0,0 @@
1
- u = up.util
2
- e = up.element
3
- $ = jQuery
4
-
5
- describe 'up.form', ->
6
-
7
- describe 'JavaScript functions', ->
8
-
9
- describe 'up.form.fields', ->
10
-
11
- it 'returns a list of form fields within the given element', ->
12
- form = fixture('form')
13
- textField = e.affix(form, 'input[type=text]')
14
- select = e.affix(form, 'select')
15
- results = up.form.fields(form)
16
- expect(results).toMatchList([textField, select])
17
-
18
- it 'returns an empty list if the given element contains no form fields', ->
19
- form = fixture('form')
20
- results = up.form.fields(form)
21
- expect(results).toMatchList([])
22
-
23
- it 'returns a list of the given element if the element is itself a form field', ->
24
- textArea = fixture('textarea')
25
- results = up.form.fields(textArea)
26
- expect(results).toMatchList([textArea])
27
-
28
- describe 'up.observe', ->
29
-
30
- beforeEach ->
31
- up.form.config.observeDelay = 0
32
-
33
- # Actually we only need `input`, but we want to notice
34
- # if another script manually triggers `change` on the element.
35
- changeEvents = ['input', 'change']
36
-
37
- describe 'when the first argument is a form field', ->
38
-
39
- u.each changeEvents, (eventName) ->
40
-
41
- describe "when the input receives a #{eventName} event", ->
42
-
43
- it "runs the callback if the value changed", asyncSpec (next) ->
44
- $input = $fixture('input[name="input-name"][value="old-value"]')
45
- callback = jasmine.createSpy('change callback')
46
- up.observe($input, callback)
47
- $input.val('new-value')
48
- u.times 2, -> Trigger[eventName]($input)
49
- next =>
50
- expect(callback).toHaveBeenCalledWith('new-value', 'input-name')
51
- expect(callback.calls.count()).toEqual(1)
52
-
53
- it "does not run the callback if the value didn't change", asyncSpec (next) ->
54
- $input = $fixture('input[name="input-name"][value="old-value"]')
55
- callback = jasmine.createSpy('change callback')
56
- up.observe($input, callback)
57
- Trigger[eventName]($input)
58
- next =>
59
- expect(callback).not.toHaveBeenCalled()
60
-
61
- it 'debounces the callback when the { delay } option is given', asyncSpec (next) ->
62
- $input = $fixture('input[name="input-name"][value="old-value"]')
63
- callback = jasmine.createSpy('change callback')
64
- up.observe($input, { delay: 200 }, callback)
65
- $input.val('new-value-1')
66
- Trigger[eventName]($input)
67
-
68
- next.after 100, ->
69
- # 100 ms after change 1: We're still waiting for the 200ms delay to expire
70
- expect(callback.calls.count()).toEqual(0)
71
-
72
- next.after 200, ->
73
- # 300 ms after change 1: The 200ms delay has expired
74
- expect(callback.calls.count()).toEqual(1)
75
- expect(callback.calls.mostRecent().args[0]).toEqual('new-value-1')
76
- $input.val('new-value-2')
77
- Trigger[eventName]($input)
78
-
79
- next.after 80, ->
80
- # 80 ms after change 2: We change again, resetting the delay
81
- expect(callback.calls.count()).toEqual(1)
82
- $input.val('new-value-3')
83
- Trigger[eventName]($input)
84
-
85
- next.after 170, ->
86
- # 250 ms after change 2, which was superseded by change 3
87
- # 170 ms after change 3
88
- expect(callback.calls.count()).toEqual(1)
89
-
90
- next.after 130, ->
91
- # 190 ms after change 2, which was superseded by change 3
92
- # 150 ms after change 3
93
- expect(callback.calls.count()).toEqual(2)
94
- expect(callback.calls.mostRecent().args[0]).toEqual('new-value-3')
95
-
96
- it 'delays a callback if a previous async callback is taking long to execute', asyncSpec (next) ->
97
- $input = $fixture('input[name="input-name"][value="old-value"]')
98
- callbackCount = 0
99
- callback = ->
100
- callbackCount += 1
101
- return up.specUtil.promiseTimer(100)
102
- up.observe($input, { delay: 1 }, callback)
103
- $input.val('new-value-1')
104
- Trigger[eventName]($input)
105
-
106
- next.after 30, ->
107
- # Callback has been called and takes 100 ms to complete
108
- expect(callbackCount).toEqual(1)
109
- $input.val('new-value-2')
110
- Trigger[eventName]($input)
111
-
112
- next.after 30, ->
113
- # Second callback is triggerd, but waits for first callback to complete
114
- expect(callbackCount).toEqual(1)
115
-
116
- next.after 90, ->
117
- # After 150 ms the first callback should be finished and the queued 2nd callback has executed
118
- expect(callbackCount).toEqual(2)
119
-
120
- it 'only runs the last callback when a previous long-running callback has been delaying multiple callbacks', asyncSpec (next) ->
121
- $input = $fixture('input[name="input-name"][value="old-value"]')
122
-
123
- callbackArgs = []
124
- callback = (value, field) ->
125
- callbackArgs.push(value)
126
- return up.specUtil.promiseTimer(100)
127
-
128
- up.observe($input, { delay: 1 }, callback)
129
- $input.val('new-value-1')
130
- Trigger[eventName]($input)
131
-
132
- next.after 10, ->
133
- # Callback has been called and takes 100 ms to complete
134
- expect(callbackArgs).toEqual ['new-value-1']
135
- $input.val('new-value-2')
136
- Trigger[eventName]($input)
137
-
138
- next.after 10, ->
139
- expect(callbackArgs).toEqual ['new-value-1']
140
- $input.val('new-value-3')
141
- Trigger[eventName]($input)
142
-
143
- next.after 100, ->
144
- expect(callbackArgs).toEqual ['new-value-1', 'new-value-3']
145
-
146
- describe 'when the first argument is a checkbox', ->
147
-
148
- it 'runs the callback when the checkbox changes its checked state', asyncSpec (next) ->
149
- $form = $fixture('form')
150
- $checkbox = $form.affix('input[name="input-name"][type="checkbox"][value="checkbox-value"]')
151
- callback = jasmine.createSpy('change callback')
152
- up.observe($checkbox, callback)
153
- expect($checkbox.is(':checked')).toBe(false)
154
- Trigger.clickSequence($checkbox)
155
-
156
- next =>
157
- expect($checkbox.is(':checked')).toBe(true)
158
- expect(callback.calls.count()).toEqual(1)
159
- Trigger.clickSequence($checkbox)
160
-
161
- next =>
162
- expect($checkbox.is(':checked')).toBe(false)
163
- expect(callback.calls.count()).toEqual(2)
164
-
165
- it 'runs the callback when the checkbox is toggled by clicking its label', asyncSpec (next) ->
166
- $form = $fixture('form')
167
- $checkbox = $form.affix('input#tick[name="input-name"][type="checkbox"][value="checkbox-value"]')
168
- $label = $form.affix('label[for="tick"]').text('tick label')
169
- callback = jasmine.createSpy('change callback')
170
- up.observe($checkbox, callback)
171
- expect($checkbox.is(':checked')).toBe(false)
172
- Trigger.clickSequence($label)
173
-
174
- next =>
175
- expect($checkbox.is(':checked')).toBe(true)
176
- expect(callback.calls.count()).toEqual(1)
177
- Trigger.clickSequence($label)
178
-
179
- next =>
180
- expect($checkbox.is(':checked')).toBe(false)
181
- expect(callback.calls.count()).toEqual(2)
182
-
183
- describe 'when the first argument is a radio button group', ->
184
-
185
- it 'runs the callback when the group changes its selection', asyncSpec (next) ->
186
- $form = $fixture('form')
187
- $radio1 = $form.affix('input[type="radio"][name="group"][value="1"]')
188
- $radio2 = $form.affix('input[type="radio"][name="group"][value="2"]')
189
- $group = $radio1.add($radio2)
190
- callback = jasmine.createSpy('change callback')
191
- up.observe($group, callback)
192
- expect($radio1.is(':checked')).toBe(false)
193
-
194
- Trigger.clickSequence($radio1)
195
-
196
- next =>
197
- expect($radio1.is(':checked')).toBe(true)
198
- expect(callback.calls.count()).toEqual(1)
199
- # Trigger.clickSequence($radio2)
200
- $radio1[0].checked = false
201
- $radio2[0].checked = true
202
- Trigger.change($radio2)
203
-
204
- next =>
205
- expect($radio1.is(':checked')).toBe(false)
206
- expect(callback.calls.count()).toEqual(2)
207
-
208
- it "runs the callbacks when a radio button is selected or deselected by clicking a label in the group", asyncSpec (next) ->
209
- $form = $fixture('form')
210
- $radio1 = $form.affix('input#radio1[type="radio"][name="group"][value="1"]')
211
- $radio1Label = $form.affix('label[for="radio1"]').text('label 1')
212
- $radio2 = $form.affix('input#radio2[type="radio"][name="group"][value="2"]')
213
- $radio2Label = $form.affix('label[for="radio2"]').text('label 2')
214
- $group = $radio1.add($radio2)
215
- callback = jasmine.createSpy('change callback')
216
- up.observe($group, callback)
217
- expect($radio1.is(':checked')).toBe(false)
218
- Trigger.clickSequence($radio1Label)
219
-
220
- next =>
221
- expect($radio1.is(':checked')).toBe(true)
222
- expect(callback.calls.count()).toEqual(1)
223
- Trigger.clickSequence($radio2Label)
224
-
225
- next =>
226
- expect($radio1.is(':checked')).toBe(false)
227
- expect(callback.calls.count()).toEqual(2)
228
-
229
- it "takes the group's initial selected value into account", asyncSpec (next) ->
230
- $form = $fixture('form')
231
- $radio1 = $form.affix('input[type="radio"][name="group"][value="1"][checked="checked"]')
232
- $radio2 = $form.affix('input[type="radio"][name="group"][value="2"]')
233
- $group = $radio1.add($radio2)
234
- callback = jasmine.createSpy('change callback')
235
- up.observe($group, callback)
236
- expect($radio1.is(':checked')).toBe(true)
237
- expect($radio2.is(':checked')).toBe(false)
238
- Trigger.clickSequence($radio1)
239
-
240
- next =>
241
- # Since the radio button was already checked, the click doesn't do anything
242
- expect($radio1.is(':checked')).toBe(true)
243
- expect($radio2.is(':checked')).toBe(false)
244
- # Since the radio button was already checked, clicking it again won't trigger the callback
245
- expect(callback.calls.count()).toEqual(0)
246
- Trigger.clickSequence($radio2)
247
-
248
- next =>
249
- expect($radio1.is(':checked')).toBe(false)
250
- expect($radio2.is(':checked')).toBe(true)
251
- expect(callback.calls.count()).toEqual(1)
252
-
253
- describe 'when the first argument is a form', ->
254
-
255
- u.each changeEvents, (eventName) ->
256
-
257
- describe "when any of the form's inputs receives a #{eventName} event", ->
258
-
259
- it "runs the callback if the value changed", asyncSpec (next) ->
260
- $form = $fixture('form')
261
- $input = $form.affix('input[name="input-name"][value="old-value"]')
262
- callback = jasmine.createSpy('change callback')
263
- up.observe($form, callback)
264
- $input.val('new-value')
265
- u.times 2, -> Trigger[eventName]($input)
266
- next =>
267
- expect(callback).toHaveBeenCalledWith('new-value', 'input-name')
268
- expect(callback.calls.count()).toEqual(1)
269
-
270
- it "does not run the callback if the value didn't change", asyncSpec (next) ->
271
- $form = $fixture('form')
272
- $input = $form.affix('input[name="input-name"][value="old-value"]')
273
- callback = jasmine.createSpy('change callback')
274
- up.observe($form, callback)
275
- Trigger[eventName]($input)
276
- next =>
277
- expect(callback).not.toHaveBeenCalled()
278
-
279
- # it 'runs the callback only once when a radio button group changes its selection', ->
280
- # $form = $fixture('form')
281
- # $radio1 = $form.affix('input[type="radio"][name="group"][value="1"][checked="checked"]')
282
- # $radio2 = $form.affix('input[type="radio"][name="group"][value="2"]')
283
- # callback = jasmine.createSpy('change callback')
284
- # up.observe($form, callback)
285
- # $radio2.get(0).click()
286
- # u.task ->
287
- # expect(callback.calls.count()).toEqual(1)
288
-
289
-
290
- describe 'with { batch: true } options', ->
291
-
292
- it 'calls the callback once with all collected changes in a diff object', asyncSpec (next) ->
293
- $form = $fixture('form')
294
- $input1 = $form.affix('input[name="input1"][value="input1-a"]')
295
- $input2 = $form.affix('input[name="input2"][value="input2-a"]')
296
- callback = jasmine.createSpy('change callback')
297
- up.observe($form, { batch: true }, callback)
298
-
299
- next ->
300
- expect(callback.calls.count()).toEqual(0)
301
-
302
- $input1.val('input1-b')
303
- Trigger.change($input1)
304
- $input2.val('input2-b')
305
- Trigger.change($input2)
306
-
307
- next ->
308
- expect(callback.calls.count()).toEqual(1)
309
- expect(callback.calls.mostRecent().args[0]).toEqual {
310
- 'input1': 'input1-b'
311
- 'input2': 'input2-b'
312
- }
313
-
314
- $input2.val('input2-c')
315
- Trigger.change($input2)
316
-
317
- next ->
318
- expect(callback.calls.count()).toEqual(2)
319
- expect(callback.calls.mostRecent().args[0]).toEqual {
320
- 'input2': 'input2-c'
321
- }
322
-
323
-
324
- describe 'up.submit', ->
325
-
326
- it 'emits a preventable up:form:submit event', asyncSpec (next) ->
327
- $form = $fixture('form[action="/form-target"][up-target=".response"]')
328
-
329
- listener = jasmine.createSpy('submit listener').and.callFake (event) ->
330
- event.preventDefault()
331
-
332
- $form.on('up:form:submit', listener)
333
-
334
- up.submit($form)
335
-
336
- next =>
337
- expect(listener).toHaveBeenCalled()
338
- element = listener.calls.mostRecent().args[1]
339
- expect(element).toEqual(element)
340
-
341
- # No request should be made because we prevented the event
342
- expect(jasmine.Ajax.requests.count()).toEqual(0)
343
-
344
- describeCapability 'canPushState', ->
345
-
346
- beforeEach ->
347
- up.history.config.enabled = true
348
- @$form = $fixture('form[action="/form-target"][method="put"][up-target=".response"]')
349
- @$form.append('<input name="field1" value="value1">')
350
- @$form.append('<input name="field2" value="value2">')
351
- $fixture('.response').text('old-text')
352
-
353
- it 'submits the given form and replaces the target with the response', asyncSpec (next) ->
354
- up.submit(@$form)
355
-
356
- next =>
357
- expect(@lastRequest().url).toMatchUrl('/form-target')
358
- expect(@lastRequest()).toHaveRequestMethod('PUT')
359
- expect(@lastRequest().data()['field1']).toEqual(['value1'])
360
- expect(@lastRequest().data()['field2']).toEqual(['value2'])
361
- expect(@lastRequest().requestHeaders['X-Up-Target']).toEqual('.response')
362
-
363
- @respondWith
364
- responseHeaders:
365
- 'X-Up-Location': '/redirect-target'
366
- 'X-Up-Method': 'GET'
367
- responseText: """
368
- <div class='before'>
369
- new-before
370
- </div>
371
-
372
- <div class="response">
373
- new-text
374
- </div>
375
-
376
- <div class='after'>
377
- new-after
378
- </div>
379
- """
380
-
381
- next =>
382
- expect(up.browser.url()).toMatchUrl('/redirect-target')
383
- expect('.response').toHaveText('new-text')
384
- # See that containers outside the form have not changed
385
- expect('.before').not.toHaveText('old-before')
386
- expect('.after').not.toHaveText('old-after')
387
-
388
- it "places the response into the form and doesn't update the browser URL if the submission returns a 5xx status code", asyncSpec (next) ->
389
- up.submit(@$form)
390
-
391
- next =>
392
- @respondWith
393
- status: 500
394
- contentType: 'text/html'
395
- responseText:
396
- """
397
- <div class='before'>
398
- new-before
399
- </div>
400
-
401
- <form>
402
- error-messages
403
- </form>
404
-
405
- <div class='after'>
406
- new-after
407
- </div>
408
- """
409
-
410
- next =>
411
- expect(up.browser.url()).toEqual(@hrefBeforeExample)
412
- expect('.response').toHaveText('old-text')
413
- expect('form').toHaveText('error-messages')
414
- # See that containers outside the form have not changed
415
- expect('.before').not.toHaveText('old-before')
416
- expect('.after').not.toHaveText('old-after')
417
-
418
- expect(window).toHaveUnhandledRejections() if REJECTION_EVENTS_SUPPORTED
419
-
420
-
421
- it 'respects X-Up-Method and X-Up-Location response headers so the server can show that it redirected to a GET URL', asyncSpec (next) ->
422
- up.submit(@$form)
423
-
424
- next =>
425
- @respondWith
426
- status: 200
427
- contentType: 'text/html'
428
- responseHeaders:
429
- 'X-Up-Location': '/other-path'
430
- 'X-Up-Method': 'GET'
431
- responseText:
432
- """
433
- <div class="response">
434
- new-text
435
- </div>
436
- """
437
-
438
- next =>
439
- expect(up.browser.url()).toMatchUrl('/other-path')
440
-
441
- it 'submits the form to the current URL if the form has no [action] attribute', asyncSpec (next) ->
442
- form = fixture('form')
443
- hrefBeforeSubmit = location.href
444
-
445
- up.submit(form)
446
-
447
- next =>
448
- expect(@lastRequest().url).toMatchUrl(hrefBeforeSubmit)
449
-
450
- describe 'handling of query params in the [action] URL', ->
451
-
452
- describe 'for forms with GET method', ->
453
-
454
- it 'discards query params from an [action] attribute (like browsers do)', asyncSpec (next) ->
455
- # See design/query-params-in-form-actions/cases.html for
456
- # a demo of vanilla browser behavior.
457
-
458
- form = fixture('form[method="GET"][action="/action?foo=value-from-action"]')
459
- input1 = e.affix(form, 'input[name="foo"][value="value-from-input"]')
460
- input2 = e.affix(form, 'input[name="foo"][value="other-value-from-input"]')
461
-
462
- up.submit(form)
463
-
464
- next =>
465
- expect(@lastRequest().url).toMatchUrl('/action?foo=value-from-input&foo=other-value-from-input')
466
-
467
- describe 'for forms with POST method' ,->
468
-
469
- it 'keeps all query params in the URL', asyncSpec (next) ->
470
-
471
- form = fixture('form[method="POST"][action="/action?foo=value-from-action"]')
472
- input1 = e.affix(form, 'input[name="foo"][value="value-from-input"]')
473
- input2 = e.affix(form, 'input[name="foo"][value="other-value-from-input"]')
474
-
475
- up.submit(form)
476
-
477
- next =>
478
- expect(@lastRequest().url).toMatchUrl('/action?foo=value-from-action')
479
- expect(@lastRequest().data()['foo']).toEqual ['value-from-input', 'other-value-from-input']
480
-
481
- describe 'with { history } option', ->
482
-
483
- it 'uses the given URL as the new browser location if the request succeeded', asyncSpec (next) ->
484
- up.submit(@$form, history: '/given-path')
485
- next => @respondWith('<div class="response">new-text</div>')
486
- next => expect(up.browser.url()).toMatchUrl('/given-path')
487
-
488
- it 'keeps the current browser location if the request failed', asyncSpec (next) ->
489
- up.submit(@$form, history: '/given-path', failTarget: '.response')
490
- next => @respondWith('<div class="response">new-text</div>', status: 500)
491
- next => expect(up.browser.url()).toEqual(@hrefBeforeExample)
492
-
493
- it 'keeps the current browser location if the option is set to false', asyncSpec (next) ->
494
- up.submit(@$form, history: false)
495
- next => @respondWith('<div class="response">new-text</div>')
496
- next =>expect(up.browser.url()).toEqual(@hrefBeforeExample)
497
-
498
- describe 'revealing', ->
499
-
500
- it 'reaveals the target fragment if the submission succeeds', asyncSpec (next) ->
501
- $form = $fixture('form[action="/action"][up-target=".target"]')
502
- $target = $fixture('.target')
503
-
504
- revealStub = up.viewport.knife.mock('reveal')
505
-
506
- up.submit($form)
507
-
508
- next =>
509
- @respondWith('<div class="target">new text</div>')
510
-
511
- next =>
512
- expect(revealStub).toHaveBeenCalled()
513
- expect(revealStub.calls.mostRecent().args[0]).toMatchSelector('.target')
514
-
515
- it 'reveals the form if the submission fails', asyncSpec (next) ->
516
- $form = $fixture('form#foo-form[action="/action"][up-target=".target"]')
517
- $target = $fixture('.target')
518
-
519
- revealStub = up.viewport.knife.mock('reveal')
520
-
521
- up.submit($form)
522
-
523
- next =>
524
- @respondWith
525
- status: 500,
526
- responseText: """
527
- <form id="foo-form">
528
- Errors here
529
- </form>
530
- """
531
-
532
- next =>
533
- expect(revealStub).toHaveBeenCalled()
534
- expect(revealStub.calls.mostRecent().args[0]).toMatchSelector('#foo-form')
535
-
536
-
537
- describe 'with { reveal } option', ->
538
-
539
- it 'allows to reveal a different selector', asyncSpec (next) ->
540
- $form = $fixture('form[action="/action"][up-target=".target"]')
541
- $target = $fixture('.target')
542
- $other = $fixture('.other')
543
-
544
- revealStub = up.viewport.knife.mock('reveal')
545
-
546
- up.submit($form, reveal: '.other')
547
-
548
- next =>
549
- @respondWith """
550
- <div class="target">
551
- new text
552
- </div>
553
- <div class="other">
554
- new other
555
- </div>
556
- """
557
-
558
- next =>
559
- expect(revealStub).toHaveBeenCalled()
560
- expect(revealStub.calls.mostRecent().args[0]).toMatchSelector('.other')
561
-
562
- it 'still reveals the form for a failed submission', asyncSpec (next) ->
563
- $form = $fixture('form#foo-form[action="/action"][up-target=".target"]')
564
- $target = $fixture('.target')
565
- $other = $fixture('.other')
566
-
567
- revealStub = up.viewport.knife.mock('reveal')
568
-
569
- up.submit($form, reveal: '.other')
570
-
571
- next =>
572
- @respondWith
573
- status: 500,
574
- responseText: """
575
- <form id="foo-form">
576
- Errors here
577
- </form>
578
- """
579
-
580
- next =>
581
- expect(revealStub).toHaveBeenCalled()
582
- expect(revealStub.calls.mostRecent().args[0]).toMatchSelector('#foo-form')
583
-
584
- it 'allows to refer to this form as "&" in the selector', asyncSpec (next) ->
585
- $form = $fixture('form#foo-form[action="/action"][up-target="#foo-form"]')
586
-
587
- revealStub = up.viewport.knife.mock('reveal')
588
-
589
- up.submit($form, reveal: '& .form-child')
590
-
591
- next =>
592
- @respondWith """
593
- <div class="target">
594
- new text
595
- </div>
596
-
597
- <form id="foo-form">
598
- <div class="form-child">other</div>
599
- </form>
600
- """
601
-
602
- next =>
603
- expect(revealStub).toHaveBeenCalled()
604
- expect(revealStub.calls.mostRecent().args[0]).toEqual(e.first('#foo-form .form-child'))
605
-
606
- describe 'with { failReveal } option', ->
607
-
608
- it 'reveals the given selector for a failed submission', asyncSpec (next) ->
609
- $form = $fixture('form#foo-form[action="/action"][up-target=".target"]')
610
- $target = $fixture('.target')
611
- $other = $fixture('.other')
612
-
613
- revealStub = up.viewport.knife.mock('reveal')
614
-
615
- up.submit($form, reveal: '.other', failReveal: '.error')
616
-
617
- next =>
618
- @respondWith
619
- status: 500,
620
- responseText: """
621
- <form id="foo-form">
622
- <div class="error">Errors here</div>
623
- </form>
624
- """
625
-
626
- next =>
627
- expect(revealStub).toHaveBeenCalled()
628
- expect(revealStub.calls.mostRecent().args[0]).toMatchSelector('.error')
629
-
630
- it 'allows to refer to this form as "&" in the selector', asyncSpec (next) ->
631
- $form = $fixture('form#foo-form[action="/action"][up-target=".target"][up-fail-reveal="#foo-form .form-child"]')
632
- $target = $fixture('.target')
633
-
634
- revealStub = up.viewport.knife.mock('reveal')
635
-
636
- up.submit($form, reveal: '& .form-child')
637
-
638
- next =>
639
- @respondWith
640
- status: 500
641
- responseText: """
642
- <div class="target">
643
- new text
644
- </div>
645
-
646
- <form id="foo-form">
647
- <div class="form-child">other</div>
648
- </form>
649
- """
650
-
651
- next =>
652
- expect(revealStub).toHaveBeenCalled()
653
- expect(revealStub.calls.mostRecent().args[0]).toEqual(e.first('#foo-form .form-child'))
654
-
655
- describe 'in a form with file inputs', ->
656
-
657
- beforeEach ->
658
- @$form.affix('input[name="text-field"][type="text"]').val("value")
659
- @$form.affix('input[name="file-field"][type="file"]')
660
-
661
- it 'transfers the form fields via FormData', asyncSpec (next) ->
662
- up.submit(@$form)
663
- next =>
664
- rawData = @lastRequest().params
665
- expect(u.isFormData(rawData)).toBe(true)
666
-
667
- describeFallback 'canPushState', ->
668
-
669
- it 'falls back to a vanilla form submission', asyncSpec (next) ->
670
- $form = $fixture('form[action="/path/to"][method="put"][up-target=".response"]')
671
- form = $form.get(0)
672
- spyOn(form, 'submit')
673
-
674
- up.submit($form)
675
-
676
- next => expect(form.submit).toHaveBeenCalled()
677
-
678
- describe 'unobtrusive behavior', ->
679
-
680
- describe 'form[up-target]', ->
681
-
682
- it 'submits the form with AJAX and replaces the [up-target] selector', asyncSpec (next) ->
683
- up.history.config.enabled = true
684
-
685
- $fixture('.response').text('old text')
686
-
687
- $form = $fixture('form[action="/form-target"][method="put"][up-target=".response"]')
688
- $form.append('<input name="field1" value="value1">')
689
- $form.append('<input name="field2" value="value2">')
690
- $submitButton = $form.affix('input[type="submit"][name="submit-button"][value="submit-button-value"]')
691
- up.hello($form)
692
-
693
- Trigger.clickSequence($submitButton)
694
-
695
- next =>
696
- params = @lastRequest().data()
697
- expect(params['field1']).toEqual(['value1'])
698
- expect(params['field2']).toEqual(['value2'])
699
-
700
- next =>
701
- @respondWith """
702
- <div class="response">
703
- new text
704
- </div>
705
- """
706
-
707
- next =>
708
- expect('.response').toHaveText('new text')
709
-
710
- it 'allows to refer to this form as "&" in the target selector', asyncSpec (next) ->
711
- $form = $fixture('form.my-form[action="/form-target"][up-target="&"]').text('old form text')
712
- $submitButton = $form.affix('input[type="submit"]')
713
- up.hello($form)
714
-
715
- Trigger.clickSequence($submitButton)
716
-
717
- next =>
718
- @respondWith """
719
- <form class="my-form">
720
- new form text
721
- </form>
722
- """
723
-
724
- next =>
725
- expect('.my-form').toHaveText('new form text')
726
-
727
- describe 'when the server responds with an error code', ->
728
-
729
- it 'replaces the form instead of the [up-target] selector', asyncSpec (next) ->
730
- up.history.config.enabled = true
731
-
732
- $fixture('.response').text('old text')
733
-
734
- $form = $fixture('form.test-form[action="/form-target"][method="put"][up-target=".response"]')
735
- $form.append('<input name="field1" value="value1">')
736
- $form.append('<input name="field2" value="value2">')
737
- $submitButton = $form.affix('input[type="submit"][name="submit-button"][value="submit-button-value"]')
738
- up.hello($form)
739
-
740
- Trigger.clickSequence($submitButton)
741
-
742
- next =>
743
- params = @lastRequest().data()
744
- expect(params['field1']).toEqual(['value1'])
745
- expect(params['field2']).toEqual(['value2'])
746
-
747
- next =>
748
- @respondWith
749
- status: 500
750
- responseText: """
751
- <form class="test-form">
752
- validation errors
753
- </form>
754
- """
755
-
756
- next =>
757
- expect('.response').toHaveText('old text')
758
- expect('form.test-form').toHaveText('validation errors')
759
-
760
- # Since there isn't anyone who could handle the rejection inside
761
- # the event handler, our handler mutes the rejection.
762
- expect(window).not.toHaveUnhandledRejections() if REJECTION_EVENTS_SUPPORTED
763
-
764
- it 'updates a given selector when an [up-fail-target] is given', asyncSpec (next) ->
765
- $form = $fixture('form.my-form[action="/path"][up-target=".target"][up-fail-target=".errors"]').text('old form text')
766
- $errors = $fixture('.target').text('old target text')
767
- $errors = $fixture('.errors').text('old errors text')
768
-
769
- $submitButton = $form.affix('input[type="submit"]')
770
- up.hello($form)
771
-
772
- Trigger.clickSequence($submitButton)
773
-
774
- next =>
775
- @respondWith
776
- status: 500
777
- responseText: """
778
- <form class="my-form">
779
- new form text
780
- </form>
781
-
782
- <div class="errors">
783
- new errors text
784
- </div>
785
- """
786
-
787
- next =>
788
- expect('.my-form').toHaveText('old form text')
789
- expect('.target').toHaveText('old target text')
790
- expect('.errors').toHaveText('new errors text')
791
-
792
- it 'allows to refer to this form as "&" in the [up-fail-target] selector', asyncSpec (next) ->
793
- $form = $fixture('form.my-form[action="/form-target"][up-target=".target"][up-fail-target="&"]').text('old form text')
794
- $target = $fixture('.target').text('old target text')
795
-
796
- $submitButton = $form.affix('input[type="submit"]')
797
- up.hello($form)
798
-
799
- Trigger.clickSequence($submitButton)
800
-
801
- next =>
802
- @respondWith
803
- status: 500,
804
- responseText: """
805
- <form class="my-form">
806
- new form text
807
- </form>
808
- """
809
-
810
- next =>
811
- expect('.target').toHaveText('old target text')
812
- expect('.my-form').toHaveText('new form text')
813
-
814
- describe 'submit buttons', ->
815
-
816
- it 'includes the clicked submit button in the params', asyncSpec (next) ->
817
- $form = $fixture('form[action="/action"][up-target=".target"]')
818
- $textField = $form.affix('input[type="text"][name="text-field"][value="text-field-value"]')
819
- $submitButton = $form.affix('input[type="submit"][name="submit-button"][value="submit-button-value"]')
820
- up.hello($form)
821
- Trigger.clickSequence($submitButton)
822
-
823
- next =>
824
- params = @lastRequest().data()
825
- expect(params['text-field']).toEqual(['text-field-value'])
826
- expect(params['submit-button']).toEqual(['submit-button-value'])
827
-
828
- it 'excludes an unused submit button in the params', asyncSpec (next) ->
829
- $form = $fixture('form[action="/action"][up-target=".target"]')
830
- $textField = $form.affix('input[type="text"][name="text-field"][value="text-field-value"]')
831
- $submitButton1 = $form.affix('input[type="submit"][name="submit-button-1"][value="submit-button-1-value"]')
832
- $submitButton2 = $form.affix('input[type="submit"][name="submit-button-2"][value="submit-button-2-value"]')
833
- up.hello($form)
834
- Trigger.clickSequence($submitButton2)
835
-
836
- next =>
837
- params = @lastRequest().data()
838
- expect(params['text-field']).toEqual(['text-field-value'])
839
- expect(params['submit-button-1']).toBeUndefined()
840
- expect(params['submit-button-2']).toEqual(['submit-button-2-value'])
841
-
842
- it 'includes the first submit button if the form was submitted with enter', asyncSpec (next) ->
843
- $form = $fixture('form[action="/action"][up-target=".target"]')
844
- $textField = $form.affix('input[type="text"][name="text-field"][value="text-field-value"]')
845
- $submitButton1 = $form.affix('input[type="submit"][name="submit-button-1"][value="submit-button-1-value"]')
846
- $submitButton2 = $form.affix('input[type="submit"][name="submit-button-2"][value="submit-button-2-value"]')
847
- up.hello($form)
848
-
849
- Trigger.submit($form) # sorry
850
-
851
- next =>
852
- params = @lastRequest().data()
853
- expect(params['text-field']).toEqual(['text-field-value'])
854
- expect(params['submit-button-1']).toEqual(['submit-button-1-value'])
855
- expect(params['submit-button-2']).toBeUndefined()
856
-
857
- it 'does not explode if the form has no submit buttons', asyncSpec (next) ->
858
- $form = $fixture('form[action="/action"][up-target=".target"]')
859
- $textField = $form.affix('input[type="text"][name="text-field"][value="text-field-value"]')
860
- up.hello($form)
861
-
862
- Trigger.submit($form) # sorry
863
-
864
- next =>
865
- params = @lastRequest().data()
866
- keys = Object.keys(params)
867
- expect(keys).toEqual(['text-field'])
868
-
869
- describe 'input[up-autosubmit]', ->
870
-
871
- it 'submits the form when a change is observed in the given form field', asyncSpec (next) ->
872
- $form = $fixture('form')
873
- $field = $form.affix('input[up-autosubmit][name="input-name"][value="old-value"]')
874
- up.hello($field)
875
- submitSpy = up.form.knife.mock('submit').and.returnValue(u.unresolvablePromise())
876
- $field.val('new-value')
877
- Trigger.change($field)
878
- next => expect(submitSpy).toHaveBeenCalled()
879
-
880
- describe 'form[up-autosubmit]', ->
881
-
882
- it 'submits the form when a change is observed in any of its fields', asyncSpec (next) ->
883
- $form = $fixture('form[up-autosubmit]')
884
- $field = $form.affix('input[name="input-name"][value="old-value"]')
885
- up.hello($form)
886
- submitSpy = up.form.knife.mock('submit').and.returnValue(u.unresolvablePromise())
887
- $field.val('new-value')
888
- Trigger.change($field)
889
- next => expect(submitSpy).toHaveBeenCalled()
890
-
891
- describe 'with [up-delay] modifier', ->
892
-
893
- it 'debounces the form submission', asyncSpec (next) ->
894
- $form = $fixture('form[up-autosubmit][up-delay="50"]')
895
- $field = $form.affix('input[name="input-name"][value="old-value"]')
896
- up.hello($form)
897
- submitSpy = up.form.knife.mock('submit').and.returnValue(u.unresolvablePromise())
898
- $field.val('new-value-1')
899
- Trigger.change($field)
900
- $field.val('new-value-2')
901
- Trigger.change($field)
902
-
903
- next =>
904
- expect(submitSpy.calls.count()).toBe(0)
905
-
906
- next.after 80, =>
907
- expect(submitSpy.calls.count()).toBe(1)
908
-
909
- describe 'input[up-observe]', ->
910
-
911
- afterEach ->
912
- window.observeCallbackSpy = undefined
913
-
914
- it 'runs the JavaScript code in the attribute value when a change is observed in the field', asyncSpec (next) ->
915
- $form = $fixture('form')
916
- window.observeCallbackSpy = jasmine.createSpy('observe callback')
917
- $field = $form.affix('input[name="input-name"][value="old-value"][up-observe="window.observeCallbackSpy(value, name)"]')
918
- up.hello($form)
919
- $field.val('new-value')
920
- Trigger.change($field)
921
-
922
- next =>
923
- expect(window.observeCallbackSpy).toHaveBeenCalledWith('new-value', 'input-name')
924
-
925
- describe 'with [up-delay] modifier', ->
926
-
927
- it 'debounces the callback', asyncSpec (next) ->
928
- $form = $fixture('form')
929
- window.observeCallbackSpy = jasmine.createSpy('observe callback')
930
- $field = $form.affix('input[name="input-name"][value="old-value"][up-observe="window.observeCallbackSpy()"][up-delay="50"]')
931
- up.hello($form)
932
- $field.val('new-value')
933
- Trigger.change($field)
934
-
935
- next => expect(window.observeCallbackSpy).not.toHaveBeenCalled()
936
- next.after 80, => expect(window.observeCallbackSpy).toHaveBeenCalled()
937
-
938
- describe 'form[up-observe]', ->
939
-
940
- afterEach ->
941
- window.observeCallbackSpy = undefined
942
-
943
- it 'runs the JavaScript code in the attribute value when a change is observed in any contained field', asyncSpec (next) ->
944
- window.observeCallbackSpy = jasmine.createSpy('observe callback')
945
- $form = $fixture('form[up-observe="window.observeCallbackSpy(value, name)"]')
946
- $field1 = $form.affix('input[name="field1"][value="field1-old-value"]')
947
- $field2 = $form.affix('input[name="field2"][value="field2-old-value"]')
948
- up.hello($form)
949
- $field1.val('field1-new-value')
950
- Trigger.change($field1)
951
-
952
- next =>
953
- expect(window.observeCallbackSpy.calls.allArgs()).toEqual [
954
- ['field1-new-value', 'field1']
955
- ]
956
-
957
- $field2.val('field2-new-value')
958
- Trigger.change($field2)
959
-
960
- next =>
961
- expect(window.observeCallbackSpy.calls.allArgs()).toEqual [
962
- ['field1-new-value', 'field1'],
963
- ['field2-new-value', 'field2']
964
- ]
965
-
966
- describe 'input[up-validate]', ->
967
-
968
- describe 'when a selector is given', ->
969
-
970
- it "submits the input's form with an 'X-Up-Validate' header and replaces the selector with the response", asyncSpec (next) ->
971
-
972
- $form = $fixture('form[action="/path/to"]')
973
- $group = $("""
974
- <div class="field-group">
975
- <input name="user" value="judy" up-validate=".field-group:has(&)">
976
- </div>
977
- """).appendTo($form)
978
-
979
- Trigger.change($group.find('input'))
980
-
981
- next =>
982
- request = @lastRequest()
983
- expect(request.requestHeaders['X-Up-Validate']).toEqual('user')
984
- expect(request.requestHeaders['X-Up-Target']).toEqual('.field-group:has(input[name="user"])')
985
-
986
- @respondWith
987
- status: 500
988
- responseText: """
989
- <div class="field-group has-error">
990
- <div class='error'>Username has already been taken</div>
991
- <input name="user" value="judy" up-validate=".field-group:has(&)">
992
- </div>
993
- """
994
-
995
- next =>
996
- $group = $('.field-group')
997
- expect($group.length).toBe(1)
998
- expect($group).toHaveClass('has-error')
999
- expect($group).toHaveText('Username has already been taken')
1000
-
1001
- # Since there isn't anyone who could handle the rejection inside
1002
- # the event handler, our handler mutes the rejection.
1003
- expect(window).not.toHaveUnhandledRejections() if REJECTION_EVENTS_SUPPORTED
1004
-
1005
- it 'does not reveal the updated fragment (bugfix)', asyncSpec (next) ->
1006
- revealSpy = up.viewport.knife.mock('reveal').and.returnValue(Promise.resolve())
1007
-
1008
- $form = $fixture('form[action="/path/to"]')
1009
- $group = $("""
1010
- <div class="field-group">
1011
- <input name="user" value="judy" up-validate=".field-group:has(&)">
1012
- </div>
1013
- """).appendTo($form)
1014
- Trigger.change($group.find('input'))
1015
-
1016
- next =>
1017
- @respondWith """
1018
- <div class="field-group has-error">
1019
- <div class='error'>Username has already been taken</div>
1020
- <input name="user" value="judy" up-validate=".field-group:has(&)">
1021
- </div>
1022
- """
1023
-
1024
- next =>
1025
- expect(revealSpy).not.toHaveBeenCalled()
1026
-
1027
-
1028
- describe 'when no selector is given', ->
1029
-
1030
- it 'automatically finds a form group around the input field and only updates that', asyncSpec (next) ->
1031
- container = fixture('.container')
1032
- container.innerHTML = """
1033
- <form action="/users" id="registration">
1034
-
1035
- <div up-fieldset>
1036
- <input type="text" name="email" up-validate />
1037
- </div>
1038
-
1039
- <div up-fieldset>
1040
- <input type="password" name="password" up-validate />
1041
- </div>
1042
-
1043
- </form>
1044
- """
1045
- up.hello(container)
1046
-
1047
- Trigger.change $('#registration input[name=password]')
1048
-
1049
- next =>
1050
- @respondWith """
1051
- <form action="/users" id="registration">
1052
-
1053
- <div up-fieldset>
1054
- Validation message
1055
- <input type="text" name="email" up-validate />
1056
- </div>
1057
-
1058
- <div up-fieldset>
1059
- Validation message
1060
- <input type="password" name="password" up-validate />
1061
- </div>
1062
-
1063
- </form>
1064
- """
1065
-
1066
- next =>
1067
- $labels = $('#registration [up-fieldset]')
1068
- expect($labels[0]).not.toHaveText('Validation message')
1069
- expect($labels[1]).toHaveText('Validation message')
1070
-
1071
- describe 'form[up-validate]', ->
1072
-
1073
- # it 'prints an error saying that this form is not yet supported', ->
1074
-
1075
- it 'performs server-side validation for all fieldsets contained within the form', asyncSpec (next) ->
1076
- container = fixture('.container')
1077
- container.innerHTML = """
1078
- <form action="/users" id="registration" up-validate>
1079
-
1080
- <div up-fieldset>
1081
- <input type="text" name="email">
1082
- </div>
1083
-
1084
- <div up-fieldset>
1085
- <input type="password" name="password">
1086
- </div>
1087
-
1088
- </form>
1089
- """
1090
- up.hello(container)
1091
-
1092
- Trigger.change $('#registration input[name=password]')
1093
-
1094
- next =>
1095
- expect(jasmine.Ajax.requests.count()).toEqual(1)
1096
- expect(@lastRequest().requestHeaders['X-Up-Validate']).toEqual('password')
1097
- expect(@lastRequest().requestHeaders['X-Up-Target']).toEqual('[up-fieldset]:has(input[name="password"])')
1098
-
1099
-
1100
- @respondWith """
1101
- <form action="/users" id="registration" up-validate>
1102
-
1103
- <div up-fieldset>
1104
- Validation message
1105
- <input type="text" name="email">
1106
- </div>
1107
-
1108
- <div up-fieldset>
1109
- Validation message
1110
- <input type="password" name="password">
1111
- </div>
1112
-
1113
- </form>
1114
- """
1115
-
1116
- next =>
1117
- $labels = $('#registration [up-fieldset]')
1118
- expect($labels[0]).not.toHaveText('Validation message')
1119
- expect($labels[1]).toHaveText('Validation message')
1120
-
1121
- it 'only sends a single request when a radio button group changes', asyncSpec (next) ->
1122
- container = fixture('.container')
1123
- container.innerHTML = """
1124
- <form action="/users" id="registration" up-validate>
1125
-
1126
- <div up-fieldset>
1127
- <input type="radio" name="foo" value="1" checked>
1128
- <input type="radio" name="foo" value="2">
1129
- </div>
1130
-
1131
- </form>
1132
- """
1133
- up.hello(container)
1134
-
1135
- Trigger.change $('#registration input[value="2"]')
1136
-
1137
- next =>
1138
- expect(jasmine.Ajax.requests.count()).toEqual(1)
1139
-
1140
- describe '[up-switch]', ->
1141
-
1142
- describe 'on a select', ->
1143
-
1144
- beforeEach ->
1145
- @$select = $fixture('select[name="select-name"][up-switch=".target"]')
1146
- @$blankOption = @$select.affix('option').text('<Please select something>').val('')
1147
- @$fooOption = @$select.affix('option[value="foo"]').text('Foo')
1148
- @$barOption = @$select.affix('option[value="bar"]').text('Bar')
1149
- @$bazOption = @$select.affix('option[value="baz"]').text('Baz')
1150
-
1151
- it "shows the target element iff its up-show-for attribute contains the select value", asyncSpec (next) ->
1152
- $target = $fixture('.target[up-show-for="something bar other"]')
1153
- up.hello(@$select)
1154
-
1155
- next =>
1156
- expect($target).toBeHidden()
1157
- @$select.val('bar')
1158
- Trigger.change(@$select)
1159
-
1160
- next =>
1161
- expect($target).toBeVisible()
1162
-
1163
- it "shows the target element iff its up-hide-for attribute doesn't contain the select value", asyncSpec (next) ->
1164
- $target = $fixture('.target[up-hide-for="something bar other"]')
1165
- up.hello(@$select)
1166
-
1167
- next =>
1168
- expect($target).toBeVisible()
1169
- @$select.val('bar')
1170
- Trigger.change(@$select)
1171
-
1172
- next =>
1173
- expect($target).toBeHidden()
1174
-
1175
- it "shows the target element iff it has neither up-show-for nor up-hide-for and the select value is present", asyncSpec (next) ->
1176
- $target = $fixture('.target')
1177
- up.hello(@$select)
1178
-
1179
- next =>
1180
- expect($target).toBeHidden()
1181
- @$select.val('bar')
1182
- Trigger.change(@$select)
1183
-
1184
- next =>
1185
- expect($target).toBeVisible()
1186
-
1187
- it "shows the target element iff its up-show-for attribute contains a value ':present' and the select value is present", asyncSpec (next) ->
1188
- $target = $fixture('.target[up-show-for=":present"]')
1189
- up.hello(@$select)
1190
-
1191
- next =>
1192
- expect($target).toBeHidden()
1193
- @$select.val('bar')
1194
- Trigger.change(@$select)
1195
-
1196
- next =>
1197
- expect($target).toBeVisible()
1198
-
1199
- it "shows the target element iff its up-show-for attribute contains a value ':blank' and the select value is blank", asyncSpec (next) ->
1200
- $target = $fixture('.target[up-show-for=":blank"]')
1201
- up.hello(@$select)
1202
-
1203
- next =>
1204
- expect($target).toBeVisible()
1205
- @$select.val('bar')
1206
- Trigger.change(@$select)
1207
-
1208
- next =>
1209
- expect($target).toBeHidden()
1210
-
1211
- describe 'on a checkbox', ->
1212
-
1213
- beforeEach ->
1214
- @$checkbox = $fixture('input[name="input-name"][type="checkbox"][value="1"][up-switch=".target"]')
1215
-
1216
- it "shows the target element iff its up-show-for attribute is :checked and the checkbox is checked", asyncSpec (next) ->
1217
- $target = $fixture('.target[up-show-for=":checked"]')
1218
- up.hello(@$checkbox)
1219
-
1220
- next =>
1221
- expect($target).toBeHidden()
1222
- @$checkbox.prop('checked', true)
1223
- Trigger.change(@$checkbox)
1224
-
1225
- next =>
1226
- expect($target).toBeVisible()
1227
-
1228
- it "shows the target element iff its up-show-for attribute is :unchecked and the checkbox is unchecked", asyncSpec (next) ->
1229
- $target = $fixture('.target[up-show-for=":unchecked"]')
1230
- up.hello(@$checkbox)
1231
-
1232
- next =>
1233
- expect($target).toBeVisible()
1234
- @$checkbox.prop('checked', true)
1235
- Trigger.change(@$checkbox)
1236
-
1237
- next =>
1238
- expect($target).toBeHidden()
1239
-
1240
- it "shows the target element iff its up-hide-for attribute is :checked and the checkbox is unchecked", asyncSpec (next) ->
1241
- $target = $fixture('.target[up-hide-for=":checked"]')
1242
- up.hello(@$checkbox)
1243
-
1244
- next =>
1245
- expect($target).toBeVisible()
1246
- @$checkbox.prop('checked', true)
1247
- Trigger.change(@$checkbox)
1248
-
1249
- next =>
1250
- expect($target).toBeHidden()
1251
-
1252
- it "shows the target element iff its up-hide-for attribute is :unchecked and the checkbox is checked", asyncSpec (next) ->
1253
- $target = $fixture('.target[up-hide-for=":unchecked"]')
1254
- up.hello(@$checkbox)
1255
-
1256
- next =>
1257
- expect($target).toBeHidden()
1258
- @$checkbox.prop('checked', true)
1259
- Trigger.change(@$checkbox)
1260
-
1261
- next =>
1262
- expect($target).toBeVisible()
1263
-
1264
- it "shows the target element iff it has neither up-show-for nor up-hide-for and the checkbox is checked", asyncSpec (next) ->
1265
- $target = $fixture('.target')
1266
- up.hello(@$checkbox)
1267
-
1268
- next =>
1269
- expect($target).toBeHidden()
1270
- @$checkbox.prop('checked', true)
1271
- Trigger.change(@$checkbox)
1272
-
1273
- next =>
1274
- expect($target).toBeVisible()
1275
-
1276
- describe 'on a group of radio buttons', ->
1277
-
1278
- beforeEach ->
1279
- @$buttons = $fixture('.radio-buttons')
1280
- @$blankButton = @$buttons.affix('input[type="radio"][name="group"][up-switch=".target"]').val('')
1281
- @$fooButton = @$buttons.affix('input[type="radio"][name="group"][up-switch=".target"]').val('foo')
1282
- @$barButton = @$buttons.affix('input[type="radio"][name="group"][up-switch=".target"]').val('bar')
1283
- @$bazkButton = @$buttons.affix('input[type="radio"][name="group"][up-switch=".target"]').val('baz')
1284
-
1285
- it "shows the target element iff its up-show-for attribute contains the selected button value", asyncSpec (next) ->
1286
- $target = $fixture('.target[up-show-for="something bar other"]')
1287
- up.hello(@$buttons)
1288
-
1289
- next =>
1290
- expect($target).toBeHidden()
1291
- @$barButton.prop('checked', true)
1292
- Trigger.change(@$barButton)
1293
-
1294
- next =>
1295
- expect($target).toBeVisible()
1296
-
1297
- it "shows the target element iff its up-hide-for attribute doesn't contain the selected button value", asyncSpec (next) ->
1298
- $target = $fixture('.target[up-hide-for="something bar other"]')
1299
- up.hello(@$buttons)
1300
-
1301
- next =>
1302
- expect($target).toBeVisible()
1303
- @$barButton.prop('checked', true)
1304
- Trigger.change(@$barButton)
1305
-
1306
- next =>
1307
- expect($target).toBeHidden()
1308
-
1309
- it "shows the target element iff it has neither up-show-for nor up-hide-for and the selected button value is present", asyncSpec (next) ->
1310
- $target = $fixture('.target')
1311
- up.hello(@$buttons)
1312
-
1313
- next =>
1314
- expect($target).toBeHidden()
1315
- @$barButton.prop('checked', true)
1316
- Trigger.change(@$barButton)
1317
-
1318
- next =>
1319
- expect($target).toBeVisible()
1320
-
1321
- it "shows the target element iff its up-show-for attribute contains a value ':present' and the selected button value is present", asyncSpec (next) ->
1322
- $target = $fixture('.target[up-show-for=":present"]')
1323
- up.hello(@$buttons)
1324
-
1325
- next =>
1326
- expect($target).toBeHidden()
1327
- @$blankButton.prop('checked', true)
1328
- Trigger.change(@$blankButton)
1329
-
1330
- next =>
1331
- expect($target).toBeHidden()
1332
- @$barButton.prop('checked', true)
1333
- Trigger.change(@$barButton)
1334
-
1335
- next =>
1336
- expect($target).toBeVisible()
1337
-
1338
- it "shows the target element iff its up-show-for attribute contains a value ':blank' and the selected button value is blank", asyncSpec (next) ->
1339
- $target = $fixture('.target[up-show-for=":blank"]')
1340
- up.hello(@$buttons)
1341
-
1342
- next =>
1343
- expect($target).toBeVisible()
1344
- @$blankButton.prop('checked', true)
1345
- Trigger.change(@$blankButton)
1346
-
1347
- next =>
1348
- expect($target).toBeVisible()
1349
- @$barButton.prop('checked', true)
1350
- Trigger.change(@$barButton)
1351
-
1352
- next =>
1353
- expect($target).toBeHidden()
1354
-
1355
- it "shows the target element iff its up-show-for attribute contains a value ':checked' and any button is checked", asyncSpec (next) ->
1356
- $target = $fixture('.target[up-show-for=":checked"]')
1357
- up.hello(@$buttons)
1358
-
1359
- next =>
1360
- expect($target).toBeHidden()
1361
- @$blankButton.prop('checked', true)
1362
- Trigger.change(@$blankButton)
1363
-
1364
- next =>
1365
- expect($target).toBeVisible()
1366
-
1367
- it "shows the target element iff its up-show-for attribute contains a value ':unchecked' and no button is checked", asyncSpec (next) ->
1368
- $target = $fixture('.target[up-show-for=":unchecked"]')
1369
- up.hello(@$buttons)
1370
-
1371
- next =>
1372
- expect($target).toBeVisible()
1373
- @$blankButton.prop('checked', true)
1374
- Trigger.change(@$blankButton)
1375
-
1376
- next =>
1377
- expect($target).toBeHidden()
1378
-
1379
- describe 'on a text input', ->
1380
-
1381
- beforeEach ->
1382
- @$textInput = $fixture('input[name="input-name"][type="text"][up-switch=".target"]')
1383
-
1384
- it "shows the target element iff its up-show-for attribute contains the input value", asyncSpec (next) ->
1385
- $target = $fixture('.target[up-show-for="something bar other"]')
1386
- up.hello(@$textInput)
1387
-
1388
- next =>
1389
- expect($target).toBeHidden()
1390
- @$textInput.val('bar')
1391
- Trigger.change(@$textInput)
1392
-
1393
- next =>
1394
- expect($target).toBeVisible()
1395
-
1396
- it "shows the target element iff its up-hide-for attribute doesn't contain the input value", asyncSpec (next) ->
1397
- $target = $fixture('.target[up-hide-for="something bar other"]')
1398
- up.hello(@$textInput)
1399
-
1400
- next =>
1401
- expect($target).toBeVisible()
1402
- @$textInput.val('bar')
1403
- Trigger.change(@$textInput)
1404
-
1405
- next =>
1406
- expect($target).toBeHidden()
1407
-
1408
- it "shows the target element iff it has neither up-show-for nor up-hide-for and the input value is present", asyncSpec (next) ->
1409
- $target = $fixture('.target')
1410
- up.hello(@$textInput)
1411
-
1412
- next =>
1413
- expect($target).toBeHidden()
1414
- @$textInput.val('bar')
1415
- Trigger.change(@$textInput)
1416
-
1417
- next =>
1418
- expect($target).toBeVisible()
1419
-
1420
- it "shows the target element iff its up-show-for attribute contains a value ':present' and the input value is present", asyncSpec (next) ->
1421
- $target = $fixture('.target[up-show-for=":present"]')
1422
- up.hello(@$textInput)
1423
-
1424
- next =>
1425
- expect($target).toBeHidden()
1426
- @$textInput.val('bar')
1427
- Trigger.change(@$textInput)
1428
-
1429
- next =>
1430
- expect($target).toBeVisible()
1431
-
1432
- it "shows the target element iff its up-show-for attribute contains a value ':blank' and the input value is blank", asyncSpec (next) ->
1433
- $target = $fixture('.target[up-show-for=":blank"]')
1434
- up.hello(@$textInput)
1435
-
1436
- next =>
1437
- expect($target).toBeVisible()
1438
- @$textInput.val('bar')
1439
- Trigger.change(@$textInput)
1440
-
1441
- next =>
1442
- expect($target).toBeHidden()
1443
-
1444
- describe 'when an [up-show-for] element is dynamically inserted later', ->
1445
-
1446
- it "shows the element iff it matches the [up-switch] control's value", asyncSpec (next) ->
1447
- $select = $fixture('select[name="select-name"][up-switch=".target"]')
1448
- $select.affix('option[value="foo"]').text('Foo')
1449
- $select.affix('option[value="bar"]').text('Bar')
1450
- $select.val('foo')
1451
- up.hello($select)
1452
-
1453
- next =>
1454
- # New target enters the DOM after [up-switch] has been compiled
1455
- @$target = $fixture('.target[up-show-for="bar"]')
1456
- up.hello(@$target)
1457
-
1458
- next =>
1459
- expect(@$target).toBeHidden()
1460
-
1461
- next =>
1462
- # Check that the new element will notify subsequent changes
1463
- $select.val('bar')
1464
- Trigger.change($select)
1465
- expect(@$target).toBeVisible()
1466
-
1467
- it "doesn't re-switch targets that were part of the original compile run", asyncSpec (next) ->
1468
- $container = $fixture('.container')
1469
-
1470
- $select = $container.affix('select[name="select-name"][up-switch=".target"]')
1471
- $select.affix('option[value="foo"]').text('Foo')
1472
- $select.affix('option[value="bar"]').text('Bar')
1473
- $select.val('foo')
1474
- $existingTarget = $container.affix('.target.existing[up-show-for="bar"]')
1475
-
1476
- switchTargetSpy = up.form.knife.mock('switchTarget').and.callThrough()
1477
-
1478
- up.hello($container)
1479
-
1480
- next =>
1481
- # New target enters the DOM after [up-switch] has been compiled
1482
- @$lateTarget = $container.affix('.target.late[up-show-for="bar"]')
1483
- up.hello(@$lateTarget)
1484
-
1485
- next =>
1486
- expect(switchTargetSpy.calls.count()).toBe(2)
1487
- expect(switchTargetSpy.calls.argsFor(0)[0]).toEqual($existingTarget[0])
1488
- expect(switchTargetSpy.calls.argsFor(1)[0]).toEqual(@$lateTarget[0])