Skip to content

Commit 62f6308

Browse files
committed
Ad Unit Tests
1 parent bd0d0c0 commit 62f6308

File tree

5 files changed

+71
-12
lines changed

5 files changed

+71
-12
lines changed

src/Core/Components/KeyCode/FluentKeyPressEventArgs.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@ public class FluentKeyPressEventArgs : EventArgs
1313
/// Gets the key press event data associated with the current operation.
1414
/// </summary>
1515
public required KeyPress KeyPress { get; init; }
16+
17+
/// <summary>
18+
/// Gets the value associated with this instance.
19+
/// </summary>
20+
public required string Value { get; init; }
1621
}

src/Core/Components/TextArea/FluentTextArea.razor.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,18 @@ public FluentTextArea()
109109
[JSInvokable]
110110
public async Task ChangeAfterKeyPressHandlerAsync(string value, KeyPress key)
111111
{
112-
await ChangeHandlerAsync(new ChangeEventArgs() { Value = value });
112+
await ChangeHandlerAsync(new ChangeEventArgs()
113+
{
114+
Value = value,
115+
});
113116

114117
if (OnChangeAfterKeyPress.HasDelegate)
115118
{
116-
await OnChangeAfterKeyPress.InvokeAsync(new FluentKeyPressEventArgs() { KeyPress = key });
119+
await OnChangeAfterKeyPress.InvokeAsync(new FluentKeyPressEventArgs()
120+
{
121+
Value = value,
122+
KeyPress = key,
123+
});
117124
}
118125
}
119126

src/Core/Components/TextInput/FluentTextInput.razor.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,18 @@ public FluentTextInput()
135135
[JSInvokable]
136136
public async Task ChangeAfterKeyPressHandlerAsync(string value, KeyPress key)
137137
{
138-
await ChangeHandlerAsync(new ChangeEventArgs() { Value = value });
138+
await ChangeHandlerAsync(new ChangeEventArgs()
139+
{
140+
Value = value,
141+
});
139142

140143
if (OnChangeAfterKeyPress.HasDelegate)
141144
{
142-
await OnChangeAfterKeyPress.InvokeAsync(new FluentKeyPressEventArgs() { KeyPress = key});
145+
await OnChangeAfterKeyPress.InvokeAsync(new FluentKeyPressEventArgs()
146+
{
147+
Value = value,
148+
KeyPress = key,
149+
});
143150
}
144151
}
145152

tests/Core/Components/TextArea/FluentTextAreaTests.razor

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
{
1919
// Arrange && Act
2020
var cut = Render(@<FluentTextArea Appearance="@TextAreaAppearance.Outline"
21-
Autofocus="true"
22-
AriaLabel="My aria label"
23-
Label="My Label"
24-
Name="MyName"
25-
Placeholder="My help"
26-
Value="My Value" />
21+
Autofocus="true"
22+
AriaLabel="My aria label"
23+
Label="My Label"
24+
Name="MyName"
25+
Placeholder="My help"
26+
Value="My Value" />
2727
);
2828

2929
// Assert
@@ -96,8 +96,8 @@
9696
// Arrange && Act
9797
var cut = Render(
9898
@<FluentTextArea>
99-
<LabelTemplate><div style="font-weight: bold;">My label</div></LabelTemplate>
100-
</FluentTextArea>
99+
<LabelTemplate><div style="font-weight: bold;">My label</div></LabelTemplate>
100+
</FluentTextArea>
101101
);
102102

103103
// Assert
@@ -169,4 +169,24 @@
169169

170170
Assert.Equal(expected, value);
171171
}
172+
173+
[Fact]
174+
public async Task FluentTextArea_ChangeAfterKeyPress()
175+
{
176+
var value = string.Empty;
177+
var lastEventArgs = new FluentKeyPressEventArgs() { KeyPress = new KeyPress(), Value = "" };
178+
179+
// Arrange && Act
180+
var cut = Render(@<FluentTextArea @bind-Value="@value"
181+
ChangeAfterKeyPress="@([KeyPress.For(KeyCode.Enter)])"
182+
OnChangeAfterKeyPress="@(e => lastEventArgs = e)" />
183+
);
184+
185+
// Act
186+
await cut.FindComponent<FluentTextArea>().Instance.ChangeAfterKeyPressHandlerAsync("MyValue", KeyPress.For(KeyCode.Enter));
187+
188+
// Assert
189+
Assert.Equal(KeyCode.Enter, lastEventArgs.KeyPress.Key);
190+
Assert.Equal("MyValue", lastEventArgs.Value);
191+
}
172192
}

tests/Core/Components/TextInput/FluentTextInputTests.razor

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,24 @@
181181

182182
Assert.Equal(expected, value);
183183
}
184+
185+
[Fact]
186+
public async Task FluentInputText_ChangeAfterKeyPress()
187+
{
188+
var value = string.Empty;
189+
var lastEventArgs = new FluentKeyPressEventArgs() { KeyPress = new KeyPress(), Value = "" };
190+
191+
// Arrange && Act
192+
var cut = Render(@<FluentTextInput @bind-Value="@value"
193+
ChangeAfterKeyPress="@([KeyPress.For(KeyCode.Enter)])"
194+
OnChangeAfterKeyPress="@(e => lastEventArgs = e)" />
195+
);
196+
197+
// Act
198+
await cut.FindComponent<FluentTextInput>().Instance.ChangeAfterKeyPressHandlerAsync("MyValue", KeyPress.For(KeyCode.Enter));
199+
200+
// Assert
201+
Assert.Equal(KeyCode.Enter, lastEventArgs.KeyPress.Key);
202+
Assert.Equal("MyValue", lastEventArgs.Value);
203+
}
184204
}

0 commit comments

Comments
 (0)