Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TestViewer: Better search and other minor tweaks #7353

Merged
merged 7 commits into from
Oct 15, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 12 additions & 22 deletions src/MudBlazor.UnitTests.Viewer/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
</MudAppBar>
<MudDrawer Open="@drawerOpen" DisableOverlay="true" Variant="DrawerVariant.Responsive" ClipMode="DrawerClipMode.Always" Breakpoint="Breakpoint.Sm">
<MudDrawerHeader>
<MudText Typo="Typo.h6">TestComponents</MudText>
<MudText Typo="Typo.h6">Test Components</MudText>
</MudDrawerHeader>
<MudList>
<MudNavMenu>
@foreach (var type in availableComponentTypes)
{
<MudListItem OnClick="@(() => selectedType = type)" @key="type.Name">@type.Name</MudListItem>
<MudNavLink OnClick="@(() => selectedType = type)" @key="type.Name">@type.Name</MudNavLink>
}
</MudList>
</MudNavMenu>
</MudDrawer>
<MudMainContent Class="mt-4">

Expand Down Expand Up @@ -66,17 +66,16 @@
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
availableComponentTypes = getTestComponenTypes().ToArray();
availableComponentTypes = getTestComponentTypes().ToArray();
}

RenderFragment TestComponent() => builder =>
{
builder.OpenComponent(0, selectedType);
//builder.AddAttribute(1, "Title", "Some title");
builder.CloseComponent();
};

IEnumerable<Type> getTestComponenTypes()
IEnumerable<Type> getTestComponentTypes()
{
foreach (var type in typeof(Program).Assembly.GetTypes().OrderBy(x => x.Name))
{
Expand All @@ -102,28 +101,19 @@
{
if (type == null)
return "";
try
{
var field = type.GetField("__description__", BindingFlags.Public | BindingFlags.Static | BindingFlags.GetField);
return (string)field.GetValue(null);
}
catch (Exception)
{
return "public static string __description__ = \"...\"; not found in this component.";
}
var field = type.GetField("__description__", BindingFlags.Public | BindingFlags.Static | BindingFlags.GetField);
if (field == null || field.FieldType != typeof(string))
return "This test component does not have a description. Field \"public static string __description__\" not found in this component.";
return (string)field.GetValue(null);
}

private Task<IEnumerable<Type>> Search(string text)
{
if (string.IsNullOrWhiteSpace(text))
{
// the user just clicked the autocomplete open, show the most popular pages as search result according to our analytics data
// ordered by popularity
return Task.FromResult<IEnumerable<Type>>(new Type[0]);
}
var lowerText = text.ToLowerInvariant();

return Task.FromResult<IEnumerable<Type>>(
availableComponentTypes.Where(type => type.Name.ToLowerInvariant().StartsWith(lowerText))
availableComponentTypes.Where(type => type.Name.Contains(text, StringComparison.OrdinalIgnoreCase))
);
}

Expand Down
12 changes: 11 additions & 1 deletion src/MudBlazor.UnitTests.Viewer/Shared/MainLayout.razor
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
@inherits LayoutComponentBase

<MudThemeProvider/>
<MudThemeProvider Theme="@customTheme"/>
<MudDialogProvider/>
<MudSnackbarProvider/>

@Body

@code {
MudTheme customTheme = new MudTheme()
{
LayoutProperties = new LayoutProperties()
{
DrawerWidthLeft = "350px"
}
};
}