From b6a01bd27dbcd2f9c9df917ecc96b8a2bd88413d Mon Sep 17 00:00:00 2001
From: Misko Hevery
Date: Thu, 3 Feb 2011 12:25:51 -0800
Subject: fixed population of value attribute on option
The value attribute must be populated manually, since different
browsers default to different value of option when not explicitly
defined.
---
test/markupSpec.js | 36 +++++++++++++++++++++++++++++++++---
test/sanitizerSpec.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 79 insertions(+), 3 deletions(-)
(limited to 'test')
diff --git a/test/markupSpec.js b/test/markupSpec.js
index f78112d7..f629378d 100644
--- a/test/markupSpec.js
+++ b/test/markupSpec.js
@@ -41,9 +41,39 @@ describe("markups", function(){
expect(element.attr('src')).toEqual("http://server/a/b.png");
});
- it('should populate value attribute on OPTION', function(){
- compile('');
- expect(sortedHtml(element).replace(' selected="true"', '')).toEqual('');
+ describe('OPTION value', function(){
+ beforeEach(function(){
+ this.addMatchers({
+ toHaveValue: function(expected){
+ this.message = function(){
+ return 'Expected "' + sortedHtml(this.actual) + '" to have value="' + expected + '".';
+ };
+
+ return this.actual.html().indexOf('value="' + expected + '"') != -1;
+ }
+ });
+ });
+
+ it('should populate value attribute on OPTION', function(){
+ compile('');
+ expect(element).toHaveValue('abc');
+ });
+
+ it('should ignore value if already exists', function(){
+ compile('');
+ expect(element).toHaveValue('abc');
+ });
+
+ it('should set value even if newlines present', function(){
+ compile('');
+ expect(element).toHaveValue('\nabc\n');
+ });
+
+ it('should set value even if self closing HTML', function(){
+ compile('');
+ expect(element).toHaveValue('\n');
+ });
+
});
it('should bind href', function() {
diff --git a/test/sanitizerSpec.js b/test/sanitizerSpec.js
index 57eedec9..7158fbee 100644
--- a/test/sanitizerSpec.js
+++ b/test/sanitizerSpec.js
@@ -4,6 +4,52 @@ describe('HTML', function(){
return expect(new HTML(html).get());
}
+ describe('htmlParser', function(){
+ var handler, start, text;
+ beforeEach(function(){
+ handler = {
+ start: function(tag, attrs, unary){
+ start = {
+ tag: tag,
+ attrs: attrs,
+ unary: unary
+ };
+ },
+ chars: function(text_){
+ text = text_;
+ },
+ end:function(tag) {
+ expect(tag).toEqual(start.tag);
+ }
+ };
+ });
+
+ it('should parse basic format', function(){
+ htmlParser('text', handler);
+ expect(start).toEqual({tag:'tag', attrs:{attr:'value'}, unary:false});
+ expect(text).toEqual('text');
+ });
+
+ it('should parse newlines in tags', function(){
+ htmlParser('<\ntag\n attr="value"\n>text<\n/\ntag\n>', handler);
+ expect(start).toEqual({tag:'tag', attrs:{attr:'value'}, unary:false});
+ expect(text).toEqual('text');
+ });
+
+ it('should parse newlines in attributes', function(){
+ htmlParser('text', handler);
+ expect(start).toEqual({tag:'tag', attrs:{attr:'\nvalue\n'}, unary:false});
+ expect(text).toEqual('text');
+ });
+
+ it('should parse namespace', function(){
+ htmlParser('text', handler);
+ expect(start).toEqual({tag:'ns:t-a-g', attrs:{'ns:a-t-t-r':'\nvalue\n'}, unary:false});
+ expect(text).toEqual('text');
+ });
+
+ });
+
it('should echo html', function(){
expectHTML('helloworld.').
toEqual('helloworld.');
--
cgit v1.2.3