<commit_before>using System;
using System.Collections.Generic;
using System.Linq;
using Content.Client.UserInterface.Controls;
using NUnit.Framework;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.UnitTesting;

namespace Content.Tests.Client.UserInterface.Controls;

[TestFixture]
[TestOf(typeof(ListContainer))]
public sealed class ListContainerTest : RobustUnitTest
{
    public override UnitTestProject Project => UnitTestProject.Client;

    private record TestListData(int Id) : ListData;

    [OneTimeSetUp]
    public void Setup()
    {
        IoCManager.Resolve<IUserInterfaceManager>().InitializeTesting();
    }

    [Test]
    public void TestLayoutBasic()
    {
        var root = new Control { MinSize = (50, 60) };
        var listContainer = new ListContainer { SeparationOverride = 3 };
        root.AddChild(listContainer);
        listContainer.GenerateItem += (_, button) => {
            button.AddChild(new Control { MinSize = (10, 10) });
        };

        var list = new List<TestListData> {new(0), new(1)};
        listContainer.PopulateList(list);
        root.Arrange(new UIBox2(0, 0, 50, 60));

        Assert.That(listContainer.ChildCount, Is.EqualTo(3));
        var children = listContainer.Children.ToList();
        Assert.That(children[0].Height, Is.EqualTo(10));
        Assert.That(children[1].Height, Is.EqualTo(10));

        Assert.That(children[0].Position.Y, Is.EqualTo(0));
        Assert.That(children[1].Position.Y, Is.EqualTo(13)); // Item height + separation
    }

    [Test]
    public void TestOnlyVisibleItemsAreAdded()
    {
        /*
         * 6 items * 10 height + 5 separation * 3 height = 75
         * One items should be off the render
         * 0 13 26 39 52 65 | 75 height
         */
        var root = new Control { MinSize = (50, 60) };
        var listContainer = new ListContainer { SeparationOverride = 3 };
        root.AddChild(listContainer);
        listContainer.GenerateItem += (_, button) => {
            button.AddChild(new Control { MinSize = (10, 10) });
        };

        var list = new List<TestListData> {new(0), new(1), new(2), new(3), new(4), new(5)};
        listContainer.PopulateList(list);
        root.Arrange(new UIBox2(0, 0, 50, 60));

        // 6 ControlData<commit_msg>Add test for empty ListContainer (#11297)<commit_after>using System;
using System.Collections.Generic;
using System.Linq;
using Content.Client.UserInterface.Controls;
using NUnit.Framework;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.UnitTesting;

namespace Content.Tests.Client.UserInterface.Controls;

[TestFixture]
[TestOf(typeof(ListContainer))]
public sealed class ListContainerTest : RobustUnitTest
{
    public override UnitTestProject Project => UnitTestProject.Client;

    private record TestListData(int Id) : ListData;

    [OneTimeSetUp]
    public void Setup()
    {
        IoCManager.Resolve<IUserInterfaceManager>().InitializeTesting();
    }

    [Test]
    public void TestLayoutBasic()
    {
        var root = new Control { MinSize = (50, 60) };
        var listContainer = new ListContainer { SeparationOverride = 3 };
        root.AddChild(listContainer);
        listContainer.GenerateItem += (_, button) => {
            button.AddChild(new Control { MinSize = (10, 10) });
        };

        var list = new List<TestListData> {new(0), new(1)};
        listContainer.PopulateList(list);
        root.Arrange(new UIBox2(0, 0, 50, 60));

        Assert.That(listContainer.ChildCount, Is.EqualTo(3));
        var children = listContainer.Children.ToList();
        Assert.That(children[0].Height, Is.EqualTo(10));
        Assert.That(children[1].Height, Is.EqualTo(10));

        Assert.That(children[0].Position.Y, Is.EqualTo(0));
        Assert.That(children[1].Position.Y, Is.EqualTo(13)); // Item height + separation
    }

    [Test]
    public void TestCreatePopulateAndEmpty()
    {
        const int x = 50;
        const int y = 10;
        var root = new Control { MinSize = (x, y) };
        var listContainer = new ListContainer { SeparationOverride = 3 };
        root.AddChild(listContainer);
        listContainer.GenerateItem += (_, button) => {
            button.AddChild(new Control { MinSize = (10, 10) });
        };

        var list = new List<TestListData>();
        listContainer.PopulateList(list);
        root.Arrange(new UIBox2(0, 0, x, y));

        list.Add(new(0));
        list.Add(new (1));
        listContainer.PopulateList(list);
        root.Arrange(new UIBox2(0, 0, x, y));

        list.Clear();
        listContainer.PopulateList(list);
        root.Arrange(new UIBox2(0, 0, x, y));
    }

    [Test]
    public void TestOnlyVisibleItemsAreAdded()
    {
        /*
         * 6 items * 10 height + 5 separation * 3 height = 75
         * One items should be off the render
         * 0 13 26 39 52 65 | 75 height
         */
        var root = new Control { MinSize = (50, 60) };
        var listContainer = new ListContainer { SeparationOverride = 3 };
        root.AddChild(listContainer);
        listContainer.GenerateItem += (_, button) => {
            button.AddChild(new Control { MinSize = (10, 10) });
        };

        var list = new List<TestListData> {new(0), new(1), new(2), new(3), new(4), new(5)};
        listContainer.PopulateList(list);
        root.Arrange(new UIBox2(0, 0, 50, 60));

        // 6 ControlData
{'fraction_non_alphanumeric': 0.12553956834532373, 'fraction_numerical': 0.030755395683453236, 'mean_word_length': 2.7829931972789117, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5831064', 'n_tokens_mistral': 1763, 'n_tokens_neox': 1651, 'n_words': 391}