gaf-mobile
Version:
GAF mobile Web site
87 lines (69 loc) • 2.22 kB
JavaScript
'use strict';
describe('Controller: inbox', function() {
var $q, $rootScope, $scope;
var ThreadsMock, PagerMock, AuthMock;
var createCtrl;
beforeEach(module('gafMobileApp'));
beforeEach(inject(function($controller, _$rootScope_, _$q_) {
$controller = $controller;
$rootScope = _$rootScope_;
$scope = $rootScope.$new();
$q = _$q_;
createCtrl = function() {
return $controller('InboxCtrl', {
$scope: $scope,
$rootScope: $rootScope,
Threads: ThreadsMock,
Pager: PagerMock,
Auth: AuthMock
});
};
}));
beforeEach(function() {
ThreadsMock = jasmine.createSpyObj('Threads', ['getList']);
AuthMock = jasmine.createSpyObj('Auth', ['getUserId']);
PagerMock = jasmine.createSpyObj('Pager', ['getList', 'nextPage',
'hasNext'
]);
PagerMock.nextPage.and.returnValue($q.when({
getList: function() {
return [{ id: 1, message: 'message0' }, { id: 3, message: 'message1' }];
}
}));
PagerMock.hasNext.and.returnValue(true);
});
describe('upon init', function() {
it('should set state to loading',
function() {
var ctrl = createCtrl();
expect(ctrl.state).toBe('loading');
});
});
describe('load messages', function() {
it('should successfully load threads and set state to threadlist',
function() {
var ctrl = createCtrl();
$scope.$digest();
expect(ctrl.hasMoreMessages).toBeTruthy();
expect(ctrl.state).toBe('threadList');
});
it('should successfully load threads and set state to empty',
function() {
PagerMock.nextPage.and.returnValue($q.when({
getList: function() { return []; }
}));
PagerMock.hasNext.and.returnValue(false);
var ctrl = createCtrl();
$scope.$digest();
expect(ctrl.hasMoreMessages).toBeFalsy();
expect(ctrl.state).toBe('empty');
});
it('should state to error if query returned error',
function() {
PagerMock.nextPage.and.returnValue($q.reject());
var ctrl = createCtrl();
$scope.$digest();
expect(ctrl.state).toBe('error');
});
});
});