Extract graph data retrieval to a service

This commit is contained in:
Joe Fiorini
2015-01-21 11:31:36 -05:00
parent 1697aff309
commit d7a150befe
4 changed files with 132 additions and 3 deletions

View File

@@ -1,3 +1,94 @@
describe("JobStatusGraphDataFactory", function() {
it('should fail', function() { expect(true).to.be.true; });
describe('Job Status Graph Data Service', function() {
var q;
var jobStatusGraphData, httpBackend, rootScope, timeout;
var jobStatusChange = {
$on: sinon.spy(),
};
function flushPromises() {
window.setTimeout(function() {
inject(function($rootScope) {
$rootScope.$apply();
});
}, 100);
}
var restStub = {
setUrl: angular.noop,
reset: function() {
delete restStub.deferred;
},
get: function() {
if (angular.isUndefined(restStub.deferred)) {
restStub.deferred = q.defer();
}
return restStub.deferred.promise;
},
succeed: function(value) {
restStub.deferred.resolve(value);
},
fail: function(value) {
restStub.deferred.reject(value);
}
};
beforeEach(module("Tower"));
beforeEach(module(function($provide) {
$provide.value("$cookieStore", { get: angular.noop });
$provide.value('RestServices', restStub);
}));
afterEach(function() {
restStub.reset();
});
beforeEach(inject(function(_jobStatusGraphData_, $httpBackend, $q, $rootScope, $timeout) {
jobStatusGraphData = _jobStatusGraphData_;
httpBackend = $httpBackend;
rootScope = $rootScope;
timeout = $timeout;
$httpBackend.expectGET('/static/js/local_config.js').respond({
});
q = $q;
}));
it('returns a promise to be fulfilled when data comes in', function() {
var firstResult = "result";
var result = jobStatusGraphData.get('', '');
restStub.succeed(firstResult);
flushPromises();
return expect(result).to.eventually.equal(firstResult);;
});
it('broadcasts event when data is received', function() {
var expected = "value";
var result = q.defer();
jobStatusGraphData.setupWatcher();
inject(function($rootScope) {
$rootScope.$on('DataReceived:JobStatusGraph', function(e, data) {
result.resolve(data);
});
$rootScope.$emit('JobStatusChange');
restStub.succeed(expected);
flushPromises();
});
return expect(result.promise).to.eventually.equal(expected);
});
xit('processes errors through error handler', function() {
});
});