forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModeratedColumnHeaderSpec.coffee
More file actions
128 lines (103 loc) · 6.04 KB
/
Copy pathModeratedColumnHeaderSpec.coffee
File metadata and controls
128 lines (103 loc) · 6.04 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
define [
'react'
'react-dom'
'react-addons-test-utils'
'jsx/assignments/ModeratedColumnHeader'
'jsx/assignments/constants'
], (React, ReactDOM, TestUtils, ModeratedColumnHeader, Constants) ->
QUnit.module 'ModeratedColumnHeader',
setup: ->
@props =
markColumn: Constants.markColumnNames.MARK_ONE
currentSortDirection: Constants.sortDirections.DESCENDING
includeModerationSetHeaders:true
handleSortMark1: ->
handleSortMark2: ->
handleSortMark3: ->
handleSelectAll: ->
permissions:
viewGrades: true
teardown: ->
@props = null
test 'calls the handleSortMark1 function when mark1 sort is pressed', ->
callback = sinon.spy()
@props.handleSortMark1 = callback
@props.includeModerationSetHeaders = false
columnHeader = TestUtils.renderIntoDocument(React.createElement(ModeratedColumnHeader, @props))
link = TestUtils.findRenderedDOMComponentWithTag(columnHeader, 'a')
TestUtils.Simulate.click(link)
ok callback.called
ReactDOM.unmountComponentAtNode(ReactDOM.findDOMNode(columnHeader).parentNode)
test 'calls the handleSortMark2 function when mark2 sort is pressed', ->
callback = sinon.spy()
@props.markColumn = Constants.markColumnNames.MARK_TWO
@props.handleSortMark2 = callback
columnHeader = TestUtils.renderIntoDocument(React.createElement(ModeratedColumnHeader, @props))
links = TestUtils.scryRenderedDOMComponentsWithTag(columnHeader, 'a')
TestUtils.Simulate.click(links[1])
ok callback.called
ReactDOM.unmountComponentAtNode(ReactDOM.findDOMNode(columnHeader).parentNode)
test 'calls the handleSortMark3 function when mark3 sort is pressed', ->
callback = sinon.spy()
@props.markColumn = Constants.markColumnNames.MARK_THREE
@props.currentSortDirection = Constants.sortDirections.DESCENDING
@props.handleSortMark3 = callback
columnHeader = TestUtils.renderIntoDocument(React.createElement(ModeratedColumnHeader, @props))
links = TestUtils.scryRenderedDOMComponentsWithTag(columnHeader, 'a')
TestUtils.Simulate.click(links[2])
ok callback.called
ReactDOM.unmountComponentAtNode(ReactDOM.findDOMNode(columnHeader).parentNode)
test 'calls the handleSelectAll function when the select all checkbox is checked', ->
callback = sinon.spy()
@props.handleSelectAll = callback
columnHeader = TestUtils.renderIntoDocument(React.createElement(ModeratedColumnHeader, @props))
checkbox = TestUtils.findRenderedDOMComponentWithTag(columnHeader, 'input')
TestUtils.Simulate.change(ReactDOM.findDOMNode(checkbox))
ok callback.called
ReactDOM.unmountComponentAtNode(ReactDOM.findDOMNode(columnHeader).parentNode)
test 'displays down arrow when sort direction is DESCENDING', ->
@props.markColumn = Constants.markColumnNames.MARK_ONE
@props.sortDirection = Constants.sortDirections.DESCENDING
@props.includeModerationSetHeaders = false
columnHeader = TestUtils.renderIntoDocument(React.createElement(ModeratedColumnHeader, @props))
ok TestUtils. findRenderedDOMComponentWithClass(columnHeader, 'icon-mini-arrow-down'), 'finds the down arrow'
ReactDOM.unmountComponentAtNode(ReactDOM.findDOMNode(columnHeader).parentNode)
test 'displays up arrow when sort direction is ASCENDING', ->
@props.markColumn = Constants.markColumnNames.MARK_ONE
@props.sortDirection = Constants.sortDirections.ASCENDING
@props.includeModerationSetHeaders = false
columnHeader = TestUtils.renderIntoDocument(React.createElement(ModeratedColumnHeader, @props))
ok TestUtils. findRenderedDOMComponentWithClass(columnHeader, 'icon-mini-arrow-up'), 'finds the up arrow'
ReactDOM.unmountComponentAtNode(ReactDOM.findDOMNode(columnHeader).parentNode)
test 'only shows two column when includeModerationSetHeaders is false', ->
# Tests that name is shown and one grade
@props.includeModerationSetHeaders = false
columnHeader = TestUtils.renderIntoDocument(React.createElement(ModeratedColumnHeader, @props))
headers = TestUtils.scryRenderedDOMComponentsWithClass(columnHeader, 'ColumnHeader__Item')
equal headers.length, 2, 'only shows two header columns'
ReactDOM.unmountComponentAtNode(ReactDOM.findDOMNode(columnHeader).parentNode)
test 'only shows all columns when includeModerationSetHeaders is true', ->
columnHeader = TestUtils.renderIntoDocument(React.createElement(ModeratedColumnHeader, @props))
headers = TestUtils.scryRenderedDOMComponentsWithClass(columnHeader, 'ColumnHeader__Item')
equal headers.length, 5, 'show all headers when true'
ReactDOM.unmountComponentAtNode(ReactDOM.findDOMNode(columnHeader).parentNode)
test 'includes the checkbox if the user has permission to view grades', ->
columnHeader = TestUtils.renderIntoDocument(React.createElement(ModeratedColumnHeader, @props))
ok columnHeader.checkbox
ReactDOM.unmountComponentAtNode(ReactDOM.findDOMNode(columnHeader).parentNode)
test 'does not include the checkbox if the user does not have permission to view grades', ->
@props.permissions.viewGrades = false
columnHeader = TestUtils.renderIntoDocument(React.createElement(ModeratedColumnHeader, @props))
notOk columnHeader.checkbox
ReactDOM.unmountComponentAtNode(ReactDOM.findDOMNode(columnHeader).parentNode)
test 'includes the checkbox if the user has permission to view grades without moderation set headers', ->
@props.includeModerationSetHeaders = false
columnHeader = TestUtils.renderIntoDocument(React.createElement(ModeratedColumnHeader, @props))
ok columnHeader.checkbox
ReactDOM.unmountComponentAtNode(ReactDOM.findDOMNode(columnHeader).parentNode)
test 'does not include the checkbox if the user does not have permission to view grades without moderation set headers', ->
@props.permissions.viewGrades = false
@props.includeModerationSetHeaders = false
columnHeader = TestUtils.renderIntoDocument(React.createElement(ModeratedColumnHeader, @props))
notOk columnHeader.checkbox
ReactDOM.unmountComponentAtNode(ReactDOM.findDOMNode(columnHeader).parentNode)