Fixes js tests

This commit is contained in:
Shannon
2018-08-09 19:34:32 +10:00
parent d237fd7e26
commit 601c30c39a
9 changed files with 87 additions and 32 deletions
+5 -5
View File
@@ -955,12 +955,12 @@
"dependencies": {
"extend-shallow": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-2.0.1.tgz",
"integrity": "sha1-Ua99YUrZqfYQ6huvu5idaxxWiQ8=",
"dev": true,
"requires": {
"is-extendable": "0.1.1"
},
"resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-2.0.1.tgz"
"is-extendable": "^0.1.0"
}
}
}
},
@@ -1670,9 +1670,9 @@
"dependencies": {
"source-map": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
"integrity": "sha1-dHIq8y6WFOnCh6jQu95IteLxomM=",
"dev": true,
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz"
"dev": true
}
}
},
@@ -344,7 +344,7 @@ function contentTypeResource($q, $http, umbRequestHelper, umbDataFormatter, loca
$http.post(umbRequestHelper.getApiUrl("contentTypeApiBaseUrl", "Import", { file: file })),
"Failed to import document type " + file
);
},
}
};
}
angular.module('umbraco.resources').factory('contentTypeResource', contentTypeResource);
@@ -443,7 +443,7 @@ function contentEditingHelper(fileManager, $q, $location, $routeParams, notifica
"removeDateMonth",
"removeDateDayNumber",
"removeDateDay",
"removeDateTime",
"removeDateTime"
], function (i) {
return i === propName;
});
@@ -519,25 +519,32 @@ function contentEditingHelper(fileManager, $q, $location, $routeParams, notifica
var allNewProps = this.getAllProps(savedVariant);
//check for changed properties of the content
for (var p in allOrigProps) {
var alias = allOrigProps[p].alias;
for (var k = 0; k < allOrigProps.length; k++) {
var origProp = allOrigProps[k];
var alias = origProp.alias;
var newProp = getNewProp(alias, allNewProps);
if (newProp && !_.isEqual(alias, newProp.value)) {
if (newProp && !_.isEqual(origProp.value, newProp.value)) {
//they have changed so set the origContent prop to the new one
var origVal = allOrigProps[p].value;
allOrigProps[p].value = newProp.value;
var origVal = origProp.value;
origProp.value = newProp.value;
//instead of having a property editor $watch their expression to check if it has
// been updated, instead we'll check for the existence of a special method on their model
// and just call it.
if (angular.isFunction(allOrigProps[p].onValueChanged)) {
if (angular.isFunction(origProp.onValueChanged)) {
//send the newVal + oldVal
allOrigProps[p].onValueChanged(allOrigProps[p].value, origVal);
origProp.onValueChanged(origProp.value, origVal);
}
changed.push(allOrigProps[p]);
changed.push(origProp);
}
}
for (var p in allOrigProps) {
}
}
@@ -159,10 +159,18 @@ function formHelper(angularHelper, serverValidationManager, $timeout, notificati
//Check if this is for content properties - specific to content/media/member editors because those are special
// user defined properties with custom controls.
if (parts.length > 2 && parts[0] === "_Properties") {
if (parts.length > 1 && parts[0] === "_Properties") {
var propertyAlias = parts[1];
var culture = parts[2];
var culture = null;
if (parts.length > 2) {
culture = parts[2];
//special check in case the string is formatted this way
if (culture === "null") {
culture = null;
}
}
//if it contains 3 '.' then we will wire it up to a property's html field
if (parts.length > 3) {
@@ -140,8 +140,9 @@ function serverValidationManager($timeout) {
}
}
else if (propertyAlias !== undefined) {
//normalize culture to null
if (!culture) {
culture = null; // if empty or null, always make null
culture = null;
}
//don't add it if it already exists
var exists2 = _.find(callbacks, function (item) {
@@ -165,8 +166,9 @@ function serverValidationManager($timeout) {
}
else if (propertyAlias !== undefined) {
//normalize culture to null
if (!culture) {
culture = null; // if empty or null, always make null
culture = null;
}
//remove all callbacks for the content property
@@ -192,8 +194,9 @@ function serverValidationManager($timeout) {
*/
getPropertyCallbacks: function (propertyAlias, culture, fieldName) {
//normalize culture to null
if (!culture) {
culture = null; // if empty or null, always make null
culture = null;
}
var found = _.filter(callbacks, function (item) {
@@ -268,8 +271,9 @@ function serverValidationManager($timeout) {
return;
}
//normalize culture to null
if (!culture) {
culture = null; // if empty or null, always make null
culture = null;
}
//only add the item if it doesn't exist
@@ -306,6 +310,12 @@ function serverValidationManager($timeout) {
if (!propertyAlias) {
return;
}
//normalize culture to null
if (!culture) {
culture = null;
}
//remove the item
this.items = _.reject(this.items, function (item) {
return (item.propertyAlias === propertyAlias && item.culture === culture && (item.fieldName === fieldName || (fieldName === undefined || fieldName === "")));
@@ -354,6 +364,12 @@ function serverValidationManager($timeout) {
* Gets the error message for the content property
*/
getPropertyError: function (propertyAlias, culture, fieldName) {
//normalize culture to null
if (!culture) {
culture = null;
}
var err = _.find(this.items, function (item) {
//return true if the property alias matches and if an empty field name is specified or the field name matches
return (item.propertyAlias === propertyAlias && item.culture === culture && (item.fieldName === fieldName || (fieldName === undefined || fieldName === "")));
@@ -388,6 +404,12 @@ function serverValidationManager($timeout) {
* Checks if the content property + culture + field name combo has an error
*/
hasPropertyError: function (propertyAlias, culture, fieldName) {
//normalize culture to null
if (!culture) {
culture = null;
}
var err = _.find(this.items, function (item) {
//return true if the property alias matches and if an empty field name is specified or the field name matches
return (item.propertyAlias === propertyAlias && item.culture === culture && (item.fieldName === fieldName || (fieldName === undefined || fieldName === "")));
@@ -50,7 +50,7 @@ angular.module("umbraco")
pageSize: 100,
totalItems: 0,
totalPages: 0,
filter: '',
filter: ''
};
//preload selected item
@@ -435,4 +435,4 @@ angular.module("umbraco")
onInit();
});
});
@@ -21,7 +21,7 @@
var labelKeys = [
"treeHeaders_languages",
"general_mandatory",
"general_default",
"general_default"
];
localizationService.localizeMany(labelKeys).then(function (values) {
@@ -123,7 +123,8 @@ describe('contentEditingHelper tests', function () {
var allProps = contentEditingHelper.getAllProps(content);
//act
formHelper.handleServerValidation({ "_Properties.bodyText.value": ["Required"] });
//note the null, that's because culture is null
formHelper.handleServerValidation({ "_Properties.bodyText.null.value": ["Required"] });
//assert
expect(serverValidationManager.items.length).toBe(1);
@@ -143,7 +144,8 @@ describe('contentEditingHelper tests', function () {
{
"Name": ["Required"],
"UpdateDate": ["Invalid date"],
"_Properties.bodyText.value": ["Required field"],
//note the null, that's because culture is null
"_Properties.bodyText.null.value": ["Required field"],
"_Properties.textarea": ["Invalid format"]
});
@@ -226,6 +228,7 @@ describe('contentEditingHelper tests', function () {
//act
var changed = contentEditingHelper.reBindChangedProperties(origContent, newContent);
//assert
expect(changed.length).toBe(2);
expect(changed[0].alias).toBe("grid");
@@ -10,24 +10,39 @@ describe('file manager tests', function () {
describe('file management', function () {
it('adding a file adds to the collection', function () {
fileManager.setFiles('testProp', ["testFile"]);
fileManager.setFiles({
propertyAlias: 'testProp',
files: ["testFile"]
});
expect(fileManager.getFiles().length).toBe(1);
});
it('adding a file with the same property id replaces the existing one', function () {
fileManager.setFiles('testProp', ["testFile"]);
fileManager.setFiles('testProp', ["testFile2"]);
fileManager.setFiles({
propertyAlias: 'testProp',
files: ["testFile"]
});
fileManager.setFiles({
propertyAlias: 'testProp',
files: ["testFile2"]
});
expect(fileManager.getFiles().length).toBe(1);
expect(fileManager.getFiles()[0].file).toBe("testFile2");
});
it('clears all files', function () {
fileManager.setFiles('testProp1', ["testFile"]);
fileManager.setFiles('testProp2', ["testFile"]);
fileManager.setFiles({
propertyAlias: 'testProp',
files: ["testFile"]
});
fileManager.setFiles({
propertyAlias: 'testProp2',
files: ["testFile"]
});
expect(fileManager.getFiles().length).toBe(2);
fileManager.clearFiles();
expect(fileManager.getFiles().length).toBe(0);
});
});
});
});