82 lines
2.6 KiB
C#
82 lines
2.6 KiB
C#
using System.ComponentModel;
|
|
using Omika.App.Local.Models;
|
|
|
|
namespace Omika.Tests.Mobile.Local;
|
|
|
|
/// <summary>
|
|
/// L'état d'épinglage des éléments de liste (dossiers, clients, sites,
|
|
/// interventions) est OBSERVABLE : c'est ce qui permet de basculer l'étoile
|
|
/// immédiatement, sans reconstruire la liste affichée ni relire la base locale.
|
|
/// Ces tests verrouillent cette propriété, dont dépend la réactivité du bouton
|
|
/// « Épingler ».
|
|
/// </summary>
|
|
public class ListItemsEpinglageObservableTests
|
|
{
|
|
[Fact]
|
|
public void DossierListItem_IsPinned_NotifieUneSeuleFois()
|
|
{
|
|
var item = new DossierListItem { DossierGuid = Guid.NewGuid() };
|
|
var notifications = Collecter(item);
|
|
|
|
item.IsPinned = true;
|
|
item.IsPinned = true;
|
|
|
|
Assert.True(item.IsPinned);
|
|
Assert.Single(notifications);
|
|
Assert.Equal(nameof(DossierListItem.IsPinned), notifications[0]);
|
|
}
|
|
|
|
[Fact]
|
|
public void ClientListItem_IsPinned_NotifieUneSeuleFois()
|
|
{
|
|
var item = new ClientListItem { ClientGuid = Guid.NewGuid() };
|
|
var notifications = Collecter(item);
|
|
|
|
item.IsPinned = true;
|
|
item.IsPinned = false;
|
|
|
|
Assert.False(item.IsPinned);
|
|
Assert.Equal(2, notifications.Count);
|
|
Assert.All(notifications, n => Assert.Equal(nameof(ClientListItem.IsPinned), n));
|
|
}
|
|
|
|
[Fact]
|
|
public void SiteListItem_IsPinned_NotifieUneSeuleFois()
|
|
{
|
|
var item = new SiteListItem { SiteGuid = Guid.NewGuid() };
|
|
var notifications = Collecter(item);
|
|
|
|
item.IsPinned = true;
|
|
item.IsPinned = true;
|
|
|
|
Assert.True(item.IsPinned);
|
|
Assert.Single(notifications);
|
|
Assert.Equal(nameof(SiteListItem.IsPinned), notifications[0]);
|
|
}
|
|
|
|
[Fact]
|
|
public void InterventionCardItem_IsPinned_NotifieUneSeuleFois()
|
|
{
|
|
var item = new InterventionCardItem { InterventionGuid = Guid.NewGuid() };
|
|
var notifications = Collecter(item);
|
|
|
|
item.IsPinned = true;
|
|
item.IsPinned = true;
|
|
|
|
Assert.True(item.IsPinned);
|
|
Assert.Single(notifications);
|
|
Assert.Equal(nameof(InterventionCardItem.IsPinned), notifications[0]);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Abonne un collecteur de notifications et retourne la liste des noms de
|
|
/// propriétés notifiées (une valeur identique ne doit rien notifier).
|
|
/// </summary>
|
|
private static List<string?> Collecter(INotifyPropertyChanged source)
|
|
{
|
|
var notifications = new List<string?>();
|
|
source.PropertyChanged += (_, e) => notifications.Add(e.PropertyName);
|
|
return notifications;
|
|
}
|
|
}
|