68945d931f
Two non-blocking suggestions from the PR #124 code review: 1. Symmetric coverage for the Discord PoolSlotCapacity no-limit button. The Capacity step already had a customId-shape assertion for the '♾ Без лимита' button; PoolSlotCapacity only had a label-presence assertion. If ChoiceButtonCustomId's wire format ever diverged between the two steps, only Capacity would catch it. Convert the single Fact to a Theory with two InlineData rows so a regression in either step produces a targeted test failure. 2. Brittle hard-coded version literal in NavMenu_ShouldExposeCurrent ProjectVersion. The test had to be hand-edited on every version bump (we hit this in PR #124 — bumping 3.9.2 -> 3.9.3 broke CI). Read the version from Directory.Build.props via XDocument instead so the test only fails when the rendered NavMenu actually disagrees with the canonical version, not when someone forgot to update a literal. Tolerant of whitespace, comments and attribute order; the <Version> element is a plain string body in the MSBuild schema. No production code changes; production version is bumped in a follow-up commit. Closes #125
67 lines
2.7 KiB
C#
67 lines
2.7 KiB
C#
using GmRelay.DiscordBot.Features.Sessions.Wizard;
|
|
using GmRelay.Shared.Features.Sessions.CreateSession.Wizard;
|
|
using NetCord.Rest;
|
|
using Xunit;
|
|
|
|
namespace GmRelay.Bot.Tests.Discord.Wizard;
|
|
|
|
/// <summary>
|
|
/// Renderer tests for the Discord wizard's Capacity / PoolSlotCapacity steps.
|
|
/// Locks in the presence of the "♾ Без лимита" button so the user can pick
|
|
/// a session with no player cap (null in <c>sessions.max_players</c>), the
|
|
/// same affordance the Telegram wizard provides.
|
|
/// </summary>
|
|
public sealed class DiscordWizardStepCapacityRenderTests
|
|
{
|
|
[Fact]
|
|
public void RenderCapacity_ContainsNoLimitButton()
|
|
{
|
|
var draft = new WizardDraft { Step = WizardStepNames.Capacity };
|
|
var render = DiscordWizardStep.Render(draft, new WizardPayload());
|
|
|
|
var labels = ExtractButtonLabels(render);
|
|
Assert.Contains(labels, l => l.Contains("Без лимита", System.StringComparison.Ordinal));
|
|
}
|
|
|
|
[Fact]
|
|
public void RenderPoolSlotCapacity_ContainsNoLimitButton()
|
|
{
|
|
var draft = new WizardDraft { Step = WizardStepNames.PoolSlotCapacity };
|
|
var render = DiscordWizardStep.Render(draft, new WizardPayload());
|
|
|
|
var labels = ExtractButtonLabels(render);
|
|
Assert.Contains(labels, l => l.Contains("Без лимита", System.StringComparison.Ordinal));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(WizardStepNames.Capacity, "wizard:btn:choice:Capacity:no_limit")]
|
|
[InlineData(WizardStepNames.PoolSlotCapacity, "wizard:btn:choice:PoolSlotCapacity:no_limit")]
|
|
public void Render_NoLimitButton_HasChoiceCustomIdForNoLimit(string step, string expectedCustomIdPrefix)
|
|
{
|
|
var draft = new WizardDraft { Step = step };
|
|
var render = DiscordWizardStep.Render(draft, new WizardPayload());
|
|
|
|
var buttons = ExtractButtons(render);
|
|
var noLimit = buttons.SingleOrDefault(b => b.Label?.Contains("Без лимита", System.StringComparison.Ordinal) == true);
|
|
Assert.NotNull(noLimit);
|
|
Assert.StartsWith(expectedCustomIdPrefix, noLimit!.CustomId);
|
|
}
|
|
|
|
private static System.Collections.Generic.List<string> ExtractButtonLabels(
|
|
DiscordWizardStep.DiscordWizardRender render) =>
|
|
render.Components
|
|
.OfType<ActionRowProperties>()
|
|
.SelectMany(r => r.Components)
|
|
.OfType<ButtonProperties>()
|
|
.Select(b => b.Label ?? string.Empty)
|
|
.ToList();
|
|
|
|
private static System.Collections.Generic.List<ButtonProperties> ExtractButtons(
|
|
DiscordWizardStep.DiscordWizardRender render) =>
|
|
render.Components
|
|
.OfType<ActionRowProperties>()
|
|
.SelectMany(r => r.Components)
|
|
.OfType<ButtonProperties>()
|
|
.ToList();
|
|
}
|