From ac8a2331b405a0453e158c30579b009bca5c30d8 Mon Sep 17 00:00:00 2001 From: Justin Yoo Date: Thu, 22 Aug 2024 17:39:50 +0900 Subject: [PATCH 1/7] Update main layout to show/hide the sidebar --- .../Components/Layout/MainLayout.razor | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/AzureOpenAIProxy.PlaygroundApp/Components/Layout/MainLayout.razor b/src/AzureOpenAIProxy.PlaygroundApp/Components/Layout/MainLayout.razor index 4836891f..440a53d9 100644 --- a/src/AzureOpenAIProxy.PlaygroundApp/Components/Layout/MainLayout.razor +++ b/src/AzureOpenAIProxy.PlaygroundApp/Components/Layout/MainLayout.razor @@ -1,15 +1,15 @@ @inherits LayoutComponentBase +@inject NavigationManager NavMan
- - -
-
- About + @if (this._isAdmin == true) + { + + } +
@Body
@@ -26,3 +26,16 @@ + +@code +{ + private bool _isAdmin; + + protected override async Task OnInitializedAsync() + { + var path = new Uri(this.NavMan.Uri).AbsolutePath; + this._isAdmin = path.StartsWith("/admin", StringComparison.CurrentCultureIgnoreCase); + + await Task.CompletedTask; + } +} \ No newline at end of file From 2e545bca610d7a13e5c1eb0d523d130c99b32c3b Mon Sep 17 00:00:00 2001 From: Justin Yoo Date: Thu, 22 Aug 2024 18:05:19 +0900 Subject: [PATCH 2/7] Refactor the codebase from UI --- .../Components/Layout/MainLayout.razor | 14 ---------- .../Components/Layout/MainLayout.razor.cs | 26 +++++++++++++++++++ 2 files changed, 26 insertions(+), 14 deletions(-) create mode 100644 src/AzureOpenAIProxy.PlaygroundApp/Components/Layout/MainLayout.razor.cs diff --git a/src/AzureOpenAIProxy.PlaygroundApp/Components/Layout/MainLayout.razor b/src/AzureOpenAIProxy.PlaygroundApp/Components/Layout/MainLayout.razor index 440a53d9..1bad0f45 100644 --- a/src/AzureOpenAIProxy.PlaygroundApp/Components/Layout/MainLayout.razor +++ b/src/AzureOpenAIProxy.PlaygroundApp/Components/Layout/MainLayout.razor @@ -1,5 +1,4 @@ @inherits LayoutComponentBase -@inject NavigationManager NavMan
@if (this._isAdmin == true) @@ -26,16 +25,3 @@ - -@code -{ - private bool _isAdmin; - - protected override async Task OnInitializedAsync() - { - var path = new Uri(this.NavMan.Uri).AbsolutePath; - this._isAdmin = path.StartsWith("/admin", StringComparison.CurrentCultureIgnoreCase); - - await Task.CompletedTask; - } -} \ No newline at end of file diff --git a/src/AzureOpenAIProxy.PlaygroundApp/Components/Layout/MainLayout.razor.cs b/src/AzureOpenAIProxy.PlaygroundApp/Components/Layout/MainLayout.razor.cs new file mode 100644 index 00000000..4e40a58a --- /dev/null +++ b/src/AzureOpenAIProxy.PlaygroundApp/Components/Layout/MainLayout.razor.cs @@ -0,0 +1,26 @@ +using Microsoft.AspNetCore.Components; + +namespace AzureOpenAIProxy.PlaygroundApp.Components.Layout; + +/// +/// This represents the layout component for the main layout. +/// +public partial class MainLayout : LayoutComponentBase +{ + private bool _isAdmin; + + /// + /// Injects the instance. + /// + [Inject] + private NavigationManager? NavMan { get; set; } + + /// + protected override async Task OnInitializedAsync() + { + var path = new Uri(this.NavMan!.Uri).AbsolutePath; + this._isAdmin = path.StartsWith("/admin", StringComparison.CurrentCultureIgnoreCase); + + await Task.CompletedTask; + } +} From f1bb081cf3c7cbffe104da22622c4f9201acb2d6 Mon Sep 17 00:00:00 2001 From: Justin Yoo Date: Thu, 22 Aug 2024 19:05:54 +0900 Subject: [PATCH 3/7] Add UI test for sidebar --- .../UnitTest1.cs | 9 -------- ...zureOpenAIProxy.PlaygroundApp.Tests.csproj | 13 ++++++----- .../Pages/HomePageTests.cs | 22 +++++++++++++++++++ .../UnitTest1.cs | 9 -------- 4 files changed, 29 insertions(+), 24 deletions(-) delete mode 100644 test/AzureOpenAIProxy.ApiApp.Tests/UnitTest1.cs create mode 100644 test/AzureOpenAIProxy.PlaygroundApp.Tests/Pages/HomePageTests.cs delete mode 100644 test/AzureOpenAIProxy.PlaygroundApp.Tests/UnitTest1.cs diff --git a/test/AzureOpenAIProxy.ApiApp.Tests/UnitTest1.cs b/test/AzureOpenAIProxy.ApiApp.Tests/UnitTest1.cs deleted file mode 100644 index 924359ec..00000000 --- a/test/AzureOpenAIProxy.ApiApp.Tests/UnitTest1.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace AzureOpenAIProxy.ApiApp.Tests; - -public class UnitTest1 -{ - [Fact] - public void Test1() - { - } -} diff --git a/test/AzureOpenAIProxy.PlaygroundApp.Tests/AzureOpenAIProxy.PlaygroundApp.Tests.csproj b/test/AzureOpenAIProxy.PlaygroundApp.Tests/AzureOpenAIProxy.PlaygroundApp.Tests.csproj index 1a9f53fe..de2aabd0 100644 --- a/test/AzureOpenAIProxy.PlaygroundApp.Tests/AzureOpenAIProxy.PlaygroundApp.Tests.csproj +++ b/test/AzureOpenAIProxy.PlaygroundApp.Tests/AzureOpenAIProxy.PlaygroundApp.Tests.csproj @@ -1,4 +1,4 @@ - + false @@ -15,19 +15,20 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive + - + - + diff --git a/test/AzureOpenAIProxy.PlaygroundApp.Tests/Pages/HomePageTests.cs b/test/AzureOpenAIProxy.PlaygroundApp.Tests/Pages/HomePageTests.cs new file mode 100644 index 00000000..f10216ad --- /dev/null +++ b/test/AzureOpenAIProxy.PlaygroundApp.Tests/Pages/HomePageTests.cs @@ -0,0 +1,22 @@ +using Microsoft.Playwright.NUnit; + +namespace AzureOpenAIProxy.PlaygroundApp.Tests.Pages; + +[Parallelizable(ParallelScope.Self)] +[TestFixture] +[Property("Category", "Integration")] +public class HomePageTests : PageTest +{ + [Test] + public async Task Given_Root_Page_When_Navigated_Then_It_Should_No_Sidebar() + { + // Arrange + await this.Page.GotoAsync("https://localhost:5001"); + + // Act + var sidebar = this.Page.Locator("div.sidebar"); + + // Assert + Expect(sidebar).Equals(null); + } +} diff --git a/test/AzureOpenAIProxy.PlaygroundApp.Tests/UnitTest1.cs b/test/AzureOpenAIProxy.PlaygroundApp.Tests/UnitTest1.cs deleted file mode 100644 index 63e32861..00000000 --- a/test/AzureOpenAIProxy.PlaygroundApp.Tests/UnitTest1.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace AzureOpenAIProxy.PlaygroundApp.Tests; - -public class UnitTest1 -{ - [Fact] - public void Test1() - { - } -} From 4579103c5e155f1306ff5a1696e835382618dbfb Mon Sep 17 00:00:00 2001 From: Justin Yoo Date: Thu, 22 Aug 2024 19:09:08 +0900 Subject: [PATCH 4/7] Update build props --- Directory.Build.props | 4 +++- .../AzureOpenAIProxy.PlaygroundApp.Tests.csproj | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index a3531f4c..e3377330 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -15,13 +15,15 @@ 1.* 1.* 6.* + 8.* 4.* 6.* 6.* 17.* 5.* - 8.* + 4.* + 1.* 2.* diff --git a/test/AzureOpenAIProxy.PlaygroundApp.Tests/AzureOpenAIProxy.PlaygroundApp.Tests.csproj b/test/AzureOpenAIProxy.PlaygroundApp.Tests/AzureOpenAIProxy.PlaygroundApp.Tests.csproj index de2aabd0..0b9dccf2 100644 --- a/test/AzureOpenAIProxy.PlaygroundApp.Tests/AzureOpenAIProxy.PlaygroundApp.Tests.csproj +++ b/test/AzureOpenAIProxy.PlaygroundApp.Tests/AzureOpenAIProxy.PlaygroundApp.Tests.csproj @@ -15,12 +15,12 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - +