forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFindFlickrImageViewSpec.js
143 lines (136 loc) · 3.77 KB
/
FindFlickrImageViewSpec.js
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
139
140
141
142
143
/*
* Copyright (C) 2013 - 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/>.
*/
import $ from 'jquery'
import FindFlickrImageView from '@canvas/rce/backbone/views/FindFlickrImageView.coffee'
import 'helpers/jquery.simulate'
const searchTerm = 'bunnies'
const photoData = [
{
id: 'noooooo',
secret: 'whyyyyy',
farm: 'moooo',
owner: 'notyou',
server: 'maneframe',
needs_interstitial: 0
},
{
id: 'nooope',
secret: 'sobbbbb',
farm: 'sadface',
owner: 'meeee',
server: 'mwhahahah',
needs_interstitial: 0
},
{
id: 'nsfwid',
secret: 'nsfwsecret',
farm: 'nsfwfarm',
owner: 'nsfwowner',
server: 'nsfwserver',
needs_interstitial: 1
}
]
function setupServerResponses() {
const server = sinon.fakeServer.create()
server.respondWith(/\/mock_flickr\/(.*)/, request => {
const response = {photos: {photo: photoData}}
if (request.url.indexOf(searchTerm) !== -1) {
return request.respond(200, {'Content-Type': 'application/json'}, JSON.stringify(response))
}
})
return server
}
QUnit.module('FindFlickrImage', {
setup() {
this.server = setupServerResponses()
const $fixtures = $('#fixtures')
const view = new FindFlickrImageView()
view.flickrUrl = '/mock_flickr'
view.render().$el.appendTo($fixtures)
this.form = $('form.FindFlickrImageView').first()
},
teardown() {
this.form.remove()
this.server.restore()
}
})
test('render', function() {
expect(6)
ok(this.form.length, 'flickr - form added to dom')
ok(this.form.is(':visible'), 'flickr - form is visible')
const input = $('input.flickrSearchTerm', this.form)
ok(input.length, 'flickr - search bar is added')
ok(input.is(':visible'), 'flickr - search bar is visible')
const button = $('button[type=submit]', this.form)
ok(button.length, 'flickr - submit button is added')
ok(button.is(':visible'), 'flickr - submit button form is visible')
})
test('search', function() {
expect(13)
const input = $('input.flickrSearchTerm', this.form)
const button = $('button[type=submit]', this.form)
input.val(searchTerm)
this.form.submit()
this.server.respond()
const results = $('ul.flickrResults li a.thumbnail', this.form)
equal(results.length, 2, 'non-nsfw images are added to the results')
for (let idx = 0; idx <= 1; idx++) {
ok(
results
.eq(idx)
.attr('data-fullsize')
.includes(photoData[idx].id),
'flickr - img src has id'
)
ok(
results
.eq(idx)
.attr('data-fullsize')
.includes(photoData[idx].secret),
'flickr - img src has secret'
)
ok(
results
.eq(idx)
.attr('data-fullsize')
.includes(photoData[idx].farm),
'flickr - img src has farm'
)
ok(
results
.eq(idx)
.attr('data-fullsize')
.includes(photoData[idx].server),
'flickr - img src has server'
)
ok(
results
.eq(idx)
.attr('data-linkto')
.includes(photoData[idx].id),
'flickr - link has id'
)
ok(
results
.eq(idx)
.attr('data-linkto')
.includes(photoData[idx].owner),
'flickr - link has owner'
)
}
})