-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Views can now have deferred properties.
I need this functionality for a sub-project, and it wasn't sensible to make changes without tests!
- Loading branch information
Showing
2 changed files
with
133 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
describe('ViewParser', function() { | ||
var viewParser; | ||
beforeEach(function() { | ||
viewParser = require('../../Views/viewParser'); | ||
}); | ||
|
||
describe('parse', function() { | ||
it('should return an empty string for an empty view.', function(done) { | ||
var result = viewParser.parse('testViewName', ''); | ||
|
||
result.properties.should.eql([]); | ||
|
||
var deferred = result.view({}); | ||
|
||
deferred.onComplete(function(resultHtml) { | ||
resultHtml.should.equal(''); | ||
|
||
done(); | ||
}); | ||
}); | ||
|
||
it('should return raw HTML from a view with no properties.', function(done) { | ||
var result = viewParser.parse('testViewName', '<html></html>'); | ||
|
||
result.properties.should.eql([]); | ||
|
||
var deferred = result.view({}); | ||
|
||
deferred.onComplete(function(resultHtml) { | ||
resultHtml.should.equal('<html></html>'); | ||
|
||
done(); | ||
}); | ||
}); | ||
|
||
it('should return just a variable for a view with only a bound variable.', function(done) { | ||
var result = viewParser.parse('testViewName', '<%= test %>'); | ||
|
||
result.properties.should.eql([]); | ||
|
||
var deferred = result.view({ | ||
test: 'Some data.' | ||
}); | ||
|
||
deferred.onComplete(function(resultHtml) { | ||
resultHtml.should.equal('Some data.'); | ||
|
||
done(); | ||
}); | ||
}); | ||
|
||
it('should return a variable embedded in HTML for a complex view.', function(done) { | ||
var result = viewParser.parse('testViewName', '<div><%= test %></div>'); | ||
|
||
result.properties.should.eql([]); | ||
|
||
var deferred = result.view({ | ||
test: 'Some data.' | ||
}); | ||
|
||
deferred.onComplete(function(resultHtml) { | ||
resultHtml.should.equal('<div>Some data.</div>'); | ||
|
||
done(); | ||
}); | ||
}); | ||
|
||
it('should allow arbitrary code in a view.', function(done) { | ||
var result = viewParser.parse('testViewName', '<div><% if (showTest) { %><%= test %><% } %></div>'); | ||
|
||
result.properties.should.eql([]); | ||
|
||
var deferred = result.view({ | ||
test: 'Some data.', | ||
showTest: false | ||
}); | ||
|
||
deferred.onComplete(function(resultHtml) { | ||
resultHtml.should.equal('<div></div>'); | ||
|
||
done(); | ||
}); | ||
}); | ||
|
||
it('should wait for the result of a deferred parameter.', function(done) { | ||
var result = viewParser.parse('testViewName', '<div><% if (showTest) { %><%= test %><% } %></div>'); | ||
|
||
result.properties.should.eql([]); | ||
|
||
var testDeferred = new Deferred(); | ||
|
||
var deferred = result.view({ | ||
test: testDeferred, | ||
showTest: true | ||
}); | ||
|
||
deferred.onComplete(function(resultHtml) { | ||
resultHtml.should.equal('<div>Some data.</div>'); | ||
|
||
done(); | ||
}); | ||
|
||
testDeferred.complete('Some data.'); | ||
}); | ||
}); | ||
}); |