Merge remote-tracking branch 'origin/v8/feature/AB4550-segments-clientcode' into v8/feature/AB6057-segment-feature
This commit is contained in:
@@ -63,7 +63,7 @@ namespace Umbraco.Tests.Web
|
||||
|
||||
ms.AddPropertyError(new ValidationResult("no header image"), "headerImage", null); //invariant property
|
||||
|
||||
Assert.AreEqual("_Properties.headerImage.invariant", ms.Keys.First());
|
||||
Assert.AreEqual("_Properties.headerImage.invariant.null", ms.Keys.First());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -73,9 +73,57 @@ namespace Umbraco.Tests.Web
|
||||
var localizationService = new Mock<ILocalizationService>();
|
||||
localizationService.Setup(x => x.GetDefaultLanguageIsoCode()).Returns("en-US");
|
||||
|
||||
ms.AddPropertyError(new ValidationResult("no header image"), "headerImage", "en-US"); //invariant property
|
||||
ms.AddPropertyError(new ValidationResult("no header image"), "headerImage", "en-US"); //variant property
|
||||
|
||||
Assert.AreEqual("_Properties.headerImage.en-US", ms.Keys.First());
|
||||
Assert.AreEqual("_Properties.headerImage.en-US.null", ms.Keys.First());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Add_Invariant_Segment_Property_Error()
|
||||
{
|
||||
var ms = new ModelStateDictionary();
|
||||
var localizationService = new Mock<ILocalizationService>();
|
||||
localizationService.Setup(x => x.GetDefaultLanguageIsoCode()).Returns("en-US");
|
||||
|
||||
ms.AddPropertyError(new ValidationResult("no header image"), "headerImage", null, "mySegment"); //invariant/segment property
|
||||
|
||||
Assert.AreEqual("_Properties.headerImage.invariant.mySegment", ms.Keys.First());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Add_Variant_Segment_Property_Error()
|
||||
{
|
||||
var ms = new ModelStateDictionary();
|
||||
var localizationService = new Mock<ILocalizationService>();
|
||||
localizationService.Setup(x => x.GetDefaultLanguageIsoCode()).Returns("en-US");
|
||||
|
||||
ms.AddPropertyError(new ValidationResult("no header image"), "headerImage", "en-US", "mySegment"); //variant/segment property
|
||||
|
||||
Assert.AreEqual("_Properties.headerImage.en-US.mySegment", ms.Keys.First());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Add_Invariant_Segment_Field_Property_Error()
|
||||
{
|
||||
var ms = new ModelStateDictionary();
|
||||
var localizationService = new Mock<ILocalizationService>();
|
||||
localizationService.Setup(x => x.GetDefaultLanguageIsoCode()).Returns("en-US");
|
||||
|
||||
ms.AddPropertyError(new ValidationResult("no header image", new[] { "myField" }), "headerImage", null, "mySegment"); //invariant/segment property
|
||||
|
||||
Assert.AreEqual("_Properties.headerImage.invariant.mySegment.myField", ms.Keys.First());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Add_Variant_Segment_Field_Property_Error()
|
||||
{
|
||||
var ms = new ModelStateDictionary();
|
||||
var localizationService = new Mock<ILocalizationService>();
|
||||
localizationService.Setup(x => x.GetDefaultLanguageIsoCode()).Returns("en-US");
|
||||
|
||||
ms.AddPropertyError(new ValidationResult("no header image", new[] { "myField" }), "headerImage", "en-US", "mySegment"); //variant/segment property
|
||||
|
||||
Assert.AreEqual("_Properties.headerImage.en-US.mySegment.myField", ms.Keys.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,9 +159,16 @@ function formHelper(angularHelper, serverValidationManager, notificationsService
|
||||
//the alias in model state can be in dot notation which indicates
|
||||
// * the first part is the content property alias
|
||||
// * the second part is the field to which the valiation msg is associated with
|
||||
//There will always be at least 3 parts for content properties since all model errors for properties are prefixed with "_Properties"
|
||||
//There will always be at least 4 parts for content properties since all model errors for properties are prefixed with "_Properties"
|
||||
//If it is not prefixed with "_Properties" that means the error is for a field of the object directly.
|
||||
|
||||
// Example: "_Properties.headerImage.en-US.mySegment.myField"
|
||||
// * it's for a property since it has a _Properties prefix
|
||||
// * it's for the headerImage property type
|
||||
// * it's for the en-US culture
|
||||
// * it's for the mySegment segment
|
||||
// * it's for the myField html field (optional)
|
||||
|
||||
var parts = e.split(".");
|
||||
|
||||
//Check if this is for content properties - specific to content/media/member editors because those are special
|
||||
@@ -179,21 +186,20 @@ function formHelper(angularHelper, serverValidationManager, notificationsService
|
||||
}
|
||||
}
|
||||
|
||||
var htmlFieldReference = "";
|
||||
if (parts.length > 3) {
|
||||
htmlFieldReference = parts[3] || "";
|
||||
}
|
||||
|
||||
// SEGMENTS_TODO: Need to investigate wether we have updated validation to handle segments, plus could it be the third parameter, so we leave the HTML Field ref as optional and last?
|
||||
var segment = null;
|
||||
if (parts.length > 4) {
|
||||
segment = parts[4];
|
||||
if (parts.length > 3) {
|
||||
segment = parts[3];
|
||||
//special check in case the string is formatted this way
|
||||
if (segment === "null") {
|
||||
segment = null;
|
||||
}
|
||||
}
|
||||
|
||||
var htmlFieldReference = "";
|
||||
if (parts.length > 4) {
|
||||
htmlFieldReference = parts[4] || "";
|
||||
}
|
||||
|
||||
// add a generic error for the property
|
||||
serverValidationManager.addPropertyError(propertyAlias, culture, segment, htmlFieldReference, modelState[e][0]);
|
||||
|
||||
|
||||
@@ -121,13 +121,15 @@ describe('contentEditingHelper tests', function () {
|
||||
|
||||
//act
|
||||
//note the null, that's because culture is null
|
||||
formHelper.handleServerValidation({ "_Properties.bodyText.null.value": ["Required"] });
|
||||
formHelper.handleServerValidation({ "_Properties.bodyText.null.null.value": ["Required"] });
|
||||
|
||||
//assert
|
||||
expect(serverValidationManager.items.length).toBe(1);
|
||||
expect(serverValidationManager.items[0].fieldName).toBe("value");
|
||||
expect(serverValidationManager.items[0].errorMsg).toBe("Required");
|
||||
expect(serverValidationManager.items[0].propertyAlias).toBe("bodyText");
|
||||
expect(serverValidationManager.items[0].culture).toBe("invariant");
|
||||
expect(serverValidationManager.items[0].segment).toBeNull();
|
||||
});
|
||||
|
||||
it('adds a multiple property and field level server validation errors when they are invalid', function () {
|
||||
@@ -142,7 +144,7 @@ describe('contentEditingHelper tests', function () {
|
||||
"Name": ["Required"],
|
||||
"UpdateDate": ["Invalid date"],
|
||||
//note the null, that's because culture is null
|
||||
"_Properties.bodyText.null.value": ["Required field"],
|
||||
"_Properties.bodyText.en-US.mySegment.value": ["Required field"],
|
||||
"_Properties.textarea": ["Invalid format"]
|
||||
});
|
||||
|
||||
@@ -157,6 +159,8 @@ describe('contentEditingHelper tests', function () {
|
||||
expect(serverValidationManager.items[2].fieldName).toBe("value");
|
||||
expect(serverValidationManager.items[2].errorMsg).toBe("Required field");
|
||||
expect(serverValidationManager.items[2].propertyAlias).toBe("bodyText");
|
||||
expect(serverValidationManager.items[2].culture).toBe("en-US");
|
||||
expect(serverValidationManager.items[2].segment).toBe("mySegment");
|
||||
expect(serverValidationManager.items[3].fieldName).toBe("");
|
||||
expect(serverValidationManager.items[3].errorMsg).toBe("Invalid format");
|
||||
expect(serverValidationManager.items[3].propertyAlias).toBe("textarea");
|
||||
|
||||
@@ -198,7 +198,7 @@ namespace Umbraco.Web.Editors.Filters
|
||||
r.ErrorMessage = property.ValidationRegExpMessage;
|
||||
}
|
||||
|
||||
modelState.AddPropertyError(r, property.Alias, property.Culture);
|
||||
modelState.AddPropertyError(r, property.Alias, property.Culture, property.Segment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,13 +49,15 @@ namespace Umbraco.Web
|
||||
/// <param name="propertyAlias"></param>
|
||||
/// <param name="culture">The culture for the property, if the property is invariant than this is empty</param>
|
||||
internal static void AddPropertyError(this System.Web.Http.ModelBinding.ModelStateDictionary modelState,
|
||||
ValidationResult result, string propertyAlias, string culture = "")
|
||||
ValidationResult result, string propertyAlias, string culture = "", string segment = "")
|
||||
{
|
||||
if (culture == null)
|
||||
culture = "";
|
||||
modelState.AddValidationError(result, "_Properties", propertyAlias,
|
||||
//if the culture is null, we'll add the term 'invariant' as part of the key
|
||||
culture.IsNullOrWhiteSpace() ? "invariant" : culture);
|
||||
culture.IsNullOrWhiteSpace() ? "invariant" : culture,
|
||||
// if the segment is null, we'll add the term 'null' as part of the key
|
||||
segment.IsNullOrWhiteSpace() ? "null" : segment);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user