using NUnit.Framework;

namespace e_suite.Modules.FormsManagerUnitTests.FormsManagerUnitTests;

[TestFixture]
public class GetCustomFieldsFromDefinitionUnitTests : FormsManagerUnitTestBase
{

    [SetUp]
    public async Task SetUp()
    {
        await base.Setup();
    }

    [Test]
    public async Task GetCustomFieldsFromDefinition_ExtractsFieldInfoFromDefinition()
    {
        //Arrange
        var formDefinition = "<span fieldType=\"CustomField\" guid=\"7e826fe9-1fe2-4a7d-82bd-d510773e9761\" /><span fieldType=\"CustomField\" guid=\"a681c714-500c-4036-8470-40f8f107bfa0\" />";

        //Act
        var result = await FormsManager.FormsManager.GetCustomFieldsFromDefinition(formDefinition);

        //Assert
        Assert.Multiple(() =>
        {
            Assert.That(result, Is.Not.Null);
            Assert.That(result, Has.Count.EqualTo(2));
            Assert.That(result[0].Guid, Is.EqualTo(new Guid("7e826fe9-1fe2-4a7d-82bd-d510773e9761")));
            Assert.That(result[1].Guid, Is.EqualTo(new Guid("a681c714-500c-4036-8470-40f8f107bfa0")));
        });
    }

    [Test]
    public async Task GetCustomFieldsFromDefinition_DoesNotReturnsValuesThatAreNotCustomFields()
    {
        //Arrange
        var formDefinition = "<span /><span fieldType=\"SomethingElse\" guid=\"a681c714-500c-4036-8470-40f8f107bfa0\" /><div/>";

        //Act
        var result = await FormsManager.FormsManager.GetCustomFieldsFromDefinition(formDefinition);

        //Assert
        Assert.That(result, Is.Not.Null);
        Assert.That(result, Has.Count.EqualTo(0));
    }
}