Tests for the create content controller
This commit is contained in:
@@ -14,48 +14,54 @@ function contentCreateController($scope,
|
||||
navigationService,
|
||||
blueprintConfig) {
|
||||
|
||||
contentTypeResource.getAllowedTypes($scope.currentNode.id).then(function(data) {
|
||||
$scope.allowedTypes = iconHelper.formatContentTypeIcons(data);
|
||||
});
|
||||
function initialize() {
|
||||
contentTypeResource.getAllowedTypes($scope.currentNode.id).then(function (data) {
|
||||
$scope.allowedTypes = iconHelper.formatContentTypeIcons(data);
|
||||
});
|
||||
|
||||
$scope.selectContentType = true;
|
||||
$scope.selectBlueprint = false;
|
||||
$scope.allowBlank = blueprintConfig.allowBlank;
|
||||
|
||||
$scope.createBlank = function(docType) {
|
||||
$scope.selectContentType = true;
|
||||
$scope.selectBlueprint = false;
|
||||
$scope.allowBlank = blueprintConfig.allowBlank;
|
||||
}
|
||||
|
||||
function close() {
|
||||
navigationService.hideMenu();
|
||||
}
|
||||
|
||||
function createBlank(docType) {
|
||||
$location
|
||||
.path("/content/content/edit/" + $scope.currentNode.id)
|
||||
.search("doctype=" + docType.alias + "&create=true");
|
||||
navigationService.hideMenu();
|
||||
};
|
||||
|
||||
$scope.createOrSelectBlueprintIfAny = function(docType) {
|
||||
close();
|
||||
}
|
||||
|
||||
function createOrSelectBlueprintIfAny(docType) {
|
||||
var blueprintIds = _.keys(docType.blueprints || {});
|
||||
$scope.docType = docType;
|
||||
if (blueprintIds.length) {
|
||||
if (blueprintIds.length) {
|
||||
if (blueprintConfig.skipSelect) {
|
||||
$scope.createFromBlueprint(blueprintIds[0]);
|
||||
createFromBlueprint(blueprintIds[0]);
|
||||
} else {
|
||||
$scope.selectContentType = false;
|
||||
$scope.selectBlueprint = true;
|
||||
}
|
||||
} else {
|
||||
$scope.createBlank(docType);
|
||||
createBlank(docType);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
$scope.createFromBlueprint = function(blueprintId) {
|
||||
function createFromBlueprint(blueprintId) {
|
||||
$location
|
||||
.path("/content/content/edit/" + $scope.currentNode.id)
|
||||
.search(
|
||||
"doctype=" +
|
||||
$scope.docType.alias +
|
||||
"&create=true" +
|
||||
"&blueprintId=" +
|
||||
blueprintId
|
||||
);
|
||||
navigationService.hideMenu();
|
||||
};
|
||||
.search("doctype=" + $scope.docType.alias + "&create=true&blueprintId=" + blueprintId);
|
||||
close();
|
||||
}
|
||||
|
||||
$scope.createBlank = createBlank;
|
||||
$scope.createOrSelectBlueprintIfAny = createOrSelectBlueprintIfAny;
|
||||
$scope.createFromBlueprint = createFromBlueprint;
|
||||
|
||||
initialize();
|
||||
}
|
||||
|
||||
angular.module("umbraco").controller("Umbraco.Editors.Content.CreateController", contentCreateController);
|
||||
|
||||
@@ -4,51 +4,121 @@
|
||||
function() {
|
||||
|
||||
var scope,
|
||||
allowedTypes = [{ id: 1, alias: "x" }, { id: 2, alias: "y" }],
|
||||
location;
|
||||
allowedTypes = [
|
||||
{ id: 1, alias: "x" },
|
||||
{ id: 2, alias: "y", blueprints: { "1": "a", "2": "b" } }
|
||||
],
|
||||
location,
|
||||
searcher,
|
||||
controller,
|
||||
rootScope,
|
||||
contentTypeResource;
|
||||
|
||||
beforeEach(module("umbraco"));
|
||||
|
||||
beforeEach(inject(function ($controller, $rootScope, $q, $location) {
|
||||
var contentTypeResource = {
|
||||
function initialize(blueprintConfig) {
|
||||
scope = rootScope.$new();
|
||||
scope.currentNode = { id: 1234 };
|
||||
var dependencies = {
|
||||
$scope: scope,
|
||||
contentTypeResource: contentTypeResource
|
||||
};
|
||||
if (blueprintConfig) {
|
||||
dependencies.blueprintConfig = blueprintConfig;
|
||||
}
|
||||
controller("Umbraco.Editors.Content.CreateController",
|
||||
dependencies);
|
||||
|
||||
scope.$digest();
|
||||
|
||||
}
|
||||
|
||||
beforeEach(inject(function($controller, $rootScope, $q, $location) {
|
||||
contentTypeResource = {
|
||||
getAllowedTypes: function() {
|
||||
var def = $q.defer();
|
||||
def.resolve(allowedTypes);
|
||||
return def.promise;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
location = $location;
|
||||
controller = $controller;
|
||||
rootScope = $rootScope;
|
||||
|
||||
scope = $rootScope.$new();
|
||||
scope.currentNode = { id: 1234 };
|
||||
|
||||
$controller("Umbraco.Editors.Content.CreateController", {
|
||||
$scope: scope,
|
||||
contentTypeResource: contentTypeResource
|
||||
});
|
||||
|
||||
scope.$digest();
|
||||
searcher = { search: function() {} };
|
||||
spyOn(location, "path").andReturn(searcher);
|
||||
spyOn(searcher, "search");
|
||||
|
||||
initialize();
|
||||
}));
|
||||
|
||||
it("shows available child document types for the given node", function() {
|
||||
expect(scope.allowedTypes).toBe(allowedTypes);
|
||||
});
|
||||
it("shows available child document types for the given node",
|
||||
function() {
|
||||
expect(scope.selectContentType).toBe(true);
|
||||
expect(scope.allowedTypes).toBe(allowedTypes);
|
||||
});
|
||||
|
||||
it("creates content directly when there are no blueprints",
|
||||
function() {
|
||||
var searcher = {search:function(){}};
|
||||
spyOn(location, "path").andReturn(searcher);
|
||||
spyOn(searcher, "search");
|
||||
|
||||
scope.createOrSelectBlueprintIfAny(allowedTypes[0]);
|
||||
|
||||
expect(location.path).toHaveBeenCalledWith("/content/content/edit/1234");
|
||||
expect(searcher.search).toHaveBeenCalledWith("doctype=x&create=true");
|
||||
});
|
||||
|
||||
it("shows list of blueprints when there are some",
|
||||
function() {
|
||||
scope.createOrSelectBlueprintIfAny(allowedTypes[1]);
|
||||
expect(scope.selectContentType).toBe(false);
|
||||
expect(scope.selectBlueprint).toBe(true);
|
||||
expect(scope.docType).toBe(allowedTypes[1]);
|
||||
});
|
||||
|
||||
it("creates blueprint when selected",
|
||||
function() {
|
||||
scope.createOrSelectBlueprintIfAny(allowedTypes[1]);
|
||||
scope.createFromBlueprint("1");
|
||||
|
||||
expect(location.path).toHaveBeenCalledWith("/content/content/edit/1234");
|
||||
expect(searcher.search).toHaveBeenCalledWith("doctype=y&create=true&blueprintId=1");
|
||||
});
|
||||
|
||||
it("skips selection and creates first blueprint when configured to",
|
||||
function() {
|
||||
initialize({
|
||||
allowBlank: true,
|
||||
skipSelect: true
|
||||
});
|
||||
|
||||
scope.createOrSelectBlueprintIfAny(allowedTypes[1]);
|
||||
|
||||
expect(location.path).toHaveBeenCalledWith("/content/content/edit/1234");
|
||||
expect(searcher.search).toHaveBeenCalledWith("doctype=y&create=true&blueprintId=1");
|
||||
});
|
||||
|
||||
it("allows blank to be selected",
|
||||
function() {
|
||||
expect(scope.allowBlank).toBe(true);
|
||||
});
|
||||
|
||||
it("creates blank when selected",
|
||||
function() {
|
||||
scope.createBlank(allowedTypes[1]);
|
||||
|
||||
expect(location.path).toHaveBeenCalledWith("/content/content/edit/1234");
|
||||
expect(searcher.search).toHaveBeenCalledWith("doctype=y&create=true");
|
||||
});
|
||||
|
||||
it("hides blank when configured to",
|
||||
function() {
|
||||
initialize({
|
||||
allowBlank: false,
|
||||
skipSelect: false
|
||||
});
|
||||
|
||||
expect(scope.allowBlank).toBe(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
}());
|
||||
|
||||
}());
|
||||
Reference in New Issue
Block a user