Skip to content

Commit 9c02255

Browse files
committed
fixes IE related failures, and form submit event handling in ie
1 parent 40d7e66 commit 9c02255

14 files changed

Lines changed: 131 additions & 86 deletions

File tree

example/personalLog/personalLog.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @fileOverview Very simple personal log demo application to demostrate angular functionality,
2+
* @fileOverview Very simple personal log demo application to demonstrate angular functionality,
33
* especially:
44
* - the MVC model
55
* - testability of controllers
@@ -46,7 +46,7 @@ function LogCtrl($cookieStore) {
4646
logs.push(log);
4747
$cookieStore.put(LOGS, logs);
4848
self.newMsg = '';
49-
}
49+
};
5050

5151

5252
/**
@@ -56,16 +56,16 @@ function LogCtrl($cookieStore) {
5656
this.rmLog = function(msgIdx) {
5757
logs.splice(msgIdx,1);
5858
$cookieStore.put(LOGS, logs);
59-
}
59+
};
6060

6161

6262
/**
6363
* Persistently removes all logs.
6464
*/
6565
this.rmLogs = function() {
66-
logs.splice(0);
66+
logs.splice(0, logs.length);
6767
$cookieStore.remove(LOGS);
68-
}
68+
};
6969
}
7070

7171
//inject

scenario/widgets-scenario.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,22 @@ describe('widgets', function() {
2727
expect(binding('multiselect').fromJson()).toEqual(['A', 'C']);
2828

2929
expect(binding('button').fromJson()).toEqual({'count': 0});
30+
expect(binding('form').fromJson()).toEqual({'count': 0});
31+
3032
element('form a').click();
3133
expect(binding('button').fromJson()).toEqual({'count': 1});
32-
element('input[value="submit"]').click();
34+
35+
element('input[value="submit input"]').click();
36+
expect(binding('button').fromJson()).toEqual({'count': 2});
37+
expect(binding('form').fromJson()).toEqual({'count': 1});
38+
39+
element('button:contains("submit button")').click();
3340
expect(binding('button').fromJson()).toEqual({'count': 2});
41+
expect(binding('form').fromJson()).toEqual({'count': 2});
42+
3443
element('input[value="button"]').click();
3544
expect(binding('button').fromJson()).toEqual({'count': 3});
45+
3646
element('input[type="image"]').click();
3747
expect(binding('button').fromJson()).toEqual({'count': 4});
3848

scenario/widgets.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,16 @@
7373
<tr><th colspan="3">Buttons</th></tr>
7474
<tr>
7575
<td>ng:change<br/>ng:click</td>
76-
<td ng:init="button.count = 0">
77-
<form>
76+
<td ng:init="button.count = 0; form.count = 0;">
77+
<form ng:submit="form.count = form.count + 1">
7878
<input type="button" value="button" ng:change="button.count = button.count + 1"/> <br/>
79-
<input type="submit" value="submit" ng:change="button.count = button.count + 1"/><br/>
79+
<input type="submit" value="submit input" ng:change="button.count = button.count + 1"/><br/>
80+
<button type="submit">submit button</button>
8081
<input type="image" src="" ng:change="button.count = button.count + 1"/><br/>
8182
<a href="" ng:click="button.count = button.count + 1">action</a>
8283
</form>
8384
</td>
84-
<td>button={{button}}</td>
85+
<td>button={{button}} form={{form}}</td>
8586
</tr>
8687
<tr><th colspan="3">Repeaters</th></tr>
8788
<tr id="repeater-row">

src/scenario/Scenario.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,15 @@ function browserTrigger(element, type) {
246246
break;
247247
}
248248
element.fireEvent('on' + type);
249+
if (lowercase(element.type) == 'submit') {
250+
while(element) {
251+
if (lowercase(element.nodeName) == 'form') {
252+
element.fireEvent('onsubmit');
253+
break;
254+
}
255+
element = element.parentNode;
256+
}
257+
}
249258
} else {
250259
var evnt = document.createEvent('MouseEvents');
251260
evnt.initMouseEvent(type, true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, element);

src/scenario/output/Xml.js

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
*/
44
angular.scenario.output('xml', function(context, runner) {
55
var model = new angular.scenario.ObjectModel(runner);
6-
6+
var $ = function(args) {return new context.init(args);};
77
runner.on('RunnerEnd', function() {
8-
context.append('<scenario></scenario>');
9-
serializeXml(context.find('> scenario'), model.value);
8+
var scenario = $('<scenario></scenario>');
9+
context.append(scenario);
10+
serializeXml(scenario, model.value);
1011
});
1112

1213
/**
@@ -17,30 +18,31 @@ angular.scenario.output('xml', function(context, runner) {
1718
*/
1819
function serializeXml(context, tree) {
1920
angular.foreach(tree.children, function(child) {
20-
context.append('<describe></describe>');
21-
var describeContext = context.find('> describe:last');
21+
var describeContext = $('<describe></describe>');
2222
describeContext.attr('id', child.id);
2323
describeContext.attr('name', child.name);
24+
context.append(describeContext);
2425
serializeXml(describeContext, child);
2526
});
26-
context.append('<its></its>');
27-
context = context.find('> its');
27+
var its = $('<its></its>');
28+
context.append(its);
2829
angular.foreach(tree.specs, function(spec) {
29-
context.append('<it></it>')
30-
var specContext = context.find('> it:last');
31-
specContext.attr('id', spec.id);
32-
specContext.attr('name', spec.name);
33-
specContext.attr('duration', spec.duration);
34-
specContext.attr('status', spec.status);
30+
var it = $('<it></it>');
31+
it.attr('id', spec.id);
32+
it.attr('name', spec.name);
33+
it.attr('duration', spec.duration);
34+
it.attr('status', spec.status);
35+
its.append(it);
3536
angular.foreach(spec.steps, function(step) {
36-
specContext.append('<step></step>');
37-
var stepContext = specContext.find('> step:last');
37+
var stepContext = $('<step></step>');
3838
stepContext.attr('name', step.name);
3939
stepContext.attr('duration', step.duration);
4040
stepContext.attr('status', step.status);
41+
it.append(stepContext);
4142
if (step.error) {
42-
stepContext.append('<error></error');
43-
stepContext.find('error').text(formatException(step.error));
43+
var error = $('<error></error');
44+
stepContext.append(error);
45+
error.text(formatException(stepContext.error));
4446
}
4547
});
4648
});

src/widgets.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,6 @@ function inputWidget(events, modelAccessor, viewAccessor, initFn) {
203203
lastValue = model.get();
204204
scope.$tryEval(action, element);
205205
scope.$root.$eval();
206-
// if we have noop initFn than we are just a button,
207-
// therefore we want to prevent default action
208-
if(initFn == noop)
209-
event.preventDefault();
210206
});
211207
}
212208
function updateView(){

test/directivesSpec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ describe("directives", function(){
206206
describe('ng:submit', function() {
207207
it('should get called on form submit', function() {
208208
var scope = compile('<form action="" ng:submit="submitted = true">' +
209-
'<input id="submit" type="submit"/>' +
209+
'<input type="submit"/>' +
210210
'</form>');
211211
scope.$eval();
212212
expect(scope.submitted).not.toBeDefined();

test/manual.html

Lines changed: 62 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -39,64 +39,91 @@
3939
<script type="text/javascript" src="../src/scenario/SpecRunner.js"></script>
4040
<script type="text/javascript" src="../src/scenario/dsl.js"></script>
4141
<script type="text/javascript" src="../src/scenario/matchers.js"></script>
42+
<script type="text/javascript" src="../src/scenario/ObjectModel.js"></script>
43+
44+
<script type="text/javascript" src="../src/scenario/output/Html.js"></script>
45+
<script type="text/javascript" src="../src/scenario/output/Object.js"></script>
46+
<script type="text/javascript" src="../src/scenario/output/Json.js"></script>
47+
<script type="text/javascript" src="../src/scenario/output/Xml.js"></script>
4248

4349
<script type="text/javascript" src="angular-mocks.js"></script>
50+
<script type="text/javascript" src="../test/scenario/mocks.js"></script>
4451
<script type="text/javascript" src="testabilityPatch.js"></script>
4552

4653
<!-- include spec files here... -->
4754
<script type="text/javascript">
4855
describe('manual', function(){
49-
var scope;
56+
var compile, model, element;
5057

51-
function compile(html, initialScope, parent) {
58+
beforeEach(function() {
5259
var compiler = new Compiler(angularTextMarkup, angularAttrMarkup, angularDirective, angularWidget);
53-
var element = self.element = jqLite(html);
54-
scope = compiler.compile(element)(element);
55-
56-
if (parent) parent.append(element);
57-
58-
extend(scope, initialScope);
59-
scope.$init();
60-
return {node:element, scope:scope};
61-
};
60+
compile = function(html) {
61+
element = jqLite(html);
62+
model = compiler.compile(element)(element);
63+
model.$init();
64+
return model;
65+
};
66+
});
6267

63-
it('should debug', function(){
64-
var x = compile(
65-
'<select name="selection" ng:format="number">' +
66-
'<option value="{{$index}}" ng:repeat="name in [\'A\', \'B\', \'C\']">{{name}}</option>' +
67-
'</select>');
68-
expect(scope.selection).toEqual(undefined);
68+
it('should get called on form submit', function() {
69+
var scope = compile('<form action="" ng:submit="submitted = true">' +
70+
'<input type="submit"/>' +
71+
'</form>');
72+
scope.$eval();
73+
expect(scope.submitted).not.toBeDefined();
6974

70-
browserTrigger(element[0].childNodes[2], 'change');
71-
expect(scope.selection).toEqual(1);
75+
browserTrigger(element.children()[0]);
76+
expect(scope.submitted).toEqual(true);
77+
});
78+
});
7279

73-
scope.selection = 2;
74-
scope.$eval();
75-
expect(element[0].childNodes[3].selected).toEqual(true);
80+
describe('angular.scenario.output.json', function() {
81+
var output, context;
82+
var runner, $window;
83+
var spec, step;
84+
85+
beforeEach(function() {
86+
$window = {};
87+
context = _jQuery('<div>text</div>');
88+
$(document.body).append(context);
89+
runner = new angular.scenario.testing.MockRunner();
90+
output = angular.scenario.output.xml(context, runner);
91+
spec = {
92+
name: 'test spec',
93+
definition: {
94+
id: 10,
95+
name: 'describe'
96+
}
97+
};
98+
step = {
99+
name: 'some step',
100+
line: function() { return 'unknown:-1'; }
101+
};
76102
});
77103

78-
it('should reproduce', function(){
79-
var select = $('<select name=""><option>a</option></select>');
80-
var log = '';
81-
select.bind('change', function(){ log += 'change;'; });
82-
select.bind('click', function(){ log += 'click;'; });
83-
select.bind('keyup', function(){ log += 'keyup;'; });
84-
select[0].attachEvent('onchange', function(){ log += 'CHANGE;';});
85-
select[0].fireEvent('onfocusout');
86-
select[0].fireEvent('onchange');
87-
select[0].fireEvent('onclick');
88-
select[0].fireEvent('onkeyup');
89-
expect(log).toEqual('CHANGE;change;click;keyup;');
104+
it('should create XML nodes for object model', function() {
105+
runner.emit('SpecBegin', spec);
106+
runner.emit('StepBegin', spec, step);
107+
runner.emit('StepEnd', spec, step);
108+
runner.emit('SpecEnd', spec);
109+
runner.emit('RunnerEnd');
110+
expect(_jQuery(context).find('it').attr('status')).toEqual('success');
111+
expect(_jQuery(context).find('it step').attr('status')).toEqual('success');
90112
});
91113
});
114+
115+
92116
</script>
93117

94118
</head>
95119
<body>
96120

97121
<script type="text/javascript">
98122
jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
99-
jasmine.getEnv().execute();
123+
function run(){
124+
jasmine.getEnv().execute();
125+
}
126+
run();
100127
</script>
101128

102129
</body>

test/scenario/ApplicationSpec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ describe('angular.scenario.Application', function() {
8888
var testWindow = {
8989
document: _jQuery('<div class="test-foo"></div>'),
9090
angular: {
91-
service: {},
91+
service: {}
9292
}
9393
};
9494
testWindow.angular.service.$browser = function() {

test/scenario/dslSpec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ describe("angular.scenario.dsl", function() {
177177
expect($window.location).not.toEqual('#foo');
178178
doc.append('<a href="#foo"></a>');
179179
$root.dsl.element('a').click();
180-
expect($window.location).toEqual('#foo');
180+
expect($window.location).toMatch(/#foo$/);
181181
});
182182

183183
it('should count matching elements', function() {

0 commit comments

Comments
 (0)