/* Filters */
-angular.module('KiteMail.filters', []).
+angular.module('KiteMail.filters', ['KiteMail.services']).
filter('truncate', function() {
return function(text) {
return text.slice(0, 35) + "...";
}).
/* takes a date object and returns a formatted object */
- filter('formatDate', function() {
+ filter('formatDate', function(Utils) {
return function(date) {
- var date2array = function(date) {
- return (date+'').split(' ');
- }
-
- var today = date2array(new Date(Date.now()));
- var da = date2array(date);
+ var today = Utils.date2array(new Date(Date.now()));
+ var da = Utils.date2array(date);
if(da[3] == today[3]) {
return da[1] + ", " + da[2];
transformResponse: function(data) {
var data = angular.fromJson(data);
- debugger;
// convert date string to js date objects
for(var i = 0; i < data.length; i++) {
data[i]["date"] = new Date(data[i]["date"]);
return data;
},
-
},
});
return res;
}
-]);
+]).factory('Utils', function() {
+ return {
+ date2array: function(date) {
+ return (date+'').split(' ');
+ }
+ };
+});
}));
- it('should truncate text', inject(function(truncateFilter) {
+ it('should truncate text', inject(function(Utils, truncateFilter) {
var testStr = "This is a long string with a lot of chars";
var resStr = "This is a long string with a lot of" + "...";
expect(truncateFilter(testStr)).toEqual(resStr);
}));
- it('should format a date', inject(function(formatDateFilter) {
+ it('should format a date', inject(function(Utils, formatDateFilter) {
var date = new Date(2013, 9, 13);
expect(formatDateFilter(date)).toEqual("Oct, 13");
}));
/* jasmine specs for services go here */
-describe('service', function() {
+describe('Emails service', function() {
var mockResource, $httpBackend;
beforeEach(angular.mock.module('KiteMail.services'));
- beforeEach(function() {
- inject(function($injector) {
- /*
- $httpBackend = $injector.get('$httpBackend');
- mockResource = $injector.get('Emails');
- */
- });
- });
-
describe('EmailsService', function() {
it('should do an ajax request to get the list of emails', inject(function(Emails, $httpBackend) {
var mockResponse = [
"name": "Michel De Test",
"from": "michel@example.com",
"to": "gerard@example.com",
- "date": new Date(1992, 4, 24),
+ "date": "September 24 2013"
}
];
$httpBackend.expectGET('/kite/test/mail').respond(mockResponse);
var result = Emails.emails({username: "test"});
- console.log(result);
- expect(result == mockResponse).toBe(true);
+ $httpBackend.flush();
+ var date = result[0]["date"];
+ expect(date instanceof Date).toBe(true);
+ expect(date.getDate() == 24).toBe(true);
+ expect(date.getMonth() == 8).toBe(true);
+ expect(date.getFullYear() == 2013).toBe(true);
+
+ }))});
+});
+describe('Utils service', function() {
+ beforeEach(angular.mock.module('KiteMail.services'));
+
+ describe('date2array', function() {
+ it("should convert dates to arrays", inject(function(Utils) {
+ var date = new Date("May 30 2013");
+ var array = Utils.date2array(date);
+ expect(array[1]).toEqual("May");
+ expect(array[2]).toEqual("30");
+ expect(array[3]).toEqual("2013");
}))});
});