From 2430f52bb97fa9d682e5f028c977c5bf94c5ec38 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Fri, 23 Mar 2012 14:03:24 -0700 Subject: chore(module): move files around in preparation for more modules --- test/ngScenario/ApplicationSpec.js | 141 +++++ test/ngScenario/DescribeSpec.js | 122 ++++ test/ngScenario/FutureSpec.js | 77 +++ test/ngScenario/ObjectModelSpec.js | 333 +++++++++++ test/ngScenario/RunnerSpec.js | 116 ++++ test/ngScenario/ScenarioSpec.js | 32 ++ test/ngScenario/SpecRunnerSpec.js | 177 ++++++ test/ngScenario/dslSpec.js | 629 +++++++++++++++++++++ test/ngScenario/e2e/Runner-compiled.html | 9 + test/ngScenario/e2e/Runner.html | 9 + test/ngScenario/e2e/style.css | 11 + test/ngScenario/e2e/widgets-scenario.js | 67 +++ test/ngScenario/e2e/widgets.html | 99 ++++ .../jstd-scenario-adapter/AdapterSpecs.js | 322 +++++++++++ test/ngScenario/matchersSpec.js | 51 ++ test/ngScenario/mocks.js | 33 ++ test/ngScenario/output/HtmlSpec.js | 126 +++++ test/ngScenario/output/jsonSpec.js | 37 ++ test/ngScenario/output/objectSpec.js | 40 ++ test/ngScenario/output/xmlSpec.js | 36 ++ 20 files changed, 2467 insertions(+) create mode 100644 test/ngScenario/ApplicationSpec.js create mode 100644 test/ngScenario/DescribeSpec.js create mode 100644 test/ngScenario/FutureSpec.js create mode 100644 test/ngScenario/ObjectModelSpec.js create mode 100644 test/ngScenario/RunnerSpec.js create mode 100644 test/ngScenario/ScenarioSpec.js create mode 100644 test/ngScenario/SpecRunnerSpec.js create mode 100644 test/ngScenario/dslSpec.js create mode 100644 test/ngScenario/e2e/Runner-compiled.html create mode 100644 test/ngScenario/e2e/Runner.html create mode 100644 test/ngScenario/e2e/style.css create mode 100644 test/ngScenario/e2e/widgets-scenario.js create mode 100644 test/ngScenario/e2e/widgets.html create mode 100644 test/ngScenario/jstd-scenario-adapter/AdapterSpecs.js create mode 100644 test/ngScenario/matchersSpec.js create mode 100644 test/ngScenario/mocks.js create mode 100644 test/ngScenario/output/HtmlSpec.js create mode 100644 test/ngScenario/output/jsonSpec.js create mode 100644 test/ngScenario/output/objectSpec.js create mode 100644 test/ngScenario/output/xmlSpec.js (limited to 'test/ngScenario') diff --git a/test/ngScenario/ApplicationSpec.js b/test/ngScenario/ApplicationSpec.js new file mode 100644 index 00000000..7384ecaa --- /dev/null +++ b/test/ngScenario/ApplicationSpec.js @@ -0,0 +1,141 @@ +'use strict'; + +describe('angular.scenario.Application', function() { + var $window; + var app, frames; + + function callLoadHandlers(app) { + var handlers = app.getFrame_().data('events').load; + expect(handlers).toBeDefined(); + expect(handlers.length).toEqual(1); + handlers[0].handler(); + } + + beforeEach(function() { + frames = _jQuery("
"); + app = new angular.scenario.Application(frames); + }); + + it('should return new $window and $document after navigate', function() { + var called; + var testWindow, testDocument, counter = 0; + app.getWindow_ = function() { + return {x:counter++, document:{x:counter++}}; + }; + app.navigateTo('http://www.google.com/'); + app.executeAction(function($document, $window) { + testWindow = $window; + testDocument = $document; + }); + app.navigateTo('http://www.google.com/'); + app.executeAction(function($window, $document) { + expect($window).not.toEqual(testWindow); + expect($document).not.toEqual(testDocument); + called = true; + }); + expect(called).toBeTruthy(); + }); + + it('should execute callback with correct arguments', function() { + var called; + var testWindow = {document: {}}; + app.getWindow_ = function() { + return testWindow; + }; + app.executeAction(function($window, $document) { + expect(this).toEqual(app); + expect($document).toEqual(_jQuery($window.document)); + expect($window).toEqual(testWindow); + called = true; + }); + expect(called).toBeTruthy(); + }); + + it('should use a new iframe each time', function() { + app.navigateTo('http://localhost/'); + var frame = app.getFrame_(); + frame.attr('test', true); + app.navigateTo('http://localhost/'); + expect(app.getFrame_().attr('test')).toBeFalsy(); + }); + + it('should call error handler if document not accessible', function() { + var called; + app.getWindow_ = function() { + return {}; + }; + app.navigateTo('http://localhost/', angular.noop, function(error) { + expect(error).toMatch(/Sandbox Error/); + called = true; + }); + callLoadHandlers(app); + expect(called).toBeTruthy(); + }); + + it('should call error handler if navigating to about:blank', function() { + var called; + app.navigateTo('about:blank', angular.noop, function(error) { + expect(error).toMatch(/Sandbox Error/); + called = true; + }); + expect(called).toBeTruthy(); + }); + + it('should remove old iframes', function() { + app.navigateTo('http://localhost/#foo'); + frames.find('iframe')[0].id = 'test'; + + app.navigateTo('http://localhost/#bar'); + var iframes = frames.find('iframe'); + + expect(iframes.length).toEqual(1); + expect(iframes[0].src).toEqual('http://localhost/#bar'); + expect(iframes[0].id).toBeFalsy(); + }); + + it('should URL update description bar', function() { + app.navigateTo('http://localhost/'); + var anchor = frames.find('> h2 a'); + expect(anchor.attr('href')).toEqual('http://localhost/'); + expect(anchor.text()).toEqual('http://localhost/'); + }); + + it('should call onload handler when frame loads', function() { + var called; + app.getWindow_ = function() { + return {document: {}}; + }; + app.navigateTo('http://localhost/', function($window, $document) { + called = true; + }); + callLoadHandlers(app); + expect(called).toBeTruthy(); + }); + + it('should wait for pending requests in executeAction', inject(function($injector, $browser) { + var called, polled; + var handlers = []; + var testWindow = { + document: jqLite('')[0], + angular: { + element: jqLite, + service: {} + } + }; + $browser.notifyWhenNoOutstandingRequests = function(fn) { + handlers.push(fn); + }; + jqLite(testWindow.document).data('$injector', $injector); + app.getWindow_ = function() { + return testWindow; + }; + app.executeAction(function($window, $document) { + expect($window).toEqual(testWindow); + expect($document).toBeDefined(); + expect($document[0].className).toEqual('test-foo'); + }); + expect(handlers.length).toEqual(1); + handlers[0](); + dealoc(testWindow.document); + })); +}); diff --git a/test/ngScenario/DescribeSpec.js b/test/ngScenario/DescribeSpec.js new file mode 100644 index 00000000..6741ed6d --- /dev/null +++ b/test/ngScenario/DescribeSpec.js @@ -0,0 +1,122 @@ +'use strict'; + +describe('angular.scenario.Describe', function() { + var log; + var root; + + beforeEach(function() { + root = new angular.scenario.Describe(); + + /** + * Simple callback logging system. Use to assert proper order of calls. + */ + log = function(text) { + log.text = log.text + text; + }; + log.fn = function(text) { + return function(done){ + log(text); + (done || angular.noop)(); + }; + }; + log.reset = function() { + log.text = ''; + }; + log.reset(); + }); + + it('should handle basic nested case', function() { + root.describe('A', function() { + this.beforeEach(log.fn('{')); + this.afterEach(log.fn('}')); + this.it('1', log.fn('1')); + this.describe('B', function() { + this.beforeEach(log.fn('(')); + this.afterEach(log.fn(')')); + this.it('2', log.fn('2')); + }); + }); + var specs = root.getSpecs(); + expect(specs.length).toEqual(2); + + expect(specs[0].name).toEqual('2'); + specs[0].before(); + specs[0].body(); + specs[0].after(); + expect(log.text).toEqual('{(2)}'); + + log.reset(); + expect(specs[1].name).toEqual('1'); + specs[1].before(); + specs[1].body(); + specs[1].after(); + expect(log.text).toEqual('{1}'); + }); + + it('should link nested describe blocks with parent and children', function() { + root.describe('A', function() { + this.it('1', angular.noop); + this.describe('B', function() { + this.it('2', angular.noop); + this.describe('C', function() { + this.it('3', angular.noop); + }); + }); + }); + var specs = root.getSpecs(); + expect(specs[2].definition.parent).toEqual(root); + expect(specs[0].definition.parent).toEqual(specs[2].definition.children[0]); + }); + + it('should not process xit and xdescribe', function() { + root.describe('A', function() { + this.xit('1', angular.noop); + this.xdescribe('B', function() { + this.it('2', angular.noop); + this.describe('C', function() { + this.it('3', angular.noop); + }); + }); + }); + var specs = root.getSpecs(); + expect(specs.length).toEqual(0); + }); + + it('should only return iit and ddescribe if present', function() { + root.describe('A', function() { + this.it('1', angular.noop); + this.iit('2', angular.noop); + this.describe('B', function() { + this.it('3', angular.noop); + this.ddescribe('C', function() { + this.it('4', angular.noop); + this.describe('D', function() { + this.it('5', angular.noop); + }); + }); + }); + }); + var specs = root.getSpecs(); + expect(specs.length).toEqual(3); + expect(specs[0].name).toEqual('5'); + expect(specs[1].name).toEqual('4'); + expect(specs[2].name).toEqual('2'); + }); + + it('should create uniqueIds in the tree', function() { + angular.scenario.Describe.id = 0; + var a = new angular.scenario.Describe(); + var b = new angular.scenario.Describe(); + expect(a.id).toNotEqual(b.id); + }); + + it('should create uniqueIds for each spec', function() { + var d = new angular.scenario.Describe(); + d.it('fake', function() {}); + d.it('fake', function() {}); + + expect(d.its[0].id).toBeDefined(); + expect(d.its[1].id).toBeDefined(); + expect(d.its[0].id).not.toEqual(d.its[1].id); + }); +}); diff --git a/test/ngScenario/FutureSpec.js b/test/ngScenario/FutureSpec.js new file mode 100644 index 00000000..2a75f275 --- /dev/null +++ b/test/ngScenario/FutureSpec.js @@ -0,0 +1,77 @@ +'use strict'; + +describe('angular.scenario.Future', function() { + var future; + + it('should set the sane defaults', function() { + var behavior = function() {}; + var future = new angular.scenario.Future('test name', behavior, 'foo'); + expect(future.name).toEqual('test name'); + expect(future.behavior).toEqual(behavior); + expect(future.line).toEqual('foo'); + expect(future.value).toBeUndefined(); + expect(future.fulfilled).toBeFalsy(); + expect(future.parser).toEqual(angular.identity); + }); + + it('should be fulfilled after execution and done callback', function() { + var future = new angular.scenario.Future('test name', function(done) { + done(); + }); + future.execute(angular.noop); + expect(future.fulfilled).toBeTruthy(); + }); + + it('should take callback with (error, result) and forward', function() { + var future = new angular.scenario.Future('test name', function(done) { + done(10, 20); + }); + future.execute(function(error, result) { + expect(error).toEqual(10); + expect(result).toEqual(20); + }); + }); + + it('should use error as value if provided', function() { + var future = new angular.scenario.Future('test name', function(done) { + done(10, 20); + }); + future.execute(angular.noop); + expect(future.value).toEqual(10); + }); + + it('should parse json with fromJson', function() { + var future = new angular.scenario.Future('test name', function(done) { + done(null, "{test: 'foo'}"); + }); + future.fromJson().execute(angular.noop); + expect(future.value).toEqual({test: 'foo'}); + }); + + it('should convert to json with toJson', function() { + var future = new angular.scenario.Future('test name', function(done) { + done(null, {test: 'foo'}); + }); + future.toJson().execute(angular.noop); + expect(future.value).toEqual('{"test":"foo"}'); + }); + + it('should convert with custom parser', function() { + var future = new angular.scenario.Future('test name', function(done) { + done(null, 'foo'); + }); + future.parsedWith(function(value) { + return value.toUpperCase(); + }).execute(angular.noop); + expect(future.value).toEqual('FOO'); + }); + + it('should pass error if parser fails', function() { + var future = new angular.scenario.Future('test name', function(done) { + done(null, '{'); + }); + future.fromJson().execute(function(error, result) { + expect(error).toBeDefined(); + }); + }); +}); diff --git a/test/ngScenario/ObjectModelSpec.js b/test/ngScenario/ObjectModelSpec.js new file mode 100644 index 00000000..e0da628d --- /dev/null +++ b/test/ngScenario/ObjectModelSpec.js @@ -0,0 +1,333 @@ +'use strict'; + +describe('angular.scenario.ObjectModel', function() { + var model; + var runner; + var spec, step; + + function buildSpec(id, name, definitions) { + var spec = { + id: id, + name: name, + definition: { + name: definitions.shift() + } + }; + var currentDef = spec.definition; + + forEach(definitions, function(defName) { + currentDef.parent = { + name: defName + }; + currentDef = currentDef.parent; + }); + + return spec; + } + + function buildStep(name, line) { + return { + name: name || 'test step', + line: function() { return line || ''; } + }; + } + + beforeEach(function() { + spec = buildSpec(1, 'test spec', ['describe 1']); + step = buildStep(); + runner = new angular.scenario.testing.MockRunner(); + model = new angular.scenario.ObjectModel(runner); + }); + + it('should value default empty value', function() { + expect(model.value).toEqual({ + name: '', + children: [] + }); + }); + + it('should add spec and create describe blocks on SpecBegin event', function() { + runner.emit('SpecBegin', buildSpec(1, 'test spec', ['describe 2', 'describe 1'])); + + expect(model.value.children['describe 1']).toBeDefined(); + expect(model.value.children['describe 1'].children['describe 2']).toBeDefined(); + expect(model.value.children['describe 1'].children['describe 2'].specs['test spec']).toBeDefined(); + }); + + it('should set fullDefinitionName on SpecBegin event', function() { + runner.emit('SpecBegin', buildSpec(1, 'fake spec', ['describe 2'])); + var spec = model.getSpec(1); + + expect(spec.fullDefinitionName).toBeDefined(); + expect(spec.fullDefinitionName).toEqual('describe 2'); + }); + + it('should set fullDefinitionName on SpecBegin event (join more names by space)', function() { + runner.emit('SpecBegin', buildSpec(1, 'fake spec', ['describe 2', 'describe 1'])); + var spec = model.getSpec(1); + + expect(spec.fullDefinitionName).toEqual('describe 1 describe 2'); + }); + + it('should add step to spec on StepBegin', function() { + runner.emit('SpecBegin', spec); + runner.emit('StepBegin', spec, step); + runner.emit('StepEnd', spec, step); + runner.emit('SpecEnd', spec); + + expect(model.value.children['describe 1'].specs['test spec'].steps.length).toEqual(1); + }); + + it('should update spec timer duration on SpecEnd event', function() { + runner.emit('SpecBegin', spec); + runner.emit('SpecEnd', spec); + + expect(model.value.children['describe 1'].specs['test spec'].duration).toBeDefined(); + }); + + it('should update step timer duration on StepEnd event', function() { + runner.emit('SpecBegin', spec); + runner.emit('StepBegin', spec, step); + runner.emit('StepEnd', spec, step); + runner.emit('SpecEnd', spec); + + expect(model.value.children['describe 1'].specs['test spec'].steps[0].duration).toBeDefined(); + }); + + it('should set spec status on SpecEnd to success if no status set', function() { + runner.emit('SpecBegin', spec); + runner.emit('SpecEnd', spec); + + expect(model.value.children['describe 1'].specs['test spec'].status).toEqual('success'); + }); + + it('should set status to error after SpecError', function() { + runner.emit('SpecBegin', spec); + runner.emit('SpecError', spec, 'error'); + + expect(model.value.children['describe 1'].specs['test spec'].status).toEqual('error'); + }); + + it('should set spec status to failure if step fails', function() { + runner.emit('SpecBegin', spec); + runner.emit('StepBegin', spec, step); + runner.emit('StepEnd', spec, step); + runner.emit('StepBegin', spec, step); + runner.emit('StepFailure', spec, step, 'error'); + runner.emit('StepEnd', spec, step); + runner.emit('StepBegin', spec, step); + runner.emit('StepEnd', spec, step); + runner.emit('SpecEnd', spec); + + expect(model.value.children['describe 1'].specs['test spec'].status).toEqual('failure'); + }); + + it('should set spec status to error if step errors', function() { + runner.emit('SpecBegin', spec); + runner.emit('StepBegin', spec, step); + runner.emit('StepError', spec, step, 'error'); + runner.emit('StepEnd', spec, step); + runner.emit('StepBegin', spec, step); + runner.emit('StepFailure', spec, step, 'error'); + runner.emit('StepEnd', spec, step); + runner.emit('SpecEnd', spec); + + expect(model.value.children['describe 1'].specs['test spec'].status).toEqual('error'); + }); + + describe('events', function() { + var Spec = angular.scenario.ObjectModel.Spec, + Step = angular.scenario.ObjectModel.Step, + callback; + + beforeEach(function() { + callback = jasmine.createSpy('listener'); + }); + + it('should provide method for registering a listener', function() { + expect(model.on).toBeDefined(); + expect(model.on instanceof Function).toBe(true); + }); + + it('should forward SpecBegin event', function() { + model.on('SpecBegin', callback); + runner.emit('SpecBegin', spec); + + expect(callback).toHaveBeenCalled(); + }); + + it('should forward SpecBegin event with ObjectModel.Spec as a param', function() { + model.on('SpecBegin', callback); + runner.emit('SpecBegin', spec); + + expect(callback.mostRecentCall.args[0] instanceof Spec).toBe(true); + expect(callback.mostRecentCall.args[0].name).toEqual(spec.name); + }); + + it('should forward SpecError event', function() { + model.on('SpecError', callback); + runner.emit('SpecBegin', spec); + runner.emit('SpecError', spec, {}); + + expect(callback).toHaveBeenCalled(); + }); + + it('should forward SpecError event with ObjectModel.Spec and error as a params', function() { + var error = {}; + model.on('SpecError', callback); + runner.emit('SpecBegin', spec); + runner.emit('SpecError', spec, error); + + var param = callback.mostRecentCall.args[0]; + expect(param instanceof Spec).toBe(true); + expect(param.name).toEqual(spec.name); + expect(param.status).toEqual('error'); + expect(param.error).toBe(error); + }); + + it('should forward SpecEnd event', function() { + model.on('SpecEnd', callback); + runner.emit('SpecBegin', spec); + runner.emit('SpecEnd', spec); + + expect(callback).toHaveBeenCalled(); + }); + + it('should forward SpecEnd event with ObjectModel.Spec as a param', function() { + model.on('SpecEnd', callback); + runner.emit('SpecBegin', spec); + runner.emit('SpecEnd', spec); + + expect(callback.mostRecentCall.args[0] instanceof Spec).toBe(true); + expect(callback.mostRecentCall.args[0].name).toEqual(spec.name); + }); + + it('should forward StepBegin event', function() { + model.on('StepBegin', callback); + runner.emit('SpecBegin', spec); + runner.emit('StepBegin', spec, step); + + expect(callback).toHaveBeenCalled(); + }); + + it('should forward StepBegin event with Spec and Step as params', function() { + model.on('StepBegin', callback); + runner.emit('SpecBegin', spec); + runner.emit('StepBegin', spec, step); + + var params = callback.mostRecentCall.args; + expect(params[0] instanceof Spec).toBe(true); + expect(params[0].name).toEqual(spec.name); + expect(params[1] instanceof Step).toBe(true); + }); + + it('should forward StepError event', function() { + model.on('StepError', callback); + runner.emit('SpecBegin', spec); + runner.emit('StepBegin', spec, step); + runner.emit('StepError', spec, step, {}); + + expect(callback).toHaveBeenCalled(); + }); + + it('should forward StepError event with Spec, Step and error as params', function() { + var error = {}; + model.on('StepError', callback); + runner.emit('SpecBegin', spec); + runner.emit('StepBegin', spec, step); + runner.emit('StepError', spec, step, error); + + var params = callback.mostRecentCall.args; + expect(params[0] instanceof Spec).toBe(true); + expect(params[0].name).toEqual(spec.name); + expect(params[1] instanceof Step).toBe(true); + expect(params[1].status).toEqual('error'); + expect(params[2]).toBe(error); + }); + + it('should forward StepFailure event', function() { + model.on('StepFailure', callback); + runner.emit('SpecBegin', spec); + runner.emit('StepBegin', spec, step); + runner.emit('StepFailure', spec, step, {}); + + expect(callback).toHaveBeenCalled(); + }); + + it('should forward StepFailure event with Spec, Step and error as params', function() { + var error = {}; + model.on('StepFailure', callback); + runner.emit('SpecBegin', spec); + runner.emit('StepBegin', spec, step); + runner.emit('StepFailure', spec, step, error); + + var params = callback.mostRecentCall.args; + expect(params[0] instanceof Spec).toBe(true); + expect(params[0].name).toEqual(spec.name); + expect(params[1] instanceof Step).toBe(true); + expect(params[1].status).toEqual('failure'); + expect(params[2]).toBe(error); + }); + + it('should forward StepEnd event', function() { + model.on('StepEnd', callback); + runner.emit('SpecBegin', spec); + runner.emit('StepBegin', spec, step); + runner.emit('StepEnd', spec, step); + + expect(callback).toHaveBeenCalled(); + }); + + it('should forward StepEnd event with Spec and Step as params', function() { + model.on('StepEnd', callback); + runner.emit('SpecBegin', spec); + runner.emit('StepBegin', spec, step); + runner.emit('StepEnd', spec, step); + + var params = callback.mostRecentCall.args; + expect(params[0] instanceof Spec).toBe(true); + expect(params[0].name).toEqual(spec.name); + expect(params[1] instanceof Step).toBe(true); + }); + + it('should forward RunnerEnd event', function() { + model.on('RunnerEnd', callback); + runner.emit('RunnerEnd'); + expect(callback).toHaveBeenCalled(); + }); + + it('should set error of first failure', function() { + var error = 'first-error', + step2 = buildStep(); + + model.on('SpecEnd', function(spec) { + expect(spec.error).toBeDefined(); + expect(spec.error).toBe(error); + }); + + runner.emit('SpecBegin', spec); + runner.emit('StepBegin', spec, step); + runner.emit('StepFailure', spec, step, error); + runner.emit('StepBegin', spec, step2); + runner.emit('StepFailure', spec, step2, 'second-error'); + runner.emit('SpecEnd', spec); + }); + + it('should set line number of first failure', function() { + var step = buildStep('fake', 'first-line'), + step2 = buildStep('fake2', 'second-line'); + + model.on('SpecEnd', function(spec) { + expect(spec.line).toBeDefined(); + expect(spec.line).toBe('first-line'); + }); + + runner.emit('SpecBegin', spec); + runner.emit('StepBegin', spec, step); + runner.emit('StepFailure', spec, step, null); + runner.emit('StepBegin', spec, step2); + runner.emit('StepFailure', spec, step2, null); + runner.emit('SpecEnd', spec); + }); + }); +}); diff --git a/test/ngScenario/RunnerSpec.js b/test/ngScenario/RunnerSpec.js new file mode 100644 index 00000000..c4ad6f95 --- /dev/null +++ b/test/ngScenario/RunnerSpec.js @@ -0,0 +1,116 @@ +'use strict'; + +/** + * Mock spec runner. + */ +function MockSpecRunner() {} +MockSpecRunner.prototype.run = function(spec, specDone) { + spec.before.call(this); + spec.body.call(this); + spec.after.call(this); + specDone(); +}; + +MockSpecRunner.prototype.addFuture = function(name, fn, line) { + return {name: name, fn: fn, line: line}; +}; + +describe('angular.scenario.Runner', function() { + var $window; + var runner; + + beforeEach(function() { + // Trick to get the scope out of a DSL statement + angular.scenario.dsl('dslAddFuture', function() { + return function() { + return this.addFuture('future name', angular.noop); + }; + }); + // Trick to get the scope out of a DSL statement + angular.scenario.dsl('dslScope', function() { + var scope = this; + return function() { return scope; }; + }); + // Trick to get the scope out of a DSL statement + angular.scenario.dsl('dslChain', function() { + return function() { + this.chained = 0; + this.chain = function() { this.chained++; return this; }; + return this; + }; + }); + $window = { + location: {} + }; + runner = new angular.scenario.Runner($window); + runner.on('SpecError', angular.mock.rethrow); + runner.on('StepError', angular.mock.rethrow); + }); + + afterEach(function() { + delete angular.scenario.dsl.dslScope; + delete angular.scenario.dsl.dslChain; + }); + + it('should publish the functions in the public API', function() { + angular.forEach(runner.api, function(fn, name) { + var func; + if (name in $window) { + func = $window[name]; + } + expect(angular.isFunction(func)).toBeTruthy(); + }); + }); + + it('should construct valid describe trees with public API', function() { + var before = []; + var after = []; + $window.describe('A', function() { + $window.beforeEach(function() { before.push('A'); }); + $window.afterEach(function() { after.push('A'); }); + $window.it('1', angular.noop); + $window.describe('B', function() { + $window.beforeEach(function() { before.push('B'); }); + $window.afterEach(function() { after.push('B'); }); + $window.it('2', angular.noop); + $window.describe('C', function() { + $window.beforeEach(function() { before.push('C'); }); + $window.afterEach(function() { after.push('C'); }); + $window.it('3', angular.noop); + }); + }); + }); + var specs = runner.rootDescribe.getSpecs(); + specs[0].before(); + specs[0].body(); + specs[0].after(); + expect(before).toEqual(['A', 'B', 'C']); + expect(after).toEqual(['C', 'B', 'A']); + expect(specs[2].definition.parent).toEqual(runner.rootDescribe); + expect(specs[0].definition.parent).toEqual(specs[2].definition.children[0]); + }); + + it('should publish the DSL statements to the $window', function() { + $window.describe('describe', function() { + $window.it('1', function() { + expect($window.dslScope).toBeDefined(); + }); + }); + runner.run(null/*application*/); + }); + + it('should create a new scope for each DSL chain', function() { + $window.describe('describe', function() { + $window.it('1', function() { + var scope = $window.dslScope(); + scope.test = "foo"; + expect($window.dslScope().test).toBeUndefined(); + }); + $window.it('2', function() { + var scope = $window.dslChain().chain().chain(); + expect(scope.chained).toEqual(2); + }); + }); + runner.run(null/*application*/); + }); +}); diff --git a/test/ngScenario/ScenarioSpec.js b/test/ngScenario/ScenarioSpec.js new file mode 100644 index 00000000..cc2efd1e --- /dev/null +++ b/test/ngScenario/ScenarioSpec.js @@ -0,0 +1,32 @@ +'use strict'; + +describe("ScenarioSpec: Compilation", function() { + var element; + + afterEach(function() { + dealoc(element); + }); + + + describe('compilation', function() { + it("should compile dom node and return scope", inject(function($rootScope, $compile) { + var node = jqLite('| Description | +Test | +Result | +
|---|---|---|
| Input text field | ||
| basic | ++ + | +text.basic={{text.basic}} | +
| password | ++ | text.password={{text.password}} | +
| hidden | ++ | text.hidden={{text.hidden}} | +
| Input selection field | ||
| radio | +
+ Female + Male + |
+ gender={{gender}} | +
| checkbox | +
+ Tea + Coffe + |
+
+ checkbox={{checkbox}}
+ |
+
| select | ++ + | +select={{select}} | +
| multiselect | ++ + | +multiselect={{multiselect}} | +
| Buttons | ||
| ng-change ng-click |
+ + + | +button={{button}} form={{form}} | +
| Repeaters | ||
| ng-repeat | +
+
|
+ + |