test for blockEditorService

This commit is contained in:
Niels Lyngsø
2020-02-26 17:03:06 +01:00
parent 3779ea8050
commit 4a6484b577
8 changed files with 301 additions and 2 deletions
+1 -1
View File
@@ -32,5 +32,5 @@ exports.dev = series(setDevelopmentMode, parallel(dependencies, js, less, views)
exports.watch = series(watchTask);
//
exports.runTests = series(js, testUnit);
exports.runUnit = series(runUnitTestServer);
exports.runUnit = series(js, runUnitTestServer, watchTask);
exports.testE2e = series(testE2e);
+6
View File
@@ -8066,6 +8066,12 @@
"integrity": "sha512-nCeAiw37MIMA9w9IXso7bRaLl+c/ef3wnxsoSAlYrzS+Ot0zTG6nU8G/cIfGkqpkjX2wNaIW9RFG0TwIFnG6bA==",
"dev": true
},
"jasmine-promise-matchers": {
"version": "2.6.0",
"resolved": "https://registry.npmjs.org/jasmine-promise-matchers/-/jasmine-promise-matchers-2.6.0.tgz",
"integrity": "sha1-J1ASqFEeXoh9g11TWKutIMAmz2M=",
"dev": true
},
"jpegtran-bin": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/jpegtran-bin/-/jpegtran-bin-4.0.0.tgz",
+1
View File
@@ -71,6 +71,7 @@
"gulp-wrap": "0.15.0",
"gulp-wrap-js": "0.4.1",
"jasmine-core": "3.5.0",
"jasmine-promise-matchers": "^2.6.0",
"karma": "4.4.1",
"karma-chrome-launcher": "^3.1.0",
"karma-jasmine": "2.0.1",
@@ -280,6 +280,174 @@ angular.module('umbraco.mocks').
return node;
},
/** Creats a mock variant content object */
getMockVariantContent: function(id) {
var node = {
name: "My content with id: " + id,
updateDate: new Date().toIsoDateTimeString(),
publishDate: new Date().toIsoDateTimeString(),
createDate: new Date().toIsoDateTimeString(),
id: id,
parentId: 1234,
icon: "icon-umb-content",
owner: { name: "Administrator", id: 0 },
updater: { name: "Per Ploug Krogslund", id: 1 },
path: "-1,1234,2455",
allowedActions: ["U", "H", "A"],
variants: [
{
name: "",
language: null,
segment: null,
state: "NotCreated",
updateDate: "0001-01-01 00:00:00",
createDate: "0001-01-01 00:00:00",
publishDate: null,
releaseDate: null,
expireDate: null,
notifications: [],
tabs: [
{
label: "Content",
id: 2,
properties: [
{ alias: "valTest", label: "Validation test", view: "validationtest", value: "asdfasdf" },
{ alias: "bodyText", label: "Body Text", description: "Here you enter the primary article contents", view: "rte", value: "<p>askjdkasj lasjd</p>", config: {} },
{ alias: "textarea", label: "textarea", view: "textarea", value: "ajsdka sdjkds", config: { rows: 4 } },
{ alias: "media", label: "Media picker", view: "mediapicker", value: "1234,23242,23232,23231", config: {multiPicker: 1} }
]
},
{
label: "Sample Editor",
id: 3,
properties: [
{ alias: "datepicker", label: "Datepicker", view: "datepicker", config: { pickTime: false, format: "yyyy-MM-dd" } },
{ alias: "tags", label: "Tags", view: "tags", value: "" }
]
},
{
label: "This",
id: 4,
properties: [
{ alias: "valTest4", label: "Validation test", view: "validationtest", value: "asdfasdf" },
{ alias: "bodyText4", label: "Body Text", description: "Here you enter the primary article contents", view: "rte", value: "<p>askjdkasj lasjd</p>", config: {} },
{ alias: "textarea4", label: "textarea", view: "textarea", value: "ajsdka sdjkds", config: { rows: 4 } },
{ alias: "content4", label: "Content picker", view: "contentpicker", value: "1234,23242,23232,23231" }
]
},
{
label: "Is",
id: 5,
properties: [
{ alias: "valTest5", label: "Validation test", view: "validationtest", value: "asdfasdf" },
{ alias: "bodyText5", label: "Body Text", description: "Here you enter the primary article contents", view: "rte", value: "<p>askjdkasj lasjd</p>", config: {} },
{ alias: "textarea5", label: "textarea", view: "textarea", value: "ajsdka sdjkds", config: { rows: 4 } },
{ alias: "content5", label: "Content picker", view: "contentpicker", value: "1234,23242,23232,23231" }
]
},
{
label: "Overflown",
id: 6,
properties: [
{ alias: "valTest6", label: "Validation test", view: "validationtest", value: "asdfasdf" },
{ alias: "bodyText6", label: "Body Text", description: "Here you enter the primary article contents", view: "rte", value: "<p>askjdkasj lasjd</p>", config: {} },
{ alias: "textarea6", label: "textarea", view: "textarea", value: "ajsdka sdjkds", config: { rows: 4 } },
{ alias: "content6", label: "Content picker", view: "contentpicker", value: "1234,23242,23232,23231" }
]
},
{
label: "Generic Properties",
id: 0,
properties: [
{
label: 'Id',
value: 1234,
view: "readonlyvalue",
alias: "_umb_id"
},
{
label: 'Created by',
description: 'Original author',
value: "Administrator",
view: "readonlyvalue",
alias: "_umb_createdby"
},
{
label: 'Created',
description: 'Date/time this document was created',
value: new Date().toIsoDateTimeString(),
view: "readonlyvalue",
alias: "_umb_createdate"
},
{
label: 'Updated',
description: 'Date/time this document was created',
value: new Date().toIsoDateTimeString(),
view: "readonlyvalue",
alias: "_umb_updatedate"
},
{
label: 'Document Type',
value: "Home page",
view: "readonlyvalue",
alias: "_umb_doctype"
},
{
label: 'Publish at',
description: 'Date/time to publish this document',
value: new Date().toIsoDateTimeString(),
view: "datepicker",
alias: "_umb_releasedate"
},
{
label: 'Unpublish at',
description: 'Date/time to un-publish this document',
value: new Date().toIsoDateTimeString(),
view: "datepicker",
alias: "_umb_expiredate"
},
{
label: 'Template',
value: "myTemplate",
view: "dropdown",
alias: "_umb_template",
config: {
items: {
"" : "-- Choose template --",
"myTemplate" : "My Templates",
"home" : "Home Page",
"news" : "News Page"
}
}
},
{
label: 'Link to document',
value: ["/testing" + id, "http://localhost/testing" + id, "http://mydomain.com/testing" + id].join(),
view: "urllist",
alias: "_umb_urllist"
},
{
alias: "test", label: "Stuff", view: "test", value: "",
config: {
fields: [
{ alias: "embedded", label: "Embbeded", view: "textstring", value: "" },
{ alias: "embedded2", label: "Embbeded 2", view: "contentpicker", value: "" },
{ alias: "embedded3", label: "Embbeded 3", view: "textarea", value: "" },
{ alias: "embedded4", label: "Embbeded 4", view: "datepicker", value: "" }
]
}
}
]
}
]
}
]
};
return node;
},
getMockEntity : function(id){
return {name: "hello", id: id, icon: "icon-file"};
},
@@ -0,0 +1,56 @@
angular.module('umbraco.mocks').
factory('variantContentMocks', ['$httpBackend', 'mocksUtils', function ($httpBackend, mocksUtils) {
'use strict';
function returnEmptyVariantNode(status, data, headers) {
if (!mocksUtils.checkAuth()) {
return [401, null, null];
}
var response = returnVariantNodebyId(200, "", null);
var node = response[1];
var parentId = mocksUtils.getParameterByName(data, "parentId") || 1234;
node.name = "";
node.id = 0;
node.parentId = parentId;
$(node.tabs).each(function(i,tab){
$(tab.properties).each(function(i, property){
property.value = "";
});
});
return response;
}
function returnVariantNodebyId(status, data, headers) {
if (!mocksUtils.checkAuth()) {
return [401, null, null];
}
var id = mocksUtils.getParameterByName(data, "id") || "1234";
id = parseInt(id, 10);
var node = mocksUtils.getMockVariantContent(id);
return [200, node, null];
}
return {
register: function () {
$httpBackend
.whenGET(mocksUtils.urlRegex('/umbraco/UmbracoApi/Content/GetById?'))
.respond(returnVariantNodebyId);
$httpBackend
.whenGET(mocksUtils.urlRegex('/umbraco/UmbracoApi/Content/GetEmpty'))
.respond(returnEmptyVariantNode);
}
};
}]);
@@ -10,6 +10,9 @@ module.exports = function (config) {
// list of files / patterns to load in the browser
files: [
// Jasmine plugins
'node_modules/jasmine-promise-matchers/dist/jasmine-promise-matchers.js',
//libraries
'node_modules/jquery/dist/jquery.min.js',
'node_modules/angular/angular.js',
@@ -53,7 +53,6 @@
testCases.forEach(function(test){
it('Expects \'' + test.input + '\' to be truncated as \''+ test.expectedResult + '\', when noOfChars=' + test.noOfChars + ', and appendDots=' + test.appendDots, function() {
console.log($truncate(test.input, test.noOfChars, test.appendDots));
expect($truncate(test.input, test.noOfChars, test.appendDots)).toBe(test.expectedResult);
});
});
@@ -0,0 +1,66 @@
describe('blockEditorService tests', function () {
var blockEditorService, $rootScope, $httpBackend, varaintMocks, contentResource;
beforeEach(module('umbraco.services'));
beforeEach(module('umbraco.mocks'));
beforeEach(inject(function ($injector, mocksUtils) {
mocksUtils.disableAuth();
blockEditorService = $injector.get('blockEditorService');
$rootScope = $injector.get('$rootScope');
$httpBackend = $injector.get('$httpBackend');
varaintMocks = $injector.get("variantContentMocks");
varaintMocks.register();
contentResource = $injector.get('contentResource');
}));
var simpleBlockConfigurationMock = {contentTypeAlias: "testAlias", label:"Test", settingsElementTypeAlias: null, view: "testview.html"};
describe('init blockEditoModelObject', function () {
it('fail if no model value', function () {
function createWithNoModelValue() {
blockEditorService.createModelObject(null, "test", []);
}
expect(createWithNoModelValue).toThrow();
});
it('return a object, with methods', function () {
var modelObject = blockEditorService.createModelObject({}, "test", []);
expect(modelObject).not.toBeUndefined();
expect(modelObject.loadScaffolding).not.toBeUndefined();
});
it('getBlockConfiguration provide the requested block configurtion', function () {
var modelObject = blockEditorService.createModelObject({}, "test", [simpleBlockConfigurationMock]);
expect(modelObject.getBlockConfiguration(simpleBlockConfigurationMock.contentTypeAlias).label).toBe(simpleBlockConfigurationMock.label);
});
it('loadScaffolding provides data for itemPicker', function () {
var modelObject = blockEditorService.createModelObject({}, "test", [simpleBlockConfigurationMock]);
var itemPickerOptions;
var pendingPromise = modelObject.loadScaffolding(contentResource).then(() => {
itemPickerOptions = modelObject.getAvailableBlocksForItemPicker();
});
$rootScope.$digest();
$httpBackend.flush();
expect(itemPickerOptions.length).toBe(1);
});
});
});