From 63e3da04b1775d81aa09c59e1b4502f43017f4e4 Mon Sep 17 00:00:00 2001 From: Shane Neuville Date: Mon, 23 Feb 2026 10:10:35 -0600 Subject: [PATCH 1/2] Fix QrCodeBlurTests and scenario to match independent QR toggles (showQrCode/showDirectQrCode) PR #194 introduced QR blur using showToken, but PR #197 subsequently replaced that with independent showQrCode/showDirectQrCode variables and dedicated qr-reveal-btn buttons. The tests were left asserting the old showToken-based behaviour, causing them to fail against current main. - Update QrCodeImages_UseBlurredClassFromShowTokenToggle to match the two independent variables (showQrCode, showDirectQrCode) with specific patterns per img src, replacing the fragile count-based regex check - Update TokenValue_UsesBlurredClassFromShowTokenToggle to assert the blur expression is specifically on the token-value element (not just anywhere in the file), preventing false positives from QR img tags - Extend ShowToken_DefaultsFalse to also verify showQrCode and showDirectQrCode default to false - Fix settings-qr-code-blur scenario: click .qr-code .qr-reveal-btn (not .tunnel-token .copy-btn) and assert QR+token are independent Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- PolyPilot.Tests/QrCodeBlurTests.cs | 27 +++++++++++-------- .../Scenarios/mode-switch-scenarios.json | 16 +++++------ 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/PolyPilot.Tests/QrCodeBlurTests.cs b/PolyPilot.Tests/QrCodeBlurTests.cs index 62ccff8aa1..6c2a9d9a11 100644 --- a/PolyPilot.Tests/QrCodeBlurTests.cs +++ b/PolyPilot.Tests/QrCodeBlurTests.cs @@ -25,17 +25,18 @@ private static string GetSettingsCssPath() } [Fact] - public void QrCodeImages_UseBlurredClassFromShowTokenToggle() + public void QrCodeImages_UseBlurredClassFromIndependentQrToggles() { var razorContent = File.ReadAllText(GetSettingsRazorPath()); - // Both QR code img tags should use the showToken toggle for blurred class - var qrImgPattern = new Regex(@"= 2, - $"Expected at least 2 QR code tags with showToken-based blur class, found {matches.Count}. " + - "Both tunnel and direct QR codes must be blurred when token is hidden."); + Assert.True(tunnelQrPattern.IsMatch(razorContent), + "Tunnel QR code must use showQrCode for the blurred class."); + Assert.True(directQrPattern.IsMatch(razorContent), + "Direct QR code must use showDirectQrCode for the blurred class."); } [Fact] @@ -43,8 +44,8 @@ public void TokenValue_UsesBlurredClassFromShowTokenToggle() { var razorContent = File.ReadAllText(GetSettingsRazorPath()); - // Token code element should also use showToken toggle - Assert.Contains(@"@(showToken ? """" : ""blurred"")", razorContent); + // Token code element must specifically use showToken toggle (independent from QR toggles) + Assert.Matches(@"class=""token-value @\(showToken \? """" : ""blurred""\)""", razorContent); } [Fact] @@ -54,9 +55,13 @@ public void ShowToken_DefaultsFalse() // showToken should be declared as bool (defaults to false) Assert.Matches(@"private\s+bool\s+showToken\s*;", razorContent); - - // It should NOT be initialized to true Assert.DoesNotMatch(@"private\s+bool\s+showToken\s*=\s*true", razorContent); + + // QR code toggles must also default to false + Assert.Matches(@"private\s+bool\s+showQrCode\s*;", razorContent); + Assert.Matches(@"private\s+bool\s+showDirectQrCode\s*;", razorContent); + Assert.DoesNotMatch(@"private\s+bool\s+showQrCode\s*=\s*true", razorContent); + Assert.DoesNotMatch(@"private\s+bool\s+showDirectQrCode\s*=\s*true", razorContent); } [Fact] diff --git a/PolyPilot.Tests/Scenarios/mode-switch-scenarios.json b/PolyPilot.Tests/Scenarios/mode-switch-scenarios.json index a338a15112..53d0d006f0 100644 --- a/PolyPilot.Tests/Scenarios/mode-switch-scenarios.json +++ b/PolyPilot.Tests/Scenarios/mode-switch-scenarios.json @@ -828,7 +828,7 @@ }, { "id": "settings-qr-code-blur", - "name": "QR code is blurred by default alongside token", + "name": "QR code and token have independent blur toggles", "steps": [ { "action": "note", @@ -840,7 +840,7 @@ "expect": { "equals": true }, - "note": "QR code image is blurred by default (showToken=false)" + "note": "QR code image is blurred by default (showQrCode=false)" }, { "action": "evaluate", @@ -848,12 +848,12 @@ "expect": { "equals": true }, - "note": "Token value is also blurred by default" + "note": "Token value is also blurred by default (showToken=false)" }, { "action": "click", - "selector": ".tunnel-token .copy-btn", - "note": "Click reveal/hide token button" + "selector": ".qr-code .qr-reveal-btn", + "note": "Click the QR-specific reveal button (independent from token reveal)" }, { "action": "evaluate", @@ -861,15 +861,15 @@ "expect": { "equals": false }, - "note": "QR code is revealed when token is shown" + "note": "QR code is revealed after clicking its own reveal button" }, { "action": "evaluate", "script": "document.querySelector('.token-value')?.classList.contains('blurred')", "expect": { - "equals": false + "equals": true }, - "note": "Token is also revealed" + "note": "Token remains blurred — QR and token toggles are independent" } ] } From 715a9f2b280ff5fcc0f46112365d669425cc0b80 Mon Sep 17 00:00:00 2001 From: Shane Neuville Date: Mon, 23 Feb 2026 10:46:41 -0600 Subject: [PATCH 2/2] Polish QrCodeBlurTests: fix stale docstring, rename test, improve regex tolerance - Update class docstring to reflect independent toggles (showQrCode, showDirectQrCode, showToken) rather than the old 'when showToken is false' - Rename ShowToken_DefaultsFalse -> AllBlurToggles_DefaultFalse to match its expanded scope (tests all three bool fields) - Replace rigid positional regex patterns with ]*src=...[^>]*class=...> so adding/reordering attributes on the img element doesn't break the test Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- PolyPilot.Tests/QrCodeBlurTests.cs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/PolyPilot.Tests/QrCodeBlurTests.cs b/PolyPilot.Tests/QrCodeBlurTests.cs index 6c2a9d9a11..ebff8bf995 100644 --- a/PolyPilot.Tests/QrCodeBlurTests.cs +++ b/PolyPilot.Tests/QrCodeBlurTests.cs @@ -3,9 +3,10 @@ namespace PolyPilot.Tests; /// -/// Tests that verify the QR code images in Settings are blurred by default -/// (when showToken is false), matching the token's blur behavior. -/// Since these are Blazor components, we verify the source markup contracts. +/// Tests that verify QR code images and the token value in Settings are blurred +/// by default, each controlled by an independent toggle (showQrCode, +/// showDirectQrCode, showToken). Since these are Blazor components, we verify +/// the source markup contracts. /// public class QrCodeBlurTests { @@ -29,9 +30,10 @@ public void QrCodeImages_UseBlurredClassFromIndependentQrToggles() { var razorContent = File.ReadAllText(GetSettingsRazorPath()); - // Each QR code img tag must use its own independent toggle for the blurred class - var tunnelQrPattern = new Regex(@"]* between attributes so harmless additions/reordering don't break the test. + var tunnelQrPattern = new Regex(@"]*src=""@qrCodeDataUri""[^>]*class=""@\(showQrCode \? """" : ""blurred""\)"""); + var directQrPattern = new Regex(@"]*src=""@directQrCodeDataUri""[^>]*class=""@\(showDirectQrCode \? """" : ""blurred""\)"""); Assert.True(tunnelQrPattern.IsMatch(razorContent), "Tunnel QR code must use showQrCode for the blurred class."); @@ -49,7 +51,7 @@ public void TokenValue_UsesBlurredClassFromShowTokenToggle() } [Fact] - public void ShowToken_DefaultsFalse() + public void AllBlurToggles_DefaultFalse() { var razorContent = File.ReadAllText(GetSettingsRazorPath());