]> khamidou — GitHub mirrors - kite.git/commitdiff
WIP - working on threads interface
authorkarim hamidou <khamidou@gmail.com>
Fri, 1 Nov 2013 10:05:18 +0000 (11:05 +0100)
committerkarim hamidou <khamidou@gmail.com>
Fri, 1 Nov 2013 10:05:18 +0000 (11:05 +0100)
src/front/app/js/app.js
src/front/app/js/controllers.js
src/front/app/js/services.js
src/front/app/partials/mailbox.html
src/front/test/unit/controllers.spec.js
src/front/test/unit/services.spec.js

index d65c5c9ca7644851cd55e730ac6ce99276bb0531..cfd250fde0c2094fd3bf73f092e93c183d123098 100644 (file)
@@ -6,6 +6,6 @@ angular.module('KiteMail', ['KiteMail.filters', 'KiteMail.services', 'KiteMail.d
   config(['$routeProvider', function($routeProvider) {
     $routeProvider.when('/mail', {templateUrl: 'partials/mailbox.html', controller: 'InboxesListController'});
     $routeProvider.when('/login', {templateUrl: 'partials/login.html', controller: 'LoginController'});
-    $routeProvider.when('/thread', {templateUrl: 'partials/thread.html', controller: 'ThreadController'});
+    $routeProvider.when('/thread/:id', {templateUrl: 'partials/thread.html', controller: 'ThreadController'});
     $routeProvider.otherwise({redirectTo: '/login'});
   }]);
index 06ba834871ba21db2e632e03077332ad98b76490..435900c567bf96ea21e0a1d78ac90a9d3de58937 100644 (file)
@@ -10,11 +10,11 @@ angular.module('KiteMail.controllers', []).
             {"name": "Spam",  },];
             
 }).controller('MailsListController', ['$scope', 'Emails', function($scope, Emails) {
-        $scope.mails = Emails.query(); /*; */
+        $scope.mails = Emails.emails();
 }]).controller('LoginController', function($scope) {
     
     
-}).controller('ThreadController', function($scope) {
+}).controller('ThreadController', function($scope, $routeParams) {
     $scope.thread = [
         {"subject": "Hi",
          "contents": "We haven't spoke in a long time !",
index 51a535a53f51f3325de936cc85b35d27f8288e8b..7a04b018acc7a9f72a6c7f4a0634b43137a51b48 100644 (file)
@@ -5,10 +5,10 @@
 angular.module('KiteMail.services', ['ngResource']).
 factory('Emails', ['$resource',
     function($resource) {
-        var res = $resource('/kite/:user/mail/', {}, {
-            query: {
+        var res = $resource('/kite/:username/mail/', {}, {
+            emails: {
                 method:'GET',
-                params:{user: "karim"},
+                params:{username: "@username"},
                 isArray:true,
                 transformResponse: function(data) {
                     var data = angular.fromJson(data);
index b2723f305a00c9f0b475ba80a4a570eb40561ef5..b3220bb853fe85cfceca1d92dd8a76d68f9a8858 100644 (file)
                 <th>Date</th>
             </tr>
             <tr ng-repeat="mail in mails | orderBy:'-date':reverse ">
-                <td>
-                    <span ng-show="mail.name">
-                        {{mail.name}} ({{mail.from}})
-                    </span>
-                    <span ng-hide="mail.name">
-                        {{ mail.from }}
-                    </span>
-                </td>
-                <td><b>{{mail.subject}}</b> {{mail.contents | truncate}}</td>
-                <td>{{mail.date|formatDate}}</td>
+                    <td>
+                        <span ng-show="mail.name">
+                            {{mail.name}} ({{mail.from}})
+                        </span>
+                        <span ng-hide="mail.name">
+                            {{ mail.from }}
+                        </span>
+                    </td>
+                    <td>
+                        <a ng-href="#/thread/{{mail.id}}">
+                            <b>{{mail.subject}}</b> {{mail.contents | truncate}}
+                        </a>    
+                    </td>
+                    <td>{{mail.date|formatDate}}</td>
+                </a>
             </tr>
         </table>
     </div> <!-- row-fluid -->
index f81477eb96fd61cf197055ae77b2b1f33736650b..3466c251b01c72241ee4dd1c9a412e5ecb7b523a 100644 (file)
@@ -13,11 +13,11 @@ describe('controllers', function(){
         it('should call Email.query service to query mails', inject(function($controller, $rootScope) {
             var locals = {
                 $scope: $rootScope,
-                Emails: jasmine.createSpyObj('Emails', ['query']),
+                Emails: jasmine.createSpyObj('Emails', ['emails']),
             };
             
             var ctrl = $controller("MailsListController", locals)
-            expect(locals.Emails.query).toHaveBeenCalled();
+            expect(locals.Emails.emails).toHaveBeenCalled();
         }));
 
         it('should ....', inject(function() {
index 4f619628ccad3aecdacbed06f9f315edb3c51f1d..64f1b6d7c4aa4edf6097e660fb813735a84ecc82 100644 (file)
@@ -3,13 +3,34 @@
 /* jasmine specs for services go here */
 
 describe('service', function() {
-    beforeEach(module('KiteMail.services'));
+    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 services', inject(function($service) {
-        var resourceMock = jasmine.createSpy('$resource').andReturn([{"subject": "mock", "date": "2013-04-23"}]);
-        var service = $service("EmailsService", resourceMock);
-        expect(resourceMock).toHaveBeenCalled();
-        
+    it('should do an ajax request to get the list of emails', inject(function(Emails, $httpBackend) {
+        var mockResponse = [
+            {"subject": "Hi",
+             "contents": "We haven't spoke in a long time !",
+             "name": "Michel De Test",
+             "from": "michel@example.com",
+             "to": "gerard@example.com",
+             "date": new Date(1992, 4, 24),
+            }
+        ];
+
+        $httpBackend.expectGET('/kite/test/mail').respond(mockResponse);
+        var result = Emails.emails({username: "test"});
+        console.log(result);
+        expect(result == mockResponse).toBe(true);
+
     }))});
 });