Merge branch 'repeater'

This commit is contained in:
Andres Ornelas 2010-06-09 16:05:51 -07:00
commit bbb45a7eed
4 changed files with 82 additions and 18 deletions

View file

@ -2,7 +2,7 @@ angular.scenario.dsl.browser = {
navigateTo: function(url){ navigateTo: function(url){
$scenario.addStep('Navigate to: ' + url, function(done){ $scenario.addStep('Navigate to: ' + url, function(done){
var self = this; var self = this;
self.testFrame.load(function(){ this.testFrame.load(function(){
self.testFrame.unbind(); self.testFrame.unbind();
self.testWindow = self.testFrame[0].contentWindow; self.testWindow = self.testFrame[0].contentWindow;
self.testDocument = jQuery(self.testWindow.document); self.testDocument = jQuery(self.testWindow.document);
@ -11,7 +11,7 @@ angular.scenario.dsl.browser = {
self.notifyWhenNoOutstandingRequests(done); self.notifyWhenNoOutstandingRequests(done);
}); });
if (this.testFrame.attr('src') == url) { if (this.testFrame.attr('src') == url) {
this.testWindow.location.reload(); this.testFrame[0].contentWindow.location.reload();
} else { } else {
this.testFrame.attr('src', url); this.testFrame.attr('src', url);
} }
@ -44,17 +44,20 @@ angular.scenario.dsl.input = function(selector) {
}; };
}; };
angular.scenario.dsl.expect = function(selector) { angular.scenario.dsl.expect = {
return { repeater: function(selector) {
toEqual: function(expected) { return {
$scenario.addStep("Expect that " + selector + " equals '" + expected + "'", function(done){ count: {
var attrName = selector.substring(2, selector.length - 2); toEqual: function(number) {
var binding = this.testDocument.find('span[ng-bind=' + attrName + ']'); $scenario.addStep("Expect that there are " + number + " items in Repeater with selector '" + selector + "'", function(done) {
if (binding.text() != expected) { var items = this.testDocument.find(selector);
this.result.fail("Expected '" + expected + "' but was '" + binding.text() + "'"); if (items.length != number) {
this.result.fail("Expected " + number + " but was " + items.length);
}
done();
});
} }
done(); }
}); };
} }
};
}; };

View file

@ -8,23 +8,34 @@ angular.scenario.Runner = function(scope, jQuery){
var specs = this.specs = {}; var specs = this.specs = {};
var path = []; var path = [];
this.scope.describe = function describe(name, body){ this.scope.describe = function(name, body){
path.push(name); path.push(name);
body(); body();
path.pop(); path.pop();
}; };
this.scope.it = function it(name, body) { var beforeEach = noop;
var afterEach = noop;
this.scope.beforeEach = function(body) {
beforeEach = body;
};
this.scope.afterEach = function(body) {
afterEach = body;
};
this.scope.it = function(name, body) {
var specName = path.join(' ') + ': it ' + name; var specName = path.join(' ') + ': it ' + name;
self.currentSpec = specs[specName] = { self.currentSpec = specs[specName] = {
name: specName, name: specName,
steps:[] steps:[]
}; };
try { try {
beforeEach();
body(); body();
} catch(err) { } catch(err) {
self.addStep(err.message || 'ERROR', function(){ self.addStep(err.message || 'ERROR', function(){
throw err; throw err;
}); });
} finally {
afterEach();
} }
self.currentSpec = null; self.currentSpec = null;
}; };

View file

@ -40,4 +40,16 @@ describe("DSL", function() {
expect(lastDocument.find(':radio:checked').val()).toEqual('female'); expect(lastDocument.find(':radio:checked').val()).toEqual('female');
}); });
}); });
});
describe('expect', function() {
var dslExpect = angular.scenario.dsl.expect;
describe('repeater', function() {
it('should check the count of repeated elements', function() {
dslExpect.repeater('.repeater-row').count.toEqual(2);
expect(lastStep.name).toEqual("Expect that there are 2 items in Repeater with selector '.repeater-row'");
var html = "<div class='repeater-row'>a</div><div class='repeater-row'>b</div>";
executeStep(lastStep, html);
});
});
});
});

View file

@ -14,6 +14,8 @@ describe('Runner', function(){
body = _jQuery('<div></div>'); body = _jQuery('<div></div>');
runner = new angular.scenario.Runner(scenario, _jQuery); runner = new angular.scenario.Runner(scenario, _jQuery);
Describe = scenario.describe; Describe = scenario.describe;
BeforeEach = scenario.beforeEach;
AfterEach = scenario.afterEach;
It = scenario.it; It = scenario.it;
$scenario = scenario.$scenario; $scenario = scenario.$scenario;
}); });
@ -36,7 +38,10 @@ describe('Runner', function(){
expect(spec.name).toEqual('describe name: it should text'); expect(spec.name).toEqual('describe name: it should text');
}); });
it('should camplain on duplicate it', angular.noop); it('should complain on duplicate it', function() {
// WRITE ME!!!!
});
it('should create a failing step if there is a javascript error', function(){ it('should create a failing step if there is a javascript error', function(){
var spec; var spec;
Describe('D1', function(){ Describe('D1', function(){
@ -55,6 +60,39 @@ describe('Runner', function(){
}; };
}); });
}); });
describe('beforeEach', function() {
it('should execute beforeEach before every it', function() {
Describe('describe name', function(){
BeforeEach(logger('before;'));
It('should text', logger('body;'));
It('should text2', logger('body2;'));
});
expect(log).toEqual('before;body;before;body2;');
});
});
describe('afterEach', function() {
it('should execute afterEach after every it', function() {
Describe('describe name', function(){
AfterEach(logger('after;'));
It('should text', logger('body;'));
It('should text2', logger('body2;'));
});
expect(log).toEqual('body;after;body2;after;');
});
it('should always execute afterEach after every it', function() {
Describe('describe name', function(){
AfterEach(logger('after;'));
It('should text', function() {
log = 'body;';
throw "MyError";
});
It('should text2', logger('body2;'));
});
expect(log).toEqual('body;after;body2;after;');
});
});
}); });
describe('steps building', function(){ describe('steps building', function(){