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/scenario/ApplicationSpec.js | 141 -------- test/scenario/DescribeSpec.js | 122 ------- test/scenario/FutureSpec.js | 77 ---- test/scenario/ObjectModelSpec.js | 333 ----------------- test/scenario/RunnerSpec.js | 116 ------ test/scenario/SpecRunnerSpec.js | 177 ---------- test/scenario/dslSpec.js | 629 --------------------------------- test/scenario/e2e/Runner-compiled.html | 9 - test/scenario/e2e/Runner.html | 9 - test/scenario/e2e/style.css | 11 - test/scenario/e2e/widgets-scenario.js | 67 ---- test/scenario/e2e/widgets.html | 99 ------ test/scenario/matchersSpec.js | 51 --- test/scenario/mocks.js | 33 -- test/scenario/output/HtmlSpec.js | 126 ------- test/scenario/output/jsonSpec.js | 37 -- test/scenario/output/objectSpec.js | 40 --- test/scenario/output/xmlSpec.js | 36 -- 18 files changed, 2113 deletions(-) delete mode 100644 test/scenario/ApplicationSpec.js delete mode 100644 test/scenario/DescribeSpec.js delete mode 100644 test/scenario/FutureSpec.js delete mode 100644 test/scenario/ObjectModelSpec.js delete mode 100644 test/scenario/RunnerSpec.js delete mode 100644 test/scenario/SpecRunnerSpec.js delete mode 100644 test/scenario/dslSpec.js delete mode 100644 test/scenario/e2e/Runner-compiled.html delete mode 100644 test/scenario/e2e/Runner.html delete mode 100644 test/scenario/e2e/style.css delete mode 100644 test/scenario/e2e/widgets-scenario.js delete mode 100644 test/scenario/e2e/widgets.html delete mode 100644 test/scenario/matchersSpec.js delete mode 100644 test/scenario/mocks.js delete mode 100644 test/scenario/output/HtmlSpec.js delete mode 100644 test/scenario/output/jsonSpec.js delete mode 100644 test/scenario/output/objectSpec.js delete mode 100644 test/scenario/output/xmlSpec.js (limited to 'test/scenario') diff --git a/test/scenario/ApplicationSpec.js b/test/scenario/ApplicationSpec.js deleted file mode 100644 index 7384ecaa..00000000 --- a/test/scenario/ApplicationSpec.js +++ /dev/null @@ -1,141 +0,0 @@ -'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/scenario/DescribeSpec.js b/test/scenario/DescribeSpec.js deleted file mode 100644 index 6741ed6d..00000000 --- a/test/scenario/DescribeSpec.js +++ /dev/null @@ -1,122 +0,0 @@ -'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/scenario/FutureSpec.js b/test/scenario/FutureSpec.js deleted file mode 100644 index 2a75f275..00000000 --- a/test/scenario/FutureSpec.js +++ /dev/null @@ -1,77 +0,0 @@ -'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/scenario/ObjectModelSpec.js b/test/scenario/ObjectModelSpec.js deleted file mode 100644 index e0da628d..00000000 --- a/test/scenario/ObjectModelSpec.js +++ /dev/null @@ -1,333 +0,0 @@ -'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/scenario/RunnerSpec.js b/test/scenario/RunnerSpec.js deleted file mode 100644 index c4ad6f95..00000000 --- a/test/scenario/RunnerSpec.js +++ /dev/null @@ -1,116 +0,0 @@ -'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/scenario/SpecRunnerSpec.js b/test/scenario/SpecRunnerSpec.js deleted file mode 100644 index c104a9b7..00000000 --- a/test/scenario/SpecRunnerSpec.js +++ /dev/null @@ -1,177 +0,0 @@ -'use strict'; - -/** - * Mock Application - */ -function ApplicationMock($window) { - this.$window = $window; -} -ApplicationMock.prototype = { - executeAction: function(callback) { - callback.call(this.$window, _jQuery(this.$window.document), this.$window); - } -}; - -describe('angular.scenario.SpecRunner', function() { - var $window, $root, log; - var runner; - - function createSpec(name, body) { - return { - name: name, - before: angular.noop, - body: body || angular.noop, - after: angular.noop - }; - } - - beforeEach(inject(function($rootScope) { - log = []; - $window = {}; - $window.setTimeout = function(fn, timeout) { - fn(); - }; - $root = $rootScope; - $root.emit = function(eventName) { - log.push(eventName); - }; - $root.on = function(eventName) { - log.push('Listener Added for ' + eventName); - }; - $root.application = new ApplicationMock($window); - $root.$window = $window; - runner = $root.$new(); - - var Cls = angular.scenario.SpecRunner; - for (var name in Cls.prototype) - runner[name] = angular.bind(runner, Cls.prototype[name]); - - Cls.call(runner); - })); - - it('should bind futures to the spec', function() { - runner.addFuture('test future', function(done) { - this.value = 10; - done(); - }); - runner.futures[0].execute(angular.noop); - expect(runner.value).toEqual(10); - }); - - it('should pass done to future action behavior', function() { - runner.addFutureAction('test future', function($window, $document, done) { - expect(angular.isFunction(done)).toBeTruthy(); - done(10, 20); - }); - runner.futures[0].execute(function(error, result) { - expect(error).toEqual(10); - expect(result).toEqual(20); - }); - }); - - it('should execute spec function and notify UI', function() { - var finished; - var spec = createSpec('test spec', function() { - this.test = 'some value'; - }); - runner.addFuture('test future', function(done) { - done(); - }); - runner.run(spec, function() { - finished = true; - }); - expect(runner.test).toEqual('some value'); - expect(finished).toBeTruthy(); - expect(log).toEqual([ - 'SpecBegin', - 'StepBegin', - 'StepEnd', - 'SpecEnd' - ]); - }); - - it('should execute notify UI on spec setup error', function() { - var finished; - var spec = createSpec('test spec', function() { - throw 'message'; - }); - runner.run(spec, function() { - finished = true; - }); - expect(finished).toBeTruthy(); - expect(log).toEqual([ - 'SpecBegin', - 'SpecError', - 'SpecEnd' - ]); - }); - - it('should execute notify UI on step failure', function() { - var finished; - var spec = createSpec('test spec'); - runner.addFuture('test future', function(done) { - done('failure message'); - }); - runner.run(spec, function() { - finished = true; - }); - expect(finished).toBeTruthy(); - expect(log).toEqual([ - 'SpecBegin', - 'StepBegin', - 'StepFailure', - 'StepEnd', - 'SpecEnd' - ]); - }); - - it('should execute notify UI on step error', function() { - var finished; - var spec = createSpec('test spec', function() { - this.addFuture('test future', function(done) { - throw 'error message'; - }); - }); - runner.run(spec, function() { - finished = true; - }); - expect(finished).toBeTruthy(); - expect(log).toEqual([ - 'SpecBegin', - 'StepBegin', - 'StepError', - 'StepEnd', - 'SpecEnd' - ]); - }); - - it('should run after handlers even if error in body of spec', function() { - var finished, after; - var spec = createSpec('test spec', function() { - this.addFuture('body', function(done) { - throw 'error message'; - }); - }); - spec.after = function() { - this.addFuture('after', function(done) { - after = true; - done(); - }); - }; - runner.run(spec, function() { - finished = true; - }); - expect(finished).toBeTruthy(); - expect(after).toBeTruthy(); - expect(log).toEqual([ - 'SpecBegin', - 'StepBegin', - 'StepError', - 'StepEnd', - 'StepBegin', - 'StepEnd', - 'SpecEnd' - ]); - }); - -}); diff --git a/test/scenario/dslSpec.js b/test/scenario/dslSpec.js deleted file mode 100644 index 0a8ab762..00000000 --- a/test/scenario/dslSpec.js +++ /dev/null @@ -1,629 +0,0 @@ -'use strict'; - -describe("angular.scenario.dsl", function() { - var element; - var $window, $root; - var eventLog; - - afterEach(function() { - dealoc(element); - }); - - beforeEach(inject(function($injector) { - eventLog = []; - $window = { - document: window.document.body, - angular: new angular.scenario.testing.MockAngular() - }; - jqLite($window.document).data('$injector', $injector).attr('ng-app', '').addClass('html'); - $root = $injector.get('$rootScope'); - $root.emit = function(eventName) { - eventLog.push(eventName); - }; - $root.on = function(eventName) { - eventLog.push('Listener Added for ' + eventName); - }; - $root.futures = []; - $root.futureLog = []; - $root.$window = $window; - $root.addFuture = function(name, fn) { - this.futures.push(name); - fn.call(this, function(error, result) { - $root.futureError = error; - $root.futureResult = result; - $root.futureLog.push(name); - }); - }; - $root.dsl = {}; - angular.forEach(angular.scenario.dsl, function(fn, name) { - $root.dsl[name] = function() { - return fn.call($root).apply($root, arguments); - }; - }); - $root.application = new angular.scenario.Application(jqLite($window.document)); - $root.application.getWindow_ = function() { - return $window; - }; - $root.application.navigateTo = function(url, callback) { - $window.location = url; - callback(); - }; - // Just use the real one since it delegates to this.addFuture - $root.addFutureAction = angular.scenario. - SpecRunner.prototype.addFutureAction; - jqLite($window.document).html(''); - })); - - afterEach(function(){ - jqLite($window.document).removeData('$injector'); - }); - - describe('Pause', function() { - it('should pause until resume to complete', function() { - expect($window.resume).toBeUndefined(); - $root.dsl.pause(); - expect(angular.isFunction($window.resume)).toBeTruthy(); - expect($root.futureLog).toEqual([]); - $window.resume(); - expect($root.futureLog). - toEqual(['pausing for you to resume']); - expect(eventLog).toContain('InteractivePause'); - }); - }); - - describe('Sleep', function() { - beforeEach(function() { - $root.$window.setTimeout = function(fn, value) { - $root.timerValue = value; - fn(); - }; - }); - - it('should sleep for specified seconds', function() { - $root.dsl.sleep(10); - expect($root.timerValue).toEqual(10000); - expect($root.futureResult).toEqual(10000); - }); - }); - - describe('Expect', function() { - it('should chain and execute matcher', function() { - var future = {value: 10}; - var result = $root.dsl.expect(future); - result.toEqual(10); - expect($root.futureError).toBeUndefined(); - expect($root.futureResult).toBeUndefined(); - result = $root.dsl.expect(future); - result.toEqual(20); - expect($root.futureError).toBeDefined(); - }); - }); - - describe('Browser', function() { - describe('Reload', function() { - it('should navigateTo', function() { - $window.location = { - href: '#foo' - }; - $root.dsl.browser().reload(); - expect($root.futureResult).toEqual('#foo'); - expect($window.location).toEqual('#foo'); - }); - }); - - describe('NavigateTo', function() { - it('should allow a string url', function() { - $root.dsl.browser().navigateTo('http://myurl'); - expect($window.location).toEqual('http://myurl'); - expect($root.futureResult).toEqual('http://myurl'); - }); - - it('should allow a future url', function() { - $root.dsl.browser().navigateTo('http://myurl', function() { - return 'http://futureUrl/'; - }); - expect($window.location).toEqual('http://futureUrl/'); - expect($root.futureResult).toEqual('http://futureUrl/'); - }); - - it('should complete if angular is missing from app frame', function() { - delete $window.angular; - $root.dsl.browser().navigateTo('http://myurl'); - expect($window.location).toEqual('http://myurl'); - expect($root.futureResult).toEqual('http://myurl'); - }); - }); - - describe('window', function() { - beforeEach(function() { - $window.location = { - href: 'http://myurl/some/path?foo=10#/bar?x=2', - pathname: '/some/path', - search: '?foo=10', - hash: '#bar?x=2' - }; - }); - - it('should return full URL for href', function() { - $root.dsl.browser().window().href(); - expect($root.futureResult).toEqual($window.location.href); - }); - - it('should return the pathname', function() { - $root.dsl.browser().window().path(); - expect($root.futureResult).toEqual($window.location.pathname); - }); - - it('should return the search part', function() { - $root.dsl.browser().window().search(); - expect($root.futureResult).toEqual($window.location.search); - }); - - it('should return the hash without the #', function() { - $root.dsl.browser().window().hash(); - expect($root.futureResult).toEqual('bar?x=2'); - }); - }); - - describe('location', function() { - beforeEach(function() { - $window.angular.injector = function() { - return { - get: function(serviceId) { - if (serviceId == '$location') { - return { - url: function() {return '/path?search=a#hhh';}, - path: function() {return '/path';}, - search: function() {return {search: 'a'};}, - hash: function() {return 'hhh';} - }; - } - throw new Error('unknown service id ' + serviceId); - } - }; - }; - }); - - it('should return full url', function() { - $root.dsl.browser().location().url(); - expect($root.futureResult).toEqual('/path?search=a#hhh'); - }); - - it('should return the pathname', function() { - $root.dsl.browser().location().path(); - expect($root.futureResult).toEqual('/path'); - }); - - it('should return the query string as an object', function() { - $root.dsl.browser().location().search(); - expect($root.futureResult).toEqual({search: 'a'}); - }); - - it('should return the hash without the #', function() { - $root.dsl.browser().location().hash(); - expect($root.futureResult).toEqual('hhh'); - }); - }); - }); - - describe('Element Finding', function() { - var doc; - beforeEach(inject(function($injector) { - doc = _jQuery($window.document).append('').find('.body'); - })); - - describe('Select', function() { - it('should select single option', function() { - doc.append( - '' - ); - $root.dsl.select('test').option('A'); - expect(doc.find('[ng-model="test"]').val()).toEqual('A'); - }); - - it('should select option by name', function() { - doc.append( - '' - ); - $root.dsl.select('test').option('one'); - expect(doc.find('[ng-model="test"]').val()).toEqual('A'); - }); - - it('should select multiple options', function() { - doc.append( - '' - ); - $root.dsl.select('test').options('A', 'B'); - expect(doc.find('[ng-model="test"]').val()).toEqual(['A','B']); - }); - - it('should fail to select multiple options on non-multiple select', function() { - doc.append(''); - $root.dsl.select('test').options('A', 'B'); - expect($root.futureError).toMatch(/did not match/); - }); - }); - - describe('Element', function() { - it('should execute click', function() { - var clicked; - // Hash is important, otherwise we actually - // go to a different page and break the runner - doc.append(''); - doc.find('a').click(function() { - clicked = true; - }); - $root.dsl.element('a').click(); - }); - - it('should navigate page if click on anchor', function() { - expect($window.location).not.toEqual('#foo'); - doc.append(''); - $root.dsl.element('a').click(); - expect($window.location).toMatch(/#foo$/); - }); - - it('should not navigate if click event was cancelled', function() { - var initLocation = $window.location, - elm = jqLite(''); - - doc.append(elm); - elm.bind('click', function(event) { - event.preventDefault(); - }); - - $root.dsl.element('a').click(); - expect($window.location).toBe(initLocation); - dealoc(elm); - }); - - it('should count matching elements', function() { - doc.append(''); - $root.dsl.element('span').count(); - expect($root.futureResult).toEqual(2); - }); - - it('should return count of 0 if no matching elements', function() { - $root.dsl.element('span').count(); - expect($root.futureResult).toEqual(0); - }); - - it('should get attribute', function() { - doc.append(''); - $root.dsl.element('#test').attr('class'); - expect($root.futureResult).toEqual('foo'); - }); - - it('should set attribute', function() { - doc.append(''); - $root.dsl.element('#test').attr('class', 'bam'); - expect(doc.find('#test').attr('class')).toEqual('bam'); - }); - - it('should get property', function() { - doc.append(''); - $root.dsl.element('#test').prop('className'); - expect($root.futureResult).toEqual('foo'); - }); - - it('should set property', function() { - doc.append(''); - $root.dsl.element('#test').prop('className', 'bam'); - expect(doc.find('#test').prop('className')).toEqual('bam'); - }); - - it('should get css', function() { - doc.append(''); - $root.dsl.element('#test').css('height'); - expect($root.futureResult).toMatch(/30px/); - }); - - it('should set css', function() { - doc.append(''); - $root.dsl.element('#test').css('height', '20px'); - expect(doc.find('#test').css('height')).toEqual('20px'); - }); - - it('should add all jQuery key/value methods', function() { - var METHODS = ['css', 'attr']; - var chain = $root.dsl.element('input'); - angular.forEach(METHODS, function(name) { - expect(angular.isFunction(chain[name])).toBeTruthy(); - }); - }); - - it('should get val', function() { - doc.append(''); - $root.dsl.element('input').val(); - expect($root.futureResult).toEqual('bar'); - }); - - it('should set val', function() { - doc.append(''); - $root.dsl.element('input').val('baz'); - expect(doc.find('input').val()).toEqual('baz'); - }); - - it('should use correct future name for generated set methods', function() { - doc.append(''); - $root.dsl.element('input').val(false); - expect($root.futures.pop()).toMatch(/element 'input' set val/); - }); - - it('should use correct future name for generated get methods', function() { - doc.append(''); - $root.dsl.element('input').val(); - expect($root.futures.pop()).toMatch(/element 'input' val/); - }); - - it('should add all jQuery property methods', function() { - var METHODS = [ - 'val', 'text', 'html', 'height', 'innerHeight', 'outerHeight', 'width', - 'innerWidth', 'outerWidth', 'position', 'scrollLeft', 'scrollTop', 'offset' - ]; - var chain = $root.dsl.element('input'); - angular.forEach(METHODS, function(name) { - expect(angular.isFunction(chain[name])).toBeTruthy(); - }); - }); - - it('should execute custom query', function() { - doc.append(''); - $root.dsl.element('#test').query(function(elements, done) { - done(null, elements.attr('href')); - }); - expect($root.futureResult).toEqual('http://example.com/myUrl'); - }); - - it('should use the selector as label if none is given', function() { - $root.dsl.element('mySelector'); - expect($root.label).toEqual('mySelector'); - }); - - it('should include the selector in paren when a label is given', function() { - $root.dsl.element('mySelector', 'myLabel'); - expect($root.label).toEqual('myLabel ( mySelector )'); - }); - }); - - describe('Repeater', function() { - var chain; - beforeEach(inject(function($compile, $rootScope) { - element = $compile( - '| 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 | -
-
|
- - |