-
Notifications
You must be signed in to change notification settings - Fork 6
/
test.coffee
44 lines (39 loc) · 1.92 KB
/
test.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
$(->
module("knockback-page-navigator-panes.js")
# import Underscore (or Lo-Dash with precedence), Backbone, Knockout, and Knockback
_ = if not window._ and (typeof(require) isnt 'undefined') then require('underscore') else window._
_ = _._ if _ and _.hasOwnProperty('_') # LEGACY
Backbone = if not window.Backbone and (typeof(require) isnt 'undefined') then require('backbone') else window.Backbone
ko = if not window.ko and (typeof(require) isnt 'undefined') then require('knockout') else window.ko
kb = if not window.kb and (typeof(require) isnt 'undefined') then require('knockback') else window.kb
require('knockback-page-navigator-panes') if (typeof(require) isnt 'undefined')
test("TEST DEPENDENCY MISSING", ->
ok(!!_, '_'); ok(!!Backbone, 'Backbone'); ok(!!ko, 'ko'); ok(!!kb, 'kb'); ok(!!kb.PageNavigatorPanes, 'kb.PageNavigatorPanes')
)
test("1. Basic Usage", ->
el = $('<div></div>')[0]
page_navigator = new kb.PageNavigatorPanes(el)
equal(el, page_navigator.el, "container element")
)
test("2. Click-Based navigation", ->
# onclick
el = $("""
<a onclick="kb.loadUrl('test1', {name: 'NavigationSlide', inverse: true})">Examples</a>
""")[0]
window.location.hash = ''
equal(window.location.hash, '', "onclick: no location hash")
$(el).click()
equal(window.location.hash, '#test1', "onclick: test1 location hash")
equal(kb.popOverrideTransition().name, 'NavigationSlide', "onclick: transition found")
# bound view model
el = $("""
<a data-bind="click: kb.loadUrlFn('test1', {name: 'NavigationSlide', inverse: true})">Examples</a>
""")[0]
ko.applyBindings({}, el)
window.location.hash = ''
equal(window.location.hash, '', "onclick: no location hash")
$(el).click()
equal(window.location.hash, '#test1', "onclick: test1 location hash")
equal(kb.popOverrideTransition().name, 'NavigationSlide', "onclick: transition found")
)
)