Browse Source
Fix NotificationCard pseudo class state when NotificationType changes (#21490)
* Fix NotificationCard pseudo class state when NotificationType changes
* Add test for NotificationCard pseudo-class updates
pull/21506/head
yoyo
4 months ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with
35 additions and
18 deletions
-
src/Avalonia.Controls/Notifications/NotificationCard.cs
-
tests/Avalonia.Controls.UnitTests/NotificationsTests.cs
|
|
@ -170,24 +170,10 @@ namespace Avalonia.Controls.Notifications |
|
|
|
|
|
|
|
|
private void UpdateNotificationType() |
|
|
private void UpdateNotificationType() |
|
|
{ |
|
|
{ |
|
|
switch (NotificationType) |
|
|
PseudoClasses.Set(":error", NotificationType == NotificationType.Error); |
|
|
{ |
|
|
PseudoClasses.Set(":information", NotificationType == NotificationType.Information); |
|
|
case NotificationType.Error: |
|
|
PseudoClasses.Set(":success", NotificationType == NotificationType.Success); |
|
|
PseudoClasses.Add(":error"); |
|
|
PseudoClasses.Set(":warning", NotificationType == NotificationType.Warning); |
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case NotificationType.Information: |
|
|
|
|
|
PseudoClasses.Add(":information"); |
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case NotificationType.Success: |
|
|
|
|
|
PseudoClasses.Add(":success"); |
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case NotificationType.Warning: |
|
|
|
|
|
PseudoClasses.Add(":warning"); |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
@ -113,4 +113,35 @@ namespace Avalonia.Controls.UnitTests |
|
|
Assert.True(!((WindowNotificationManager)manager).Notifications.Any(x => !x.IsClosing)); |
|
|
Assert.True(!((WindowNotificationManager)manager).Notifications.Any(x => !x.IsClosing)); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public class NotificationCardTests : ScopedTestBase |
|
|
|
|
|
{ |
|
|
|
|
|
[Fact] |
|
|
|
|
|
public void Should_Update_Pseudoclasses_When_NotificationType_Changes() |
|
|
|
|
|
{ |
|
|
|
|
|
var target = new NotificationCard(); |
|
|
|
|
|
|
|
|
|
|
|
target.NotificationType = NotificationType.Error; |
|
|
|
|
|
AssertPseudoClasses(target, ":error"); |
|
|
|
|
|
|
|
|
|
|
|
target.NotificationType = NotificationType.Information; |
|
|
|
|
|
AssertPseudoClasses(target, ":information"); |
|
|
|
|
|
|
|
|
|
|
|
target.NotificationType = NotificationType.Success; |
|
|
|
|
|
AssertPseudoClasses(target, ":success"); |
|
|
|
|
|
|
|
|
|
|
|
target.NotificationType = NotificationType.Warning; |
|
|
|
|
|
AssertPseudoClasses(target, ":warning"); |
|
|
|
|
|
|
|
|
|
|
|
static void AssertPseudoClasses(NotificationCard target, string expected) |
|
|
|
|
|
{ |
|
|
|
|
|
Assert.Contains(expected, target.Classes); |
|
|
|
|
|
|
|
|
|
|
|
foreach (var pseudoclass in new[] { ":error", ":information", ":success", ":warning" }.Where(x => x != expected)) |
|
|
|
|
|
{ |
|
|
|
|
|
Assert.DoesNotContain(pseudoclass, target.Classes); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|