forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntryViewSpec.coffee
More file actions
102 lines (88 loc) · 3.42 KB
/
Copy pathEntryViewSpec.coffee
File metadata and controls
102 lines (88 loc) · 3.42 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
101
102
#
# Copyright (C) 2015 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
define [
'jquery'
'compiled/models/Entry'
'compiled/views/DiscussionTopic/EntryView'
'compiled/discussions/Reply'
'helpers/fakeENV'
], ($, Entry, EntryView, Reply, fakeENV) ->
QUnit.module 'EntryView',
setup: ->
fakeENV.setup
DISCUSSION:
PERMISSIONS: { CAN_REPLY: true }
CURRENT_USER: {}
THREADED: true
teardown: ->
fakeENV.teardown()
$('#fixtures').empty()
test 'renders', ->
entry = new Entry(id: 1, message: 'hi')
$('#fixtures').append($('<div />').attr('id', 'e1'))
view = new EntryView
model: entry
el: '#e1'
view.render()
ok view
test 'two entries do not render keyboard shortcuts to the same place', ->
clock = sinon.useFakeTimers()
@stub(Reply.prototype, 'edit')
$('#fixtures').append($('<div />').attr('id', 'e1'))
$('#fixtures').append($('<div />').attr('id', 'e2'))
entry1 = new Entry(id: 1, message: 'hi')
entry2 = new Entry(id: 2, message: 'reply')
view1 = new EntryView
model: entry1
el: '#e1'
view1.render()
view1.addReply()
view2 = new EntryView
model: entry2
el: '#e2'
view2.render()
view2.addReply()
clock.tick 1
equal view1.$('.tinymce-keyboard-shortcuts-toggle').length, 1
equal view2.$('.tinymce-keyboard-shortcuts-toggle').length, 1
clock.restore()
test 'should listen on model change:replies', ->
entry = new Entry(id: 1, message: 'a comment, wooper')
spy = @stub(EntryView.prototype, 'renderTree')
view = new EntryView(model: entry)
entry.set('replies', [new Entry(id: 2, message: 'a reply', parent_id: 1)])
ok spy.called, 'should renderTree when value is not empty'
spy.reset()
entry.set('replies', [])
ok !spy.called, 'should not renderTree when value is empty'
test 'mark deleted and childless entries with css classes', ->
$('#fixtures').append($('<div />').attr('id', 'e1'))
entry = new Entry(id: 1, message: 'a comment, wooper', deleted: true, replies: [{id: 2, message: 'a reply', parent_id: 1, deleted: true}])
view = new EntryView(model: entry, el: '#e1')
view.render()
ok view.$el.hasClass('no-replies')
ok view.$el.hasClass('deleted')
test 'checks for deeply nested replies when marking childless entries', ->
$('#fixtures').append($('<div />').attr('id', 'e1'))
entry = new Entry(id: 1, message: 'a comment, wooper', deleted: true, replies: [
{id: 2, message: 'a reply', parent_id: 1, deleted: true, replies: [
{id: 3, message: 'another reply', parent_id: 2, deleted: true, replies: []},
{id: 4, message: 'not deleted', parent_id: 2}]}])
view = new EntryView(model: entry, el: '#e1')
view.render()
ok !view.$el.hasClass('no-replies')
ok view.$el.hasClass('deleted')