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
3 changes: 2 additions & 1 deletion docs/en/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ builder.Services.AddEnfilade(shell => shell.Appearance = Appearance.System);
| Option | Default | Description |
| ----------------------- | ------------ | ----------------------------------------------- |
| `Brand` | `Enfilade` | Name in the navigation and document titles. |
| `ShowVersion` | `true` | Shows the Enfilade version under the brand. |
| `ShowVersion` | `true` | Shows the version under the brand. |
| `Version` | — | Version to display. Defaults to the Enfilade version. |
| `Favicon` | — | Static asset path of the icon. |
| `Language` | `en` | Default language. Must be one of `Languages`. |
| `Languages` | — | Languages offered in the switch. |
Expand Down
3 changes: 2 additions & 1 deletion docs/ru/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ builder.Services.AddEnfilade(shell => shell.Appearance = Appearance.System);
| Параметр | По умолчанию | Описание |
| ----------------------- | ------------ | ----------------------------------------------- |
| `Brand` | `Enfilade` | Название в навигации и в заголовках документов. |
| `ShowVersion` | `true` | Показывает версию Enfilade под названием. |
| `ShowVersion` | `true` | Показывает версию под названием. |
| `Version` | — | Версия для отображения. По умолчанию используется версия Enfilade. |
| `Favicon` | — | Путь к значку среди статических файлов. |
| `Language` | `en` | Язык по умолчанию. Должен входить в `Languages`. |
| `Languages` | — | Языки, предлагаемые в переключателе. |
Expand Down
2 changes: 2 additions & 0 deletions src/Enfilade/EnfiladeOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public sealed partial class EnfiladeOptions

public bool ShowVersion { get; set; } = true;

public string? Version { get; set; }

public string? Favicon { get; set; }

public string Language { get; set; } = "en";
Expand Down
2 changes: 1 addition & 1 deletion src/Enfilade/Layout/MainLayout.razor
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<span class="brand">@Options.Value.Brand</span>
@if (Options.Value.ShowVersion)
{
<span class="version">@Words.Format(EnfiladeText.Version, LibraryVersion)</span>
<span class="version">@Words.Format(EnfiladeText.Version, Options.Value.Version ?? LibraryVersion)</span>
}
<Navigation />
<AuthorizeView Context="auth">
Expand Down
42 changes: 42 additions & 0 deletions tests/Enfilade.Tests/VersionTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System.Reflection;
using Enfilade.Layout;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace Enfilade.Tests;

public class VersionTests : PanelContext
{
[Theory]
[InlineData(null)]
[InlineData("1.2.3-rc.1")]
public void The_layout_shows_the_configured_version_or_the_library_version(string? version)
{
ConfigureVersion(version, showVersion: true);
var expected = version ?? typeof(MainLayout).Assembly
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()!.InformationalVersion.Split('+')[0];

var layout = Render<MainLayout>();

Assert.EndsWith(expected, layout.Find(".version").TextContent, StringComparison.Ordinal);
}

[Fact]
public void The_layout_hides_a_configured_version_when_disabled()
{
ConfigureVersion("1.2.3", showVersion: false);

var layout = Render<MainLayout>();

Assert.Empty(layout.FindAll(".version"));
}

private void ConfigureVersion(string? version, bool showVersion)
{
AddAuthorization();
var settings = new Dictionary<string, string?> { ["Enfilade:ShowVersion"] = showVersion.ToString() };
if (version is not null)
settings["Enfilade:Version"] = version;
Services.AddSingleton<IConfiguration>(new ConfigurationBuilder().AddInMemoryCollection(settings).Build());
}
}