Files
frameledger/tests/FrameLedger.App.Tests/LanguageFollowingTests.cs
poli0981andClaude Opus 5.5 fd4b2f0d5d fix(app): every list of choices, the tray's menu and the Agent pill follow a change of language at once (beta.15 PR-1) (#274)
From the beta.14 audit (chip, owner: fold the five into beta.15). A change of language rebuilds the window and its
pages, so their own text followed; two kinds did not, until a restart:

- Lists of choices built once in a static and bound with x:Static: Settings' Themes and UpdateChannels (D47's
  "Automatic (Beta)" label too), Logs' Sources and Levels, Games' Sorts. They are instance properties now, bound through
  the view model - built per page, in the language the page opens in (GameDetail's TrendMetrics has worked that way
  since beta.8). Languages stays static: each language in its own words, the same in every language.
- Singletons that outlive the rebuilt window: the tray's menu and tooltip (TrayHost) and the Agent pill and update
  banner (MainWindowViewModel). Both implement ILanguageFollower; ShellHost.Rebuild calls every registered follower once
  the new window is up. The shell's registrations moved to App.AddShell (MA0051).

Tests: LanguageFollowingTests (no view model may keep a static list of labelled choices but the languages - red on the
five lists before), SettingsViewModelTests / GamesViewModelTests / GameDetailViewModelTests (a page opened in Vietnamese
lists Vietnamese choices; the trend selector pinned for the first time), TrayHostTests (the menu relabelled, now in the
strings-culture collection).

Docs: 09_I18N (runtime switching), CHANGELOG.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 07:26:19 +07:00

36 lines
1.8 KiB
C#

// SPDX-License-Identifier: GPL-3.0-only
// Copyright (C) 2026 poli0981 - additional terms under GPLv3 section 7: see NOTICE
using System.Reflection;
using FluentAssertions;
using FrameLedger.App.ViewModels;
namespace FrameLedger.App.Tests;
/// <summary>
/// beta.15: a list of choices built once, in a static, keeps the language the App started in after a change of language,
/// while the page around it — rebuilt — follows. The themes, the update channels, the Logs page's two lists and the
/// Games page's sort order were such lists until beta.15; this keeps a new one from appearing. The language list is the
/// one exception: each language is named in its own words, the same in every language.
/// </summary>
public sealed class LanguageFollowingTests
{
[Fact]
public void NoViewModelKeepsAStaticListOfLabelledChoices()
{
string[] statics =
[
.. typeof(SettingsViewModel).Assembly.GetTypes()
.Where(static t => string.Equals(t.Namespace, "FrameLedger.App.ViewModels", StringComparison.Ordinal))
.SelectMany(static t => t.GetProperties(BindingFlags.Public | BindingFlags.Static).Select(p => (Type: t, Property: p)))
.Where(static x => x.Property.PropertyType.IsGenericType
&& x.Property.PropertyType.GetGenericTypeDefinition() == typeof(IReadOnlyList<>)
&& x.Property.PropertyType.GetGenericArguments()[0] is { IsGenericType: true } item
&& item.GetGenericTypeDefinition() == typeof(Choice<>))
.Select(static x => x.Type.Name + "." + x.Property.Name),
];
statics.Should().Equal(["SettingsViewModel.Languages"], "every other list is labelled in a language, and must be built per page");
}
}