angular.js/test/scenario/DSLSpec.js

58 lines
1.9 KiB
JavaScript
Raw Normal View History

2010-05-25 00:48:17 +00:00
describe("DSL", function() {
var lastDocument, executeFuture, Expect;
2010-05-25 00:48:17 +00:00
beforeEach(function() {
setUpContext();
executeFuture = function(future, html, callback) {
2010-05-25 00:48:17 +00:00
lastDocument =_jQuery('<div>' + html + '</div>');
_jQuery(document.body).append(lastDocument);
2010-05-25 00:48:17 +00:00
var specThis = {
testWindow: window,
testDocument: lastDocument
};
future.behavior.call(specThis, callback || noop);
2010-05-25 00:48:17 +00:00
};
Expect = scenario.expect;
2010-05-25 00:48:17 +00:00
});
describe("input", function() {
var input = angular.scenario.dsl.input;
2010-07-27 22:43:14 +00:00
2010-05-25 00:48:17 +00:00
it('should enter', function() {
2010-07-27 22:43:14 +00:00
var future = input('name').enter('John');
expect(future.name).toEqual("input 'name' enter 'John'");
executeFuture(future, '<input type="text" name="name" />');
2010-05-25 00:48:17 +00:00
expect(lastDocument.find('input').val()).toEqual('John');
});
it('should select', function() {
2010-07-27 22:43:14 +00:00
var future = input('gender').select('female');
expect(future.name).toEqual("input 'gender' select 'female'");
executeFuture(future,
'<input type="radio" name="0@gender" value="male" checked/>' +
2010-05-25 00:48:17 +00:00
'<input type="radio" name="0@gender" value="female"/>');
expect(lastDocument.find(':radio:checked').length).toEqual(1);
2010-05-25 00:48:17 +00:00
expect(lastDocument.find(':radio:checked').val()).toEqual('female');
});
});
2010-06-09 19:35:40 +00:00
2010-07-27 22:43:14 +00:00
describe('repeater', function() {
var repeater = angular.scenario.dsl.repeater;
it('should fetch the count of repeated elements', function() {
var future = repeater('.repeater-row').count();
expect(future.name).toEqual("repeater '.repeater-row' count");
executeFuture(future, "<div class='repeater-row'>a</div>" +
2010-08-04 18:47:10 +00:00
"<div class='repeater-row'>b</div>",
function(value) {
future.fulfill(value);
});
expect(future.fulfilled).toBeTruthy();
expect(future.value).toEqual(2);
2010-06-09 19:35:40 +00:00
});
});
});