joosy 1.2.0.alpha.41 → 1.2.0.alpha.51
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/Gruntfile.coffee +27 -7
- data/bin/joosy +1 -1
- data/bower.json +3 -2
- data/build/joosy/extensions/preloaders.js +189 -0
- data/build/joosy/extensions/resources-form.js +588 -0
- data/build/joosy/extensions/resources.js +673 -0
- data/build/joosy.js +2395 -0
- data/{src/joosy/generators → generators}/base.coffee +2 -2
- data/{src/joosy/generators → generators/command}/command.coffee +16 -3
- data/generators/command/help.coffee +38 -0
- data/{src/joosy/generators → generators}/layout.coffee +0 -0
- data/{src/joosy/generators → generators}/page.coffee +0 -0
- data/{src/joosy/generators → generators}/project/base.coffee +2 -4
- data/{src/joosy/generators → generators}/project/standalone.coffee +4 -3
- data/{src/joosy/generators → generators}/project.coffee +0 -0
- data/generators/templates/application/base/application.coffee +13 -0
- data/{templates → generators/templates}/application/base/helpers/application.coffee +0 -0
- data/{templates → generators/templates}/application/base/layouts/application.coffee +0 -0
- data/{templates → generators/templates}/application/base/pages/application.coffee +0 -0
- data/{templates → generators/templates}/application/base/pages/welcome/index.coffee +0 -0
- data/{templates → generators/templates}/application/base/routes.coffee +0 -0
- data/{templates → generators/templates}/application/base/templates/layouts/application.jst.hamlc +0 -0
- data/{templates → generators/templates}/application/base/templates/pages/welcome/index.jst.hamlc +0 -0
- data/{templates → generators/templates}/application/standalone/Gruntfile.coffee +1 -0
- data/{templates → generators/templates}/application/standalone/Procfile +0 -0
- data/{templates → generators/templates}/application/standalone/_gitignore +0 -0
- data/generators/templates/application/standalone/bower.json +17 -0
- data/{templates → generators/templates}/application/standalone/package.json +0 -0
- data/{templates → generators/templates}/application/standalone/source/haml/index.haml +0 -0
- data/{templates → generators/templates}/application/standalone/source/stylesheets/application.styl +0 -0
- data/{templates → generators/templates}/layout/basic.coffee +0 -0
- data/{templates → generators/templates}/layout/namespaced.coffee +0 -0
- data/{templates → generators/templates}/page/basic.coffee +0 -0
- data/{templates → generators/templates}/page/namespaced.coffee +0 -0
- data/{templates → generators/templates}/widget/basic.coffee +0 -0
- data/{templates → generators/templates}/widget/namespaced.coffee +0 -0
- data/{src/joosy/generators → generators}/widget.coffee +0 -0
- data/lib/joosy.rb +3 -3
- data/package.json +2 -3
- data/source/joosy/application.coffee +95 -0
- data/source/joosy/events/namespace.coffee +24 -0
- data/{src → source}/joosy/extensions/preloaders/caching.coffee +0 -0
- data/{src → source}/joosy/extensions/preloaders/index.coffee +0 -0
- data/{src → source}/joosy/extensions/preloaders/inline.coffee +0 -0
- data/{src → source}/joosy/extensions/resources/base.coffee +16 -8
- data/{src → source}/joosy/extensions/resources/collection.coffee +0 -0
- data/{src → source}/joosy/extensions/resources/index.coffee +0 -0
- data/{src → source}/joosy/extensions/resources/rest.coffee +0 -0
- data/{src → source}/joosy/extensions/resources/rest_collection.coffee +0 -0
- data/{src → source}/joosy/extensions/resources-form/form.coffee +18 -18
- data/{src → source}/joosy/extensions/resources-form/helpers/form.coffee +6 -6
- data/{src → source}/joosy/extensions/resources-form/index.coffee +0 -0
- data/source/joosy/helpers/routes.coffee +10 -0
- data/source/joosy/helpers/view.coffee +115 -0
- data/{src/joosy/core → source/joosy}/helpers/widgets.coffee +1 -1
- data/{src/joosy/core → source/joosy}/joosy.coffee +59 -19
- data/source/joosy/layout.coffee +73 -0
- data/{src/joosy/core → source/joosy}/module.coffee +7 -2
- data/{src/joosy/core/modules/container.coffee → source/joosy/modules/dom.coffee} +24 -17
- data/source/joosy/modules/events.coffee +156 -0
- data/source/joosy/modules/filters.coffee +67 -0
- data/{src/joosy/core → source/joosy}/modules/log.coffee +7 -3
- data/source/joosy/modules/page/scrolling.coffee +51 -0
- data/source/joosy/modules/page/title.coffee +18 -0
- data/{src/joosy/core → source/joosy}/modules/renderer.coffee +12 -13
- data/{src/joosy/core → source/joosy}/modules/time_manager.coffee +5 -1
- data/{src/joosy/core → source/joosy}/modules/widgets_manager.coffee +9 -5
- data/source/joosy/page.coffee +68 -0
- data/{src/joosy/core → source/joosy}/resources/watcher.coffee +5 -1
- data/source/joosy/router.coffee +305 -0
- data/{src/joosy/core → source/joosy}/templaters/jst.coffee +10 -7
- data/source/joosy/widget.coffee +385 -0
- data/source/joosy.coffee +1 -0
- data/{src/vendor → source}/metamorph.coffee +0 -0
- data/spec/helpers/matchers.coffee +8 -1
- data/spec/joosy/core/application_spec.coffee +121 -20
- data/spec/joosy/core/helpers/view_spec.coffee +3 -3
- data/spec/joosy/core/helpers/widgets_spec.coffee +3 -6
- data/spec/joosy/core/joosy_spec.coffee +0 -5
- data/spec/joosy/core/layout_spec.coffee +2 -28
- data/spec/joosy/core/modules/dom_spec.coffee +133 -0
- data/spec/joosy/core/modules/events_spec.coffee +16 -9
- data/spec/joosy/core/modules/filters_spec.coffee +232 -89
- data/spec/joosy/core/modules/log_spec.coffee +2 -2
- data/spec/joosy/core/modules/renderer_spec.coffee +8 -4
- data/spec/joosy/core/page_spec.coffee +2 -201
- data/spec/joosy/core/router_spec.coffee +295 -233
- data/spec/joosy/core/templaters/jst_spec.coffee +1 -1
- data/spec/joosy/core/widget_spec.coffee +373 -34
- data/spec/joosy/environments/amd_spec.coffee +38 -0
- data/spec/joosy/environments/global_spec.coffee +21 -0
- data/spec/joosy/extensions/form/form_spec.coffee +18 -18
- data/spec/joosy/extensions/form/helpers/forms_spec.coffee +1 -1
- data/spec/joosy/extensions/resources/base_spec.coffee +23 -11
- data/tasks/joosy.coffee +6 -9
- metadata +75 -69
- data/lib/extensions/preloaders.js +0 -193
- data/lib/extensions/resources-form.js +0 -592
- data/lib/extensions/resources.js +0 -675
- data/lib/joosy.js +0 -2199
- data/spec/joosy/core/modules/container_spec.coffee +0 -153
- data/spec/joosy/core/modules/widget_manager_spec.coffee +0 -96
- data/src/joosy/core/application.coffee +0 -59
- data/src/joosy/core/helpers/view.coffee +0 -52
- data/src/joosy/core/layout.coffee +0 -174
- data/src/joosy/core/modules/events.coffee +0 -188
- data/src/joosy/core/modules/filters.coffee +0 -42
- data/src/joosy/core/page.coffee +0 -383
- data/src/joosy/core/router.coffee +0 -313
- data/src/joosy/core/widget.coffee +0 -88
- data/src/joosy.coffee +0 -1
- data/templates/application/base/application.coffee +0 -9
- data/templates/application/standalone/bower.json +0 -7
@@ -1,238 +1,300 @@
|
|
1
1
|
describe "Joosy.Router", ->
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
spies =
|
6
|
-
root: sinon.spy()
|
7
|
-
section: sinon.spy()
|
8
|
-
wildcard: sinon.spy()
|
9
|
-
|
10
|
-
map =
|
11
|
-
Object.extended
|
12
|
-
'/': spies.root
|
13
|
-
'/page': TestPage
|
14
|
-
'/section':
|
15
|
-
'/page/:id': spies.section
|
16
|
-
'/page2/:more': TestPage
|
17
|
-
404: spies.wildcard
|
3
|
+
pathname = location.pathname
|
18
4
|
|
19
5
|
beforeEach ->
|
20
|
-
Joosy.
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
Joosy.Router.map map
|
35
|
-
Joosy.Router.__setupRoutes()
|
36
|
-
expect(Joosy.Router.__prepareRoutes.callCount).toEqual 1
|
37
|
-
expect(Joosy.Router.__prepareRoutes.args[0][0]).toEqual map
|
38
|
-
expect(Joosy.Router.__respondRoute.callCount).toEqual 1
|
39
|
-
expect(Joosy.Router.__respondRoute.args[0][0]).toEqual location.hash
|
40
|
-
Joosy.Router.__prepareRoutes.restore()
|
41
|
-
Joosy.Router.__respondRoute.restore()
|
42
|
-
|
43
|
-
it "should prepare route", ->
|
44
|
-
route = Joosy.Router.__prepareRoute "/such/a/long/long/url/:with/:plenty/:of/:params", "123"
|
45
|
-
|
46
|
-
expect(route).toEqual Object.extended
|
47
|
-
'^/?such/a/long/long/url/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$':
|
48
|
-
capture: ['with', 'plenty', 'of', 'params']
|
49
|
-
action: "123"
|
50
|
-
|
51
|
-
it "should cook routes", ->
|
52
|
-
sinon.stub Joosy.Router, '__respondRoute'
|
53
|
-
|
54
|
-
Joosy.Router.map map
|
55
|
-
Joosy.Router.__setupRoutes()
|
56
|
-
|
57
|
-
expect(Joosy.Router.routes).toEqual Object.extended
|
58
|
-
'^/?/?$':
|
59
|
-
capture: []
|
60
|
-
action: spies.root
|
61
|
-
'^/?page/?$':
|
62
|
-
capture: []
|
63
|
-
action: TestPage
|
64
|
-
'^/?section/page/([^/]+)/?$':
|
65
|
-
capture: ['id']
|
66
|
-
action: spies.section
|
67
|
-
'^/?section/page2/([^/]+)/?$':
|
68
|
-
capture: ['more']
|
69
|
-
action: TestPage
|
70
|
-
|
71
|
-
Joosy.Router.__respondRoute.restore()
|
72
|
-
|
73
|
-
it "should get route params", ->
|
74
|
-
route = Joosy.Router.__prepareRoute "/such/a/long/long/url/:with/:plenty/:of/:params", "123"
|
75
|
-
result = Joosy.Router.__paramsFromRouteMatch ['full regex match here', 1, 2, 3, 4], route.values().first()
|
76
|
-
|
77
|
-
expect(result).toEqual Object.extended
|
78
|
-
'with': 1
|
79
|
-
'plenty': 2
|
80
|
-
'of': 3
|
81
|
-
'params': 4
|
82
|
-
|
83
|
-
it "should build query params", ->
|
84
|
-
result = Joosy.Router.__paramsFromQueryArray ["foo=bar", "bar=baz"]
|
85
|
-
|
86
|
-
expect(result).toEqual Object.extended
|
87
|
-
foo: 'bar'
|
88
|
-
bar: 'baz'
|
89
|
-
|
90
|
-
it "should respond routes", ->
|
91
|
-
sinon.stub Joosy.Router, '__respondRoute'
|
92
|
-
sinon.stub Joosy.Application, 'setCurrentPage'
|
93
|
-
|
94
|
-
Joosy.Router.map map
|
95
|
-
Joosy.Router.__setupRoutes()
|
96
|
-
|
97
|
-
Joosy.Router.__respondRoute.restore()
|
98
|
-
|
99
|
-
Joosy.Router.__respondRoute '/'
|
100
|
-
expect(spies.root.callCount).toEqual 1
|
101
|
-
|
102
|
-
Joosy.Router.__respondRoute '#/'
|
103
|
-
expect(spies.root.callCount).toEqual 2
|
104
|
-
|
105
|
-
Joosy.Router.__respondRoute '/page'
|
106
|
-
expect(Joosy.Application.setCurrentPage.callCount).toEqual 1
|
107
|
-
expect(Joosy.Application.setCurrentPage.args.last()).toEqual [TestPage, Object.extended()]
|
108
|
-
|
109
|
-
Joosy.Router.__respondRoute '/section/page/1'
|
110
|
-
expect(spies.section.callCount).toEqual 1
|
111
|
-
expect(spies.section.args.last()).toEqual [Object.extended(id: '1')]
|
112
|
-
|
113
|
-
Joosy.Router.__respondRoute '/section/page2/1&a=b'
|
114
|
-
expect(Joosy.Application.setCurrentPage.callCount).toEqual 2
|
115
|
-
expect(Joosy.Application.setCurrentPage.args.last()).toEqual [TestPage, Object.extended(more: '1', a: 'b')]
|
116
|
-
|
117
|
-
Joosy.Router.__respondRoute '/thiswillneverbefound&a=b'
|
118
|
-
expect(spies.wildcard.callCount).toEqual 1
|
119
|
-
expect(spies.wildcard.args.last()).toEqual ['/thiswillneverbefound', Object.extended(a: 'b')]
|
120
|
-
|
121
|
-
Joosy.Application.setCurrentPage.restore()
|
122
|
-
|
123
|
-
it "should navigate", ->
|
124
|
-
Joosy.Router.navigate 'test'
|
125
|
-
expect(location.hash).toEqual "#!test"
|
126
|
-
Joosy.Router.navigate ''
|
127
|
-
expect(location.hash).toEqual '#!'
|
128
|
-
|
129
|
-
it "should restrict urls", ->
|
130
|
-
sinon.stub Joosy.Router, '__respondRoute'
|
131
|
-
sinon.stub Joosy.Application, 'setCurrentPage'
|
132
|
-
|
133
|
-
Joosy.Router.map map
|
134
|
-
Joosy.Router.__setupRoutes()
|
135
|
-
|
136
|
-
Joosy.Router.__respondRoute.restore()
|
137
|
-
|
138
|
-
Joosy.Router.restrict /^\/page$/
|
139
|
-
|
140
|
-
Joosy.Router.__respondRoute '/page'
|
141
|
-
Joosy.Router.__respondRoute '/section/page/1'
|
142
|
-
|
143
|
-
expect(Joosy.Application.setCurrentPage.callCount).toEqual 1
|
144
|
-
expect(Joosy.Application.setCurrentPage.args.last()).toEqual [TestPage, Object.extended()]
|
145
|
-
|
146
|
-
Joosy.Application.setCurrentPage.restore()
|
147
|
-
Joosy.Router.restrict false
|
148
|
-
|
149
|
-
it "should DRAW simple routes, only using match and root", ->
|
150
|
-
Joosy.Router.map
|
151
|
-
'/': spies.root
|
152
|
-
'/page': TestPage
|
153
|
-
404: spies.wildcard
|
154
|
-
raw_routes_for_map = Joosy.Router.rawRoutes
|
155
|
-
|
156
|
-
Joosy.Router.reset()
|
157
|
-
|
158
|
-
Joosy.Router.draw ->
|
159
|
-
@root to: spies.root
|
160
|
-
@match '/page', to: TestPage
|
161
|
-
@notFound to: spies.wildcard
|
162
|
-
|
163
|
-
expect(Joosy.Router.rawRoutes).toEqual(raw_routes_for_map)
|
164
|
-
|
165
|
-
it "should DRAW namespaced routes", ->
|
166
|
-
Joosy.Router.map
|
167
|
-
'/': spies.root
|
168
|
-
'/page': TestPage
|
6
|
+
class @Page extends Joosy.Page
|
7
|
+
|
8
|
+
@spies =
|
9
|
+
responder: sinon.spy()
|
10
|
+
root: sinon.spy()
|
11
|
+
base: sinon.spy()
|
12
|
+
section: sinon.spy()
|
13
|
+
wildcard: sinon.spy()
|
14
|
+
|
15
|
+
@map =
|
16
|
+
'/': @spies.root
|
17
|
+
'/base': @spies.base
|
18
|
+
'page': @Page
|
169
19
|
'/section':
|
170
|
-
'/page/:id': spies.section
|
171
|
-
'
|
172
|
-
404: spies.wildcard
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
@
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
@
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
expect(
|
237
|
-
|
238
|
-
|
20
|
+
'/page/:id': @spies.section
|
21
|
+
'page2/:more': @Page
|
22
|
+
404: @spies.wildcard
|
23
|
+
|
24
|
+
describe 'core', ->
|
25
|
+
afterEach ->
|
26
|
+
Joosy.Router.reset()
|
27
|
+
|
28
|
+
it 'draws', ->
|
29
|
+
spies = @spies
|
30
|
+
Page = @Page
|
31
|
+
|
32
|
+
Joosy.Router.draw ->
|
33
|
+
@root to: spies.root
|
34
|
+
@match '/base', to: spies.base
|
35
|
+
@match '/page', to: Page
|
36
|
+
@namespace '/section', {as: 'section'}, ->
|
37
|
+
@match '/page/:id', to: spies.section, as: 'page'
|
38
|
+
@match '/page2/:more', to: Page
|
39
|
+
@notFound to: spies.wildcard
|
40
|
+
|
41
|
+
expect(Joosy.Router.routes).toEqual
|
42
|
+
'^/?/?$':
|
43
|
+
to: spies.root
|
44
|
+
as: 'root'
|
45
|
+
capture: []
|
46
|
+
'^/?base/?$':
|
47
|
+
to: spies.base,
|
48
|
+
capture: [],
|
49
|
+
'^/?page/?$':
|
50
|
+
to: Page, capture : []
|
51
|
+
'^/?section/page/([^/]+)/?$':
|
52
|
+
to: spies.section,
|
53
|
+
as: 'sectionPage'
|
54
|
+
capture: ['id']
|
55
|
+
'^/?section/page2/([^/]+)/?$':
|
56
|
+
to: Page
|
57
|
+
capture: ['more']
|
58
|
+
|
59
|
+
expect(Joosy.Router.wildcardAction).toEqual spies.wildcard
|
60
|
+
|
61
|
+
it 'maps', ->
|
62
|
+
Joosy.Router.map @map
|
63
|
+
|
64
|
+
expect(Joosy.Router.routes).toEqual
|
65
|
+
'^/?/?$':
|
66
|
+
to: @spies.root
|
67
|
+
as: undefined
|
68
|
+
capture: []
|
69
|
+
'^/?base/?$':
|
70
|
+
to: @spies.base
|
71
|
+
as: undefined
|
72
|
+
capture: []
|
73
|
+
'^/?page/?$':
|
74
|
+
to: @Page
|
75
|
+
capture: []
|
76
|
+
as: undefined
|
77
|
+
'^/?section/page/([^/]+)/?$':
|
78
|
+
to: @spies.section
|
79
|
+
as: undefined
|
80
|
+
capture: ['id']
|
81
|
+
'^/?section/page2/([^/]+)/?$':
|
82
|
+
to: @Page
|
83
|
+
capture: ['more']
|
84
|
+
as: undefined
|
85
|
+
|
86
|
+
expect(Joosy.Router.wildcardAction).toEqual @spies.wildcard
|
87
|
+
|
88
|
+
it 'compiles plain route', ->
|
89
|
+
Joosy.Router.compileRoute '/such/a/long/long/url/:with/:plenty/:of/:params', '123'
|
90
|
+
|
91
|
+
expect(Joosy.Router.routes['^/?such/a/long/long/url/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$']).toEqual
|
92
|
+
capture: ['with', 'plenty', 'of', 'params']
|
93
|
+
to: '123'
|
94
|
+
as: undefined
|
95
|
+
|
96
|
+
it 'compiles aliased route', ->
|
97
|
+
Joosy.Router.compileRoute '/such/a/long/long/url/:with/:plenty/:of/:params', '456', '123'
|
98
|
+
|
99
|
+
expect(Joosy.Router.routes['^/?such/a/long/long/url/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$']).toEqual
|
100
|
+
capture: ['with', 'plenty', 'of', 'params']
|
101
|
+
to: '456'
|
102
|
+
as: '123'
|
103
|
+
|
104
|
+
describe 'responder', ->
|
105
|
+
|
106
|
+
describe 'hash based', ->
|
107
|
+
beforeEach ->
|
108
|
+
Joosy.Router.setup {html5: false}, @spies.responder, false
|
109
|
+
Joosy.Router.map @map
|
110
|
+
|
111
|
+
afterEach ->
|
112
|
+
Joosy.Router.reset()
|
113
|
+
location.hash = ''
|
114
|
+
waits 0
|
115
|
+
|
116
|
+
it 'resets', ->
|
117
|
+
runs -> Joosy.Router.navigate '/page'
|
118
|
+
waits 0
|
119
|
+
runs ->
|
120
|
+
Joosy.Router.reset()
|
121
|
+
Joosy.Router.navigate '/'
|
122
|
+
waits 0
|
123
|
+
runs ->
|
124
|
+
expect(@spies.responder.callCount).toEqual 1
|
125
|
+
|
126
|
+
it 'boots pages', ->
|
127
|
+
runs -> Joosy.Router.navigate '/page'
|
128
|
+
waits 0
|
129
|
+
runs ->
|
130
|
+
expect(@spies.responder.callCount).toEqual 1
|
131
|
+
expect(@spies.responder.args[0][0]).toEqual @Page
|
132
|
+
|
133
|
+
it 'runs lamdas', ->
|
134
|
+
runs -> Joosy.Router.navigate '/base'
|
135
|
+
waits 0
|
136
|
+
runs ->
|
137
|
+
expect(@spies.responder.callCount).toEqual 1
|
138
|
+
expect(@spies.responder.args[0][0]).toEqual @spies.base
|
139
|
+
|
140
|
+
it 'responds namespaced routes', ->
|
141
|
+
runs -> Joosy.Router.navigate '/section/page/1'
|
142
|
+
waits 0
|
143
|
+
runs ->
|
144
|
+
expect(@spies.responder.callCount).toEqual 1
|
145
|
+
expect(@spies.responder.args[0][0]).toEqual @spies.section
|
146
|
+
|
147
|
+
it 'parses query parametrs', ->
|
148
|
+
runs -> Joosy.Router.navigate '/?test=test&foo=bar'
|
149
|
+
waits 0
|
150
|
+
runs ->
|
151
|
+
expect(@spies.responder.callCount).toEqual 1
|
152
|
+
expect(@spies.responder.args[0][0]).toEqual @spies.root
|
153
|
+
expect(@spies.responder.args[0][1]).toEqual {test: 'test', foo: 'bar'}
|
154
|
+
|
155
|
+
it 'parses route placeholders', ->
|
156
|
+
runs -> Joosy.Router.navigate '/section/page/1'
|
157
|
+
waits 0
|
158
|
+
runs ->
|
159
|
+
expect(@spies.responder.callCount).toEqual 1
|
160
|
+
expect(@spies.responder.args[0][0]).toEqual @spies.section
|
161
|
+
expect(@spies.responder.args[0][1]).toEqual {id: '1'}
|
162
|
+
|
163
|
+
it 'ignores restricted routes', ->
|
164
|
+
Joosy.Router.restrict /^base/
|
165
|
+
|
166
|
+
runs -> Joosy.Router.navigate '/base'
|
167
|
+
waits 0
|
168
|
+
runs ->
|
169
|
+
expect(@spies.responder.callCount).toEqual 0
|
170
|
+
|
171
|
+
it 'defaults to wildcard route', ->
|
172
|
+
runs -> Joosy.Router.navigate '/trololo'
|
173
|
+
waits 0
|
174
|
+
runs ->
|
175
|
+
expect(@spies.responder.callCount).toEqual 1
|
176
|
+
expect(@spies.responder.args[0][0]).toEqual @spies.wildcard
|
177
|
+
|
178
|
+
it 'navigates', ->
|
179
|
+
runs -> Joosy.Router.navigate '/base'
|
180
|
+
waits 0
|
181
|
+
runs ->
|
182
|
+
location.hash == '#/base'
|
183
|
+
expect(@spies.responder.callCount).toEqual 1
|
184
|
+
|
185
|
+
it 'defines plain helper', ->
|
186
|
+
expect(Joosy.Helpers.Routes.rootPath()).toEqual '#'
|
187
|
+
expect(Joosy.Helpers.Routes.rootUrl()).toEqual "http://localhost:8888#{pathname}#"
|
188
|
+
|
189
|
+
it 'defines namespaced parameterized helpers', ->
|
190
|
+
expect(Joosy.Helpers.Routes.sectionPagePath(id: 1)).toEqual '#section/page/1'
|
191
|
+
expect(Joosy.Helpers.Routes.sectionPageUrl(id: 1)).toEqual "http://localhost:8888#{pathname}#section/page/1"
|
192
|
+
|
193
|
+
describe 'html5 based', ->
|
194
|
+
beforeEach ->
|
195
|
+
Joosy.Router.setup {html5: true}, @spies.responder, false
|
196
|
+
Joosy.Router.map @map
|
197
|
+
|
198
|
+
afterEach ->
|
199
|
+
Joosy.Router.reset()
|
200
|
+
history.pushState {}, '', pathname
|
201
|
+
waits 0
|
202
|
+
|
203
|
+
it 'resets', ->
|
204
|
+
runs -> Joosy.Router.navigate '/page'
|
205
|
+
waits 0
|
206
|
+
runs ->
|
207
|
+
Joosy.Router.reset()
|
208
|
+
Joosy.Router.navigate '/'
|
209
|
+
waits 0
|
210
|
+
runs ->
|
211
|
+
expect(@spies.responder.callCount).toEqual 1
|
212
|
+
|
213
|
+
it 'boots pages', ->
|
214
|
+
runs -> Joosy.Router.navigate '/page'
|
215
|
+
waits 0
|
216
|
+
runs ->
|
217
|
+
expect(@spies.responder.callCount).toEqual 1
|
218
|
+
expect(@spies.responder.args[0][0]).toEqual @Page
|
219
|
+
|
220
|
+
it 'runs lamdas', ->
|
221
|
+
runs -> Joosy.Router.navigate '/base'
|
222
|
+
waits 0
|
223
|
+
runs ->
|
224
|
+
expect(@spies.responder.callCount).toEqual 1
|
225
|
+
expect(@spies.responder.args[0][0]).toEqual @spies.base
|
226
|
+
|
227
|
+
it 'responds namespaced routes', ->
|
228
|
+
runs -> Joosy.Router.navigate '/section/page/1'
|
229
|
+
waits 0
|
230
|
+
runs ->
|
231
|
+
expect(@spies.responder.callCount).toEqual 1
|
232
|
+
expect(@spies.responder.args[0][0]).toEqual @spies.section
|
233
|
+
|
234
|
+
it 'parses query parametrs', ->
|
235
|
+
runs -> Joosy.Router.navigate '/?test=test&foo=bar'
|
236
|
+
waits 0
|
237
|
+
runs ->
|
238
|
+
expect(@spies.responder.callCount).toEqual 1
|
239
|
+
expect(@spies.responder.args[0][0]).toEqual @spies.root
|
240
|
+
expect(@spies.responder.args[0][1]).toEqual {test: 'test', foo: 'bar'}
|
241
|
+
|
242
|
+
it 'parses route placeholders', ->
|
243
|
+
runs -> Joosy.Router.navigate '/section/page/1'
|
244
|
+
waits 0
|
245
|
+
runs ->
|
246
|
+
expect(@spies.responder.callCount).toEqual 1
|
247
|
+
expect(@spies.responder.args[0][0]).toEqual @spies.section
|
248
|
+
expect(@spies.responder.args[0][1]).toEqual {id: '1'}
|
249
|
+
|
250
|
+
it 'ignores restricted routes', ->
|
251
|
+
Joosy.Router.restrict /^base/
|
252
|
+
|
253
|
+
runs -> Joosy.Router.navigate '/base'
|
254
|
+
waits 0
|
255
|
+
runs ->
|
256
|
+
expect(@spies.responder.callCount).toEqual 0
|
257
|
+
|
258
|
+
it 'defaults to wildcard route', ->
|
259
|
+
runs -> Joosy.Router.navigate '/trololo'
|
260
|
+
waits 0
|
261
|
+
runs ->
|
262
|
+
expect(@spies.responder.callCount).toEqual 1
|
263
|
+
expect(@spies.responder.args[0][0]).toEqual @spies.wildcard
|
264
|
+
|
265
|
+
it 'navigates', ->
|
266
|
+
runs -> Joosy.Router.navigate '/base'
|
267
|
+
waits 0
|
268
|
+
runs ->
|
269
|
+
location.pathname == '/base'
|
270
|
+
expect(@spies.responder.callCount).toEqual 1
|
271
|
+
|
272
|
+
it 'defines plain helper', ->
|
273
|
+
expect(Joosy.Helpers.Routes.rootPath()).toEqual '/'
|
274
|
+
expect(Joosy.Helpers.Routes.rootUrl()).toEqual 'http://localhost:8888/'
|
275
|
+
|
276
|
+
it 'defines namespaced parameterized helpers', ->
|
277
|
+
expect(Joosy.Helpers.Routes.sectionPagePath(id: 1)).toEqual '/section/page/1'
|
278
|
+
expect(Joosy.Helpers.Routes.sectionPageUrl(id: 1)).toEqual 'http://localhost:8888/section/page/1'
|
279
|
+
|
280
|
+
describe 'linker', ->
|
281
|
+
it 'defines helper', ->
|
282
|
+
tag = Joosy.Helpers.Routes.linkTo 'test', '/base', class: 'zomg!'
|
283
|
+
|
284
|
+
expect(tag).toBeTag 'a', 'test',
|
285
|
+
'data-joosy': 'true'
|
286
|
+
href: '/base'
|
287
|
+
class: 'zomg!'
|
288
|
+
|
289
|
+
it 'navigates', ->
|
290
|
+
sinon.stub Joosy.Router, 'navigate'
|
291
|
+
|
292
|
+
@$ground.html """
|
293
|
+
<a href='#' id='test1'></a>
|
294
|
+
<a href='#' id='test2' data-joosy='true'></a>
|
295
|
+
"""
|
296
|
+
$('#test1').click()
|
297
|
+
$('#test2').click()
|
298
|
+
|
299
|
+
expect(Joosy.Router.navigate.callCount).toEqual 1
|
300
|
+
Joosy.Router.navigate.restore()
|
@@ -27,7 +27,7 @@ describe "Joosy.Templaters.JST", ->
|
|
27
27
|
describe "with set application name", ->
|
28
28
|
|
29
29
|
beforeEach ->
|
30
|
-
@templater = new Joosy.Templaters.JST('application')
|
30
|
+
@templater = new Joosy.Templaters.JST(prefix: 'application')
|
31
31
|
|
32
32
|
it "resolves plain template", ->
|
33
33
|
JST['application/templates/test'] = 'template'
|