Skip to content

Commit 690e8ed

Browse files
o-iijhmin99
authored andcommittedSep 1, 2024
[Playground] Component - button to display a given input aliencube#171 (aliencube#236)
1 parent 37477eb commit 690e8ed

File tree

5 files changed

+100
-2
lines changed

5 files changed

+100
-2
lines changed
 

‎src/AzureOpenAIProxy.PlaygroundApp/Components/Layout/MainLayout.razor

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<a class="dismiss">🗙</a>
2222
</div>
2323

24-
<FluentToastProvider />
24+
<FluentToastProvider @rendermode="InteractiveServer" />
2525
<FluentDialogProvider />
2626
<FluentTooltipProvider />
27-
<FluentMessageBarProvider />
27+
<FluentMessageBarProvider />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@page "/tests"
2+
@rendermode InteractiveServer
3+
4+
<DebugTargetComponent OnValueChanged="SetInput" />
5+
<DebugButtonComponent Input="@currentValue" />
6+
7+
@code {
8+
private object? currentValue;
9+
10+
private void SetInput(int newValue)
11+
{
12+
currentValue = newValue;
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
@inject IToastService ToastService
2+
3+
<!-- This component displays the given input when the button is clicked. -->
4+
<FluentButton @onclick="ShowToast" Appearance="Appearance.Accent">Debug</FluentButton>
5+
6+
@code {
7+
[Parameter]
8+
public object? Input { get; set; }
9+
10+
private async Task ShowToast()
11+
{
12+
if (Input is null)
13+
{
14+
ToastService.ShowToast(ToastIntent.Warning, "Input is null.");
15+
await Task.CompletedTask;
16+
return;
17+
}
18+
19+
ToastService.ShowToast(ToastIntent.Success, $"{Input} (Type: {Input.GetType()})");
20+
await Task.CompletedTask;
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<FluentRadioGroup Label="UI Test #171" TValue="int" ValueChanged="SetValue" Orientation="Orientation.Vertical">
2+
<FluentRadio Value="123">123</FluentRadio>
3+
<FluentRadio Value="456">456</FluentRadio>
4+
<FluentRadio Value="789">789</FluentRadio>
5+
</FluentRadioGroup>
6+
7+
@code {
8+
[Parameter]
9+
public EventCallback<int> OnValueChanged { get; set; }
10+
11+
private async Task SetValue(int value)
12+
{
13+
await OnValueChanged.InvokeAsync(value);
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using Microsoft.Playwright;
2+
using Microsoft.Playwright.NUnit;
3+
4+
namespace AzureOpenAIProxy.PlaygroundApp.Tests.Pages;
5+
6+
[Parallelizable(ParallelScope.Self)]
7+
[TestFixture]
8+
[Property("Category", "Integration")]
9+
public class TestsPageTests : PageTest
10+
{
11+
public override BrowserNewContextOptions ContextOptions() => new()
12+
{
13+
IgnoreHTTPSErrors = true,
14+
};
15+
16+
[SetUp]
17+
public async Task Setup()
18+
{
19+
// Arrange
20+
await Page.GotoAsync("https://localhost:5001/tests");
21+
await Page.WaitForLoadStateAsync(LoadState.NetworkIdle);
22+
}
23+
24+
[Test]
25+
public async Task Given_No_Input_When_DebugButton_Clicked_Then_Toast_Should_Show_NullMessage()
26+
{
27+
// Act
28+
await Page.GetByRole(AriaRole.Button, new() { Name = "Debug" }).ClickAsync();
29+
30+
// Assert
31+
await Expect(Page.Locator(".fluent-toast-title")).ToHaveTextAsync("Input is null.");
32+
}
33+
34+
[Test]
35+
[TestCase(123, typeof(int))]
36+
[TestCase(456, typeof(int))]
37+
[TestCase(789, typeof(int))]
38+
public async Task Given_Input_When_DebugButton_Clicked_Then_Toast_Should_Show_Input(int inputValue, Type inputType)
39+
{
40+
// Act
41+
await Page.GetByRole(AriaRole.Radio, new() { Name = $"{inputValue}" }).ClickAsync();
42+
await Page.GetByRole(AriaRole.Button, new() { Name = "Debug" }).ClickAsync();
43+
44+
// Assert
45+
await Expect(Page.Locator(".fluent-toast-title")).ToHaveTextAsync($"{inputValue} (Type: {inputType})");
46+
}
47+
}

0 commit comments

Comments
 (0)
Please sign in to comment.