refactor: Update TextArea.razor.cs (#3716)

* refactor: Update TextArea.razor.cs


Updated TextAreaInfo to be a public class so that JSInterop calls can be setup for unit tests.

Closes #3714

* refactor: Update TextArea.razor.cs

Remove TextAreaInfo class from TextArea.razor.cs and define in new file with namespace AntDesign.Internal

* refactor: Create TextAreaInfo.cs

Remove TextAreaInfo class from TextArea.razor.cs and define in new file with namespace AntDesign.Internal

* refactor: Update TextArea.razor.cs

Add AntDesign.Internal using statement for TextAreaInfo class

* refactor: Update TextAreaTests.razor

Use the AntDesign.Internal namespace for TextAreaInfo
This commit is contained in:
bgraham123 2024-03-31 10:06:25 -04:00 committed by GitHub
parent 3d0ab1a8be
commit 2da7ff240e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 33 additions and 25 deletions

View File

@ -1,6 +1,7 @@
using System.Diagnostics;
using System.Text.Json;
using System.Threading.Tasks;
using AntDesign.Internal;
using AntDesign.JsInterop;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
@ -325,15 +326,5 @@ namespace AntDesign
StateHasChanged();
}
}
internal class TextAreaInfo
{
public double ScrollHeight { get; set; }
public double LineHeight { get; set; }
public double PaddingTop { get; set; }
public double PaddingBottom { get; set; }
public double BorderTop { get; set; }
public double BorderBottom { get; set; }
}
}
}

View File

@ -0,0 +1,17 @@
namespace AntDesign.Internal
{
public class TextAreaInfo
{
public double ScrollHeight { get; set; }
public double LineHeight { get; set; }
public double PaddingTop { get; set; }
public double PaddingBottom { get; set; }
public double BorderTop { get; set; }
public double BorderBottom { get; set; }
}
}

View File

@ -1,6 +1,6 @@
@inherits AntDesignTestBase
@code {
AntDesign.TextArea.TextAreaInfo _textAreaInfo = new AntDesign.TextArea.TextAreaInfo
AntDesign.Internal.TextAreaInfo _textAreaInfo = new AntDesign.Internal.TextAreaInfo
{
LineHeight = 10,
PaddingTop = 1,
@ -20,7 +20,7 @@
{
//Arrange
JSCommonMock();
JSInterop.Setup<AntDesign.TextArea.TextAreaInfo>(JSInteropConstants.InputComponentHelper.GetTextAreaInfo, _ => true)
JSInterop.Setup<AntDesign.Internal.TextAreaInfo>(JSInteropConstants.InputComponentHelper.GetTextAreaInfo, _ => true)
.SetResult(_textAreaInfo);
string value = "0123456789";
var cut = Render(
@ -38,7 +38,7 @@
{
//Arrange
JSCommonMock();
JSInterop.Setup<AntDesign.TextArea.TextAreaInfo>(JSInteropConstants.InputComponentHelper.GetTextAreaInfo, _ => true)
JSInterop.Setup<AntDesign.Internal.TextAreaInfo>(JSInteropConstants.InputComponentHelper.GetTextAreaInfo, _ => true)
.SetResult(_textAreaInfo);
string value = "0123456789";
var cut = Render(
@ -57,7 +57,7 @@
{
//Arrange
JSCommonMock();
JSInterop.Setup<AntDesign.TextArea.TextAreaInfo>(JSInteropConstants.InputComponentHelper.GetTextAreaInfo, _ => true)
JSInterop.Setup<AntDesign.Internal.TextAreaInfo>(JSInteropConstants.InputComponentHelper.GetTextAreaInfo, _ => true)
.SetResult(_textAreaInfo);
string value = "0123456789";
var cut = Render(@<AntDesign.TextArea ShowCount Value=@value Disabled/>);
@ -72,7 +72,7 @@
{
//Arrange
JSCommonMock();
JSInterop.Setup<AntDesign.TextArea.TextAreaInfo>(JSInteropConstants.InputComponentHelper.GetTextAreaInfo, _ => true)
JSInterop.Setup<AntDesign.Internal.TextAreaInfo>(JSInteropConstants.InputComponentHelper.GetTextAreaInfo, _ => true)
.SetResult(_textAreaInfo);
string value = "";
string newValue = "newValue";
@ -92,7 +92,7 @@
{
//Arrange
JSCommonMock();
JSInterop.Setup<AntDesign.TextArea.TextAreaInfo>(JSInteropConstants.InputComponentHelper.GetTextAreaInfo, _ => true)
JSInterop.Setup<AntDesign.Internal.TextAreaInfo>(JSInteropConstants.InputComponentHelper.GetTextAreaInfo, _ => true)
.SetResult(_textAreaInfo);
var cut = Render<AntDesign.TextArea>(@<AntDesign.TextArea ReadOnly Value="@("0123456789")" />);
//Act
@ -106,7 +106,7 @@
{
//Arrange
JSCommonMock();
JSInterop.Setup<AntDesign.TextArea.TextAreaInfo>(JSInteropConstants.InputComponentHelper.GetTextAreaInfo, _ => true)
JSInterop.Setup<AntDesign.Internal.TextAreaInfo>(JSInteropConstants.InputComponentHelper.GetTextAreaInfo, _ => true)
.SetResult(_textAreaInfo);
var cut = Render<AntDesign.TextArea>(@<AntDesign.TextArea Rows="1" Value="@("0123456789")" />);
//Act
@ -120,7 +120,7 @@
{
JSCommonMock();
JSInterop
.Setup<TextArea.TextAreaInfo>(JSInteropConstants.InputComponentHelper.GetTextAreaInfo, _ => true)
.Setup<AntDesign.Internal.TextAreaInfo>(JSInteropConstants.InputComponentHelper.GetTextAreaInfo, _ => true)
.SetResult(_textAreaInfo);
var cut = Render<TextArea>(@<TextArea MaxLength="50" />);
@ -135,7 +135,7 @@
{
JSCommonMock();
JSInterop
.Setup<TextArea.TextAreaInfo>(JSInteropConstants.InputComponentHelper.GetTextAreaInfo, _ => true)
.Setup<AntDesign.Internal.TextAreaInfo>(JSInteropConstants.InputComponentHelper.GetTextAreaInfo, _ => true)
.SetResult(_textAreaInfo);
var cut = Render<TextArea>(@<TextArea />);
@ -152,7 +152,7 @@
{
//Arrange
JSCommonMock();
JSInterop.Setup<AntDesign.TextArea.TextAreaInfo>(JSInteropConstants.InputComponentHelper.GetTextAreaInfo, _ => true)
JSInterop.Setup<AntDesign.Internal.TextAreaInfo>(JSInteropConstants.InputComponentHelper.GetTextAreaInfo, _ => true)
.SetResult(_textAreaInfo);
uint rows = 4;
double expectedHeight = rows * _textAreaInfo.LineHeight +
@ -173,7 +173,7 @@
{
//Arrange
JSCommonMock();
JSInterop.Setup<AntDesign.TextArea.TextAreaInfo>(JSInteropConstants.InputComponentHelper.RegisterResizeTextArea, _ => true)
JSInterop.Setup<AntDesign.Internal.TextAreaInfo>(JSInteropConstants.InputComponentHelper.RegisterResizeTextArea, _ => true)
.SetResult(_textAreaInfo);
uint rows = 4;
double expectedHeight = rows * _textAreaInfo.LineHeight +
@ -194,7 +194,7 @@
{
//Arrange
JSCommonMock();
JSInterop.Setup<AntDesign.TextArea.TextAreaInfo>(JSInteropConstants.InputComponentHelper.RegisterResizeTextArea, _ => true)
JSInterop.Setup<AntDesign.Internal.TextAreaInfo>(JSInteropConstants.InputComponentHelper.RegisterResizeTextArea, _ => true)
.SetResult(_textAreaInfo);
var cut = Render<AntDesign.TextArea>(@<AntDesign.TextArea MinRows="1" AutoSize="false" />);
//Act && Assert
@ -206,7 +206,7 @@
{
//Arrange
JSCommonMock();
JSInterop.Setup<AntDesign.TextArea.TextAreaInfo>(JSInteropConstants.InputComponentHelper.RegisterResizeTextArea, _ => true)
JSInterop.Setup<AntDesign.Internal.TextAreaInfo>(JSInteropConstants.InputComponentHelper.RegisterResizeTextArea, _ => true)
.SetResult(_textAreaInfo);
var cut = Render<AntDesign.TextArea>(@<AntDesign.TextArea MaxRows="4" AutoSize="false" />);
//Act && Assert
@ -218,7 +218,7 @@
{
//Arrange
JSCommonMock();
JSInterop.Setup<AntDesign.TextArea.TextAreaInfo>(JSInteropConstants.InputComponentHelper.RegisterResizeTextArea, _ => true)
JSInterop.Setup<AntDesign.Internal.TextAreaInfo>(JSInteropConstants.InputComponentHelper.RegisterResizeTextArea, _ => true)
.SetResult(_textAreaInfo);
uint rows = 4;
double expectedHeight = rows * _textAreaInfo.LineHeight +
@ -233,4 +233,4 @@
var styleAttribute = textAreaElement.GetAttribute("style");
styleAttribute.Should().Contain($"height: {expectedHeight}px");
}*@
}
}