Files
LlamaCasty/ytLive.Tests/EntitlementTests.cs
T
gramps a80108dd96 feat(ui): left-panel alert stack — licence indicator pinned on top, events LIFO below
Creator design (2026-11-05). A stack of red rows at the top of the left panel, above both mode grids
so it shows while editing and while live, pushing the panel's content down.

- Row 1 is the **Steam licence indicator** and nothing displaces it. It reads as status, not a
  warning: "Entitlement 30 fps · Maximum 60 fps", both numbers derived from QualityOptions and
  HasProOutput. While higher tiers are unavailable it shows a **pin** (standing indicator, no close
  control); once ownership is verified the pin becomes a **close control** and the dismissal is
  persisted (`Steam.LicenceIndicatorDismissed`), permanent while ownership holds. Losing ownership
  restores it as pinned — a change of state, not a preference. Click → About.
- **Event rows stack beneath, newest first**, one row per episode (an episode advancing its state
  updates its own row rather than adding another). Each is dismissible. Click → the Logs tab opens
  with that event's sequence range painted red (`HighlightedLogFrom/To` + `LogInRangeConverter`; two
  numbers rather than a collection because the log list is virtualised and realised rows do not
  re-evaluate on membership changes).
- Replaces the old red panel under the quality picker, which is removed.
- The Steam diagnostic text loses "Contact the creator or support" for a neutral
  "Steam licensing is not configured in this build."

Tests: `AttentionAlertStackTests` — pinned first with the status text; owned → closable and the close
survives a reload but ownership loss restores it pinned; pinned cannot be dismissed; event rows LIFO
with in-place episode updates; clicking an event opens Logs and sets its range. AboutHub + Entitlement
tests updated for the removed panel and the new wording. FAST gate: 532 passed, 0 failed, 0 warnings.
2026-11-05 11:41:59 -08:00

103 lines
3.3 KiB
C#

using System;
using System.IO;
using Xunit;
using ytLive.Services.Entitlement;
using ytLive.ViewModels;
namespace ytLive.Tests;
/// <summary>
/// Steam ownership is cached once into the app-wide binary flag.
///
/// <para>The rule that must never break: a missing paid app ID, Steam client, or native library
/// fails closed.</para>
/// </summary>
// Shares the static MainViewModel.LayoutPathOverride with the sibling class; without a
// shared collection xUnit runs them in parallel and the two view models fight over one temp DB.
[Collection("MainViewModelLayoutPath")]
public class EntitlementTests
{
[Fact]
public void No_configured_paid_app_id_reads_as_not_owned()
{
var entitlement = SteamEntitlement.NotConfigured();
Assert.False(entitlement.IsAppOwned);
// The diagnostic is deliberately neutral (2026-11-05): the licence state is shown to the
// creator as a status indicator, so the log text carries no "contact support" wording.
Assert.Contains("Steam licensing is not configured", entitlement.ErrorMessage);
}
[Fact]
public void Steam_ownership_checks_the_paid_app_id()
{
const uint paidAppId = 1234567u;
uint queriedAppId = 0;
var entitlement = new SteamEntitlement(
paidAppId,
initializeSteam: () => true,
isAppSubscribed: appId =>
{
queriedAppId = appId;
return true;
},
shutdownSteam: () => { });
Assert.True(entitlement.IsAppOwned);
Assert.Equal(paidAppId, queriedAppId);
Assert.Null(entitlement.ErrorMessage);
}
[Fact]
public void A_steam_entitlement_without_a_client_fails_closed()
{
var entitlement = new SteamEntitlement(1234567u, () => false, _ => true, () => { });
Assert.False(entitlement.IsAppOwned);
Assert.Contains("Open Steam", entitlement.ErrorMessage);
}
[Fact]
public void A_valid_steam_check_for_an_unowned_account_is_not_an_authentication_error()
{
var entitlement = new SteamEntitlement(1234567u, () => true, _ => false, () => { });
Assert.False(entitlement.IsAppOwned);
Assert.Null(entitlement.ErrorMessage);
}
[Fact]
public void The_fake_reports_what_a_test_sets()
{
var fake = new FakeEntitlement(true);
Assert.True(fake.IsAppOwned);
fake.IsAppOwned = false;
Assert.False(fake.IsAppOwned);
}
[Fact]
public void The_view_model_takes_its_answer_from_the_rail()
{
var tempDb = Path.Combine(Path.GetTempPath(), $"llamacasty-entitlement-{Guid.NewGuid():N}.db");
MainViewModel.LayoutPathOverride = tempDb;
try
{
var vm = new MainViewModel();
Assert.True(vm.IsAppOwned);
Assert.True(vm.HasProOutput);
vm.EntitlementOverride = new FakeEntitlement(false);
Assert.False(vm.IsAppOwned);
Assert.False(vm.HasProOutput);
vm.EntitlementOverride = new FakeEntitlement(true);
Assert.True(vm.IsAppOwned);
Assert.True(vm.HasProOutput);
}
finally
{
MainViewModel.LayoutPathOverride = null;
try { File.Delete(tempDb); } catch (IOException) { }
}
}
}