Add unit tests for dynamic group mode handling and exclusions
ci / build-backend (push) Successful in 1m36s
ci / build-frontend (push) Successful in 59s
ci / tests (push) Successful in 1m38s
ci / sonar (push) Successful in 4m5s

Implemented several unit tests to validate the behavior of dynamic group modes, including the preservation of pinned items when switching to dynamic mode, the dropping of exclusions when reverting to static mode, and the default pinning of new elements in dynamic groups. Additional tests ensure that exclusions are correctly applied and removed, and that static groups refuse exclusions. These tests enhance the coverage and reliability of the group management functionality.
This commit is contained in:
Leonid Pershin
2026-07-27 06:37:10 +03:00
parent 97fa77287f
commit f8923b5275
8 changed files with 1230 additions and 0 deletions
@@ -101,4 +101,93 @@ public class GroupTests
Assert.Equal(TimeSpan.FromHours(18), group.TotalDuration);
Assert.Equal(at, group.StatsComputedAt);
}
[Fact]
public void SetMode_ToDynamic_KeepsItemsAsPinned()
{
// Смена режима не должна вымывать из эфира то, что уже стояло в слотах.
var group = Group.Create("Боевики");
var show = Guid.NewGuid();
group.AddElement(GroupElementKind.Show, show);
group.SetMode(GroupMode.Dynamic);
Assert.Equal(GroupMode.Dynamic, group.Mode);
Assert.Equal(GroupItemRole.Pinned, group.Items.Single().Role);
}
[Fact]
public void SetMode_BackToStatic_DropsExclusionsAndUnpins()
{
var group = Group.Create("Боевики");
group.SetMode(GroupMode.Dynamic);
group.AddElement(GroupElementKind.Show, Guid.NewGuid());
group.Exclude(GroupElementKind.Show, Guid.NewGuid());
group.SetMode(GroupMode.Static);
// Исключать в статической группе нечего: состав и есть список.
var item = Assert.Single(group.Items);
Assert.Equal(GroupItemRole.Member, item.Role);
}
[Fact]
public void SetMode_SameMode_ChangesNothing()
{
var group = Group.Create("Боевики");
group.AddElement(GroupElementKind.Show, Guid.NewGuid());
group.SetMode(GroupMode.Static);
Assert.Equal(GroupItemRole.Member, group.Items.Single().Role);
}
[Fact]
public void AddElement_InDynamicGroup_PinsByDefault()
{
// Иначе правило вымело бы позицию на первом же обращении.
var group = Group.Create("Боевики");
group.SetMode(GroupMode.Dynamic);
var item = group.AddElement(GroupElementKind.Show, Guid.NewGuid());
Assert.Equal(GroupItemRole.Pinned, item!.Role);
}
[Fact]
public void Exclude_TurnsPinnedIntoExclusion()
{
// Держать на один элемент обе противоположные поправки нельзя.
var group = Group.Create("Боевики");
group.SetMode(GroupMode.Dynamic);
var show = Guid.NewGuid();
group.AddElement(GroupElementKind.Show, show);
Assert.True(group.Exclude(GroupElementKind.Show, show));
Assert.Equal(GroupItemRole.Excluded, group.Items.Single().Role);
}
[Fact]
public void Exclude_InStaticGroup_IsRefused()
{
var group = Group.Create("Боевики");
Assert.False(group.Exclude(GroupElementKind.Show, Guid.NewGuid()));
Assert.Empty(group.Items);
}
[Fact]
public void RemoveExclusion_ReturnsElementToTheRule()
{
var group = Group.Create("Боевики");
group.SetMode(GroupMode.Dynamic);
var show = Guid.NewGuid();
group.Exclude(GroupElementKind.Show, show);
Assert.True(group.RemoveExclusion(GroupElementKind.Show, show));
Assert.Empty(group.Items);
// Снимать нечего — второй раз это уже не поправка.
Assert.False(group.RemoveExclusion(GroupElementKind.Show, show));
}
}