File rename, refactor $httpBackend mocks

This commit is contained in:
Per Ploug Krogslund
2013-07-02 09:17:32 +02:00
parent 32d7b88b45
commit 0e431ffd3c
11 changed files with 127 additions and 120 deletions

View File

@@ -60,7 +60,7 @@ module.exports = function(karma) {
// - PhantomJS
// - IE (only Windows)
// CLI --browsers Chrome,Firefox,Safari
browsers: ['PhantomJS'],
browsers: ['Chrome'],
// If browser does not capture in given timeout [ms], kill it
// CLI --capture-timeout 5000

View File

@@ -1,44 +1,39 @@
describe('content factory tests', function () {
var $rootScope, $httpBackend, contentFactory;
var $rootScope, $httpBackend, contentFactory, mocks, $http;
beforeEach(module('umbraco.services'));
beforeEach(module('umbraco.resources'));
beforeEach(module('umbraco.httpbackend'));
beforeEach(inject(function ($injector) {
$rootScope = $injector.get('$rootScope');
$rootScope = $injector.get('$rootScope');
$httpBackend = $injector.get('$httpBackend');
mocks = $injector.get("contentMocks");
mocks.register();
contentFactory = $injector.get('contentResource');
}));
afterEach(function () {
$httpBackend.verifyNoOutstandingExpectation();
$httpBackend.verifyNoOutstandingRequest();
afterEach(function () {
$httpBackend.verifyNoOutstandingExpectation();
$httpBackend.verifyNoOutstandingRequest();
});
describe('global content factory crud', function () {
it('should return a content object, given an id', function () {
var doc = "meh";
contentFactory.getById(1234).then(function (result) {
doc = result;
});
console.log("doc:", doc);
$rootScope.$root.$digest();
//$scope.$apply();
//.then(function (doc1) {
console.log("doc:", doc);
expect(doc).toNotBe(undefined);
expect(doc.id).toBe(1234);
//});
it('should return a content object, given an id', function () {
var doc;
contentFactory.getById(1234).then(function(result){
doc = result;
});
$rootScope.$digest();
expect(doc).toNotBe(undefined);
expect(doc.id).toBe(1234);
});
it('should return a content children collection given an id', function () {
var collection = contentFactory.getChildren(1234, undefined);
expect(collection.resultSet.length).toBe(10);

View File

@@ -1,34 +1,50 @@
describe('content type factory tests', function () {
var $rootScope, contentTypeResource;
var $rootScope, $httpBackend, contentTypeResource, m;
beforeEach(module('ngMockE2E'));
beforeEach(module('umbraco.resources'));
beforeEach(module('umbraco.httpbackend'));
beforeEach(inject(function ($injector) {
$rootScope = $injector.get('$rootScope');
beforeEach(inject(function ($injector, contentTypeMocks) {
$rootScope = $injector.get('$rootScope');
$httpBackend = $injector.get('$httpBackend');
m = contentTypeMocks;
m.register();
contentTypeResource = $injector.get('contentTypeResource');
}));
describe('global content type factory crud', function () {
it('should return a content type object, given an id', function () {
var ct1 = contentTypeResource.getContentType(1234);
$rootScope.$digest();
var ct1;
contentTypeResource.getContentType(1234).then(function(result){
ct1 = result;
});
$rootScope.$digest();
$rootScope.$apply();
console.log("ct1:", ct1);
expect(ct1).toNotBe(undefined);
expect(ct1.id).toBe(1234);
});
it('should return a allowed content type collection given a document id', function(){
// var collection = contentTypeResource.getAllowedTypes(1234);
// $rootScope.$apply();
// console.log("running test", angular.toJson(collection));
// expect(collection.length).toBe(3);
m.expectAllowedChildren();
var collection;
contentTypeResource.getAllowedTypes(1234).then(function(result){
collection = result;
});
$rootScope.$digest();
$rootScope.$apply();
expect(collection.length).toBe(3);
});
});
});