Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 22 additions & 15 deletions PolyPilot.Tests/QrCodeBlurTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
namespace PolyPilot.Tests;

/// <summary>
/// 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.
/// </summary>
public class QrCodeBlurTests
{
Expand All @@ -25,38 +26,44 @@ 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(@"<img\s+src=""@(qrCodeDataUri|directQrCodeDataUri)""\s+alt=""QR Code""\s+class=""@\(showToken \? """" : ""blurred""\)""");
var matches = qrImgPattern.Matches(razorContent);
// Each QR code img tag must use its own independent toggle for the blurred class.
// Use [^>]* between attributes so harmless additions/reordering don't break the test.
var tunnelQrPattern = new Regex(@"<img\b[^>]*src=""@qrCodeDataUri""[^>]*class=""@\(showQrCode \? """" : ""blurred""\)""");
var directQrPattern = new Regex(@"<img\b[^>]*src=""@directQrCodeDataUri""[^>]*class=""@\(showDirectQrCode \? """" : ""blurred""\)""");

Assert.True(matches.Count >= 2,
$"Expected at least 2 QR code <img> 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 <img> must use showQrCode for the blurred class.");
Assert.True(directQrPattern.IsMatch(razorContent),
"Direct QR code <img> must use showDirectQrCode for the blurred class.");
}

[Fact]
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]
public void ShowToken_DefaultsFalse()
public void AllBlurToggles_DefaultFalse()
{
var razorContent = File.ReadAllText(GetSettingsRazorPath());

// 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]
Expand Down
16 changes: 8 additions & 8 deletions PolyPilot.Tests/Scenarios/mode-switch-scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -840,36 +840,36 @@
"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",
"script": "document.querySelector('.token-value')?.classList.contains('blurred')",
"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",
"script": "document.querySelector('.qr-code img')?.classList.contains('blurred')",
"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"
}
]
}
Expand Down