One plugin-bar button and one tabbed window, as the original
Live in 0.1.19 the plugin put three buttons on the plugin bar (MM, Mossy Tracker, Metas), the tracker carried the icon that belongs to the main window, and the metas downloads were in a window of their own. Now only the main window has a bar button: "MM" with the original window's icon (7735, 0x06001E37). Its tabs follow the original's notebook: Main, Settings, Statistics, Mossy Tracker, Metas, Tools. The Mossy Tracker tab is the original page, one "Open Mossy Tracker" button that opens the tracker window; that window is registered without a bar button and opened through the host's ShowPanel. The Metas tab holds everything the metas window had (list with search, refresh, check, download outdated, download one file, last check, status), plus the repository address and the two folders the files land in. The main window forwards those bindings to the meta sync's view model, since markup binds one object. Downloads already went to the host's VTank profile storage, the one MossTank reads, under mosstank/metas and mosstank/navs with each file's own name and extension; the tab now shows those full folder paths instead of the storage root. Backend frames are untouched. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
360300a1ee
commit
336c5cfdf5
15 changed files with 459 additions and 124 deletions
|
|
@ -24,6 +24,9 @@ public sealed class FakeHost : IPluginHost
|
|||
|
||||
public MemoryStorage Storage { get; } = new();
|
||||
|
||||
/// <summary>The shared automation profile storage; its own root so a test can tell the two apart.</summary>
|
||||
public MemoryStorage VtankProfiles { get; } = new() { RootPath = @"C:\Users\player\AppData\Local\OpenAC\vtank" };
|
||||
|
||||
public FakeAutomation Automation { get; } = new();
|
||||
|
||||
public FakeLootClassifierRegistry LootClassifiers { get; } = new();
|
||||
|
|
@ -48,6 +51,8 @@ public sealed class FakeHost : IPluginHost
|
|||
|
||||
IPluginStorage IPluginHost.Storage => Storage;
|
||||
|
||||
IPluginStorage IPluginHost.VtankProfiles => VtankProfiles;
|
||||
|
||||
IAutomationSurface IPluginHost.Automation => Automation;
|
||||
|
||||
IPluginLootClassifierRegistry IPluginHost.LootClassifiers => LootClassifiers;
|
||||
|
|
@ -444,6 +449,15 @@ public sealed class FakeUiRegistry : IUiRegistry
|
|||
{
|
||||
public List<RegisteredPanel> Panels { get; } = [];
|
||||
|
||||
/// <summary>Every <see cref="ShowPanel"/> call, in order.</summary>
|
||||
public List<string> ShowPanelCalls { get; } = [];
|
||||
|
||||
public bool ShowPanel(string viewName)
|
||||
{
|
||||
ShowPanelCalls.Add(viewName);
|
||||
return Panels.Exists(panel => panel.Descriptor.WindowId == viewName || panel.Descriptor.Title == viewName);
|
||||
}
|
||||
|
||||
/// <summary>Every <see cref="ShowClientWindow"/> call, in order -- a test sets <see cref="ShowClientWindowResult"/> to simulate the host refusing it.</summary>
|
||||
public List<PluginClientWindow> ShowClientWindowCalls { get; } = [];
|
||||
|
||||
|
|
|
|||
|
|
@ -55,7 +55,8 @@ public sealed class FlagTrackerTests
|
|||
RegisteredPanel panel = Assert.Single(harness.Host.Ui.Panels, registered => registered.Descriptor.WindowId == "flagtracker");
|
||||
Assert.Equal("flagtracker", panel.Descriptor.WindowId);
|
||||
Assert.Equal("Mossy Tracker", panel.Descriptor.Title);
|
||||
Assert.True(panel.Descriptor.ShowInSidePanel);
|
||||
Assert.False(panel.Descriptor.ShowInSidePanel);
|
||||
Assert.Equal(0u, panel.Descriptor.IconSurfaceId);
|
||||
Assert.EndsWith(FlagTrackerFeature.MarkupFile, panel.MarkupPath, StringComparison.Ordinal);
|
||||
Assert.Same(Panel(harness), panel.Binding);
|
||||
Assert.False(Panel(harness).IsVisible);
|
||||
|
|
|
|||
|
|
@ -289,6 +289,35 @@ public sealed class MetaSyncTests
|
|||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Downloads_land_in_the_shared_profile_storage_the_automation_plugin_loads_from()
|
||||
{
|
||||
using var harness = new PluginHarness();
|
||||
harness.Login();
|
||||
MemoryStorage profiles = harness.Host.VtankProfiles;
|
||||
|
||||
// The plugin's own sync writes to the shared profile storage, not to
|
||||
// the plugin's private storage.
|
||||
Assert.Equal(profiles.RootPath, harness.Feature<MetaSyncFeature>().Manager.StorageRoot);
|
||||
Assert.NotEqual(harness.Host.Storage.RootPath, harness.Feature<MetaSyncFeature>().Manager.StorageRoot);
|
||||
|
||||
var server = new FakeGitServer();
|
||||
server.Text(TreeUrl, TreeJson);
|
||||
server.Text(RawBase + "/hunting/Colo.met", ColoMet);
|
||||
server.Text(RawBase + "/navs/Colo%20Loop.nav", LoopNav);
|
||||
server.Text(RawBase + "/x.MET", XMet);
|
||||
using var feature = new MetaSyncFeature(harness.Context, profiles, server);
|
||||
harness.Context.Commands.Dispatch("metaspull");
|
||||
await Settle(feature);
|
||||
|
||||
// Each file under its own name and extension, metas and navs apart,
|
||||
// where a bare name in the automation plugin finds it.
|
||||
Assert.Equal(ColoMet, profiles.ReadText("mosstank/metas/Colo.met"));
|
||||
Assert.Equal(XMet, profiles.ReadText("mosstank/metas/x.MET"));
|
||||
Assert.Equal(LoopNav, profiles.ReadText("mosstank/navs/Colo Loop.nav"));
|
||||
Assert.Null(harness.Host.Storage.ReadText("mosstank/metas/Colo.met"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_headless_host_gets_the_verbs_but_no_window()
|
||||
{
|
||||
|
|
@ -310,8 +339,8 @@ public sealed class MetaSyncTests
|
|||
using (feature)
|
||||
{
|
||||
MetasViewModel panel = feature.Panel!;
|
||||
Assert.False(panel.IsVisible);
|
||||
Assert.Equal("VTank Path: C:/profiles", panel.PathText);
|
||||
Assert.Equal($"Metas: {Path.Combine("C:/profiles", "mosstank", "metas")}", panel.MetaFolderText);
|
||||
Assert.Equal($"Navs: {Path.Combine("C:/profiles", "mosstank", "navs")}", panel.NavFolderText);
|
||||
Assert.Equal(["No files loaded"], panel.FilePaths);
|
||||
storage.Seed("mosstank/metas/x.MET", "stale");
|
||||
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
using System.Reflection;
|
||||
using System.Xml.Linq;
|
||||
using OpenAC.MosswartMassacre.FlagTracker;
|
||||
using OpenAC.MosswartMassacre.Metas;
|
||||
using OpenAC.MosswartMassacre.Views;
|
||||
|
||||
namespace OpenAC.MosswartMassacre.Tests.Ui;
|
||||
|
||||
/// <summary>
|
||||
/// Proves every <c>{Binding}</c> in this slice's markup files resolves to a
|
||||
/// Proves every <c>{Binding}</c> in the plugin's window markup resolves to a
|
||||
/// public property of the right shape on its binding object, the check the
|
||||
/// host would otherwise only make when the window is built in game.
|
||||
/// </summary>
|
||||
public sealed class TrackerAndMetasMarkupContractTests
|
||||
public sealed class WindowMarkupContractTests
|
||||
{
|
||||
private static readonly string[] InteractiveElementNames =
|
||||
[
|
||||
|
|
@ -20,7 +20,13 @@ public sealed class TrackerAndMetasMarkupContractTests
|
|||
public static TheoryData<string, Type> MarkupFiles => new()
|
||||
{
|
||||
{ FlagTrackerFeature.MarkupFile, typeof(FlagTrackerViewModel) },
|
||||
{ MetaSyncFeature.MarkupFile, typeof(MetasViewModel) },
|
||||
{ MainWindow.MarkupFile, typeof(MainWindow) },
|
||||
};
|
||||
|
||||
/// <summary>The windows opened by a button of the plugin's own, whose visibility the plugin binds.</summary>
|
||||
public static TheoryData<string, Type> OpenedWindows => new()
|
||||
{
|
||||
{ FlagTrackerFeature.MarkupFile, typeof(FlagTrackerViewModel) },
|
||||
};
|
||||
|
||||
[Theory]
|
||||
|
|
@ -79,7 +85,7 @@ public sealed class TrackerAndMetasMarkupContractTests
|
|||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(MarkupFiles))]
|
||||
[MemberData(nameof(OpenedWindows))]
|
||||
public void TheRootPanelVisibilityIsTheSettableIsVisible(string file, Type bindingType)
|
||||
{
|
||||
XElement root = LoadRoot(file);
|
||||
164
tests/OpenAC.MosswartMassacre.Tests/Views/OneWindowTests.cs
Normal file
164
tests/OpenAC.MosswartMassacre.Tests/Views/OneWindowTests.cs
Normal file
|
|
@ -0,0 +1,164 @@
|
|||
using System.Reflection;
|
||||
using System.Xml.Linq;
|
||||
using OpenAC.MosswartMassacre.FlagTracker;
|
||||
using OpenAC.MosswartMassacre.Metas;
|
||||
using OpenAC.MosswartMassacre.Tests.Fakes;
|
||||
using OpenAC.MosswartMassacre.Views;
|
||||
|
||||
namespace OpenAC.MosswartMassacre.Tests.Views;
|
||||
|
||||
/// <summary>
|
||||
/// The plugin shows as the original did: one button on the plugin bar, "MM"
|
||||
/// with the original window's icon, opening one tabbed window. The Mossy
|
||||
/// Tracker tab opens the tracker window, which has no bar button of its own,
|
||||
/// and the Metas tab holds the meta and nav downloads.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The tabs are driven the way the host drives them: each binding is looked
|
||||
/// up by the name the markup gives it and read or invoked by reflection.
|
||||
/// </remarks>
|
||||
public sealed class OneWindowTests
|
||||
{
|
||||
private const uint OriginalIcon = 0x06001E37;
|
||||
|
||||
private static PluginHarness WithUi()
|
||||
{
|
||||
var harness = new PluginHarness(arrange: host => host.HasUi = true);
|
||||
harness.Login();
|
||||
return harness;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_plugin_bar_gets_one_button_MM_with_the_original_icon()
|
||||
{
|
||||
using PluginHarness harness = WithUi();
|
||||
|
||||
RegisteredPanel shelf = Assert.Single(harness.Host.Ui.Panels, panel => panel.Descriptor.ShowInSidePanel);
|
||||
Assert.Equal("main", shelf.Descriptor.WindowId);
|
||||
Assert.Equal("MM", shelf.Descriptor.IconText);
|
||||
Assert.Equal(OriginalIcon, shelf.Descriptor.IconSurfaceId);
|
||||
Assert.EndsWith(MainWindow.MarkupFile, shelf.MarkupPath, StringComparison.Ordinal);
|
||||
Assert.IsType<MainWindow>(shelf.Binding);
|
||||
|
||||
// The only other window is the tracker, opened from its tab.
|
||||
RegisteredPanel other = Assert.Single(harness.Host.Ui.Panels, panel => !panel.Descriptor.ShowInSidePanel);
|
||||
Assert.Equal("flagtracker", other.Descriptor.WindowId);
|
||||
Assert.Equal(2, harness.Host.Ui.Panels.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_main_window_has_the_original_tabs_plus_metas()
|
||||
{
|
||||
XElement root = LoadMain();
|
||||
|
||||
string[] tabs = [.. root.Elements("tab").Select(tab => (string?)tab.Attribute("text") ?? string.Empty)];
|
||||
Assert.Equal(["Main", "Settings", "Statistics", "Mossy Tracker", "Metas", "Tools"], tabs);
|
||||
foreach (string tab in tabs)
|
||||
Assert.NotNull(PageOf(root, tab));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_mossy_tracker_tab_opens_the_tracker_window()
|
||||
{
|
||||
using PluginHarness harness = WithUi();
|
||||
MainWindow window = harness.Feature<MainWindow>();
|
||||
FlagTrackerViewModel tracker = harness.Feature<FlagTrackerFeature>().Panel!;
|
||||
XElement page = PageOf(LoadMain(), "Mossy Tracker")!;
|
||||
|
||||
XElement tab = LoadMain().Elements("tab").Single(t => (string?)t.Attribute("text") == "Mossy Tracker");
|
||||
Invoke(window, (string?)tab.Attribute("onclick"));
|
||||
Assert.True(Read<bool>(window, (string?)page.Attribute("visible")));
|
||||
|
||||
XElement button = Assert.Single(page.Elements("button"), b => (string?)b.Attribute("text") == "Open Mossy Tracker");
|
||||
Assert.False(tracker.IsVisible);
|
||||
Invoke(window, (string?)button.Attribute("onclick"));
|
||||
|
||||
Assert.True(tracker.IsVisible);
|
||||
Assert.Equal(["flagtracker"], harness.Host.Ui.ShowPanelCalls);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_metas_tab_is_bound_to_the_meta_sync_and_names_the_real_folders()
|
||||
{
|
||||
using PluginHarness harness = WithUi();
|
||||
MainWindow window = harness.Feature<MainWindow>();
|
||||
MetasViewModel metas = harness.Feature<MetaSyncFeature>().Panel!;
|
||||
XElement page = PageOf(LoadMain(), "Metas")!;
|
||||
|
||||
// The file list, its search and the download buttons are all here.
|
||||
XElement list = Assert.Single(page.Elements("list"));
|
||||
string[] columnItems = [.. list.Elements("column").Select(column => (string?)column.Attribute("items") ?? string.Empty)];
|
||||
Assert.Equal(3, columnItems.Length);
|
||||
Assert.Equal(["No files loaded"], Read<IReadOnlyList<string>>(window, columnItems[1]));
|
||||
Assert.Single(page.Elements("field"), field => (string?)field.Attribute("onchange") is not null);
|
||||
string[] buttons = [.. page.Elements("button").Select(b => (string?)b.Attribute("text") ?? string.Empty)];
|
||||
Assert.Contains("Refresh List", buttons);
|
||||
Assert.Contains("Check Updates", buttons);
|
||||
Assert.Contains("Download Outdated", buttons);
|
||||
Assert.Contains("Download", buttons);
|
||||
|
||||
// The labels name the folders the automation plugin loads from.
|
||||
string vtankRoot = harness.Host.VtankProfiles.RootPath!;
|
||||
string[] labels = [.. page.Elements("label").Select(label => Text(window, (string?)label.Attribute("text")))];
|
||||
Assert.Contains(labels, text => text.EndsWith(Path.Combine(vtankRoot, "mosstank", "metas"), StringComparison.Ordinal));
|
||||
Assert.Contains(labels, text => text.EndsWith(Path.Combine(vtankRoot, "mosstank", "navs"), StringComparison.Ordinal));
|
||||
|
||||
// Typing in the tab's search reaches the meta sync and redraws the list.
|
||||
XElement search = page.Elements("field").Single(f => (string?)f.Attribute("onchange") is not null);
|
||||
Invoke(window, (string?)search.Attribute("onchange"), "zzz");
|
||||
Assert.Equal("zzz", metas.SearchText);
|
||||
Assert.Equal(["No matches"], Read<IReadOnlyList<string>>(window, columnItems[1]));
|
||||
Assert.Equal("zzz", Text(window, (string?)search.Attribute("text")));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_metas_tab_changes_the_repository_address()
|
||||
{
|
||||
using PluginHarness harness = WithUi();
|
||||
MainWindow window = harness.Feature<MainWindow>();
|
||||
XElement page = PageOf(LoadMain(), "Metas")!;
|
||||
XElement field = Assert.Single(page.Elements("field"), f => (string?)f.Attribute("onsubmit") is not null);
|
||||
|
||||
Assert.Equal(MetaSyncManager.DefaultRepositoryUrl, Text(window, (string?)field.Attribute("text")));
|
||||
Invoke(window, (string?)field.Attribute("onsubmit"), " https://example.org/club/metas ");
|
||||
Assert.Equal("https://example.org/club/metas", harness.Context.Settings.Current.MetasRepositoryUrl);
|
||||
Assert.Equal("https://example.org/club/metas", Text(window, (string?)field.Attribute("text")));
|
||||
}
|
||||
|
||||
// ── markup helpers ──
|
||||
|
||||
private static XElement LoadMain() =>
|
||||
XDocument.Load(Path.Combine(AppContext.BaseDirectory, MainWindow.MarkupFile)).Root!;
|
||||
|
||||
/// <summary>The group a tab shows: the one whose visibility is the tab's selected binding.</summary>
|
||||
private static XElement? PageOf(XElement root, string tabText)
|
||||
{
|
||||
XElement? tab = root.Elements("tab").SingleOrDefault(t => (string?)t.Attribute("text") == tabText);
|
||||
string? selected = (string?)tab?.Attribute("selected");
|
||||
return selected is null
|
||||
? null
|
||||
: root.Elements("group").SingleOrDefault(group => (string?)group.Attribute("visible") == selected);
|
||||
}
|
||||
|
||||
private static PropertyInfo Property(object binding, string? expression)
|
||||
{
|
||||
Assert.NotNull(expression);
|
||||
Assert.Matches("^\\{[^{}]+\\}$", expression);
|
||||
PropertyInfo? property = binding.GetType().GetProperty(expression[1..^1]);
|
||||
Assert.True(property is not null, $"{expression} names no public property on {binding.GetType().Name}.");
|
||||
return property;
|
||||
}
|
||||
|
||||
private static T Read<T>(object binding, string? expression) =>
|
||||
Assert.IsAssignableFrom<T>(Property(binding, expression).GetValue(binding));
|
||||
|
||||
/// <summary>A label's text: the literal, or the bound value.</summary>
|
||||
private static string Text(object binding, string? text) =>
|
||||
text is not null && text.StartsWith('{') ? Read<object>(binding, text).ToString() ?? string.Empty : text ?? string.Empty;
|
||||
|
||||
private static void Invoke(object binding, string? expression) =>
|
||||
Read<Action>(binding, expression)();
|
||||
|
||||
private static void Invoke(object binding, string? expression, string argument) =>
|
||||
Read<Action<string>>(binding, expression)(argument);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue