unpoly-rails 0.57.0 → 0.60.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +393 -1
- data/Gemfile.lock +5 -2
- data/README.md +1 -1
- data/README_RAILS.md +1 -1
- data/Rakefile +10 -1
- data/design/es6.js +32 -0
- data/design/ie11.txt +9 -0
- data/design/measure_jquery/element_list.js +41 -0
- data/design/measure_jquery/up.on_vs_addEventListener.js +56 -0
- data/design/todo_jquery.txt +13 -0
- data/dist/unpoly-bootstrap3.js +8 -8
- data/dist/unpoly-bootstrap3.min.js +1 -1
- data/dist/unpoly.css +22 -20
- data/dist/unpoly.js +6990 -5336
- data/dist/unpoly.min.css +1 -1
- data/dist/unpoly.min.js +4 -4
- data/lib/assets/javascripts/unpoly-bootstrap3/viewport-ext.coffee +5 -0
- data/lib/assets/javascripts/unpoly.coffee +8 -6
- data/lib/assets/javascripts/unpoly/browser.coffee.erb +23 -118
- data/lib/assets/javascripts/unpoly/classes/body_shifter.coffee +36 -0
- data/lib/assets/javascripts/unpoly/classes/cache.coffee +4 -4
- data/lib/assets/javascripts/unpoly/classes/compile_pass.coffee +45 -39
- data/lib/assets/javascripts/unpoly/classes/config.coffee +9 -0
- data/lib/assets/javascripts/unpoly/classes/css_transition.coffee +18 -27
- data/lib/assets/javascripts/unpoly/classes/divertible_chain.coffee +39 -0
- data/lib/assets/javascripts/unpoly/classes/event_listener.coffee +116 -0
- data/lib/assets/javascripts/unpoly/classes/extract_cascade.coffee +8 -8
- data/lib/assets/javascripts/unpoly/classes/extract_plan.coffee +19 -19
- data/lib/assets/javascripts/unpoly/classes/field_observer.coffee +54 -31
- data/lib/assets/javascripts/unpoly/classes/{focus_tracker.coffee → focus_follower.coffee} +2 -2
- data/lib/assets/javascripts/unpoly/classes/follow_variant.coffee +25 -25
- data/lib/assets/javascripts/unpoly/classes/html_parser.coffee +4 -11
- data/lib/assets/javascripts/unpoly/classes/motion_controller.coffee +157 -0
- data/lib/assets/javascripts/unpoly/classes/params.coffee.erb +525 -0
- data/lib/assets/javascripts/unpoly/classes/record.coffee +8 -2
- data/lib/assets/javascripts/unpoly/classes/rect.js +21 -0
- data/lib/assets/javascripts/unpoly/classes/request.coffee +41 -35
- data/lib/assets/javascripts/unpoly/classes/response.coffee +7 -3
- data/lib/assets/javascripts/unpoly/classes/reveal_motion.coffee +102 -0
- data/lib/assets/javascripts/unpoly/classes/scroll_motion.coffee +67 -0
- data/lib/assets/javascripts/unpoly/classes/selector.coffee +60 -0
- data/lib/assets/javascripts/unpoly/classes/tether.coffee +105 -0
- data/lib/assets/javascripts/unpoly/classes/url_set.coffee +12 -7
- data/lib/assets/javascripts/unpoly/element.coffee.erb +1126 -0
- data/lib/assets/javascripts/unpoly/event.coffee.erb +437 -0
- data/lib/assets/javascripts/unpoly/feedback.coffee +73 -94
- data/lib/assets/javascripts/unpoly/form.coffee.erb +188 -181
- data/lib/assets/javascripts/unpoly/{dom.coffee.erb → fragment.coffee.erb} +250 -283
- data/lib/assets/javascripts/unpoly/framework.coffee +67 -0
- data/lib/assets/javascripts/unpoly/history.coffee +29 -28
- data/lib/assets/javascripts/unpoly/legacy.coffee +60 -0
- data/lib/assets/javascripts/unpoly/link.coffee.erb +127 -119
- data/lib/assets/javascripts/unpoly/log.coffee +99 -19
- data/lib/assets/javascripts/unpoly/modal.coffee.erb +95 -118
- data/lib/assets/javascripts/unpoly/motion.coffee.erb +158 -138
- data/lib/assets/javascripts/unpoly/namespace.coffee.erb +0 -5
- data/lib/assets/javascripts/unpoly/popup.coffee.erb +119 -102
- data/lib/assets/javascripts/unpoly/protocol.coffee +11 -15
- data/lib/assets/javascripts/unpoly/proxy.coffee +62 -65
- data/lib/assets/javascripts/unpoly/radio.coffee +3 -5
- data/lib/assets/javascripts/unpoly/rails.coffee +8 -9
- data/lib/assets/javascripts/unpoly/syntax.coffee.erb +173 -125
- data/lib/assets/javascripts/unpoly/toast.coffee +25 -24
- data/lib/assets/javascripts/unpoly/tooltip.coffee +89 -79
- data/lib/assets/javascripts/unpoly/util.coffee.erb +579 -1074
- data/lib/assets/javascripts/unpoly/{layout.coffee.erb → viewport.coffee.erb} +334 -264
- data/lib/assets/stylesheets/unpoly/dom.sass +1 -1
- data/lib/assets/stylesheets/unpoly/layout.sass +2 -0
- data/lib/assets/stylesheets/unpoly/popup.sass +0 -1
- data/lib/assets/stylesheets/unpoly/tooltip.sass +17 -12
- data/lib/unpoly/rails/version.rb +1 -1
- data/package.json +1 -2
- data/spec_app/Gemfile +2 -1
- data/spec_app/Gemfile.lock +38 -27
- data/spec_app/app/assets/javascripts/integration_test.coffee +1 -0
- data/spec_app/app/assets/javascripts/jasmine_specs.coffee +1 -2
- data/spec_app/app/assets/stylesheets/integration_test.sass +14 -1
- data/spec_app/app/controllers/scroll_test_controller.rb +5 -0
- data/spec_app/app/views/css_test/modal.erb +6 -6
- data/spec_app/app/views/css_test/popup.erb +44 -18
- data/spec_app/app/views/css_test/tooltip.erb +23 -4
- data/spec_app/app/views/error_test/trigger.erb +1 -1
- data/spec_app/app/views/form_test/basics/new.erb +1 -3
- data/spec_app/app/views/pages/start.erb +9 -2
- data/spec_app/app/views/reveal_test/long1.erb +1 -1
- data/spec_app/app/views/reveal_test/long2.erb +1 -1
- data/spec_app/app/views/reveal_test/within_document_viewport.erb +24 -0
- data/spec_app/app/views/reveal_test/within_overflowing_div_viewport.erb +28 -0
- data/spec_app/app/views/scroll_test/long1.erb +30 -0
- data/spec_app/config/routes.rb +1 -0
- data/spec_app/spec/javascripts/helpers/agent_detector.coffee +3 -0
- data/spec_app/spec/javascripts/helpers/async_sequence.js.coffee +1 -0
- data/spec_app/spec/javascripts/helpers/browser_switches.js.coffee +17 -5
- data/spec_app/spec/javascripts/helpers/enable_logging.js.coffee +1 -1
- data/spec_app/spec/javascripts/helpers/fixture.js.coffee +25 -0
- data/spec_app/spec/javascripts/helpers/jquery_no_conflict.js +1 -0
- data/spec_app/spec/javascripts/helpers/last_request.js.coffee +1 -0
- data/spec_app/spec/javascripts/helpers/mock_ajax.js.coffee +1 -1
- data/spec_app/spec/javascripts/helpers/parse_form_data.js.coffee +2 -2
- data/spec_app/spec/javascripts/helpers/protect_jasmine_runner.coffee +4 -1
- data/spec_app/spec/javascripts/helpers/remove_body_margin.js.coffee +3 -0
- data/spec_app/spec/javascripts/helpers/reset_history.js.coffee +2 -1
- data/spec_app/spec/javascripts/helpers/reset_knife.js.coffee +2 -2
- data/spec_app/spec/javascripts/helpers/reset_up.js.coffee +18 -11
- data/spec_app/spec/javascripts/helpers/restore_body_scroll.js.coffee +3 -0
- data/spec_app/spec/javascripts/helpers/show_lib_versions.coffee +3 -0
- data/spec_app/spec/javascripts/helpers/spec_util.coffee +47 -0
- data/spec_app/spec/javascripts/helpers/to_be_around.js.coffee +3 -0
- data/spec_app/spec/javascripts/helpers/to_be_array.coffee +5 -0
- data/spec_app/spec/javascripts/helpers/to_be_attached.coffee +6 -2
- data/spec_app/spec/javascripts/helpers/to_be_blank.js.coffee +3 -0
- data/spec_app/spec/javascripts/helpers/to_be_detached.coffee +6 -2
- data/spec_app/spec/javascripts/helpers/to_be_element.js.coffee +8 -0
- data/spec_app/spec/javascripts/helpers/to_be_error.coffee +3 -0
- data/spec_app/spec/javascripts/helpers/to_be_given.js.coffee +3 -0
- data/spec_app/spec/javascripts/helpers/to_be_hidden.js.coffee +8 -0
- data/spec_app/spec/javascripts/helpers/to_be_missing.js.coffee +3 -0
- data/spec_app/spec/javascripts/helpers/to_be_present.js.coffee +3 -0
- data/spec_app/spec/javascripts/helpers/to_be_scrolled_to.coffee +3 -0
- data/spec_app/spec/javascripts/helpers/to_be_visible.js.coffee +9 -0
- data/spec_app/spec/javascripts/helpers/to_contain.js.coffee +3 -0
- data/spec_app/spec/javascripts/helpers/to_end_with.js.coffee +3 -0
- data/spec_app/spec/javascripts/helpers/to_equal_jquery.js.coffee +1 -2
- data/spec_app/spec/javascripts/helpers/to_equal_node_list.coffee +7 -0
- data/spec_app/spec/javascripts/helpers/to_equal_via_is_equal.js.coffee +7 -0
- data/spec_app/spec/javascripts/helpers/to_have_class.js.coffee +10 -0
- data/spec_app/spec/javascripts/helpers/to_have_descendant.js.coffee +10 -0
- data/spec_app/spec/javascripts/helpers/to_have_length.js.coffee +8 -0
- data/spec_app/spec/javascripts/helpers/to_have_opacity.coffee +7 -3
- data/spec_app/spec/javascripts/helpers/to_have_own_property.js.coffee +3 -0
- data/spec_app/spec/javascripts/helpers/to_have_request_method.js.coffee +1 -0
- data/spec_app/spec/javascripts/helpers/to_have_text.js.coffee +9 -0
- data/spec_app/spec/javascripts/helpers/to_have_unhandled_rejections.coffee +0 -21
- data/spec_app/spec/javascripts/helpers/to_match_list.coffee +14 -0
- data/spec_app/spec/javascripts/helpers/to_match_selector.coffee +3 -0
- data/spec_app/spec/javascripts/helpers/to_match_text.js.coffee +4 -1
- data/spec_app/spec/javascripts/helpers/to_match_url.coffee +1 -0
- data/spec_app/spec/javascripts/helpers/trigger.js.coffee +91 -7
- data/spec_app/spec/javascripts/helpers/wait_until_dom_ready.js.coffee +3 -0
- data/spec_app/spec/javascripts/up/browser_spec.js.coffee +23 -90
- data/spec_app/spec/javascripts/up/classes/cache_spec.js.coffee +3 -0
- data/spec_app/spec/javascripts/up/classes/config_spec.coffee +24 -0
- data/spec_app/spec/javascripts/up/classes/divertible_chain_spec.coffee +45 -0
- data/spec_app/spec/javascripts/up/classes/focus_tracker_spec.coffee +5 -2
- data/spec_app/spec/javascripts/up/classes/params_spec.coffee +557 -0
- data/spec_app/spec/javascripts/up/classes/request_spec.coffee +7 -4
- data/spec_app/spec/javascripts/up/classes/scroll_motion_spec.js.coffee +51 -0
- data/spec_app/spec/javascripts/up/classes/store/memory_spec.js.coffee +3 -0
- data/spec_app/spec/javascripts/up/classes/store/session_spec.js.coffee +3 -2
- data/spec_app/spec/javascripts/up/element_spec.coffee +897 -0
- data/spec_app/spec/javascripts/up/event_spec.js.coffee +496 -0
- data/spec_app/spec/javascripts/up/feedback_spec.js.coffee +69 -48
- data/spec_app/spec/javascripts/up/form_spec.js.coffee +252 -194
- data/spec_app/spec/javascripts/up/{dom_spec.js.coffee → fragment_spec.js.coffee} +381 -388
- data/spec_app/spec/javascripts/up/history_spec.js.coffee +21 -19
- data/spec_app/spec/javascripts/up/jquery_spec.js.coffee +4 -0
- data/spec_app/spec/javascripts/up/legacy_spec.js.coffee +27 -0
- data/spec_app/spec/javascripts/up/link_spec.js.coffee +163 -160
- data/spec_app/spec/javascripts/up/log_spec.js.coffee +85 -12
- data/spec_app/spec/javascripts/up/modal_spec.js.coffee +141 -123
- data/spec_app/spec/javascripts/up/motion_spec.js.coffee +117 -113
- data/spec_app/spec/javascripts/up/popup_spec.js.coffee +60 -77
- data/spec_app/spec/javascripts/up/protocol_spec.js.coffee +1 -0
- data/spec_app/spec/javascripts/up/proxy_spec.js.coffee +85 -78
- data/spec_app/spec/javascripts/up/radio_spec.js.coffee +29 -22
- data/spec_app/spec/javascripts/up/rails_spec.js.coffee +14 -13
- data/spec_app/spec/javascripts/up/spec_spec.js.coffee +9 -0
- data/spec_app/spec/javascripts/up/syntax_spec.js.coffee +96 -66
- data/spec_app/spec/javascripts/up/toast_spec.js.coffee +37 -0
- data/spec_app/spec/javascripts/up/tooltip_spec.js.coffee +31 -47
- data/spec_app/spec/javascripts/up/util_spec.js.coffee +725 -562
- data/spec_app/spec/javascripts/up/{layout_spec.js.coffee → viewport_spec.js.coffee} +175 -149
- metadata +57 -19
- data/lib/assets/javascripts/unpoly-bootstrap3/layout-ext.coffee +0 -5
- data/lib/assets/javascripts/unpoly/bus.coffee.erb +0 -518
- data/lib/assets/javascripts/unpoly/classes/extract_step.coffee +0 -4
- data/lib/assets/javascripts/unpoly/classes/motion_tracker.coffee +0 -125
- data/lib/assets/javascripts/unpoly/params.coffee.erb +0 -522
- data/spec_app/spec/javascripts/helpers/append_fixture.js.coffee +0 -8
- data/spec_app/spec/javascripts/up/bus_spec.js.coffee +0 -210
- data/spec_app/spec/javascripts/up/namespace_spec.js.coffee +0 -9
- data/spec_app/spec/javascripts/up/params_spec.coffee +0 -768
- data/spec_app/vendor/asset-libs/jasmine-fixture-1.3.4/jasmine-fixture.js +0 -433
- data/spec_app/vendor/asset-libs/jasmine-jquery-2.1.1/.bower.json +0 -26
- data/spec_app/vendor/asset-libs/jasmine-jquery-2.1.1/jasmine-jquery.js +0 -838
@@ -1,5 +1,9 @@
|
|
1
|
+
u = up.util
|
2
|
+
$ = jQuery
|
3
|
+
|
1
4
|
beforeEach ->
|
2
5
|
jasmine.addMatchers
|
3
6
|
toBeDetached: (util, customEqualityTesters) ->
|
4
|
-
compare: (
|
5
|
-
|
7
|
+
compare: (element) ->
|
8
|
+
element = up.element.get(element)
|
9
|
+
pass: element && up.specUtil.isDetached(element)
|
@@ -1,11 +1,15 @@
|
|
1
|
+
u = up.util
|
2
|
+
e = up.element
|
3
|
+
$ = jQuery
|
4
|
+
|
1
5
|
beforeEach ->
|
2
6
|
jasmine.addMatchers
|
3
7
|
toHaveOpacity: (util, customEqualityTesters) ->
|
4
8
|
compare: (element, expectedOpacity, tolerance = 0.0) ->
|
5
|
-
element =
|
6
|
-
actualOpacity =
|
9
|
+
element = e.get(element)
|
10
|
+
actualOpacity = e.styleNumber(element, 'opacity')
|
7
11
|
result = {}
|
8
12
|
result.pass = Math.abs(expectedOpacity - actualOpacity) <= tolerance
|
9
13
|
unless result.pass
|
10
|
-
result.message = up.
|
14
|
+
result.message = up.log.sprintf("Expected %o to have opacity %o, but it was %o", element, expectedOpacity, actualOpacity)
|
11
15
|
return result
|
@@ -16,24 +16,3 @@ beforeEach ->
|
|
16
16
|
# It doesn't really matter what's in actual.
|
17
17
|
# A good way to call this is e.g. `expect(window).not.toHaveUnhandledRejections()
|
18
18
|
pass: UNHANDLED_REJECTIONS.length > 0
|
19
|
-
|
20
|
-
#UnhandledRejectionTracker = do ->
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
##beforeEach (done) ->
|
27
|
-
## @unhandledRejections = []
|
28
|
-
## @trackUnhandledRejections = (event) =>
|
29
|
-
## @unhandledRejections.push(event)
|
30
|
-
## window.addEventListener('unhandledrejection', @trackUnhandledRejections)
|
31
|
-
## done()
|
32
|
-
##
|
33
|
-
##afterEach (done) ->
|
34
|
-
## hadUnhandledRejections = @unhandledRejections.length > 0
|
35
|
-
## @unhandledRejections = []
|
36
|
-
## if hadUnhandledRejections
|
37
|
-
## done.fail('There were rejected promises without a rejection handler')
|
38
|
-
## else
|
39
|
-
## done()
|
@@ -0,0 +1,14 @@
|
|
1
|
+
u = up.util
|
2
|
+
|
3
|
+
beforeEach ->
|
4
|
+
jasmine.addMatchers
|
5
|
+
toMatchList: (util, customEqualityTesters) ->
|
6
|
+
compare: (actualList, expectedList) ->
|
7
|
+
actualList = u.toArray(actualList) if actualList
|
8
|
+
expectedList = u.toArray(expectedList) if expectedList
|
9
|
+
|
10
|
+
pass:
|
11
|
+
actualList &&
|
12
|
+
expectedList &&
|
13
|
+
actualList.length == expectedList.length &&
|
14
|
+
u.every(expectedList, (elem) -> u.contains(actualList, elem))
|
@@ -1,9 +1,12 @@
|
|
1
|
+
u = up.util
|
2
|
+
$ = jQuery
|
3
|
+
|
1
4
|
beforeEach ->
|
2
5
|
jasmine.addMatchers
|
3
6
|
toMatchText: (util, customEqualityTesters) ->
|
4
7
|
compare: (actualString, expectedString) ->
|
5
8
|
normalize = (str) ->
|
6
|
-
str =
|
9
|
+
str = str.trim()
|
7
10
|
str = str.replace(/[\n\r\t ]+/g, ' ')
|
8
11
|
str
|
9
12
|
|
@@ -1,7 +1,9 @@
|
|
1
|
+
u = up.util
|
2
|
+
e = up.element
|
3
|
+
$ = jQuery
|
4
|
+
|
1
5
|
@Trigger = (->
|
2
|
-
|
3
|
-
u = up.util
|
4
|
-
|
6
|
+
|
5
7
|
mouseover = (element, options) ->
|
6
8
|
$element = $(element)
|
7
9
|
event = createMouseEvent('mouseover', options)
|
@@ -41,6 +43,41 @@
|
|
41
43
|
$element = $(element)
|
42
44
|
$element.focus()
|
43
45
|
|
46
|
+
submit = (form, options) ->
|
47
|
+
form = e.get(form)
|
48
|
+
options = u.options(options,
|
49
|
+
cancelable: true,
|
50
|
+
bubbles: true
|
51
|
+
)
|
52
|
+
event = createEvent('submit', options)
|
53
|
+
form.dispatchEvent(event)
|
54
|
+
|
55
|
+
change = (field, options) ->
|
56
|
+
field = e.get(field)
|
57
|
+
options = u.options(options,
|
58
|
+
cancelable: false,
|
59
|
+
bubbles: true
|
60
|
+
)
|
61
|
+
event = createEvent('change', options)
|
62
|
+
field.dispatchEvent(event)
|
63
|
+
|
64
|
+
input = (field, options) ->
|
65
|
+
field = e.get(field)
|
66
|
+
options = u.options(options,
|
67
|
+
cancelable: false,
|
68
|
+
bubbles: true
|
69
|
+
)
|
70
|
+
event = createEvent('input', options)
|
71
|
+
field.dispatchEvent(event)
|
72
|
+
|
73
|
+
escapeSequence = (element, options) ->
|
74
|
+
options = u.options(options,
|
75
|
+
key: 'Escape'
|
76
|
+
)
|
77
|
+
for type in ['keydown', 'keypress', 'keyup']
|
78
|
+
event = createKeyboardEvent(type, options)
|
79
|
+
element.dispatchEvent(event)
|
80
|
+
|
44
81
|
clickSequence = (element, options) ->
|
45
82
|
$element = $(element)
|
46
83
|
mouseover($element, options)
|
@@ -59,6 +96,17 @@
|
|
59
96
|
mouseout($element, options)
|
60
97
|
mouseleave($element, options)
|
61
98
|
|
99
|
+
# Can't use the new Event constructor in IE11 because computer.
|
100
|
+
# http://www.codeproject.com/Tips/893254/JavaScript-Triggering-Event-Manually-in-Internet-E
|
101
|
+
createEvent = (type, options) ->
|
102
|
+
options = u.options(options,
|
103
|
+
cancelable: true,
|
104
|
+
bubbles: true
|
105
|
+
)
|
106
|
+
event = document.createEvent('Event')
|
107
|
+
event.initEvent(type, options.bubbles, options.cancelable)
|
108
|
+
event
|
109
|
+
|
62
110
|
# Can't use the new MouseEvent constructor in IE11 because computer.
|
63
111
|
# http://www.codeproject.com/Tips/893254/JavaScript-Triggering-Event-Manually-in-Internet-E
|
64
112
|
createMouseEvent = (type, options) ->
|
@@ -97,9 +145,39 @@
|
|
97
145
|
)
|
98
146
|
event
|
99
147
|
|
100
|
-
|
101
|
-
|
102
|
-
|
148
|
+
createKeyboardEvent = (type, options) ->
|
149
|
+
options = u.options(options,
|
150
|
+
cancelable: true,
|
151
|
+
bubbles: true,
|
152
|
+
view: window,
|
153
|
+
key: null,
|
154
|
+
)
|
155
|
+
|
156
|
+
if canEventConstructors()
|
157
|
+
event = new KeyboardEvent(type, options)
|
158
|
+
else
|
159
|
+
event = document.createEvent('KeyboardEvent')
|
160
|
+
# The argument of initKeyboardEvent differs wildly between browsers.
|
161
|
+
# In IE 11 it is initKeyboardEvent(type, canBubble, cancelable, view, key, location, modifierList, repeat, locale).
|
162
|
+
event.initKeyboardEvent(type,
|
163
|
+
options.bubbles,
|
164
|
+
options.cancelable,
|
165
|
+
options.view,
|
166
|
+
options.key,
|
167
|
+
null,
|
168
|
+
null,
|
169
|
+
null,
|
170
|
+
null,
|
171
|
+
)
|
172
|
+
|
173
|
+
event
|
174
|
+
|
175
|
+
canEventConstructors = ->
|
176
|
+
typeof window.Event == "function"
|
177
|
+
|
178
|
+
dispatch = (element, event) ->
|
179
|
+
element = e.get(element)
|
180
|
+
element.dispatchEvent(event)
|
103
181
|
|
104
182
|
mouseover: mouseover
|
105
183
|
mouseenter: mouseenter
|
@@ -111,6 +189,12 @@
|
|
111
189
|
clickSequence: clickSequence
|
112
190
|
hoverSequence: hoverSequence
|
113
191
|
unhoverSequence: unhoverSequence
|
192
|
+
escapeSequence: escapeSequence
|
193
|
+
submit: submit
|
194
|
+
change: change
|
195
|
+
input: input
|
196
|
+
createEvent: createEvent
|
114
197
|
createMouseEvent: createMouseEvent
|
115
|
-
|
198
|
+
createKeyboardEvent: createKeyboardEvent
|
199
|
+
|
116
200
|
)()
|
@@ -1,6 +1,7 @@
|
|
1
|
-
|
1
|
+
u = up.util
|
2
|
+
$ = jQuery
|
2
3
|
|
3
|
-
|
4
|
+
describe 'up.browser', ->
|
4
5
|
|
5
6
|
describe 'JavaScript functions', ->
|
6
7
|
|
@@ -17,25 +18,28 @@ describe 'up.browser', ->
|
|
17
18
|
submitForm = spyOn(up.browser, 'submitForm')
|
18
19
|
up.browser.navigate('/foo', method: 'GET', params: { param1: 'param1 value', param2: 'param2 value' })
|
19
20
|
expect(submitForm).toHaveBeenCalled()
|
21
|
+
|
20
22
|
$form = $('form.up-page-loader')
|
21
|
-
|
23
|
+
|
24
|
+
expect($form).toBeAttached()
|
22
25
|
# GET forms cannot have an URL with a query section in their [action] attribute.
|
23
26
|
# The query section would be overridden by the serialized input values on submission.
|
24
27
|
expect($form.attr('action')).toMatchUrl('/foo')
|
25
|
-
|
26
|
-
expect($form.find('input[name="
|
28
|
+
|
29
|
+
expect($form.find('input[name="param1"][value="param1 value"]')).toBeAttached()
|
30
|
+
expect($form.find('input[name="param2"][value="param2 value"]')).toBeAttached()
|
27
31
|
|
28
32
|
it 'merges params from the given URL and the { params } option', ->
|
29
33
|
submitForm = spyOn(up.browser, 'submitForm')
|
30
34
|
up.browser.navigate('/foo?param1=param1%20value', method: 'GET', params: { param2: 'param2 value' })
|
31
35
|
expect(submitForm).toHaveBeenCalled()
|
32
36
|
$form = $('form.up-page-loader')
|
33
|
-
expect($form).
|
37
|
+
expect($form).toBeAttached()
|
34
38
|
# GET forms cannot have an URL with a query section in their [action] attribute.
|
35
39
|
# The query section would be overridden by the serialized input values on submission.
|
36
40
|
expect($form.attr('action')).toMatchUrl('/foo')
|
37
|
-
expect($form.find('input[name="param1"][value="param1 value"]')).
|
38
|
-
expect($form.find('input[name="param2"][value="param2 value"]')).
|
41
|
+
expect($form.find('input[name="param1"][value="param1 value"]')).toBeAttached()
|
42
|
+
expect($form.find('input[name="param2"][value="param2 value"]')).toBeAttached()
|
39
43
|
|
40
44
|
describe "for POST requests", ->
|
41
45
|
|
@@ -44,22 +48,22 @@ describe 'up.browser', ->
|
|
44
48
|
up.browser.navigate('/foo', method: 'POST', params: { param1: 'param1 value', param2: 'param2 value' })
|
45
49
|
expect(submitForm).toHaveBeenCalled()
|
46
50
|
$form = $('form.up-page-loader')
|
47
|
-
expect($form).
|
51
|
+
expect($form).toBeAttached()
|
48
52
|
expect($form.attr('action')).toMatchUrl('/foo')
|
49
53
|
expect($form.attr('method')).toEqual('POST')
|
50
|
-
expect($form.find('input[name="param1"][value="param1 value"]')).
|
51
|
-
expect($form.find('input[name="param2"][value="param2 value"]')).
|
54
|
+
expect($form.find('input[name="param1"][value="param1 value"]')).toBeAttached()
|
55
|
+
expect($form.find('input[name="param2"][value="param2 value"]')).toBeAttached()
|
52
56
|
|
53
57
|
it 'merges params from the given URL and the { params } option', ->
|
54
58
|
submitForm = spyOn(up.browser, 'submitForm')
|
55
59
|
up.browser.navigate('/foo?param1=param1%20value', method: 'POST', params: { param2: 'param2 value' })
|
56
60
|
expect(submitForm).toHaveBeenCalled()
|
57
61
|
$form = $('form.up-page-loader')
|
58
|
-
expect($form).
|
62
|
+
expect($form).toBeAttached()
|
59
63
|
expect($form.attr('action')).toMatchUrl('/foo')
|
60
64
|
expect($form.attr('method')).toEqual('POST')
|
61
|
-
expect($form.find('input[name="param1"][value="param1 value"]')).
|
62
|
-
expect($form.find('input[name="param2"][value="param2 value"]')).
|
65
|
+
expect($form.find('input[name="param1"][value="param1 value"]')).toBeAttached()
|
66
|
+
expect($form.find('input[name="param2"][value="param2 value"]')).toBeAttached()
|
63
67
|
|
64
68
|
u.each ['PUT', 'PATCH', 'DELETE'], (method) ->
|
65
69
|
|
@@ -70,7 +74,7 @@ describe 'up.browser', ->
|
|
70
74
|
up.browser.navigate('/foo', method: method)
|
71
75
|
expect(submitForm).toHaveBeenCalled()
|
72
76
|
$form = $('form.up-page-loader')
|
73
|
-
expect($form).
|
77
|
+
expect($form).toBeAttached()
|
74
78
|
expect($form.attr('method')).toEqual('POST')
|
75
79
|
expect($form.find('input[name="_method"]').val()).toEqual(method)
|
76
80
|
|
@@ -86,7 +90,7 @@ describe 'up.browser', ->
|
|
86
90
|
expect(@submitForm).toHaveBeenCalled()
|
87
91
|
$form = $('form.up-page-loader')
|
88
92
|
$tokenInput = $form.find('input[name="csrf-param"]')
|
89
|
-
expect($tokenInput).
|
93
|
+
expect($tokenInput).toBeAttached()
|
90
94
|
expect($tokenInput.val()).toEqual('csrf-token')
|
91
95
|
|
92
96
|
it 'does not add a CSRF token if there is none', ->
|
@@ -95,92 +99,21 @@ describe 'up.browser', ->
|
|
95
99
|
expect(@submitForm).toHaveBeenCalled()
|
96
100
|
$form = $('form.up-page-loader')
|
97
101
|
$tokenInput = $form.find('input[name="csrf-param"]')
|
98
|
-
expect($tokenInput).not.
|
102
|
+
expect($tokenInput).not.toBeAttached()
|
99
103
|
|
100
104
|
it 'does not add a CSRF token for GET requests', ->
|
101
105
|
up.browser.navigate('/foo', method: 'get')
|
102
106
|
expect(@submitForm).toHaveBeenCalled()
|
103
107
|
$form = $('form.up-page-loader')
|
104
108
|
$tokenInput = $form.find('input[name="csrf-param"]')
|
105
|
-
expect($tokenInput).not.
|
109
|
+
expect($tokenInput).not.toBeAttached()
|
106
110
|
|
107
111
|
it 'does not add a CSRF token when loading content from another domain', ->
|
108
112
|
up.browser.navigate('http://other-domain.tld/foo', method: 'get')
|
109
113
|
expect(@submitForm).toHaveBeenCalled()
|
110
114
|
$form = $('form.up-page-loader')
|
111
115
|
$tokenInput = $form.find('input[name="csrf-param"]')
|
112
|
-
expect($tokenInput).not.
|
113
|
-
|
114
|
-
describe 'up.browser.sprintf', ->
|
115
|
-
|
116
|
-
describe '(string argument)', ->
|
117
|
-
|
118
|
-
it 'serializes with surrounding quotes', ->
|
119
|
-
formatted = up.browser.sprintf('before %o after', 'argument')
|
120
|
-
expect(formatted).toEqual('before "argument" after')
|
121
|
-
|
122
|
-
describe '(undefined argument)', ->
|
123
|
-
|
124
|
-
it 'serializes to the word "undefined"', ->
|
125
|
-
formatted = up.browser.sprintf('before %o after', undefined)
|
126
|
-
expect(formatted).toEqual('before undefined after')
|
127
|
-
|
128
|
-
describe '(null argument)', ->
|
129
|
-
|
130
|
-
it 'serializes to the word "null"', ->
|
131
|
-
formatted = up.browser.sprintf('before %o after', null)
|
132
|
-
expect(formatted).toEqual('before null after')
|
133
|
-
|
134
|
-
describe '(number argument)', ->
|
135
|
-
|
136
|
-
it 'serializes the number as string', ->
|
137
|
-
formatted = up.browser.sprintf('before %o after', 5)
|
138
|
-
expect(formatted).toEqual('before 5 after')
|
139
|
-
|
140
|
-
describe '(function argument)', ->
|
141
|
-
|
142
|
-
it 'serializes the function code', ->
|
143
|
-
formatted = up.browser.sprintf('before %o after', `function foo() {}`)
|
144
|
-
expect(formatted).toEqual('before function foo() {} after')
|
145
|
-
|
146
|
-
describe '(array argument)', ->
|
147
|
-
|
148
|
-
it 'recursively serializes the elements', ->
|
149
|
-
formatted = up.browser.sprintf('before %o after', [1, "foo"])
|
150
|
-
expect(formatted).toEqual('before [1, "foo"] after')
|
151
|
-
|
152
|
-
describe '(element argument)', ->
|
153
|
-
|
154
|
-
it 'serializes the tag name with id, name and class attributes, but ignores other attributes', ->
|
155
|
-
$element = $('<table id="id-value" name="name-value" class="class-value" title="title-value">')
|
156
|
-
element = $element.get(0)
|
157
|
-
formatted = up.browser.sprintf('before %o after', element)
|
158
|
-
expect(formatted).toEqual('before <table id="id-value" name="name-value" class="class-value"> after')
|
159
|
-
|
160
|
-
describe '(jQuery argument)', ->
|
161
|
-
|
162
|
-
it 'serializes the tag name with id, name and class attributes, but ignores other attributes', ->
|
163
|
-
$element1 = $('<table id="table-id">')
|
164
|
-
$element2 = $('<ul id="ul-id">')
|
165
|
-
formatted = up.browser.sprintf('before %o after', $element1.add($element2))
|
166
|
-
expect(formatted).toEqual('before $(<table id="table-id">, <ul id="ul-id">) after')
|
167
|
-
|
168
|
-
describe '(object argument)', ->
|
169
|
-
|
170
|
-
it 'serializes to JSON', ->
|
171
|
-
object = { foo: 'foo-value', bar: 'bar-value' }
|
172
|
-
formatted = up.browser.sprintf('before %o after', object)
|
173
|
-
expect(formatted).toEqual('before {"foo":"foo-value","bar":"bar-value"} after')
|
174
|
-
|
175
|
-
it "skips a key if a getter crashes", ->
|
176
|
-
object = {}
|
177
|
-
Object.defineProperty(object, 'foo', get: (-> throw "error"))
|
178
|
-
formatted = up.browser.sprintf('before %o after', object)
|
179
|
-
expect(formatted).toEqual('before {} after')
|
180
|
-
|
181
|
-
object.bar = 'bar'
|
182
|
-
formatted = up.browser.sprintf('before %o after', object)
|
183
|
-
expect(formatted).toEqual('before {"bar":"bar"} after')
|
116
|
+
expect($tokenInput).not.toBeAttached()
|
184
117
|
|
185
118
|
describe 'up.browser.whenConfirmed', ->
|
186
119
|
|