diff --git a/src/AzureOpenAIProxy.PlaygroundApp/Components/Layout/MainLayout.razor b/src/AzureOpenAIProxy.PlaygroundApp/Components/Layout/MainLayout.razor index 1bad0f45..56bf7fcf 100644 --- a/src/AzureOpenAIProxy.PlaygroundApp/Components/Layout/MainLayout.razor +++ b/src/AzureOpenAIProxy.PlaygroundApp/Components/Layout/MainLayout.razor @@ -21,7 +21,7 @@ 🗙 - + - + \ No newline at end of file diff --git a/src/AzureOpenAIProxy.PlaygroundApp/Components/Pages/Tests.razor b/src/AzureOpenAIProxy.PlaygroundApp/Components/Pages/Tests.razor new file mode 100644 index 00000000..0929588c --- /dev/null +++ b/src/AzureOpenAIProxy.PlaygroundApp/Components/Pages/Tests.razor @@ -0,0 +1,14 @@ +@page "/tests" +@rendermode InteractiveServer + + + + +@code { + private object? currentValue; + + private void SetInput(int newValue) + { + currentValue = newValue; + } +} \ No newline at end of file diff --git a/src/AzureOpenAIProxy.PlaygroundApp/Components/UI/DebugButtonComponent.razor b/src/AzureOpenAIProxy.PlaygroundApp/Components/UI/DebugButtonComponent.razor new file mode 100644 index 00000000..93abbb75 --- /dev/null +++ b/src/AzureOpenAIProxy.PlaygroundApp/Components/UI/DebugButtonComponent.razor @@ -0,0 +1,22 @@ +@inject IToastService ToastService + + +Debug + +@code { + [Parameter] + public object? Input { get; set; } + + private async Task ShowToast() + { + if (Input is null) + { + ToastService.ShowToast(ToastIntent.Warning, "Input is null."); + await Task.CompletedTask; + return; + } + + ToastService.ShowToast(ToastIntent.Success, $"{Input} (Type: {Input.GetType()})"); + await Task.CompletedTask; + } +} \ No newline at end of file diff --git a/src/AzureOpenAIProxy.PlaygroundApp/Components/UI/DebugTargetComponent.razor b/src/AzureOpenAIProxy.PlaygroundApp/Components/UI/DebugTargetComponent.razor new file mode 100644 index 00000000..4f2c30bb --- /dev/null +++ b/src/AzureOpenAIProxy.PlaygroundApp/Components/UI/DebugTargetComponent.razor @@ -0,0 +1,15 @@ + + 123 + 456 + 789 + + +@code { + [Parameter] + public EventCallback OnValueChanged { get; set; } + + private async Task SetValue(int value) + { + await OnValueChanged.InvokeAsync(value); + } +} \ No newline at end of file diff --git a/test/AzureOpenAIProxy.PlaygroundApp.Tests/Pages/TestsPageTests.cs b/test/AzureOpenAIProxy.PlaygroundApp.Tests/Pages/TestsPageTests.cs new file mode 100644 index 00000000..f0b6f8c6 --- /dev/null +++ b/test/AzureOpenAIProxy.PlaygroundApp.Tests/Pages/TestsPageTests.cs @@ -0,0 +1,47 @@ +using Microsoft.Playwright; +using Microsoft.Playwright.NUnit; + +namespace AzureOpenAIProxy.PlaygroundApp.Tests.Pages; + +[Parallelizable(ParallelScope.Self)] +[TestFixture] +[Property("Category", "Integration")] +public class TestsPageTests : PageTest +{ + public override BrowserNewContextOptions ContextOptions() => new() + { + IgnoreHTTPSErrors = true, + }; + + [SetUp] + public async Task Setup() + { + // Arrange + await Page.GotoAsync("https://localhost:5001/tests"); + await Page.WaitForLoadStateAsync(LoadState.NetworkIdle); + } + + [Test] + public async Task Given_No_Input_When_DebugButton_Clicked_Then_Toast_Should_Show_NullMessage() + { + // Act + await Page.GetByRole(AriaRole.Button, new() { Name = "Debug" }).ClickAsync(); + + // Assert + await Expect(Page.Locator(".fluent-toast-title")).ToHaveTextAsync("Input is null."); + } + + [Test] + [TestCase(123, typeof(int))] + [TestCase(456, typeof(int))] + [TestCase(789, typeof(int))] + public async Task Given_Input_When_DebugButton_Clicked_Then_Toast_Should_Show_Input(int inputValue, Type inputType) + { + // Act + await Page.GetByRole(AriaRole.Radio, new() { Name = $"{inputValue}" }).ClickAsync(); + await Page.GetByRole(AriaRole.Button, new() { Name = "Debug" }).ClickAsync(); + + // Assert + await Expect(Page.Locator(".fluent-toast-title")).ToHaveTextAsync($"{inputValue} (Type: {inputType})"); + } +} \ No newline at end of file