X Tutup
Skip to content

Commit 01c7aba

Browse files
committed
Fix browser triggering in scenario to always do native events.
- Also fixed angular.suffix for scenarios - refactored click() to browserTrigger() - Fixed Rakefile with CSS and jQuery
1 parent e7e894a commit 01c7aba

File tree

16 files changed

+119
-152
lines changed

16 files changed

+119
-152
lines changed

Rakefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ end
5353

5454
desc 'Compile Scenario'
5555
task :compile_scenario do
56-
56+
5757
deps = [
5858
'lib/jquery/jquery-1.4.2.js',
5959
'src/scenario/angular.prefix',
@@ -66,7 +66,7 @@ task :compile_scenario do
6666

6767
File.open('angular-scenario.js', 'w') do |f|
6868
f.write(%x{#{concat}})
69-
f.write(gen_css('css/angular.css'))
69+
f.write(gen_css('css/angular.css') + "\n")
7070
f.write(gen_css('css/angular-scenario.css'))
7171
end
7272
end
@@ -234,7 +234,8 @@ def gen_css(cssFile, minify = false)
234234
end
235235

236236
#escape for js
237-
css.gsub! /'/, "\\'"
237+
css.gsub! /\\/, "\\\\\\"
238+
css.gsub! /'/, "\\\\'"
238239
css.gsub! /\n/, "\\n"
239240

240241
return %Q{document.write('<style type="text/css">#{css}</style>');}

css/angular-scenario.css

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ body {
3838
padding: 0.5em;
3939
font-size: 1.1em;
4040
}
41-
41+
4242
#status-legend {
4343
margin-top: 10px;
4444
margin-right: 10px;
4545
}
4646

47-
#header,
47+
#header,
4848
#frame,
49-
.test-info,
49+
.test-info,
5050
.test-actions li {
5151
overflow: hidden;
5252
}
@@ -67,10 +67,10 @@ body {
6767
#frame iframe {
6868
border: none;
6969
}
70-
71-
.tests li,
70+
71+
.tests li,
7272
.test-actions li,
73-
.test-it li,
73+
.test-it li,
7474
.test-it ol,
7575
.status-display {
7676
list-style-type: none;
@@ -83,14 +83,14 @@ body {
8383
padding: 0;
8484
}
8585

86-
.test-info {
86+
.test-info {
8787
margin-left: 1em;
8888
margin-top: 0.5em;
8989
border-radius: 8px 0 0 8px;
9090
-webkit-border-radius: 8px 0 0 8px;
9191
-moz-border-radius: 8px 0 0 8px;
9292
}
93-
93+
9494
.test-it ol {
9595
margin-left: 2.5em;
9696
}
@@ -104,7 +104,7 @@ body {
104104
padding: 5px 10px;
105105
}
106106

107-
.timer-result,
107+
.timer-result,
108108
.test-title {
109109
display: inline-block;
110110
margin: 0;
@@ -129,7 +129,7 @@ body {
129129
}
130130

131131
.test-actions .status-pending .test-title:before {
132-
content: '» ';
132+
content: '\00bb\00A0';
133133
}
134134

135135
/** Colors */
@@ -150,7 +150,7 @@ body {
150150
#frame {
151151
border: 1px solid #BABAD1;
152152
}
153-
153+
154154
.test-describe .test-describe {
155155
border-left: 1px solid #BABAD1;
156156
border-right: 1px solid #BABAD1;
@@ -168,29 +168,29 @@ body {
168168

169169
.status-display .status-success,
170170
.status-success .test-info {
171-
background-color: #B1D7A1;
171+
background-color: #B1D7A1;
172172
}
173-
173+
174174
.status-display .status-failure,
175-
.status-failure .test-info {
176-
background-color: #FF8286;
175+
.status-failure .test-info {
176+
background-color: #FF8286;
177177
}
178178

179179
.status-display .status-error,
180-
.status-error .test-info {
180+
.status-error .test-info {
181181
background-color: black;
182182
color: white;
183183
}
184184

185-
.test-actions .status-success .test-title {
186-
color: #30B30A;
185+
.test-actions .status-success .test-title {
186+
color: #30B30A;
187187
}
188188

189-
.test-actions .status-failure .test-title {
189+
.test-actions .status-failure .test-title {
190190
color: #DF0000;
191191
}
192192

193-
.test-actions .status-error .test-title {
193+
.test-actions .status-error .test-title {
194194
color: black;
195195
}
196196

scenario/widgets-scenario.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
describe('widgets', function() {
22
it('should verify that basic widgets work', function(){
33
navigateTo('widgets.html');
4-
4+
55
using('#text-basic-box').input('text.basic').enter('Carlos');
66
expect(binding('text.basic')).toEqual('Carlos');
77
input('text.basic').enter('Carlos Santana');
88
expect(binding('text.basic')).not().toEqual('Carlos Boozer');
9-
9+
1010
input('text.password').enter('secret');
1111
expect(binding('text.password')).toEqual('secret');
12-
12+
1313
expect(binding('text.hidden')).toEqual('hiddenValue');
14-
14+
1515
expect(binding('gender')).toEqual('male');
1616
input('gender').select('female');
1717
expect(using('#gender-box').binding('gender')).toEqual('female');
1818

1919
expect(repeater('#repeater-row ul li').count()).toEqual(2);
2020
expect(repeater('#repeater-row ul li').row(1)).toEqual(['adam']);
2121
expect(repeater('#repeater-row ul li').column('name')).toEqual(['misko', 'adam']);
22-
22+
2323
select('select').option('B');
2424
expect(binding('select')).toEqual('B');
25-
25+
26+
2627
select('multiselect').options('A', 'C');
2728
expect(binding('multiselect').fromJson()).toEqual(['A', 'C']);
2829

@@ -35,14 +36,14 @@ describe('widgets', function() {
3536
expect(binding('button').fromJson()).toEqual({'count': 3});
3637
element('input[type="image"]').click();
3738
expect(binding('button').fromJson()).toEqual({'count': 4});
38-
39+
3940
/**
4041
* Custom value parser for futures.
4142
*/
4243
function checkboxParser(value) {
4344
return angular.fromJson(value.substring(value.indexOf('=')+1));
4445
}
45-
46+
4647
input('checkbox.tea').check();
4748
expect(binding('checkbox').parsedWith(checkboxParser)).toEqual({coffee: false, tea: false});
4849
input('checkbox.coffee').check();

scenario/widgets.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html xmlns:ng="http://angularjs.org">
33
<head>
44
<link rel="stylesheet" type="text/css" href="style.css"/>
5-
<script type="text/javascript" src="../lib/jquery/jquery-1.4.2.js"></script>
5+
<script type="text/javascript" src="../libs/jquery/jquery-1.4.2.js"></script>
66
<script type="text/javascript" src="../src/angular-bootstrap.js" ng:autobind></script>
77
</head>
88
<body ng:init="$window.$scope = this">

src/Angular.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,12 @@ function HTML(html) {
146146

147147
if (msie) {
148148
nodeName = function(element) {
149-
element = element[0] || element;
149+
element = element.nodeName ? element : element[0];
150150
return (element.scopeName && element.scopeName != 'HTML' ) ? uppercase(element.scopeName + ':' + element.nodeName) : element.nodeName;
151151
};
152152
} else {
153153
nodeName = function(element) {
154-
return (element[0] || element).nodeName;
154+
return element.nodeName ? element.nodeName : element[0].nodeName;
155155
};
156156
}
157157

src/jqLite.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,6 @@ JQLite.prototype = {
118118
});
119119
},
120120

121-
trigger: function(type) {
122-
if (msie) {
123-
this[0].fireEvent('on' + type);
124-
} else {
125-
var evnt = document.createEvent('MouseEvents'),
126-
element = this[0];
127-
evnt.initMouseEvent(type, true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, element);
128-
element.dispatchEvent(evnt);
129-
}
130-
},
131-
132121
replaceWith: function(replaceNode) {
133122
this[0].parentNode.replaceChild(jqLite(replaceNode)[0], this[0]);
134123
},

src/scenario/Scenario.js

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Setup file for the Scenario.
2+
* Setup file for the Scenario.
33
* Must be first in the compilation/bootstrap list.
44
*/
55

@@ -19,7 +19,7 @@ angular.scenario.ui = {};
1919
* functions.
2020
*
2121
* @param {String} The name of the statement
22-
* @param {Function} Factory function(application), return a function for
22+
* @param {Function} Factory function(application), return a function for
2323
* the statement.
2424
*/
2525
angular.scenario.dsl = function(name, fn) {
@@ -50,7 +50,7 @@ angular.scenario.dsl = function(name, fn) {
5050

5151
/**
5252
* Defines a new matcher for use with the expects() statement. The value
53-
* this.actual (like in Jasmine) is available in your matcher to compare
53+
* this.actual (like in Jasmine) is available in your matcher to compare
5454
* against. Your function should return a boolean. The future is automatically
5555
* created for you.
5656
*
@@ -83,7 +83,7 @@ angular.scenario.matcher = function(name, fn) {
8383
*
8484
* @param {Array} list to iterate over
8585
* @param {Function} Callback function(value, continueFunction)
86-
* @param {Function} Callback function(error, result) called when iteration
86+
* @param {Function} Callback function(error, result) called when iteration
8787
* finishes or an error occurs.
8888
*/
8989
function asyncForEach(list, iterator, done) {
@@ -101,3 +101,44 @@ function asyncForEach(list, iterator, done) {
101101
}
102102
loop();
103103
}
104+
105+
106+
function browserTrigger(element, type) {
107+
if (!element.nodeName) element = element[0];
108+
if (!type) {
109+
type = {
110+
'text': 'change',
111+
'textarea': 'change',
112+
'hidden': 'change',
113+
'password': 'change',
114+
'button': 'click',
115+
'submit': 'click',
116+
'reset': 'click',
117+
'image': 'click',
118+
'checkbox': 'click',
119+
'radio': 'click',
120+
'select-one': 'change',
121+
'select-multiple': 'change'
122+
}[element.type] || 'click';
123+
}
124+
if (lowercase(nodeName(element)) == 'option') {
125+
element.parentNode.value = element.value;
126+
element = element.parentNode;
127+
type = 'change';
128+
}
129+
if (msie) {
130+
element.fireEvent('on' + type);
131+
} else {
132+
var evnt = document.createEvent('MouseEvents');
133+
evnt.initMouseEvent(type, true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, element);
134+
element.dispatchEvent(evnt);
135+
}
136+
}
137+
138+
_jQuery.fn.trigger = function(type) {
139+
return this.each(function(index, node) {
140+
browserTrigger(node, type);
141+
});
142+
};
143+
144+

src/scenario/SpecRunner.js

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ angular.scenario.SpecRunner = function() {
2121
*/
2222
angular.scenario.SpecRunner.prototype.run = function(ui, spec, specDone) {
2323
var specUI = ui.addSpec(spec);
24-
24+
2525
try {
2626
spec.fn.call(this);
2727
} catch (e) {
2828
specUI.error(e);
2929
specDone();
3030
return;
3131
}
32-
32+
3333
asyncForEach(
34-
this.futures,
34+
this.futures,
3535
function(future, futureDone) {
3636
var stepUI = specUI.addStep(future.name);
3737
try {
@@ -43,10 +43,10 @@ angular.scenario.SpecRunner.prototype.run = function(ui, spec, specDone) {
4343
stepUI.error(e);
4444
throw e;
4545
}
46-
},
46+
},
4747
function(e) {
48-
specUI.finish(e);
49-
specDone();
48+
specUI.finish(e);
49+
specDone();
5050
}
5151
);
5252
};
@@ -89,29 +89,9 @@ angular.scenario.SpecRunner.prototype.addFutureAction = function(name, behavior)
8989
};
9090
}
9191

92-
result.trigger = function(type) {
93-
result.each(function(index, node) {
94-
var element = $window.angular.element(node);
95-
//TODO(esprehn): HACK!!! Something is broken in angular event dispatching
96-
// and if the real jQuery is used we need to set the attribtue after too
97-
if (angular.isDefined(element.selector)) {
98-
if (type === 'click' && node.nodeName.toLowerCase() === 'input') {
99-
element.attr('checked', !element.attr('checked'));
100-
}
101-
}
102-
//TODO(esprehn): HACK!! See above comment.
103-
element.trigger(type);
104-
if (angular.isDefined(element.selector)) {
105-
if (type === 'click' && node.nodeName.toLowerCase() === 'input') {
106-
element.attr('checked', !element.attr('checked'));
107-
}
108-
}
109-
});
110-
};
111-
11292
return result;
11393
});
114-
94+
11595
try {
11696
behavior.call(this, $window, $document, done);
11797
} catch(e) {

src/scenario/angular.prefix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@
2222
* THE SOFTWARE.
2323
*/
2424
(function(window, document, previousOnLoad){
25+
var _jQuery = window.jQuery.noConflict(true);

0 commit comments

Comments
 (0)
X Tutup