Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,17 @@ jobs:
grep -q '"/counter"' Components/UI/AppSidebar.razor || (echo "AppSidebar links were not built from the pages"; exit 1)
dotnet build -c Debug

cd "$TMPDIR/app"
dotnet new blazor -o IdentityApp --auth Individual --no-restore
cd IdentityApp
shellui init --tailwind standalone --yes --dashboard 02
grep -q '<SidebarAccount />' Components/UI/AppSidebar.razor || (echo "the sidebar footer has no account menu"; exit 1)
grep -q 'StartsWithSegments("/Account")' Components/App.razor || (echo "Identity pages are not kept static"; exit 1)
shellui add auth-01
grep -q '@layout IdentityApp.Components.Layout.AuthLayout01' Components/Account/Pages/_Imports.razor || (echo "auth-01 was not set as the sign-in layout"; exit 1)
! grep -q 'class="form-control"' Components/Account/Pages/Login.razor || (echo "Login.razor was not restyled"; exit 1)
dotnet build -c Debug

# Catches missing dependencies that per-template tests can't see.
ALL=$(python3 - "$GITHUB_WORKSPACE" <<'PY'
import os, re, sys
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ShellUI is pre-1.0, so APIs and generated output can still change between minor
## Capabilities

- The CLI commands are `init`, `add`, `list`, `remove`, and `update`, plus `theme init`, `theme apply`, and `theme update`.
- The component registry has **239 entries**: **90 direct install targets** and **149 hidden dependency entries**. `list` shows direct targets; `add` resolves hidden dependencies.
- The component registry has **243 entries**: **93 direct install targets** and **150 hidden dependency entries**. `list` shows direct targets; `add` resolves hidden dependencies.
- `0.3.0` added `typed-select`, `command-palette`, `data-picker`, `multi-select`, `tag-input`, `donut-chart`, `radar-chart`, and `radial-chart`.
- `ShellUI.Components` supports a release-generated precompiled CSS bundle and a generated safelist for existing Tailwind builds.
- The CLI can install source with Tailwind's standalone executable or an npm-based build. The current Tailwind baseline is `4.3.2`.
Expand Down
111 changes: 111 additions & 0 deletions ShellUI.Tests/AccountPagesTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
using System;
using System.IO;
using System.Runtime.CompilerServices;
using ShellUI.CLI.Services;
using Xunit;

namespace ShellUI.Tests;

public class AccountPagesTests
{
[Theory]
[InlineData("net10", "Pages/Login.razor")]
[InlineData("net10", "Pages/Manage/Email.razor")]
[InlineData("net10", "Shared/ManageLayout.razor")]
[InlineData("net10", "Shared/ManageNavMenu.razor")]
[InlineData("net8", "Pages/Login.razor")]
[InlineData("net8", "Shared/ManageLayout.razor")]
public void Restyle_RemovesBootstrapFromStockPages(string framework, string file)
{
var content = Fixture(framework, file);
Assert.True(AccountPages.IsStock(file, content, DashboardSetup.StockProjectName));

var restyled = AccountPages.Restyle(content);

Assert.False(AccountPages.UsesBootstrap(restyled));
Assert.DoesNotContain("class=\"row\"", restyled);
Assert.DoesNotContain("<h1>", restyled);
Assert.DoesNotContain("<hr />", restyled);
Assert.False(AccountPages.IsStock(file, restyled, DashboardSetup.StockProjectName));
}

[Theory]
[InlineData("MyApp")]
[InlineData("my_app")]
public void IsStock_IgnoresTheProjectNamespace(string rootNamespace)
{
var content = Fixture("net10", "Pages/Login.razor").Replace(DashboardSetup.StockProjectName, rootNamespace);

Assert.True(AccountPages.IsStock("Pages/Login.razor", content, rootNamespace));
Assert.False(AccountPages.IsStock("Pages/Login.razor", content + "\n<p>mine</p>", rootNamespace));
}

[Fact]
public void Restyle_KeepsRazorExpressionsInsideTags()
{
var restyled = AccountPages.Restyle(Fixture("net10", "Pages/Login.razor"));

Assert.Contains("<a class=\"font-medium underline underline-offset-4\" href=\"@(NavigationManager.GetUriWithQueryParameters(\"Account/Register\", new Dictionary<string, object?> { [\"ReturnUrl\"] = ReturnUrl }))\">", restyled);
Assert.Contains("@bind-Value=\"Input.Email\"", restyled);
Assert.Contains("OnSubmit=\"LoginUser\"", restyled);
}

[Fact]
public void Restyle_StatusMessageUsesThemeColors()
{
var restyled = AccountPages.Restyle(Fixture("net10", "Shared/StatusMessage.razor"));

Assert.DoesNotContain("alert-@", restyled);
Assert.Contains("\"text-destructive\"", restyled);
Assert.Contains("@statusMessageClass\"", restyled);
}

[Theory]
[InlineData("btn btn-primary", "bg-primary", "h-10 px-4 py-2")]
[InlineData("w-100 btn btn-lg btn-primary", "w-full", "h-11 px-8")]
[InlineData("btn btn-danger", "bg-destructive", "h-10 px-4 py-2")]
public void MapClasses_BuildsShellUIButtons(string bootstrap, string variant, string size)
{
var mapped = AccountPages.MapClasses(bootstrap);

Assert.Contains(variant, mapped);
Assert.Contains(size, mapped);
Assert.DoesNotContain("btn", mapped.Split(' '));
Assert.DoesNotContain("w-100", mapped.Split(' '));
}

[Fact]
public void Apply_RestylesStockAccountPagesAndReportsEditedOnes()
{
var root = Path.Combine(Path.GetTempPath(), "shellui-account-" + Guid.NewGuid().ToString("N"));
try
{
var login = Fixture("net10", "Pages/Login.razor").Replace(DashboardSetup.StockProjectName, "MyApp");
Write(root, "Components/Account/Pages/Login.razor", login);
Write(root, "Components/Account/Shared/ManageLayout.razor", Fixture("net10", "Shared/ManageLayout.razor").Replace(DashboardSetup.StockProjectName, "MyApp") + "\n<p>mine</p>");
Write(root, "Components/Pages/Counter.razor", "<button class=\"btn btn-primary\"></button>");

var result = AccountPages.Apply(root, "MyApp");

Assert.Equal(new[] { "Components/Account/Pages/Login.razor" }, result.Restyled);
Assert.False(AccountPages.UsesBootstrap(File.ReadAllText(Path.Combine(root, "Components/Account/Pages/Login.razor"))));
Assert.Contains(result.Notes, n => n.Contains("Components/Account/Shared/ManageLayout.razor") && n.Contains("modified"));
Assert.Single(result.Notes);
Assert.Contains("btn btn-primary", File.ReadAllText(Path.Combine(root, "Components/Pages/Counter.razor")));
}
finally
{
Directory.Delete(root, true);
}
}

private static void Write(string root, string relative, string content)
{
var path = Path.Combine(root, relative);
Directory.CreateDirectory(Path.GetDirectoryName(path)!);
File.WriteAllText(path, content);
}

private static string Fixture(string framework, string file, [CallerFilePath] string thisFile = "") =>
File.ReadAllText(Path.Combine(Path.GetDirectoryName(thisFile)!, "Fixtures", "StockBlazor", framework, "Account", file + ".txt"));
}
61 changes: 61 additions & 0 deletions ShellUI.Tests/AuthSetupTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using ShellUI.CLI.Services;
using ShellUI.Templates;
using Xunit;

namespace ShellUI.Tests;

public class AuthSetupTests
{
private const string Layout = "MyApp.Components.Layout.AuthLayout01";

[Theory]
[InlineData("\n")]
[InlineData("\r\n")]
public void SetLayout_AddsTheLayoutWhereNoneIsSet(string newline)
{
var imports = $"@using MyApp.Components.Account.Shared{newline}@attribute [ExcludeFromInteractiveRouting]{newline}";

var updated = AuthSetup.SetLayout(imports, Layout);

Assert.Equal($"@using MyApp.Components.Account.Shared{newline}@attribute [ExcludeFromInteractiveRouting]{newline}@layout {Layout}{newline}", updated);
Assert.Equal(updated, AuthSetup.SetLayout(updated!, Layout));
}

[Theory]
[InlineData("@layout AccountLayout")]
[InlineData("@layout MyApp.Components.Layout.AuthLayout02")]
public void SetLayout_ReplacesTheNet8AccountLayoutOrAnotherAuthBlock(string directive)
{
var updated = AuthSetup.SetLayout($"@using MyApp.Components.Account.Shared\r\n{directive}\r\n", Layout);

Assert.Equal($"@using MyApp.Components.Account.Shared\r\n@layout {Layout}\r\n", updated);
}

[Fact]
public void SetLayout_LeavesACustomLayoutAlone()
{
Assert.Null(AuthSetup.SetLayout("@layout MyApp.Components.Layout.SignInLayout\n", Layout));
}

[Theory]
[InlineData("Components/Layout", "MyApp.Components.Layout.AuthLayout01")]
[InlineData("Layouts", "MyApp.Layouts.AuthLayout01")]
public void LayoutTypeName_FollowsTheLayoutPath(string layoutPath, string expected)
{
Assert.Equal(expected, AuthSetup.LayoutTypeName("MyApp", layoutPath, "AuthLayout01"));
}

[Fact]
public void EveryAuthBlock_IsAnInstallableLayout()
{
foreach (var (name, layout) in AuthSetup.Layouts)
{
var metadata = ComponentRegistry.GetMetadata(name);
Assert.NotNull(metadata);
Assert.True(metadata!.IsAvailable);
Assert.True(metadata.IsLayoutBlock);
Assert.Equal($"{layout}.razor", metadata.FilePath);
Assert.Contains("@Body", ComponentRegistry.GetComponentContent(name));
}
}
}
34 changes: 34 additions & 0 deletions ShellUI.Tests/DashboardSetupTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
using ShellUI.CLI.Services;
using ShellUI.Core.Models;
using ShellUI.Templates;
Expand Down Expand Up @@ -196,6 +197,39 @@ public void AppSidebarTemplate_LinksAreRewrittenFromPages()
Assert.Null(DashboardSetup.RewriteSidebarLinks(rewritten!, links));
}

[Fact]
public void AppSidebarTemplate_FooterBecomesTheAccountMenu()
{
var sidebar = ComponentRegistry.GetComponentContent("app-sidebar")!;
var templateFooter = Regex.Match(sidebar, "<SidebarFooter>.*?</SidebarFooter>", RegexOptions.Singleline).Value;

var rewritten = DashboardSetup.RewriteSidebarFooter(sidebar, templateFooter);

Assert.NotNull(rewritten);
Assert.Contains("<SidebarAccount />", rewritten);
Assert.DoesNotContain("user@example.com", rewritten);
Assert.Null(DashboardSetup.RewriteSidebarFooter(sidebar.Replace("user@example.com", "me@company.com"), templateFooter));
}

[Fact]
public void IsIdentityApp_NeedsAccountPagesAndIdentityRegistration()
{
var root = Path.Combine(Path.GetTempPath(), "shellui-identity-" + Guid.NewGuid().ToString("N"));
try
{
Write(root, "Program.cs", "builder.Services.AddRazorComponents();");
Write(root, "Components/Account/Pages/Login.razor", "@page \"/Account/Login\"");
Assert.False(DashboardSetup.IsIdentityApp(root));

Write(root, "Program.cs", "builder.Services.AddIdentityCore<ApplicationUser>(options => { });");
Assert.True(DashboardSetup.IsIdentityApp(root));
}
finally
{
Directory.Delete(root, true);
}
}

private static void Write(string root, string relative, string content)
{
var path = Path.Combine(root, relative);
Expand Down
Loading
Loading