joosy 0.1.0.RC3 → 0.1.0.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. data/.gitignore +0 -2
  2. data/Gemfile +2 -13
  3. data/Gemfile.lock +62 -80
  4. data/Guardfile +15 -21
  5. data/MIT-LICENSE +2 -2
  6. data/README.rdoc +3 -0
  7. data/app/helpers/joosy/sprockets_helper.rb +11 -23
  8. data/joosy.gemspec +3 -3
  9. data/lib/joosy/forms.rb +12 -2
  10. data/lib/joosy/rails/engine.rb +1 -9
  11. data/lib/joosy/rails/version.rb +2 -2
  12. data/lib/joosy-rails.rb +5 -0
  13. data/lib/rails/generators/joosy/application_generator.rb +3 -13
  14. data/lib/rails/generators/joosy/joosy_base.rb +2 -2
  15. data/lib/rails/generators/joosy/layout_generator.rb +1 -8
  16. data/lib/rails/generators/joosy/page_generator.rb +6 -21
  17. data/lib/rails/generators/joosy/preloader_generator.rb +7 -14
  18. data/lib/rails/generators/joosy/templates/app/layouts/application.js.coffee +0 -1
  19. data/lib/rails/generators/joosy/templates/app/layouts/template.js.coffee +1 -1
  20. data/lib/rails/generators/joosy/templates/app/pages/application.js.coffee +1 -1
  21. data/lib/rails/generators/joosy/templates/app/pages/template.js.coffee +3 -3
  22. data/lib/rails/generators/joosy/templates/app/routes.js.coffee +1 -7
  23. data/lib/rails/generators/joosy/templates/app/widgets/template.js.coffee +2 -2
  24. data/lib/rails/generators/joosy/templates/app.js.coffee +0 -3
  25. data/lib/rails/generators/joosy/templates/app_preloader.js.coffee.erb +12 -9
  26. data/lib/rails/generators/joosy/templates/preload.html.erb +6 -5
  27. data/lib/rails/generators/joosy/templates/preload.html.haml +5 -3
  28. data/lib/rails/generators/joosy/templates/preload.html.slim +21 -0
  29. data/lib/rails/generators/joosy/widget_generator.rb +1 -8
  30. data/spec/javascripts/helpers/spec_helper.js.coffee +0 -20
  31. data/spec/javascripts/joosy/core/modules/container_spec.js.coffee +27 -24
  32. data/spec/javascripts/joosy/core/modules/events_spec.js.coffee +18 -42
  33. data/spec/javascripts/joosy/core/modules/filters_spec.js.coffee +27 -27
  34. data/spec/javascripts/joosy/core/modules/log_spec.js.coffee +3 -3
  35. data/spec/javascripts/joosy/core/modules/module_spec.js.coffee +15 -6
  36. data/spec/javascripts/joosy/core/modules/time_manager_spec.js.coffee +7 -12
  37. data/spec/javascripts/joosy/core/modules/widget_manager_spec.js.coffee +17 -31
  38. data/tmp/javascripts/.gitignore +1 -0
  39. data/tmp/spec/javascripts/helpers/.gitignore +1 -0
  40. data/vendor/assets/javascripts/base64.js +135 -0
  41. data/vendor/assets/javascripts/joosy/core/application.js.coffee +26 -0
  42. data/vendor/assets/javascripts/joosy/core/form.js.coffee +87 -0
  43. data/vendor/assets/javascripts/joosy/core/joosy.js.coffee +62 -0
  44. data/vendor/assets/javascripts/joosy/core/layout.js.coffee +38 -0
  45. data/vendor/assets/javascripts/joosy/core/modules/container.js.coffee +51 -0
  46. data/vendor/assets/javascripts/joosy/core/modules/events.js.coffee +17 -0
  47. data/vendor/assets/javascripts/joosy/core/modules/filters.js.coffee +39 -0
  48. data/vendor/assets/javascripts/joosy/core/modules/log.js.coffee +12 -0
  49. data/vendor/assets/javascripts/joosy/core/modules/module.js.coffee +28 -0
  50. data/vendor/assets/javascripts/joosy/core/modules/time_manager.js.coffee +23 -0
  51. data/vendor/assets/javascripts/joosy/core/modules/widgets_manager.js.coffee +45 -0
  52. data/vendor/assets/javascripts/joosy/core/page.js.coffee +136 -0
  53. data/vendor/assets/javascripts/joosy/core/resource/rest.js.coffee +69 -0
  54. data/vendor/assets/javascripts/joosy/core/resource/rest_collection.js.coffee +42 -0
  55. data/vendor/assets/javascripts/joosy/core/router.js.coffee +75 -0
  56. data/vendor/assets/javascripts/joosy/core/widget.js.coffee +35 -0
  57. data/vendor/assets/javascripts/joosy/preloader/development.js.coffee +27 -0
  58. data/vendor/assets/javascripts/joosy/preloader/production.js.coffee +84 -0
  59. data/{app → vendor}/assets/javascripts/joosy.js.coffee +0 -0
  60. data/vendor/assets/javascripts/jquery.form.js +963 -978
  61. data/vendor/assets/javascripts/sugar.js +1 -1
  62. metadata +48 -77
  63. data/.codoopts +0 -5
  64. data/README.md +0 -95
  65. data/app/assets/javascripts/joosy/core/application.js.coffee +0 -50
  66. data/app/assets/javascripts/joosy/core/form.js.coffee +0 -304
  67. data/app/assets/javascripts/joosy/core/helpers/view.js.coffee +0 -30
  68. data/app/assets/javascripts/joosy/core/joosy.js.coffee +0 -129
  69. data/app/assets/javascripts/joosy/core/layout.js.coffee +0 -162
  70. data/app/assets/javascripts/joosy/core/modules/container.js.coffee +0 -104
  71. data/app/assets/javascripts/joosy/core/modules/events.js.coffee +0 -123
  72. data/app/assets/javascripts/joosy/core/modules/filters.js.coffee +0 -67
  73. data/app/assets/javascripts/joosy/core/modules/log.js.coffee +0 -36
  74. data/app/assets/javascripts/joosy/core/modules/module.js.coffee +0 -105
  75. data/app/assets/javascripts/joosy/core/modules/renderer.js.coffee +0 -195
  76. data/app/assets/javascripts/joosy/core/modules/time_manager.js.coffee +0 -46
  77. data/app/assets/javascripts/joosy/core/modules/widgets_manager.js.coffee +0 -84
  78. data/app/assets/javascripts/joosy/core/page.js.coffee +0 -375
  79. data/app/assets/javascripts/joosy/core/preloader.js.coffee +0 -13
  80. data/app/assets/javascripts/joosy/core/resource/collection.js.coffee +0 -174
  81. data/app/assets/javascripts/joosy/core/resource/generic.js.coffee +0 -254
  82. data/app/assets/javascripts/joosy/core/resource/rest.js.coffee +0 -197
  83. data/app/assets/javascripts/joosy/core/resource/rest_collection.js.coffee +0 -125
  84. data/app/assets/javascripts/joosy/core/router.js.coffee +0 -163
  85. data/app/assets/javascripts/joosy/core/templaters/rails_jst.js.coffee +0 -36
  86. data/app/assets/javascripts/joosy/core/widget.js.coffee +0 -80
  87. data/app/assets/javascripts/joosy/preloaders/caching.js.coffee +0 -169
  88. data/app/assets/javascripts/joosy/preloaders/inline.js.coffee +0 -56
  89. data/lib/joosy.rb +0 -9
  90. data/lib/rails/generators/joosy/resource_generator.rb +0 -29
  91. data/lib/rails/generators/joosy/templates/app/helpers/application.js.coffee +0 -4
  92. data/lib/rails/generators/joosy/templates/app/pages/welcome/index.js.coffee +0 -22
  93. data/lib/rails/generators/joosy/templates/app/resources/template.js.coffee +0 -2
  94. data/lib/rails/generators/joosy/templates/app/templates/layouts/application.jst.hamlc +0 -2
  95. data/lib/rails/generators/joosy/templates/app/templates/pages/welcome/index.jst.hamlc +0 -7
  96. data/spec/javascripts/joosy/core/application_spec.js.coffee +0 -40
  97. data/spec/javascripts/joosy/core/form_spec.js.coffee +0 -184
  98. data/spec/javascripts/joosy/core/joosy_spec.js.coffee +0 -72
  99. data/spec/javascripts/joosy/core/layout_spec.js.coffee +0 -50
  100. data/spec/javascripts/joosy/core/modules/renderer_spec.js.coffee +0 -185
  101. data/spec/javascripts/joosy/core/page_spec.js.coffee +0 -178
  102. data/spec/javascripts/joosy/core/resource/collection_spec.js.coffee +0 -84
  103. data/spec/javascripts/joosy/core/resource/generic_spec.js.coffee +0 -118
  104. data/spec/javascripts/joosy/core/resource/rest_collection_spec.js.coffee +0 -58
  105. data/spec/javascripts/joosy/core/resource/rest_spec.js.coffee +0 -129
  106. data/spec/javascripts/joosy/core/router_spec.js.coffee +0 -123
  107. data/spec/javascripts/joosy/core/templaters/rails_jst_spec.js.coffee +0 -25
  108. data/spec/javascripts/joosy/core/widget_spec.js.coffee +0 -40
  109. data/spec/javascripts/joosy/preloaders/caching_spec.js.coffee +0 -36
  110. data/spec/javascripts/joosy/preloaders/inline_spec.js.coffee +0 -16
  111. data/spec/javascripts/support/assets/coolface.jpg +0 -0
  112. data/spec/javascripts/support/assets/okay.jpg +0 -0
  113. data/spec/javascripts/support/assets/test.js +0 -1
  114. data/spec/javascripts/support/sinon-ie-1.3.1.js +0 -82
  115. data/vendor/assets/javascripts/metamorph.js +0 -409
@@ -1,184 +0,0 @@
1
- describe "Joosy.Form", ->
2
-
3
- beforeEach ->
4
- @server = sinon.fakeServer.create()
5
- @seedGround()
6
- @nudeForm = "<form id='nude'><input name='test[foo]'/><input name='test[bar]'/><input name='test[bool]' type='checkbox' value='1'/></form>"
7
- @putForm = "<form id='put' method='put'><input name='test[camel_baz]'/></form>"
8
- @moreForm = "<form id='more' method='put'><input name='test[ololo]'/></form>"
9
-
10
- @ground.find('#sidebar').after(@nudeForm).after(@putForm).after(@moreForm)
11
-
12
- @nudeForm = $('#nude')
13
- @putForm = $('#put')
14
- @moreForm = $('#more')
15
-
16
- class Test extends Joosy.Resource.REST
17
- @entity 'test'
18
-
19
- @resource = Test.create
20
- foo: 'foo',
21
- bar: 'bar'
22
- camelBaz: 'baz'
23
- bool: true
24
-
25
- afterEach ->
26
- @server.restore()
27
-
28
- describe "Initialization", ->
29
-
30
- beforeEach ->
31
- @spy = sinon.spy $.fn, 'ajaxForm'
32
-
33
- afterEach ->
34
- @spy.restore()
35
-
36
- it "should properly act with options", ->
37
- formWithProperties = new Joosy.Form @nudeForm, invalidationClass: 'fluffy'
38
- expect(formWithProperties.container).toEqual @nudeForm
39
- expect(formWithProperties.invalidationClass).toEqual 'fluffy'
40
- expect(formWithProperties.fields.length).toEqual 3
41
-
42
- expect(@spy.callCount).toEqual 1
43
-
44
- it "should properly act with callback", ->
45
- formWithCallback = new Joosy.Form @putForm, callback=sinon.spy()
46
- expect(formWithCallback.container).toEqual @putForm
47
- expect(formWithCallback.invalidationClass).toEqual 'field_with_errors'
48
- expect(formWithCallback.success).toBe callback
49
- expect(formWithCallback.fields.length).toEqual 1
50
-
51
- expect(@spy.callCount).toEqual 1
52
-
53
- it "should hijack form method if it differs from POST/GET", ->
54
- form = new Joosy.Form @putForm, callback=sinon.spy()
55
- marker = @putForm.find "input[type=hidden]"
56
- expect(@putForm.attr('method')?.toLowerCase()).toEqual 'post'
57
- expect(marker.attr 'name').toEqual '_method'
58
- expect(marker.attr 'value').toEqual 'put'
59
-
60
- describe "Filling", ->
61
-
62
- beforeEach ->
63
- @nudeForm = new Joosy.Form @nudeForm
64
- @putForm = new Joosy.Form @putForm
65
- @moreForm = new Joosy.Form @moreForm
66
-
67
- it "should fill form, set propert action and method and store resource", ->
68
- @nudeForm.fill @resource
69
- expect(@nudeForm.fields[0].value).toEqual 'foo'
70
- expect(@nudeForm.fields[1].value).toEqual 'bar'
71
- expect(@nudeForm.fields[2].checked).toEqual true
72
- expect(@nudeForm.fields[2].value).toEqual '1'
73
- expect(@nudeForm.container.attr('method').toLowerCase()).toEqual 'post'
74
- expect(@nudeForm.container.attr 'action').toEqual '/tests/'
75
- expect(@nudeForm.__resource).toEqual @resource
76
-
77
- it "should fill form with camelized properties", ->
78
- @putForm.fill @resource
79
- expect(@putForm.fields[0].value).toEqual 'baz'
80
- expect(@putForm.container.attr('method').toLowerCase()).toEqual 'post'
81
- expect(@putForm.container.attr 'action').toEqual '/tests/'
82
-
83
- it "should fill form with decorator", ->
84
- @moreForm.fill @resource, (e) ->
85
- e.ololo = e.camelBaz
86
- e
87
- expect(@moreForm.fields[0].value).toEqual 'baz'
88
-
89
- describe "Callbacks", ->
90
-
91
- beforeEach ->
92
- @nudeForm = new Joosy.Form @nudeForm, @spy=sinon.spy()
93
- @nudeForm.fill @resource
94
- @nudeForm.container.submit()
95
- @target = @server.requests.last()
96
-
97
- it "should trigger 'success'", ->
98
- expect(@target.method).toEqual 'POST'
99
- expect(@target.url).toEqual '/tests/'
100
- @target.respond 200, 'Content-Type': 'application/json', '{"form": "works"}'
101
- expect(@spy.callCount).toEqual 1
102
- expect(@spy.args[0][0]).toEqual {form: 'works'}
103
-
104
- it "should fill class for invalidated fields by default", ->
105
- @target.respond 422, 'Content-Type': 'application/json', '{"foo": "error!"}'
106
- expect($(@nudeForm.fields[0]).attr 'class').toEqual 'field_with_errors'
107
-
108
- it "should trigger 'error' and complete default action if it returned true", ->
109
- @nudeForm.error = sinon.spy ->
110
- true
111
- @target.respond 422, 'Content-Type': 'application/json', '{"foo": "error!"}'
112
- expect($(@nudeForm.fields[0]).attr 'class').toEqual 'field_with_errors'
113
- expect(@nudeForm.error.callCount).toEqual 1
114
- expect(@nudeForm.error.args[0][0]).toEqual
115
- "foo": "error!"
116
-
117
- it "should trigger 'error' and skip default action if it returned false", ->
118
- @nudeForm.error = sinon.spy ->
119
- false
120
- @target.respond 422, 'Content-Type': 'application/json', '{"foo": "error!"}'
121
- expect($(@nudeForm.fields[0]).attr 'class').toNotEqual 'field_with_errors'
122
- expect(@nudeForm.error.callCount).toEqual 1
123
-
124
- it "should clear fields before another submit", ->
125
- @target.respond 422, 'Content-Type': 'application/json', '{"foo": "error!"}'
126
- expect($(@nudeForm.fields[0]).attr 'class').toEqual 'field_with_errors'
127
- @nudeForm.container.submit()
128
- expect($(@nudeForm.fields[0]).attr 'class').toNotEqual 'field_with_errors'
129
-
130
- it "should trigger 'before' and do default action if it returns true", ->
131
- @target.respond 422, 'Content-Type': 'application/json', '{"foo": "error!"}'
132
- expect($(@nudeForm.fields[0]).attr 'class').toEqual 'field_with_errors'
133
- @nudeForm.before = sinon.spy ->
134
- true
135
- @nudeForm.container.submit()
136
- expect($(@nudeForm.fields[0]).attr 'class').toNotEqual 'field_with_errors'
137
- expect(@nudeForm.before.callCount).toEqual 1
138
-
139
- it "should trigger 'before' and skip default action if it returns false", ->
140
- @target.respond 422, 'Content-Type': 'application/json', '{"foo": "error!"}'
141
- expect($(@nudeForm.fields[0]).attr 'class').toEqual 'field_with_errors'
142
- @nudeForm.before = sinon.spy ->
143
- false
144
- @nudeForm.container.submit()
145
- expect($(@nudeForm.fields[0]).attr 'class').toEqual 'field_with_errors'
146
- expect(@nudeForm.before.callCount).toEqual 1
147
-
148
- describe "Error response handling", ->
149
-
150
- beforeEach ->
151
- @nudeForm = new Joosy.Form @nudeForm, @spy=sinon.spy()
152
-
153
- it "should prepare simple response", ->
154
- errors = {zombie: ['suck'], puppies: ['rock']}
155
- result = @nudeForm.__stringifyErrors(errors)
156
-
157
- expect(result).toEqual zombie: ['suck'], puppies: ['rock']
158
-
159
- it "should prepare inline response", ->
160
- errors = {"zombie.in1.subin1": ['suck'], "zombie.in2": ['rock']}
161
- result = @nudeForm.__stringifyErrors(errors)
162
-
163
- expect(result).toEqual {"zombie[in1][subin1]": ['suck'], "zombie[in2]": ['rock']}
164
-
165
- it "should prepare inline response with resource attached", ->
166
- @nudeForm.fill @resource
167
- errors = {"zombie.in1.subin1": ['suck'], "zombie.in2": ['rock']}
168
- result = @nudeForm.__stringifyErrors(errors)
169
-
170
- expect(result).toEqual {"test[zombie][in1][subin1]": ['suck'], "test[zombie][in2]": ['rock']}
171
-
172
- it "should prepare simple response with resource attached", ->
173
- @nudeForm.fill @resource
174
- errors = {zombie: ['suck'], puppies: ['rock']}
175
- result = @nudeForm.__stringifyErrors(errors)
176
-
177
- expect(result).toEqual { "test[zombie]": ['suck'], "test[puppies]": ['rock'] }
178
-
179
- it "should prepare complexe response", ->
180
- @nudeForm.fill @resource
181
- errors = {fluffies: {zombie: {mumbas: ['ololo']}}}
182
- result = @nudeForm.__stringifyErrors(errors)
183
-
184
- expect(result).toEqual { "fluffies[zombie][mumbas]": ['ololo'] }
@@ -1,72 +0,0 @@
1
- describe "Joosy", ->
2
-
3
- it "should properly initialize", ->
4
- expect(Joosy.debug).toBeFalsy()
5
- expect(Joosy.Modules).toBeDefined()
6
- expect(Joosy.Resource).toBeDefined()
7
-
8
- it "should declare namespaces", ->
9
- Joosy.namespace 'Namespaces.Test1'
10
- Joosy.namespace 'Namespaces.Test2', ->
11
- @bingo = 'bongo'
12
- expect(window.Namespaces.Test1).toBeDefined()
13
- expect(window.Namespaces.Test2.bingo).toEqual('bongo')
14
-
15
- it "should imprint namespace paths in Joosy.Module descendants", ->
16
- Joosy.namespace 'Irish', ->
17
- class @Pub extends Joosy.Module
18
-
19
- Joosy.namespace 'British', ->
20
- class @Pub extends Joosy.Module
21
-
22
- Joosy.namespace 'Keltic', ->
23
- class @Pub extends Irish.Pub
24
-
25
- expect(Irish.Pub.__namespace__).toEqual ["Irish"]
26
- expect(British.Pub.__namespace__).toEqual ["British"]
27
- expect(Keltic.Pub.__namespace__).toEqual ["Keltic"]
28
-
29
- Joosy.namespace 'Deeply.Nested', ->
30
- class @Klass extends Joosy.Module
31
-
32
- expect(Deeply.Nested.Klass.__namespace__).toEqual ["Deeply", "Nested"]
33
-
34
- class @Flat extends Joosy.Module
35
-
36
- expect(@Flat.__namespace__).toEqual []
37
-
38
- it "should set up helpers", ->
39
- Joosy.helpers 'Hoge', ->
40
- @fuga = ->
41
- "piyo"
42
-
43
- expect(window.Joosy.Helpers).toBeDefined()
44
- expect(window.Joosy.Helpers.Hoge).toBeDefined()
45
- expect(window.Joosy.Helpers.Hoge.fuga()).toBe "piyo"
46
-
47
- it "should generate proper UUIDs", ->
48
- uuids = []
49
- 2.times ->
50
- uuids.push Joosy.uuid()
51
- expect(uuids.unique().length).toEqual(2)
52
- expect(uuids[0]).toMatch /[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}/
53
-
54
- it "should build proper URLs", ->
55
- expect(Joosy.buildUrl 'http://www.org').toEqual('http://www.org')
56
- expect(Joosy.buildUrl 'http://www.org#hash').toEqual('http://www.org#hash')
57
- expect(Joosy.buildUrl 'http://www.org', {foo: 'bar'}).toEqual('http://www.org?foo=bar')
58
- expect(Joosy.buildUrl 'http://www.org?bar=baz', {foo: 'bar'}).toEqual('http://www.org?bar=baz&foo=bar')
59
-
60
- it "should preload images", ->
61
- path = "/spec/javascripts/support/assets/"
62
- images = [path+"okay.jpg", path+"okay.jpg"]
63
-
64
- callback = sinon.spy()
65
-
66
- runs -> Joosy.preloadImages path+"coolface.jpg", callback
67
- waits(150)
68
- runs -> expect(callback.callCount).toEqual(1)
69
-
70
- runs -> Joosy.preloadImages images, callback
71
- waits(150)
72
- runs -> expect(callback.callCount).toEqual(2)
@@ -1,50 +0,0 @@
1
- describe "Joosy.Layout", ->
2
-
3
- beforeEach ->
4
- class @TestLayout extends Joosy.Layout
5
- @box = new @TestLayout()
6
-
7
- it "should have appropriate accessors", ->
8
- callback_names = ['beforePaint', 'paint', 'erase']
9
- callback_names.each (func) =>
10
- @TestLayout[func] 'callback'
11
- expect(@TestLayout::['__' + func]).toEqual 'callback'
12
-
13
- it "should have default view", ->
14
- @box = new @TestLayout()
15
- expect(@box.__renderer instanceof Function).toBeTruthy()
16
-
17
- it "should use Router", ->
18
- target = sinon.stub Joosy.Router, 'navigate'
19
- @box.navigate 'there'
20
- expect(target.callCount).toEqual 1
21
- expect(target.alwaysCalledWithExactly 'there').toBeTruthy()
22
- Joosy.Router.navigate.restore()
23
-
24
- it "should load itself", ->
25
- spies = []
26
- spies.push sinon.spy(@box, 'refreshElements')
27
- spies.push sinon.spy(@box, '__delegateEvents')
28
- spies.push sinon.spy(@box, '__setupWidgets')
29
- spies.push sinon.spy(@box, '__runAfterLoads')
30
- @box.__load(@ground)
31
- expect(spies).toBeSequenced()
32
-
33
- it "should unload itself", ->
34
- spies = []
35
- spies.push sinon.spy(@box, '__clearTime')
36
- spies.push sinon.spy(@box, '__unloadWidgets')
37
- spies.push sinon.spy(@box, '__runAfterUnloads')
38
- @box.__unload()
39
- expect(spies).toBeSequenced()
40
-
41
- it "should generate uuid", ->
42
- sinon.spy Joosy, 'uuid'
43
- @box.yield()
44
- expect(Joosy.uuid.callCount).toEqual 1
45
- expect(@box.uuid).toBeDefined()
46
- Joosy.uuid.restore()
47
-
48
- it "should uuid as selector", ->
49
- @box.yield()
50
- expect(@box.content().selector).toEqual '#' + @box.uuid
@@ -1,185 +0,0 @@
1
- describe "Joosy.Modules.Renderer", ->
2
-
3
- beforeEach ->
4
- @seedGround()
5
-
6
- class @TestContainer extends Joosy.Module
7
- @include Joosy.Modules.Renderer
8
-
9
- @dummyContainer = new @TestContainer
10
-
11
- class @TestObject extends Joosy.Module
12
- @include Joosy.Modules.Events
13
-
14
- constructor: (@value) ->
15
-
16
- update: (@value) ->
17
- @trigger 'changed'
18
-
19
- @dummyObject = new @TestObject("initial")
20
-
21
- Joosy.namespace 'Joosy.Helpers.Hoge', ->
22
- @multiplier = (value) ->
23
- "#{value * 5}"
24
-
25
- it "should update contents, but only while it is bound to DOM", ->
26
- @TestContainer.view (locals) ->
27
- template = (locals) ->
28
- "#{locals.object.value}"
29
-
30
- @renderDynamic(template, locals)
31
-
32
- elem = $("<div></div>")
33
- @ground.append elem
34
-
35
- elem.html @dummyContainer.__renderer({ object: @dummyObject })
36
- expect(elem.text()).toBe "initial"
37
-
38
- @dummyObject.update "new"
39
-
40
- waits 0
41
-
42
- runs ->
43
- expect(elem.text()).toBe "new"
44
-
45
- waits 0
46
-
47
- runs ->
48
- @dummyContainer.__removeMetamorphs()
49
- @dummyObject.update "afterwards"
50
-
51
- waits 0
52
-
53
- runs ->
54
- expect(elem.text()).toBe "new"
55
-
56
- it "should render resources and keep html up2date", ->
57
- data = Joosy.Resource.Generic.create zombie: 'rock'
58
-
59
- @TestContainer.view (locals) ->
60
- template = (locals) ->
61
- "#{locals.zombie}"
62
-
63
- @renderDynamic(template, locals)
64
-
65
- elem = $("<div></div>")
66
- @ground.append elem
67
-
68
- elem.html @dummyContainer.__renderer(data)
69
-
70
- waits 0
71
-
72
- runs ->
73
- expect(elem.text()).toBe "rock"
74
-
75
- runs ->
76
- data 'zombie', 'suck'
77
-
78
- waits 0
79
-
80
- runs ->
81
- expect(elem.text()).toBe "suck"
82
-
83
- it "should render collections and keep html up2date", ->
84
- class Foo extends Joosy.Resource.Generic
85
- @entity 'foo'
86
-
87
- data = new Joosy.Resource.Collection(Foo)
88
-
89
- data.reset [
90
- { zombie: 'rock' },
91
- { zombie: 'never sleep' }
92
- ]
93
-
94
- @TestContainer.view (locals) ->
95
- template = (locals) ->
96
- "#{locals.data[1] 'zombie'}"
97
-
98
- @renderDynamic(template, locals)
99
-
100
- elem = $("<div></div>")
101
- @ground.append elem
102
-
103
- elem.html @dummyContainer.__renderer(data)
104
-
105
- waits 0
106
-
107
- runs ->
108
- expect(elem.text()).toBe "never sleep"
109
-
110
- runs ->
111
- data.data[1] 'zombie', 'suck'
112
-
113
- waits 0
114
-
115
- runs ->
116
- expect(elem.text()).toBe "suck"
117
-
118
-
119
- it "should debounce morpher updates", ->
120
- @TestContainer.view (locals) ->
121
- template = (locals) ->
122
- "#{locals.object.value}"
123
-
124
- @renderDynamic(template, locals)
125
-
126
- elem = $("<div></div>")
127
- @ground.append elem
128
-
129
- sinon.spy window, 'Metamorph'
130
-
131
- elem.html @dummyContainer.__renderer({ object: @dummyObject })
132
- expect(elem.text()).toBe "initial"
133
-
134
- updater = sinon.spy window.Metamorph.returnValues[0], 'html'
135
-
136
- @dummyObject.update "new"
137
-
138
- waits 0
139
-
140
- runs ->
141
- expect(elem.text()).toBe "new"
142
- expect(updater.callCount).toEqual 1
143
-
144
- runs ->
145
- @dummyObject.update "don't make"
146
- @dummyObject.update "me evil"
147
-
148
- waits 0
149
-
150
- runs ->
151
- expect(elem.text()).toBe "me evil"
152
- expect(updater.callCount).toEqual 2
153
-
154
- it "should include rendering helpers in locals", ->
155
- @TestContainer.helpers "Hoge"
156
-
157
- @TestContainer.view (locals) ->
158
- template = (locals) ->
159
- "#{locals.multiplier(10)}"
160
-
161
- @render(template, locals)
162
-
163
- elem = $("<div></div>")
164
- @ground.append elem
165
-
166
- elem.html @dummyContainer.__renderer({ })
167
-
168
- expect(elem.text()).toBe "50"
169
-
170
- it "should include global rendering helpers in locals", ->
171
- Joosy.Helpers.Application.globalMultiplier = (value) ->
172
- value * 6
173
-
174
- @TestContainer.view (locals) ->
175
- template = (locals) ->
176
- "#{locals.globalMultiplier(10)}"
177
-
178
- @render(template, locals)
179
-
180
- elem = $("<div></div>")
181
- @ground.append elem
182
-
183
- elem.html @dummyContainer.__renderer({ })
184
-
185
- expect(elem.text()).toBe "60"
@@ -1,178 +0,0 @@
1
- describe "Joosy.Page", ->
2
-
3
- beforeEach ->
4
- window.JST = 'app/templates/layouts/default': (->)
5
- class window.ApplicationLayout extends Joosy.Layout
6
- class @TestPage extends Joosy.Page
7
-
8
-
9
- describe "not rendered page", ->
10
-
11
- beforeEach ->
12
- sinon.stub @TestPage.prototype, '__bootstrap'
13
- sinon.stub @TestPage.prototype, '__bootstrapLayout'
14
- @box = new @TestPage()
15
- expect(@TestPage::__bootstrap.callCount).toEqual 0
16
- expect(@TestPage::__bootstrapLayout.callCount).toEqual 1
17
-
18
-
19
- it "should have appropriate accessors", ->
20
- callback_names = ['fetch', 'beforePaint', 'paint', 'afterPaint', 'erase']
21
- callback_names.each (func) =>
22
- @TestPage[func] 'callback'
23
- expect(@TestPage::['__' + func]).toEqual 'callback'
24
-
25
- @TestPage.scroll '#here'
26
- expect(@TestPage::__scrollElement).toEqual '#here'
27
- expect(@TestPage::__scrollSpeed).toEqual 500
28
- expect(@TestPage::__scrollMargin).toEqual 0
29
-
30
- @TestPage.scroll '#there', speed: 1000, margin: -5
31
- expect(@TestPage::__scrollElement).toEqual '#there'
32
- expect(@TestPage::__scrollSpeed).toEqual 1000
33
- expect(@TestPage::__scrollMargin).toEqual -5
34
-
35
- @TestPage.layout 'test'
36
- expect(@TestPage::__layoutClass).toEqual 'test'
37
-
38
- it "should not render layout if it not changes", ->
39
- @box.layout = new ApplicationLayout()
40
- @box.layout.yield()
41
- new @TestPage {}, @box
42
- expect(@TestPage::__bootstrap.callCount).toEqual 1
43
- expect(@TestPage::__bootstrapLayout.callCount).toEqual 1
44
-
45
- it "should render layout if it changes", ->
46
- class SubLayout extends Joosy.Layout
47
- @box = new @TestPage()
48
- new @TestPage {}, @box
49
- expect(@TestPage::__bootstrap.callCount).toEqual 0
50
- expect(@TestPage::__bootstrapLayout.callCount).toEqual 3
51
-
52
- it "should stop render on beforeFilter result", ->
53
- sinon.stub @TestPage.prototype, '__runBeforeLoads'
54
- @TestPage::__runBeforeLoads.returns(false)
55
- new @TestPage()
56
- expect(@TestPage::__bootstrap.callCount).toEqual 0
57
- expect(@TestPage::__bootstrapLayout.callCount).toEqual 1
58
-
59
- it "should use Router", ->
60
- target = sinon.stub Joosy.Router, 'navigate'
61
- @box.navigate 'there'
62
- expect(target.callCount).toEqual 1
63
- expect(target.alwaysCalledWithExactly 'there').toBeTruthy()
64
- Joosy.Router.navigate.restore()
65
-
66
- it "should load itself", ->
67
- spies = []
68
- spies.push sinon.spy(@box, 'refreshElements')
69
- spies.push sinon.spy(@box, '__delegateEvents')
70
- spies.push sinon.spy(@box, '__setupWidgets')
71
- spies.push sinon.spy(@box, '__runAfterLoads')
72
- @box.__load()
73
- expect(spies).toBeSequenced()
74
-
75
- it "should unload itself", ->
76
- spies = []
77
- spies.push sinon.spy(@box, '__clearTime')
78
- spies.push sinon.spy(@box, '__unloadWidgets')
79
- spies.push sinon.spy(@box, '__removeMetamorphs')
80
- spies.push sinon.spy(@box, '__runAfterUnloads')
81
- @box.__unload()
82
- expect(spies).toBeSequenced()
83
-
84
- describe "rendered page", ->
85
-
86
- beforeEach ->
87
- @box.previous = new @TestPage()
88
- @box.previous.layout = new @box.previous.__layoutClass
89
- @box.__renderer = sinon.spy()
90
- @box.__layoutClass.prototype.__renderer = sinon.spy()
91
- @TestPage::__bootstrap.restore()
92
- @TestPage::__bootstrapLayout.restore()
93
-
94
-
95
- it "should wait stageClear and dataReceived event to start render", ->
96
- spies = []
97
-
98
- spies.push @box.previous.__erase = sinon.spy (stage, callback) ->
99
- expect(stage.selector).toEqual @layout.content().selector
100
- callback()
101
-
102
- spies.push sinon.spy(@box.previous, '__unload')
103
-
104
- spies.push @box.__beforePaint = sinon.spy (stage, callback) ->
105
- expect(stage.selector).toEqual @layout.content().selector
106
- expect(@__oneShotEvents[0][0]).toEqual ['stageClear', 'dataReceived']
107
- callback()
108
- expect(@__oneShotEvents[0][0]).toEqual ['dataReceived']
109
-
110
- spies.push @box.__fetch = sinon.spy (callback) ->
111
- expect(@__oneShotEvents[0][0]).toEqual ['dataReceived']
112
- callback()
113
- expect(@__oneShotEvents).toEqual []
114
-
115
- spies.push @box.__paint = sinon.spy (stage, callback) ->
116
- expect(stage.selector).toEqual @layout.content().selector
117
- expect(typeof callback).toEqual 'function'
118
- # callback() - start rendering
119
-
120
- @box.__bootstrap()
121
-
122
- expect(spies).toBeSequenced()
123
-
124
- it "should render page", ->
125
- spies = []
126
-
127
- spies.push @box.__renderer
128
- spies.push sinon.spy(@box, 'swapContainer')
129
- spies.push sinon.spy(@box, '__load')
130
-
131
- @box.__bootstrap()
132
- expect(spies).toBeSequenced()
133
-
134
- it "should wait stageClear and dataReceived event to start layout render", ->
135
- spies = []
136
-
137
- spies.push ApplicationLayout::__erase = sinon.spy (stage, page, callback) ->
138
- expect(stage.selector).toEqual Joosy.Application.content().selector
139
- callback()
140
-
141
- spies.push sinon.spy(@box.previous.layout, '__unload')
142
- spies.push sinon.spy(@box.previous, '__unload')
143
-
144
- spies.push ApplicationLayout::__beforePaint = sinon.spy (stage, page, callback) =>
145
- expect(stage.selector).toEqual Joosy.Application.content().selector
146
- expect(@box.__oneShotEvents[0][0]).toEqual ['stageClear', 'dataReceived']
147
- callback()
148
- expect(@box.__oneShotEvents[0][0]).toEqual ['dataReceived']
149
-
150
- spies.push @box.__fetch = sinon.spy (callback) ->
151
- expect(@__oneShotEvents[0][0]).toEqual ['dataReceived']
152
- callback()
153
- expect(@__oneShotEvents).toEqual []
154
-
155
- spies.push ApplicationLayout::__paint = sinon.spy (stage, page, callback) ->
156
- expect(stage.selector).toEqual Joosy.Application.content().selector
157
- expect(typeof callback).toEqual 'function'
158
- # callback() - start rendering
159
-
160
- @box.__bootstrapLayout()
161
-
162
- expect(spies).toBeSequenced()
163
-
164
- it "should render layout and page", ->
165
- spies = []
166
-
167
- @box.params = {tested: true}
168
-
169
- spies.push @box.__layoutClass.prototype.__renderer
170
- spies.push @box.__renderer
171
- swapContainer = sinon.spy(@box, 'swapContainer')
172
- spies.push @box.__layoutClass.prototype.__load = sinon.spy()
173
- spies.push sinon.spy(@box, '__load')
174
-
175
- @box.__bootstrapLayout()
176
- expect(spies).toBeSequenced()
177
- expect(swapContainer.callCount).toEqual 2
178
- expect(@box.layout.params).toEqual {tested: true}