Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- #683 Add `DomProperties` property to `UIComponent<TOwner>`; - #684 Add `DomClasses` property to `UIComponent<TOwner>`; - #685 Make `UIComponent<TOwner>.Attributes` obsolete and replace its usage with `DomAttributes` and `DomProperties`
- Loading branch information
1 parent
a949b2f
commit b8dd57d
Showing
23 changed files
with
267 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/Atata/Attributes/Behaviors/ValueGet/GetsValueFromValueAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
namespace Atata | ||
{ | ||
/// <summary> | ||
/// Represents the behavior for control value getting from <c>value</c> attribute. | ||
/// Represents the behavior for control value getting from <c>value</c> DOM property. | ||
/// </summary> | ||
public class GetsValueFromValueAttribute : ValueGetBehaviorAttribute | ||
{ | ||
/// <inheritdoc/> | ||
public override string Execute<TOwner>(IUIComponent<TOwner> component) => | ||
component.Attributes.Value; | ||
component.DomProperties.Value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/Atata/Components/UIComponentDomAttributesProvider`1.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
namespace Atata | ||
{ | ||
/// <summary> | ||
/// Allows to access the component scope element's DOM attribute values. | ||
/// </summary> | ||
/// <typeparam name="TOwner">The type of the owner page object.</typeparam> | ||
public sealed class UIComponentDomAttributesProvider<TOwner> : UIComponentPart<TOwner> | ||
where TOwner : PageObject<TOwner> | ||
{ | ||
private const string AttributeProviderNameFormat = "\"{0}\" DOM attribute"; | ||
|
||
public UIComponentDomAttributesProvider(IUIComponent<TOwner> component) | ||
{ | ||
Component = component.CheckNotNull(nameof(component)); | ||
ComponentPartName = "DOM attributes"; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the <see cref="ValueProvider{TValue, TOwner}"/> instance for the value of the specified control's scope element attribute. | ||
/// </summary> | ||
/// <param name="attributeName">The name of the attribute.</param> | ||
/// <returns>The <see cref="ValueProvider{TValue, TOwner}"/> instance for the attribute's current value.</returns> | ||
public ValueProvider<string, TOwner> this[string attributeName] => | ||
Get<string>(attributeName); | ||
|
||
/// <summary> | ||
/// Gets the <see cref="ValueProvider{TValue, TOwner}"/> instance for the value of the specified control's scope element attribute. | ||
/// </summary> | ||
/// <typeparam name="TValue">The type of the attribute value.</typeparam> | ||
/// <param name="attributeName">The name of the attribute.</param> | ||
/// <returns>The <see cref="ValueProvider{TValue, TOwner}"/> instance for the attribute's current value.</returns> | ||
public ValueProvider<TValue, TOwner> Get<TValue>(string attributeName) | ||
{ | ||
attributeName.CheckNotNullOrWhitespace(nameof(attributeName)); | ||
|
||
return Component.CreateValueProvider( | ||
AttributeProviderNameFormat.FormatWith(attributeName), | ||
() => GetValue<TValue>(attributeName)); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the value of the specified control's scope element attribute. | ||
/// </summary> | ||
/// <param name="attributeName">The name of the attribute.</param> | ||
/// <returns>The attribute's current value. | ||
/// Returns <see langword="null"/> if the value is not set.</returns> | ||
public string GetValue(string attributeName) | ||
{ | ||
attributeName.CheckNotNullOrWhitespace(nameof(attributeName)); | ||
|
||
return Component.Scope.GetDomAttribute(attributeName); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the value of the specified control's scope element attribute. | ||
/// </summary> | ||
/// <typeparam name="TValue">The type of the attribute value.</typeparam> | ||
/// <param name="attributeName">The name of the attribute.</param> | ||
/// <returns>The attribute's current value. | ||
/// Returns <see langword="null"/> if the value is not set.</returns> | ||
public TValue GetValue<TValue>(string attributeName) | ||
{ | ||
string valueAsString = GetValue(attributeName); | ||
|
||
if (string.IsNullOrEmpty(valueAsString) && typeof(TValue) == typeof(bool)) | ||
return default; | ||
|
||
return TermResolver.FromString<TValue>(valueAsString); | ||
} | ||
} | ||
} |
100 changes: 100 additions & 0 deletions
100
src/Atata/Components/UIComponentDomPropertiesProvider`1.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
namespace Atata | ||
{ | ||
/// <summary> | ||
/// Allows to access the component scope element's DOM property values. | ||
/// </summary> | ||
/// <typeparam name="TOwner">The type of the owner page object.</typeparam> | ||
public sealed class UIComponentDomPropertiesProvider<TOwner> : UIComponentPart<TOwner> | ||
where TOwner : PageObject<TOwner> | ||
{ | ||
private const string ItemProviderNameFormat = "\"{0}\" DOM property"; | ||
|
||
public UIComponentDomPropertiesProvider(IUIComponent<TOwner> component) | ||
{ | ||
Component = component.CheckNotNull(nameof(component)); | ||
ComponentPartName = "DOM properties"; | ||
} | ||
|
||
public ValueProvider<string, TOwner> Id => | ||
Get<string>("id"); | ||
|
||
public ValueProvider<string, TOwner> Name => | ||
Get<string>("name"); | ||
|
||
public ValueProvider<string, TOwner> Value => | ||
Get<string>("value"); | ||
|
||
public ValueProvider<string, TOwner> Title => | ||
Get<string>("title"); | ||
|
||
public ValueProvider<string, TOwner> Style => | ||
Get<string>("style"); | ||
|
||
public ValueProvider<bool?, TOwner> ReadOnly => | ||
Get<bool?>("readOnly"); | ||
|
||
public ValueProvider<bool?, TOwner> Required => | ||
Get<bool?>("required"); | ||
|
||
public ValueProvider<string, TOwner> TextContent => Component.CreateValueProvider( | ||
ItemProviderNameFormat.FormatWith("textContent"), | ||
() => GetValue("textContent")?.Trim()); | ||
|
||
public ValueProvider<string, TOwner> InnerHtml => Component.CreateValueProvider( | ||
ItemProviderNameFormat.FormatWith("innerHTML"), | ||
() => GetValue("innerHTML")?.Trim()); | ||
|
||
/// <summary> | ||
/// Gets the <see cref="ValueProvider{TValue, TOwner}"/> instance for the value of the specified control's scope element property. | ||
/// </summary> | ||
/// <param name="propertyName">The name of the property.</param> | ||
/// <returns>The <see cref="ValueProvider{TValue, TOwner}"/> instance for the property's current value.</returns> | ||
public ValueProvider<string, TOwner> this[string propertyName] => | ||
Get<string>(propertyName); | ||
|
||
/// <summary> | ||
/// Gets the <see cref="ValueProvider{TValue, TOwner}"/> instance for the value of the specified control's scope element property. | ||
/// </summary> | ||
/// <typeparam name="TValue">The type of the property value.</typeparam> | ||
/// <param name="propertyName">The name of the property.</param> | ||
/// <returns>The <see cref="ValueProvider{TValue, TOwner}"/> instance for the property's current value.</returns> | ||
public ValueProvider<TValue, TOwner> Get<TValue>(string propertyName) | ||
{ | ||
propertyName.CheckNotNullOrWhitespace(nameof(propertyName)); | ||
|
||
return Component.CreateValueProvider( | ||
ItemProviderNameFormat.FormatWith(propertyName), | ||
() => GetValue<TValue>(propertyName)); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the value of the specified control's scope element property. | ||
/// </summary> | ||
/// <param name="propertyName">The name of the property.</param> | ||
/// <returns>The property's current value. | ||
/// Returns <see langword="null"/> if the value is not set.</returns> | ||
public string GetValue(string propertyName) | ||
{ | ||
propertyName.CheckNotNullOrWhitespace(nameof(propertyName)); | ||
|
||
return Component.Scope.GetDomProperty(propertyName); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the value of the specified control's scope property attribute. | ||
/// </summary> | ||
/// <typeparam name="TValue">The type of the property value.</typeparam> | ||
/// <param name="propertyName">The name of the property.</param> | ||
/// <returns>The property's current value. | ||
/// Returns <see langword="null"/> if the value is not set.</returns> | ||
public TValue GetValue<TValue>(string propertyName) | ||
{ | ||
string valueAsString = GetValue(propertyName); | ||
|
||
if (string.IsNullOrEmpty(valueAsString) && typeof(TValue) == typeof(bool)) | ||
return default; | ||
|
||
return TermResolver.FromString<TValue>(valueAsString); | ||
} | ||
} | ||
} |
Oops, something went wrong.