aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/ApiTest.js73
-rw-r--r--test/FiltersTest.js73
-rw-r--r--test/JsonTest.js10
-rw-r--r--test/directivesSpec.js6
-rw-r--r--test/scenario/DSLSpec.js59
5 files changed, 61 insertions, 160 deletions
diff --git a/test/ApiTest.js b/test/ApiTest.js
index 4035cdbb..9f09773d 100644
--- a/test/ApiTest.js
+++ b/test/ApiTest.js
@@ -18,27 +18,6 @@ ApiTest.prototype.testItShouldReturnSize = function(){
assertEquals(1, angular.Array.size([0]));
};
-ApiTest.prototype.testIncludeIf = function() {
- var array = [];
- var obj = {};
-
- angular.Array.includeIf(array, obj, true);
- angular.Array.includeIf(array, obj, true);
- assertTrue(includes(array, obj));
- assertEquals(1, array.length);
-
- angular.Array.includeIf(array, obj, false);
- assertFalse(includes(array, obj));
- assertEquals(0, array.length);
-
- angular.Array.includeIf(array, obj, 'x');
- assertTrue(includes(array, obj));
- assertEquals(1, array.length);
- angular.Array.includeIf(array, obj, '');
- assertFalse(includes(array, obj));
- assertEquals(0, array.length);
-};
-
ApiTest.prototype.testSum = function(){
assertEquals(3, angular.Array.sum([{a:"1"}, {a:"2"}], 'a'));
};
@@ -48,13 +27,6 @@ ApiTest.prototype.testSumContainingNaN = function(){
assertEquals(1, angular.Array.sum([{a:1}, {a:Number.NaN}], function($){return $.a;}));
};
-ApiTest.prototype.testInclude = function(){
- assertTrue(angular.Array.include(['a'], 'a'));
- assertTrue(angular.Array.include(['a', 'b'], 'a'));
- assertTrue(!angular.Array.include(['c'], 'a'));
- assertTrue(!angular.Array.include(['c', 'b'], 'a'));
-};
-
ApiTest.prototype.testIndex = function(){
assertEquals(angular.Array.indexOf(['a'], 'a'), 0);
assertEquals(angular.Array.indexOf(['a', 'b'], 'a'), 0);
@@ -80,14 +52,6 @@ ApiTest.prototype.testRemove = function(){
assertEquals(items.length, 0);
};
-ApiTest.prototype.testFindById = function() {
- var items = [{$id:1}, {$id:2}, {$id:3}];
- assertNull(angular.Array.findById(items, 0));
- assertEquals(items[0], angular.Array.findById(items, 1));
- assertEquals(items[1], angular.Array.findById(items, 2));
- assertEquals(items[2], angular.Array.findById(items, 3));
-};
-
ApiTest.prototype.testFilter = function() {
var items = ["MIsKO", {name:"shyam"}, ["adam"], 1234];
assertEquals(4, angular.Array.filter(items, "").length);
@@ -161,16 +125,6 @@ ApiTest.prototype.testCount = function() {
assertEquals(1, angular.Array.count(array, 'name=="a"'));
};
-ApiTest.prototype.testFind = function() {
- var array = [{name:'a'},{name:'b'},{name:''}];
- var obj = {};
-
- assertEquals(undefined, angular.Array.find(array, 'false'));
- assertEquals('default', angular.Array.find(array, 'false', 'default'));
- assertEquals('a', angular.Array.find(array, 'name == "a"').name);
- assertEquals('', angular.Array.find(array, 'name == ""').name);
-};
-
ApiTest.prototype.testItShouldSortArray = function() {
assertEquals([2,15], angular.Array.orderBy([15,2]));
assertEquals(["a","B", "c"], angular.Array.orderBy(["c","B", "a"]));
@@ -211,33 +165,6 @@ ApiTest.prototype.testQuoteUnicode = function(){
assertEquals('"abc\\u00a0def"', angular.String.quoteUnicode('abc\u00A0def'));
};
-ApiTest.prototype.testMerge = function() {
- var array = [{name:"misko"}];
- angular.Array.merge(array, 0, {name:"", email:"email1"});
- angular.Array.merge(array, 1, {name:"adam", email:"email2"});
- assertJsonEquals([{"email":"email1","name":"misko"},{"email":"email2","name":"adam"}], array);
-};
-
-ApiTest.prototype.testOrderByToggle = function() {
- var orderByToggle = angular.Array.orderByToggle;
- var predicate = [];
- assertEquals(['+a'], orderByToggle(predicate, 'a'));
- assertEquals(['-a'], orderByToggle(predicate, 'a'));
-
- assertEquals(['-a', '-b'], orderByToggle(['-b', 'a'], 'a'));
-};
-
-ApiTest.prototype.testOrderByToggle = function() {
- var orderByDirection = angular.Array.orderByDirection;
- assertEquals("", orderByDirection(['+a','b'], 'x'));
- assertEquals("", orderByDirection(['+a','b'], 'b'));
- assertEquals('ng-ascend', orderByDirection(['a','b'], 'a'));
- assertEquals('ng-ascend', orderByDirection(['+a','b'], 'a'));
- assertEquals('ng-descend', orderByDirection(['-a','b'], 'a'));
- assertEquals('up', orderByDirection(['+a','b'], 'a', 'up', 'down'));
- assertEquals('down', orderByDirection(['-a','b'], 'a', 'up', 'down'));
-};
-
ApiTest.prototype.testDateToUTC = function(){
var date = new Date("Sep 10 2003 13:02:03 GMT");
assertEquals("date", angular.Object.typeOf(date));
diff --git a/test/FiltersTest.js b/test/FiltersTest.js
index 903a7a2f..d5484fd0 100644
--- a/test/FiltersTest.js
+++ b/test/FiltersTest.js
@@ -41,54 +41,6 @@ FiltersTest.prototype.testJson = function () {
assertEquals(toJson({a:"b"}, true), angular.filter.json.call({$element:jqLite('<div></div>')}, {a:"b"}));
};
-FiltersTest.prototype.testPackageTracking = function () {
- var assert = function(title, trackingNo) {
- var val = angular.filter.trackPackage(trackingNo, title);
- assertNotNull("Did Not Match: " + trackingNo, val);
- assertEquals(title + ": " + trim(trackingNo), val.text());
- assertNotNull(val.attr('href'));
- };
- assert('UPS', ' 1Z 999 999 99 9999 999 9 ');
- assert('UPS', '1ZW5w5220379084747');
-
- assert('FedEx', '418822131061812');
- assert('FedEx', '9612019 5935 3267 2473 738');
- assert('FedEx', '9612019593532672473738');
- assert('FedEx', '235354667129449');
- assert('FedEx', '915368880571');
- assert('FedEx', '901712142390');
- assert('FedEx', '297391510063413');
-
- assert('USPS', '9101 8052 1390 7402 4335 49');
- assert('USPS', '9101010521297963339560');
- assert('USPS', '9102901001301038667029');
- assert('USPS', '910 27974 4490 3000 8916 56');
- assert('USPS', '9102801438635051633253');
-};
-
-FiltersTest.prototype.testLink = function() {
- var assert = function(text, url, obj){
- var val = angular.filter.link(obj);
- assertEquals('<a href="' + url + '">' + text + '</a>', sortedHtml(val));
- };
- assert("url", "url", "url");
- assert("hello", "url", {text:"hello", url:"url"});
- assert("a@b.com", "mailto:a@b.com", "a@b.com");
-};
-
-FiltersTest.prototype.testImage = function(){
- assertEquals(null, angular.filter.image());
- assertEquals(null, angular.filter.image({}));
- assertEquals(null, angular.filter.image(""));
- assertEquals('http://localhost/abc', angular.filter.image({url:"http://localhost/abc"}).attr('src'));
-};
-
-FiltersTest.prototype.testQRcode = function() {
- assertEquals(
- 'http://chart.apis.google.com/chart?chl=Hello%20world&chs=200x200&cht=qr',
- angular.filter.qrcode('Hello world').attr('src'));
-};
-
FiltersTest.prototype.testLowercase = function() {
assertEquals('abc', angular.filter.lowercase('AbC'));
assertEquals(null, angular.filter.lowercase(null));
@@ -99,30 +51,6 @@ FiltersTest.prototype.testUppercase = function() {
assertEquals(null, angular.filter.uppercase(null));
};
-FiltersTest.prototype.testLineCount = function() {
- assertEquals(1, angular.filter.linecount(null));
- assertEquals(1, angular.filter.linecount(''));
- assertEquals(1, angular.filter.linecount('a'));
- assertEquals(2, angular.filter.linecount('a\nb'));
- assertEquals(3, angular.filter.linecount('a\nb\nc'));
-};
-
-FiltersTest.prototype.testIf = function() {
- assertEquals('A', angular.filter['if']('A', true));
- assertEquals(undefined, angular.filter['if']('A', false));
-};
-
-FiltersTest.prototype.testUnless = function() {
- assertEquals('A', angular.filter.unless('A', false));
- assertEquals(undefined, angular.filter.unless('A', true));
-};
-
-FiltersTest.prototype.testGoogleChartApiEncode = function() {
- assertEquals(
- 'http://chart.apis.google.com/chart?chl=Hello world&chs=200x200&cht=qr',
- angular.filter.googleChartApi.encode({cht:"qr", chl:"Hello world"}).attr('src'));
-};
-
FiltersTest.prototype.testHtml = function() {
var html = angular.filter.html("a<b>c</b>d");
expect(html instanceof HTML).toBeTruthy();
@@ -140,4 +68,3 @@ FiltersTest.prototype.testLinky = function() {
assertEquals(undefined, linky(undefined));
};
-
diff --git a/test/JsonTest.js b/test/JsonTest.js
index d077c0df..f6da26b5 100644
--- a/test/JsonTest.js
+++ b/test/JsonTest.js
@@ -75,11 +75,11 @@ JsonTest.prototype.testItShouldPreventRecursion = function () {
};
JsonTest.prototype.testItShouldSerializeOnlyOwnProperties = function() {
- var parent = { p: 'p'};
- var child = { c: 'c'};
- child.__proto__ = parent;
- assertEquals('{"c":"c"}', angular.toJson(child));
-}
+ var parent = createScope();
+ var child = createScope(parent);
+ child.c = 'c';
+ expect(angular.toJson(child)).toEqual('{"c":"c"}');
+};
JsonTest.prototype.testItShouldSerializeSameObjectsMultipleTimes = function () {
var obj = {a:'b'};
diff --git a/test/directivesSpec.js b/test/directivesSpec.js
index 278f9c4c..f0eb5c09 100644
--- a/test/directivesSpec.js
+++ b/test/directivesSpec.js
@@ -216,6 +216,12 @@ describe("directives", function(){
});
});
+ it('should silently ignore undefined ng:style', function() {
+ var scope = compile('<div ng:style="myStyle"></div>');
+ scope.$eval();
+ expect(element.hasClass('ng-exception')).toBeFalsy();
+ });
+
it('should ng:show', function(){
var scope = compile('<div ng:hide="hide"></div>');
scope.$eval();
diff --git a/test/scenario/DSLSpec.js b/test/scenario/DSLSpec.js
index c8e30917..f8606641 100644
--- a/test/scenario/DSLSpec.js
+++ b/test/scenario/DSLSpec.js
@@ -6,10 +6,12 @@ describe("DSL", function() {
setUpContext();
executeFuture = function(future, html, callback) {
lastDocument = _jQuery('<div>' + html + '</div>');
+ lastFrame = _jQuery('<iframe>' + lastDocument + '</iframe>');
_jQuery(document.body).append(lastDocument);
var specThis = {
testWindow: window,
testDocument: lastDocument,
+ testFrame: lastFrame,
jQuery: _jQuery
};
future.behavior.call(specThis, callback || noop);
@@ -39,6 +41,38 @@ describe("DSL", function() {
});
});
+ describe('browser', function() {
+ var browser = angular.scenario.dsl.browser;
+ it('shoud return true if location with empty hash provided is same '
+ + 'as location of the page', function() {
+ browser.location.href = "http://server";
+ expect(browser.location.toEqual("http://server")).toEqual(true);
+ });
+ it('shoud return true if location with hash provided is same '
+ + 'as location of the page', function() {
+ browser.location.href = "http://server";
+ browser.location.hash = "hashPath";
+ expect(browser.location.toEqual("http://server/#/hashPath"))
+ .toEqual(true);
+ });
+ it('should return true if the location provided is the same as which '
+ + 'browser navigated to', function() {
+ var future = browser.navigateTo("http://server/#/hashPath");
+ expect(future.name).toEqual("Navigate to: http://server/#/hashPath");
+ executeFuture(future, '<input type="text" name="name" />');
+ expect(browser.location.toEqual("http://server/#/hashPath"))
+ .toEqual(true);
+ expect(browser.location.toEqual("http://server/"))
+ .toEqual(false);
+
+ future = browser.navigateTo("http://server/");
+ expect(future.name).toEqual("Navigate to: http://server/");
+ executeFuture(future, '<input type="text" name="name" />');
+ expect(browser.location.toEqual("http://server/"))
+ .toEqual(true);
+ });
+ });
+
describe('repeater', function() {
var repeater = angular.scenario.dsl.repeater;
@@ -125,20 +159,27 @@ describe("DSL", function() {
expect(future.fulfilled).toBeTruthy();
}
it('should find elements on the page and provide jquery api', function() {
- var future = element('.reports-detail');
- expect(future.name).toEqual("Find element '.reports-detail'");
+ var future = element('.reports-detail').text();
+ expect(future.name).toEqual("Element '.reports-detail'.text()");
timeTravel(future);
- expect(future.value.text()).
+ expect(future.value).
toEqual('Description : Details...Date created: 01/01/01');
- expect(future.value.find('.desc').text()).
- toEqual('Description : Details...');
+// expect(future.value.find('.desc').text()).
+// toEqual('Description : Details...');
});
it('should find elements with angular syntax', function() {
- var future = element('{{report.description}}');
- expect(future.name).toEqual("Find element '{{report.description}}'");
+ var future = element('{{report.description}}').text();
+ expect(future.name).toEqual("Element '{{report.description}}'.text()");
timeTravel(future);
- expect(future.value.text()).toEqual('Details...');
- expect(future.value.attr('ng:bind')).toEqual('report.description');
+ expect(future.value).toEqual('Details...');
+// expect(future.value.attr('ng:bind')).toEqual('report.description');
+ });
+ it('should be able to click elements', function(){
+ var future = element('.link-class').click();
+ expect(future.name).toEqual("Element '.link-class'.click()");
+ executeFuture(future, html, function(value) { future.fulfill(value); });
+ expect(future.fulfilled).toBeTruthy();
+ // TODO(rajat): look for some side effect from click happening?
});
});
});