1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-29 20:32:15 -05:00
mail/test/unit/util-test.js

48 lines
1.3 KiB
JavaScript
Raw Normal View History

2013-03-13 11:58:46 -04:00
module("Util");
test("JQuery and basic requirements", 7, function() {
2013-04-05 11:43:41 -04:00
ok(Array.prototype.push, "Array.push()");
ok(Function.prototype.apply, "Function.apply()");
ok(document.getElementById, "getElementById");
ok(document.getElementsByTagName, "getElementsByTagName");
ok(RegExp, "RegExp");
ok(jQuery, "jQuery");
ok($, "$");
2013-03-13 11:58:46 -04:00
});
test("UUID", 2, function() {
var util = new cryptoLib.Util(window, uuid);
2013-03-13 11:58:46 -04:00
var id = util.UUID();
ok(id, "UUID: " + id);
ok(id.length === 36, "UUID length");
});
test("random", 3, function() {
var util = new cryptoLib.Util(window, uuid);
2013-03-13 11:58:46 -04:00
var base64 = util.random(128);
var str = window.atob(base64);
ok(base64, "Random base64: " + base64);
ok(str, "Random binary string: " + str);
ok(str.length === 16, "Random length");
});
test("Parse Date", 1, function() {
var util = new cryptoLib.Util(window, uuid);
var str = '1900-01-31 18:17:53';
var date = util.parseDate(str);
var formated = util.formatDate(date);
equal(formated, str, "Date: " + date);
});
2013-04-05 11:43:41 -04:00
test("String -> Uint8Array -> String", 3, function() {
var util = new cryptoLib.Util(window);
2013-04-05 11:43:41 -04:00
2013-03-13 11:58:46 -04:00
var input = "asdf";
2013-04-05 11:43:41 -04:00
var buf = util.binStr2Uint8Arr(input);
2013-03-13 11:58:46 -04:00
ok(buf);
2013-04-05 11:43:41 -04:00
2013-03-13 11:58:46 -04:00
// test slow conversion in js
2013-04-05 11:43:41 -04:00
var binStr = util.uint8Arr2BinStr(buf);
2013-03-13 11:58:46 -04:00
ok(binStr);
equal(binStr, input);
2013-04-05 11:43:41 -04:00
});