513fa1aa16
Comment/XML-doc changes only: - add summaries to ~10k test methods, fixtures, fakes and helpers (+ <param> on theories, <returns> on async Task methods, <inheritdoc/> on interface implementations the checker can resolve) - strip ~2.6k project-tracking references (WP*, P*-*, row-NN, Task N, #NN, Component-0NN) from comments, keeping the explanatory text; reword false positives in comments only - real docs on fakes implementing BCL/library interfaces (IDisposable, ILogger, IOptionsMonitor, IAsyncLifetime) - reword the last 5 src/ false positives (CWE-1236, failures-1, year-0001, M365) Only non-comment edits: four one-line nested classes split across lines so members can carry docs. Build 0 errors / 0 warnings.
91 lines
3.5 KiB
C#
91 lines
3.5 KiB
C#
using Bunit;
|
|
using ZB.MOM.WW.ScadaBridge.CentralUI.Components.Shared;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.CentralUI.Tests.Shared;
|
|
|
|
/// <summary>
|
|
/// Tests for T34b's <see cref="DarkModeToggle"/>. The component is pure
|
|
/// JS-interop over <c>window.sbTheme</c> (theme.js): <c>sbTheme.get</c> reflects
|
|
/// the persisted theme on first render and <c>sbTheme.toggle</c> flips it on
|
|
/// click. The toggle carries the required a11y attributes
|
|
/// (<c>aria-label="Toggle dark mode"</c> + <c>aria-pressed</c>).
|
|
/// </summary>
|
|
public class DarkModeToggleTests : BunitContext
|
|
{
|
|
/// <summary>Initializes the bUnit context with loose JavaScript interop for the dark mode toggle.</summary>
|
|
public DarkModeToggleTests()
|
|
{
|
|
// Loose mode: unconfigured interop returns default. We configure the two
|
|
// calls the component actually makes (get on first render, toggle on click).
|
|
JSInterop.Mode = JSRuntimeMode.Loose;
|
|
}
|
|
|
|
/// <summary>Verifies that the toggle renders a button with the toggle dark mode aria label.</summary>
|
|
[Fact]
|
|
public void Renders_Button_WithToggleDarkModeAriaLabel()
|
|
{
|
|
JSInterop.Setup<string>("sbTheme.get").SetResult("light");
|
|
|
|
var cut = Render<DarkModeToggle>();
|
|
|
|
var button = cut.Find("button[aria-label='Toggle dark mode']");
|
|
Assert.NotNull(button);
|
|
}
|
|
|
|
/// <summary>Verifies that a persisted light preference renders the button with aria-pressed false on first render.</summary>
|
|
[Fact]
|
|
public void OnFirstRender_PersistedLight_AriaPressedFalse()
|
|
{
|
|
// sbTheme.get returns light → button reflects light (aria-pressed=false,
|
|
// moon glyph offering "switch to dark").
|
|
JSInterop.Setup<string>("sbTheme.get").SetResult("light");
|
|
|
|
var cut = Render<DarkModeToggle>();
|
|
|
|
var button = cut.Find("button.sb-theme-toggle");
|
|
Assert.Equal("false", button.GetAttribute("aria-pressed"));
|
|
Assert.NotNull(cut.Find("i.bi-moon-stars"));
|
|
}
|
|
|
|
/// <summary>Verifies that a persisted dark preference renders the button with aria-pressed true on first render.</summary>
|
|
[Fact]
|
|
public void OnFirstRender_PersistedDark_AriaPressedTrue()
|
|
{
|
|
// sbTheme.get returns dark → button reflects dark (aria-pressed=true,
|
|
// sun glyph offering "switch to light").
|
|
JSInterop.Setup<string>("sbTheme.get").SetResult("dark");
|
|
|
|
var cut = Render<DarkModeToggle>();
|
|
|
|
cut.WaitForAssertion(() =>
|
|
{
|
|
var button = cut.Find("button.sb-theme-toggle");
|
|
Assert.Equal("true", button.GetAttribute("aria-pressed"));
|
|
Assert.NotNull(cut.Find("i.bi-sun"));
|
|
});
|
|
}
|
|
|
|
/// <summary>Verifies that clicking the button invokes the toggle and reflects the new state.</summary>
|
|
[Fact]
|
|
public void Click_InvokesToggle_AndReflectsNewState()
|
|
{
|
|
// Start persisted-light; toggling returns "dark". The click handler must
|
|
// invoke sbTheme.toggle and flip aria-pressed/glyph to the dark state.
|
|
JSInterop.Setup<string>("sbTheme.get").SetResult("light");
|
|
var toggle = JSInterop.Setup<string>("sbTheme.toggle").SetResult("dark");
|
|
|
|
var cut = Render<DarkModeToggle>();
|
|
|
|
cut.Find("button.sb-theme-toggle").Click();
|
|
|
|
cut.WaitForAssertion(() =>
|
|
{
|
|
// The handler invoked sbTheme.toggle.
|
|
Assert.Single(toggle.Invocations);
|
|
var button = cut.Find("button.sb-theme-toggle");
|
|
Assert.Equal("true", button.GetAttribute("aria-pressed"));
|
|
Assert.NotNull(cut.Find("i.bi-sun"));
|
|
});
|
|
}
|
|
}
|