diff options
| -rw-r--r-- | example/personalLog/personalLog.js | 10 | ||||
| -rw-r--r-- | scenario/widgets-scenario.js | 12 | ||||
| -rw-r--r-- | scenario/widgets.html | 9 | ||||
| -rw-r--r-- | src/scenario/Scenario.js | 9 | ||||
| -rw-r--r-- | src/scenario/output/Xml.js | 36 | ||||
| -rw-r--r-- | src/widgets.js | 4 | ||||
| -rw-r--r-- | test/directivesSpec.js | 2 | ||||
| -rw-r--r-- | test/manual.html | 97 | ||||
| -rw-r--r-- | test/scenario/ApplicationSpec.js | 2 | ||||
| -rw-r--r-- | test/scenario/dslSpec.js | 2 | ||||
| -rw-r--r-- | test/scenario/output/HtmlSpec.js | 4 | ||||
| -rw-r--r-- | test/scenario/output/jsonSpec.js | 10 | ||||
| -rw-r--r-- | test/scenario/output/objectSpec.js | 8 | ||||
| -rw-r--r-- | test/scenario/output/xmlSpec.js | 12 |
14 files changed, 131 insertions, 86 deletions
diff --git a/example/personalLog/personalLog.js b/example/personalLog/personalLog.js index c0273036..da946a6f 100644 --- a/example/personalLog/personalLog.js +++ b/example/personalLog/personalLog.js @@ -1,5 +1,5 @@ /** - * @fileOverview Very simple personal log demo application to demostrate angular functionality, + * @fileOverview Very simple personal log demo application to demonstrate angular functionality, * especially: * - the MVC model * - testability of controllers @@ -46,7 +46,7 @@ function LogCtrl($cookieStore) { logs.push(log); $cookieStore.put(LOGS, logs); self.newMsg = ''; - } + }; /** @@ -56,16 +56,16 @@ function LogCtrl($cookieStore) { this.rmLog = function(msgIdx) { logs.splice(msgIdx,1); $cookieStore.put(LOGS, logs); - } + }; /** * Persistently removes all logs. */ this.rmLogs = function() { - logs.splice(0); + logs.splice(0, logs.length); $cookieStore.remove(LOGS); - } + }; } //inject diff --git a/scenario/widgets-scenario.js b/scenario/widgets-scenario.js index ba3ef3cf..7e8b8ade 100644 --- a/scenario/widgets-scenario.js +++ b/scenario/widgets-scenario.js @@ -27,12 +27,22 @@ describe('widgets', function() { expect(binding('multiselect').fromJson()).toEqual(['A', 'C']); expect(binding('button').fromJson()).toEqual({'count': 0}); + expect(binding('form').fromJson()).toEqual({'count': 0}); + element('form a').click(); expect(binding('button').fromJson()).toEqual({'count': 1}); - element('input[value="submit"]').click(); + + element('input[value="submit input"]').click(); + expect(binding('button').fromJson()).toEqual({'count': 2}); + expect(binding('form').fromJson()).toEqual({'count': 1}); + + element('button:contains("submit button")').click(); expect(binding('button').fromJson()).toEqual({'count': 2}); + expect(binding('form').fromJson()).toEqual({'count': 2}); + element('input[value="button"]').click(); expect(binding('button').fromJson()).toEqual({'count': 3}); + element('input[type="image"]').click(); expect(binding('button').fromJson()).toEqual({'count': 4}); diff --git a/scenario/widgets.html b/scenario/widgets.html index a520a326..adf2fa27 100644 --- a/scenario/widgets.html +++ b/scenario/widgets.html @@ -73,15 +73,16 @@ <tr><th colspan="3">Buttons</th></tr> <tr> <td>ng:change<br/>ng:click</td> - <td ng:init="button.count = 0"> - <form> + <td ng:init="button.count = 0; form.count = 0;"> + <form ng:submit="form.count = form.count + 1"> <input type="button" value="button" ng:change="button.count = button.count + 1"/> <br/> - <input type="submit" value="submit" ng:change="button.count = button.count + 1"/><br/> + <input type="submit" value="submit input" ng:change="button.count = button.count + 1"/><br/> + <button type="submit">submit button</button> <input type="image" src="" ng:change="button.count = button.count + 1"/><br/> <a href="" ng:click="button.count = button.count + 1">action</a> </form> </td> - <td>button={{button}}</td> + <td>button={{button}} form={{form}}</td> </tr> <tr><th colspan="3">Repeaters</th></tr> <tr id="repeater-row"> diff --git a/src/scenario/Scenario.js b/src/scenario/Scenario.js index f2ebc640..14d530ac 100644 --- a/src/scenario/Scenario.js +++ b/src/scenario/Scenario.js @@ -246,6 +246,15 @@ function browserTrigger(element, type) { break; } element.fireEvent('on' + type); + if (lowercase(element.type) == 'submit') { + while(element) { + if (lowercase(element.nodeName) == 'form') { + element.fireEvent('onsubmit'); + break; + } + element = element.parentNode; + } + } } else { var evnt = document.createEvent('MouseEvents'); evnt.initMouseEvent(type, true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, element); diff --git a/src/scenario/output/Xml.js b/src/scenario/output/Xml.js index 47d98c78..cbc55ee7 100644 --- a/src/scenario/output/Xml.js +++ b/src/scenario/output/Xml.js @@ -3,10 +3,11 @@ */ angular.scenario.output('xml', function(context, runner) { var model = new angular.scenario.ObjectModel(runner); - + var $ = function(args) {return new context.init(args);}; runner.on('RunnerEnd', function() { - context.append('<scenario></scenario>'); - serializeXml(context.find('> scenario'), model.value); + var scenario = $('<scenario></scenario>'); + context.append(scenario); + serializeXml(scenario, model.value); }); /** @@ -17,30 +18,31 @@ angular.scenario.output('xml', function(context, runner) { */ function serializeXml(context, tree) { angular.foreach(tree.children, function(child) { - context.append('<describe></describe>'); - var describeContext = context.find('> describe:last'); + var describeContext = $('<describe></describe>'); describeContext.attr('id', child.id); describeContext.attr('name', child.name); + context.append(describeContext); serializeXml(describeContext, child); }); - context.append('<its></its>'); - context = context.find('> its'); + var its = $('<its></its>'); + context.append(its); angular.foreach(tree.specs, function(spec) { - context.append('<it></it>') - var specContext = context.find('> it:last'); - specContext.attr('id', spec.id); - specContext.attr('name', spec.name); - specContext.attr('duration', spec.duration); - specContext.attr('status', spec.status); + var it = $('<it></it>'); + it.attr('id', spec.id); + it.attr('name', spec.name); + it.attr('duration', spec.duration); + it.attr('status', spec.status); + its.append(it); angular.foreach(spec.steps, function(step) { - specContext.append('<step></step>'); - var stepContext = specContext.find('> step:last'); + var stepContext = $('<step></step>'); stepContext.attr('name', step.name); stepContext.attr('duration', step.duration); stepContext.attr('status', step.status); + it.append(stepContext); if (step.error) { - stepContext.append('<error></error'); - stepContext.find('error').text(formatException(step.error)); + var error = $('<error></error'); + stepContext.append(error); + error.text(formatException(stepContext.error)); } }); }); diff --git a/src/widgets.js b/src/widgets.js index 34cc258a..4d8c71d5 100644 --- a/src/widgets.js +++ b/src/widgets.js @@ -203,10 +203,6 @@ function inputWidget(events, modelAccessor, viewAccessor, initFn) { lastValue = model.get(); scope.$tryEval(action, element); scope.$root.$eval(); - // if we have noop initFn than we are just a button, - // therefore we want to prevent default action - if(initFn == noop) - event.preventDefault(); }); } function updateView(){ diff --git a/test/directivesSpec.js b/test/directivesSpec.js index 34dcbf8d..fa2abd46 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -206,7 +206,7 @@ describe("directives", function(){ describe('ng:submit', function() { it('should get called on form submit', function() { var scope = compile('<form action="" ng:submit="submitted = true">' + - '<input id="submit" type="submit"/>' + + '<input type="submit"/>' + '</form>'); scope.$eval(); expect(scope.submitted).not.toBeDefined(); diff --git a/test/manual.html b/test/manual.html index 3b1886f3..dc491399 100644 --- a/test/manual.html +++ b/test/manual.html @@ -39,56 +39,80 @@ <script type="text/javascript" src="../src/scenario/SpecRunner.js"></script> <script type="text/javascript" src="../src/scenario/dsl.js"></script> <script type="text/javascript" src="../src/scenario/matchers.js"></script> + <script type="text/javascript" src="../src/scenario/ObjectModel.js"></script> + + <script type="text/javascript" src="../src/scenario/output/Html.js"></script> + <script type="text/javascript" src="../src/scenario/output/Object.js"></script> + <script type="text/javascript" src="../src/scenario/output/Json.js"></script> + <script type="text/javascript" src="../src/scenario/output/Xml.js"></script> <script type="text/javascript" src="angular-mocks.js"></script> + <script type="text/javascript" src="../test/scenario/mocks.js"></script> <script type="text/javascript" src="testabilityPatch.js"></script> <!-- include spec files here... --> <script type="text/javascript"> describe('manual', function(){ - var scope; + var compile, model, element; - function compile(html, initialScope, parent) { + beforeEach(function() { var compiler = new Compiler(angularTextMarkup, angularAttrMarkup, angularDirective, angularWidget); - var element = self.element = jqLite(html); - scope = compiler.compile(element)(element); - - if (parent) parent.append(element); - - extend(scope, initialScope); - scope.$init(); - return {node:element, scope:scope}; - }; + compile = function(html) { + element = jqLite(html); + model = compiler.compile(element)(element); + model.$init(); + return model; + }; + }); - it('should debug', function(){ - var x = compile( - '<select name="selection" ng:format="number">' + - '<option value="{{$index}}" ng:repeat="name in [\'A\', \'B\', \'C\']">{{name}}</option>' + - '</select>'); - expect(scope.selection).toEqual(undefined); + it('should get called on form submit', function() { + var scope = compile('<form action="" ng:submit="submitted = true">' + + '<input type="submit"/>' + + '</form>'); + scope.$eval(); + expect(scope.submitted).not.toBeDefined(); - browserTrigger(element[0].childNodes[2], 'change'); - expect(scope.selection).toEqual(1); + browserTrigger(element.children()[0]); + expect(scope.submitted).toEqual(true); + }); +}); - scope.selection = 2; - scope.$eval(); - expect(element[0].childNodes[3].selected).toEqual(true); +describe('angular.scenario.output.json', function() { + var output, context; + var runner, $window; + var spec, step; + + beforeEach(function() { + $window = {}; + context = _jQuery('<div>text</div>'); + $(document.body).append(context); + runner = new angular.scenario.testing.MockRunner(); + output = angular.scenario.output.xml(context, runner); + spec = { + name: 'test spec', + definition: { + id: 10, + name: 'describe' + } + }; + step = { + name: 'some step', + line: function() { return 'unknown:-1'; } + }; }); - it('should reproduce', function(){ - var select = $('<select name=""><option>a</option></select>'); - var log = ''; - select.bind('change', function(){ log += 'change;'; }); - select.bind('click', function(){ log += 'click;'; }); - select.bind('keyup', function(){ log += 'keyup;'; }); - select[0].attachEvent('onchange', function(){ log += 'CHANGE;';}); - select[0].fireEvent('onfocusout'); - select[0].fireEvent('onchange'); - select[0].fireEvent('onclick'); - select[0].fireEvent('onkeyup'); - expect(log).toEqual('CHANGE;change;click;keyup;'); + it('should create XML nodes for object model', function() { + runner.emit('SpecBegin', spec); + runner.emit('StepBegin', spec, step); + runner.emit('StepEnd', spec, step); + runner.emit('SpecEnd', spec); + runner.emit('RunnerEnd'); + expect(_jQuery(context).find('it').attr('status')).toEqual('success'); + expect(_jQuery(context).find('it step').attr('status')).toEqual('success'); }); }); + + </script> </head> @@ -96,7 +120,10 @@ describe('manual', function(){ <script type="text/javascript"> jasmine.getEnv().addReporter(new jasmine.TrivialReporter()); - jasmine.getEnv().execute(); + function run(){ + jasmine.getEnv().execute(); + } + run(); </script> </body> diff --git a/test/scenario/ApplicationSpec.js b/test/scenario/ApplicationSpec.js index 122292c6..3e1c862d 100644 --- a/test/scenario/ApplicationSpec.js +++ b/test/scenario/ApplicationSpec.js @@ -88,7 +88,7 @@ describe('angular.scenario.Application', function() { var testWindow = { document: _jQuery('<div class="test-foo"></div>'), angular: { - service: {}, + service: {} } }; testWindow.angular.service.$browser = function() { diff --git a/test/scenario/dslSpec.js b/test/scenario/dslSpec.js index bbba0b7d..efedeeb5 100644 --- a/test/scenario/dslSpec.js +++ b/test/scenario/dslSpec.js @@ -177,7 +177,7 @@ describe("angular.scenario.dsl", function() { expect($window.location).not.toEqual('#foo'); doc.append('<a href="#foo"></a>'); $root.dsl.element('a').click(); - expect($window.location).toEqual('#foo'); + expect($window.location).toMatch(/#foo$/); }); it('should count matching elements', function() { diff --git a/test/scenario/output/HtmlSpec.js b/test/scenario/output/HtmlSpec.js index f5bb90b0..f973397e 100644 --- a/test/scenario/output/HtmlSpec.js +++ b/test/scenario/output/HtmlSpec.js @@ -19,7 +19,7 @@ describe('angular.scenario.output.html', function() { }; step = { name: 'some step', - line: function() { return 'unknown:-1'; }, + line: function() { return 'unknown:-1'; } }; runner = new angular.scenario.testing.MockRunner(); context = _jQuery("<div></div>"); @@ -44,7 +44,7 @@ describe('angular.scenario.output.html', function() { runner.emit('StepBegin', spec, step); runner.emit('InteractiveWait', spec, step); expect(context.find('.test-actions .test-title:first').text()).toEqual('some step'); - expect(context.find('.test-actions .test-title:last').html()).toEqual( + expect(lowercase(context.find('.test-actions .test-title:last').html())).toEqual( 'waiting for you to <a href="javascript:resume()">resume</a>.' ); }); diff --git a/test/scenario/output/jsonSpec.js b/test/scenario/output/jsonSpec.js index b3592608..afc74a21 100644 --- a/test/scenario/output/jsonSpec.js +++ b/test/scenario/output/jsonSpec.js @@ -2,7 +2,7 @@ describe('angular.scenario.output.json', function() { var output, context; var runner, $window; var spec, step; - + beforeEach(function() { $window = {}; context = _jQuery('<div></div>'); @@ -12,22 +12,22 @@ describe('angular.scenario.output.json', function() { name: 'test spec', definition: { id: 10, - name: 'describe', + name: 'describe' } }; step = { name: 'some step', - line: function() { return 'unknown:-1'; }, + line: function() { return 'unknown:-1'; } }; }); - + it('should put json in context on RunnerEnd', function() { runner.emit('SpecBegin', spec); runner.emit('StepBegin', spec, step); runner.emit('StepEnd', spec, step); runner.emit('SpecEnd', spec); runner.emit('RunnerEnd'); - + expect(angular.fromJson(context.html()).children['describe'] .specs['test spec'].status).toEqual('success'); }); diff --git a/test/scenario/output/objectSpec.js b/test/scenario/output/objectSpec.js index c4e8d451..73c3dcf9 100644 --- a/test/scenario/output/objectSpec.js +++ b/test/scenario/output/objectSpec.js @@ -18,19 +18,19 @@ describe('angular.scenario.output.object', function() { }; step = { name: 'some step', - line: function() { return 'unknown:-1'; }, + line: function() { return 'unknown:-1'; } }; }); - + it('should create a global variable $result', function() { expect($window.$result).toBeDefined(); }); - + it('should maintain live state in $result', function() { runner.emit('SpecBegin', spec); runner.emit('StepBegin', spec, step); runner.emit('StepEnd', spec, step); - + expect($window.$result.children['describe'] .specs['test spec'].steps[0].duration).toBeDefined(); }); diff --git a/test/scenario/output/xmlSpec.js b/test/scenario/output/xmlSpec.js index 448c8d10..fbfabcc4 100644 --- a/test/scenario/output/xmlSpec.js +++ b/test/scenario/output/xmlSpec.js @@ -2,7 +2,7 @@ describe('angular.scenario.output.json', function() { var output, context; var runner, $window; var spec, step; - + beforeEach(function() { $window = {}; context = _jQuery('<div></div>'); @@ -12,22 +12,22 @@ describe('angular.scenario.output.json', function() { name: 'test spec', definition: { id: 10, - name: 'describe', + name: 'describe' } }; step = { name: 'some step', - line: function() { return 'unknown:-1'; }, + line: function() { return 'unknown:-1'; } }; }); - + it('should create XML nodes for object model', function() { runner.emit('SpecBegin', spec); runner.emit('StepBegin', spec, step); runner.emit('StepEnd', spec, step); runner.emit('SpecEnd', spec); runner.emit('RunnerEnd'); - expect(_jQuery(context).find('it').attr('status')).toEqual('success'); - expect(_jQuery(context).find('it step').attr('status')).toEqual('success'); + expect(context.find('it').attr('status')).toEqual('success'); + expect(context.find('it step').attr('status')).toEqual('success'); }); }); |
