forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIndexViewSpec.coffee
More file actions
138 lines (115 loc) · 4.49 KB
/
Copy pathIndexViewSpec.coffee
File metadata and controls
138 lines (115 loc) · 4.49 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
129
130
131
132
133
134
135
136
137
138
#
# Copyright (C) 2014 - 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/collections/ExternalFeedCollection'
'compiled/models/ExternalFeed'
'compiled/views/ExternalFeeds/IndexView'
'helpers/fakeENV'
], ($, ExternalFeedCollection, ExternalFeed, ExternalFeedsIndexView, fakeENV) ->
QUnit.module 'IndexView',
setup: ->
fakeENV.setup(context_asset_string: 'courses_1')
$('#fixtures').append($("<div>").attr('id', 'feed_container'))
ef = new ExternalFeed
id: 1
url: 'http://www.example.com/feed'
display_name: 'Example Feed'
verbosity: 'link_only'
header_match: null
efc = new ExternalFeedCollection [ef]
@view = new ExternalFeedsIndexView
el: '#feed_container'
permissions: { create: true }
collection: efc
@view.render()
teardown: ->
@view.remove()
$('#fixtures').empty()
fakeENV.teardown()
submitForm = (url) ->
$('.add_external_feed_link').click()
$('#external_feed_url').val(url)
$('#external_feed_verbosity').val('link_only')
$('#add_external_feed_form button').click()
test 'renders the list of feeds', ->
equal $('li.external_feed').length, 1
ok $('li.external_feed').text().match('Example Feed')
test 'validates the url properly', ->
errors = @view.validateBeforeSave(url: '')
equal errors.url.length, 1
errors = @view.validateBeforeSave(url: 'http://example.com')
ok !errors.url
# TODO: These specs are failing intermittantly and I can't figure out why,
# but it's not worth the build being super fragile
# test 'add external feed is read by screenreader', ->
# @spy($, 'screenReaderFlashMessage')
# server = sinon.fakeServer.create()
# server.respondWith('POST', '/api/v1/courses/1/external_feeds',
# [200, { 'Content-Type': 'application/json' }, JSON.stringify({
# id: 2
# url: 'http://www.example.com/feed2'
# display_name: 'Other Feed'
# verbosity: 'link_only'
# header_match: null
# })])
# submitForm('http://www.example.com/feed2')
# server.respond()
# equal $.screenReaderFlashMessage.callCount, 1
# server.restore()
# test 'delete external feed is read by screenreader', ->
# @spy($, 'screenReaderFlashMessage')
# server = sinon.fakeServer.create()
# server.respondWith('POST', '/api/v1/courses/1/external_feeds',
# [200, { 'Content-Type': 'application/json' }, JSON.stringify({
# id: 3
# url: 'http://www.example.com/feed2'
# display_name: 'Other Feed'
# verbosity: 'link_only'
# header_match: null
# })])
# submitForm('http://www.example.com/feed2')
# server.respond()
# $('.close').first().click()
# equal $.screenReaderFlashMessage.callCount, 1
# test 'allows adding a new feed', ->
# server = sinon.fakeServer.create()
# server.respondWith('POST', '/api/v1/courses/1/external_feeds',
# [200, { 'Content-Type': 'application/json' }, JSON.stringify({
# id: 2
# url: 'http://www.example.com/feed2'
# display_name: 'Other Feed'
# verbosity: 'link_only'
# header_match: null
# })])
# submitForm('http://www.example.com/feed2')
# server.respond()
# equal $('li.external_feed').length, 2
# ok $('li.external_feed').text().match('Other Feed')
# server.restore()
# test 'shows errors if save failed', ->
# server = sinon.fakeServer.create()
# server.respondWith('POST', '/api/v1/courses/1/external_feeds',
# [400, { 'Content-Type': 'application/json' }, JSON.stringify({
# errors: { url: [{ attribute: 'url', message: 'taken', type: 'taken' }] }
# })])
# submitForm('http://www.example.com/feed2')
# server.respond()
# equal $('li.external_feed').length, 1
# ok $('.errorBox').text().match('taken')
# $('.errorBox').remove()
# server.restore()