Skip to content

Commit

Permalink
added map & orientation tests; expanded contacts.find test
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Willoughby committed Dec 14, 2009
1 parent 860609b commit 87c7929
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
2 changes: 2 additions & 0 deletions index.html
Expand Up @@ -29,8 +29,10 @@
<script type="text/javascript" src="tests/device.tests.js"></script>
<script type="text/javascript" src="tests/file.tests.js"></script>
<script type="text/javascript" src="tests/geolocation.tests.js"></script>
<script type="text/javascript" src="tests/map.tests.js"></script>
<script type="text/javascript" src="tests/network.tests.js"></script>
<script type="text/javascript" src="tests/notification.tests.js"></script>
<script type="text/javascript" src="tests/orientation.tests.js"></script>
<script type="text/javascript" src="tests/sms.tests.js"></script>
<script type="text/javascript" src="tests/telephony.tests.js"></script>
</head>
Expand Down
12 changes: 12 additions & 0 deletions tests/contacts.tests.js
Expand Up @@ -12,6 +12,17 @@ Tests.prototype.ContactsTests = function() {
// TODO: Need to add tests for the find function. Need to be able to include test data, but how? How do we add a contact
// to the phone before running the test?
// TODO: Need to include tests that check error-handling, doubt there is any in the framework code.
test("contacts.find success callback should be called with an array", function() {
expect(1);
stop(tests.TEST_TIMEOUT);
var win = function(result) {
ok(typeof result.length != 'undefined', "Object returned in contacts.find success callback is a valid array (has a length property)");
start();
};
var fail = function() { start(); };
var filter = new ContactsFilter("");
navigator.contacts.find(filter,win, fail);
});

module("Contacts model");
test("should be able to define a Contacts object with name, emails, phones and id attributes.", function() {
Expand All @@ -24,4 +35,5 @@ Tests.prototype.ContactsTests = function() {
ok(con.phones != null, "new Contact() should include a 'phones' array.");
ok(con.id != null, "new Contact() should include an 'id' property.");
});

};
12 changes: 12 additions & 0 deletions tests/map.tests.js
@@ -0,0 +1,12 @@
Tests.prototype.MapTests = function() {
module('Map (navigator.map)');
test("should exist", function() {
expect(1);
ok(navigator.map != null, "navigator.map should not be null.");
});
test("should contain a show function", function() {
expect(2);
ok(navigator.map.show != null, "navigator.map.show should not be null.");
ok(typeof navigator.map.show == 'function', "navigator.map.show should be a function.");
});
};
33 changes: 33 additions & 0 deletions tests/orientation.tests.js
@@ -0,0 +1,33 @@
Tests.prototype.OrientationTests = function() {
module('Orientation (navigator.orientation)');
test("should exist", function() {
expect(1);
ok(navigator.orientation != null, "navigator.orientation should not be null.");
});
test("should have an initially null lastPosition property", function() {
expect(1);
ok(navigator.orientation.currentOrientation == null, "navigator.orientation.currentOrientation should be initially null.");
});
test("should contain a getCurrentOrientation function", function() {
expect(2);
ok(navigator.orientation.getCurrentOrientation != null, "navigator.orientation.getCurrentOrientation should not be null.");
ok(typeof navigator.orientation.getCurrentOrientation == 'function', "navigator.orientation.getCurrentOrientation should be a function.");
});
test("should contain a watchOrientation function", function() {
expect(2);
ok(navigator.orientation.watchOrientation != null, "navigator.orientation.watchOrientation should not be null.");
ok(typeof navigator.orientation.watchOrientation == 'function', "navigator.orientation.watchOrientation should be a function.");
});
test("getCurrentOrientation success callback should be called with an Orientation enumeration", function() {
expect(2);
stop(tests.TEST_TIMEOUT);
var win = function(orient) {
ok(0 <= orient <= 6, "Position object returned in getCurrentPosition success callback is a valid DisplayOrientation value.");
equals(orient, navigator.orientation.currentOrientation, "Orientation value returned in getCurrentOrientation success callback equals navigator.orientation.currentOrientation.");
start();
};
var fail = function() { start(); };
navigator.orientation.getCurrentOrientation(win, fail);
});
// TODO: Need to test watchPosition success callback, test that makes sure clearPosition works (how to test that a timer is getting cleared?)
};

0 comments on commit 87c7929

Please sign in to comment.