Skip to content

Commit

Permalink
Add test for forms
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarno Keskikangas committed Sep 25, 2011
1 parent c6e9c0b commit 44166af
Showing 1 changed file with 59 additions and 5 deletions.
64 changes: 59 additions & 5 deletions spec/nested_models.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe "Transparency", ->
this.addMatchers
htmlToBeEqual: (expected) ->
#TODO: Refactor to spec_helper.coffee or something
this.actual = this.actual.replace(/\s\s+/g, '')
this.actual = this.actual.replace(/\s\s+/g, '')
expected = expected.replace(/\s\s+/g, '')
this.actual == expected

Expand All @@ -32,9 +32,9 @@ describe "Transparency", ->
data =
title: 'Hello World'
post: 'Hi there it is me'
comments: [ {
comments: [ {
name: 'John'
text: 'That rules' }, {
text: 'That rules' }, {
name: 'Arnold'
text: 'Great post!'}
]
Expand Down Expand Up @@ -159,7 +159,7 @@ describe "Transparency", ->
release: "1.2"
profiles: [
name: 'Core'
testsets: [
testsets: [
name: "Sanity"
products: [
name: "N900"
Expand All @@ -174,7 +174,7 @@ describe "Transparency", ->
name: "Pinetrail"
]
]
,
,
name: 'Handset'
testsets: [
name: "Feature"
Expand Down Expand Up @@ -273,4 +273,58 @@ describe "Transparency", ->
</div>')

doc.find('.test_reports').render(data, directives)
expect(doc.html()).htmlToBeEqual(expected.html())

it "should render forms", ->
doc = jQuery(
'<div>
<form class="hotel_reservation">
<label>Name
<input class="name_input" type="text" />
</label>
<label>Room type
<select class="room_types">
<option class="name"></option>
</select>
</label>
</form>
</div>')

data =
name: "Michael Jackson"
room_types: [
name: "Single"
id: "1"
,
name: "Double"
id: "2"
,
name: "King Size"
id: "3"
selected: "true"
]

directives =
'name_input@value': -> @name
room_types:
'name@value': -> @id
'name@selected': -> @selected

expected = jQuery(
'<div>
<form class="hotel_reservation">
<label>Name
<input class="name_input" type="text" value="Michael Jackson"/>
</label>
<label>Room type
<select class="room_types">
<option class="name" value="1">Single</option>
<option class="name" value="2">Double</option>
<option class="name" value="3" selected="selected">King Size</option>
</select>
</label>
</form>
</div>')

doc.find('.hotel_reservation').render(data, directives)
expect(doc.html()).htmlToBeEqual(expected.html())

0 comments on commit 44166af

Please sign in to comment.