forked from peerlibrary/meteor-data-lookup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.coffee
105 lines (76 loc) · 2.89 KB
/
tests.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
class BasicTestCase extends ClassyTestCase
@testName: 'data-lookup - basic'
testBasic: ->
@assertEqual DataLookup.lookup({}, 'foo'), undefined
@assertEqual DataLookup.lookup(null, 'foo'), undefined
@assertEqual DataLookup.lookup(undefined, 'foo'), undefined
@assertEqual DataLookup.lookup(1, 'foo'), undefined
@assertEqual DataLookup.lookup({}), {}
@assertEqual DataLookup.lookup(null), null
@assertEqual DataLookup.lookup(undefined), undefined
@assertEqual DataLookup.lookup(1), 1
@assertEqual DataLookup.lookup({}, ''), undefined
@assertEqual DataLookup.lookup(null, ''), undefined
@assertEqual DataLookup.lookup(undefined, ''), undefined
@assertEqual DataLookup.lookup(1, ''), undefined
@assertEqual DataLookup.lookup({}, []), {}
@assertEqual DataLookup.lookup(null, []), null
@assertEqual DataLookup.lookup(undefined, []), undefined
@assertEqual DataLookup.lookup(1, []), 1
@assertEqual DataLookup.lookup({foo: 'bar'}, 'foo'), 'bar'
@assertEqual DataLookup.lookup({foo: {bar: 'baz'}}, 'foo'), {bar: 'baz'}
@assertEqual DataLookup.lookup({foo: {bar: 'baz'}}, 'faa'), undefined
@assertEqual DataLookup.lookup({foo: {bar: 'baz'}}, 'foo.faa'), undefined
@assertEqual DataLookup.lookup({foo: {bar: 'baz'}}, 'foo.bar'), 'baz'
@assertEqual DataLookup.lookup({foo: null}, 'foo.bar'), undefined
@assertEqual DataLookup.lookup({foo: null}, 'foo'), null
@assertEqual DataLookup.lookup((-> {foo: {bar: 'baz'}}), 'foo'), {bar: 'baz'}
@assertEqual DataLookup.lookup({foo: -> {bar: 'baz'}}, 'foo'), {bar: 'baz'}
@assertEqual DataLookup.lookup((-> {foo: -> {bar: 'baz'}}), 'foo.bar'), 'baz'
testReactive: ->
testVar = new ReactiveVar null
runs = []
@autorun (computation) =>
runs.push DataLookup.get =>
testVar.get()
,
'foo.bar'
@assertEqual runs, [undefined]
runs = []
testVar.set 'something'
Tracker.flush()
@assertEqual runs, []
runs = []
testVar.set {foo: {test: 'baz'}}
Tracker.flush()
@assertEqual runs, []
runs = []
testVar.set {foo: {bar: 'baz'}}
Tracker.flush()
@assertEqual runs, ['baz']
runs = []
testVar.set {foo: {bar: 'baz', test: 'baz'}}
Tracker.flush()
@assertEqual runs, []
runs = []
testVar.set {foo: {test: 'baz'}}
Tracker.flush()
@assertEqual runs, [undefined]
runs = []
testVar.set {foo: {bar: 'baz', test: 'baz'}}
Tracker.flush()
@assertEqual runs, ['baz']
runs = []
testVar.set {foo: {bar: 'bak', test: 'baz'}}
Tracker.flush()
@assertEqual runs, ['bak']
runs = []
testVar2 = new ReactiveVar null
testVar.set {foo: => testVar2.get()}
Tracker.flush()
@assertEqual runs, [undefined]
runs = []
testVar2.set {bar: 'bak', test: 'baz'}
Tracker.flush()
@assertEqual runs, ['bak']
ClassyTestCase.addTest new BasicTestCase()