forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputViewSpec.coffee
More file actions
56 lines (46 loc) · 1.39 KB
/
Copy pathInputViewSpec.coffee
File metadata and controls
56 lines (46 loc) · 1.39 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
define [
'Backbone'
'jquery'
'compiled/views/InputView'
], (Backbone, $, InputView) ->
view = null
QUnit.module 'InputView',
setup: ->
view = new InputView
view.render()
view.$el.appendTo $('#fixtures')
teardown: ->
view.remove()
setValue = (term) ->
view.el.value = term
test 'updates the model attribute', ->
view.model = new Backbone.Model
setValue 'foo'
view.updateModel()
equal view.model.get('unnamed'), 'foo'
test 'updates the collection parameter', ->
view.collection = new Backbone.Collection
setValue 'foo'
view.updateModel()
actual = view.collection.options.params.unnamed
equal actual, 'foo'
test 'gets modelAttribute from input name', ->
input = $('<input name="couch">').appendTo $('#fixtures')
view = new InputView
el: input[0]
equal view.modelAttribute, 'couch'
test 'sets model attribute to empty string with empty value', ->
view.model = new Backbone.Model
setValue 'foo'
view.updateModel()
setValue ''
view.updateModel()
equal view.model.get('unnamed'), ''
test 'deletes collection paramater on empty value', ->
view.collection = new Backbone.Collection
setValue 'foo'
view.updateModel()
equal view.collection.options.params.unnamed, 'foo'
setValue ''
view.updateModel()
strictEqual view.collection.options.params.unnamed, undefined