forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWikiPageIndexViewSpec.coffee
More file actions
100 lines (82 loc) · 2.86 KB
/
Copy pathWikiPageIndexViewSpec.coffee
File metadata and controls
100 lines (82 loc) · 2.86 KB
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
define [
'compiled/collections/WikiPageCollection'
'compiled/views/wiki/WikiPageIndexView'
'jquery'
'jquery.disableWhileLoading'
], (WikiPageCollection,WikiPageIndexView,$) ->
QUnit.module 'WikiPageIndexView:sort',
setup: ->
@collection = new WikiPageCollection
@view = new WikiPageIndexView
collection: @collection
@$a = $('<a/>')
@$a.data 'sort-field', 'created_at'
@ev = $.Event('click')
@ev.currentTarget = @$a.get(0)
test 'sort delegates to the collection sortByField', ->
sortByFieldStub = @stub(@collection, 'sortByField')
@view.sort(@ev)
ok sortByFieldStub.calledOnce, 'collection sortByField called once'
test 'view disabled while sorting', ->
dfd = $.Deferred()
@stub(@collection, 'fetch').returns(dfd)
disableWhileLoadingStub = @stub(@view.$el, 'disableWhileLoading')
@view.sort(@ev)
ok disableWhileLoadingStub.calledOnce, 'disableWhileLoading called once'
ok disableWhileLoadingStub.calledWith(dfd), 'disableWhileLoading called with correct deferred object'
test 'view disabled while sorting again', ->
dfd = $.Deferred()
@stub(@collection, 'fetch').returns(dfd)
disableWhileLoadingStub = @stub(@view.$el, 'disableWhileLoading')
@view.sort(@ev)
ok disableWhileLoadingStub.calledOnce, 'disableWhileLoading called once'
ok disableWhileLoadingStub.calledWith(dfd), 'disableWhileLoading called with correct deferred object'
test 'renderSortHeaders called when sorting changes', ->
renderSortHeadersStub = @stub(@view, 'renderSortHeaders')
@collection.trigger('sortChanged', 'created_at')
ok renderSortHeadersStub.calledOnce, 'renderSortHeaders called once'
equal @view.currentSortField, 'created_at', 'currentSortField set correctly'
QUnit.module 'WikiPageIndexView:JSON'
testRights = (subject, options) ->
test "#{subject}", ->
collection = new WikiPageCollection
view = new WikiPageIndexView
collection: collection
contextAssetString: options.contextAssetString
WIKI_RIGHTS: options.WIKI_RIGHTS
json = view.toJSON()
for key of options.CAN
strictEqual json.CAN[key], options.CAN[key], "CAN.#{key}"
testRights 'CAN (manage course)',
contextAssetString: 'course_73'
WIKI_RIGHTS:
read: true
create_page: true
manage: true
CAN:
CREATE: true
MANAGE: true
PUBLISH: true
testRights 'CAN (manage group)',
contextAssetString: 'group_73'
WIKI_RIGHTS:
read: true
create_page: true
manage: true
CAN:
CREATE: true
MANAGE: true
PUBLISH: false
testRights 'CAN (read)',
contextAssetString: 'course_73'
WIKI_RIGHTS:
read: true
CAN:
CREATE: false
MANAGE: false
PUBLISH: false
testRights 'CAN (null)',
CAN:
CREATE: false
MANAGE: false
PUBLISH: false