Skip to content

Commit

Permalink
bring over complex form tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hahn-kev committed Nov 5, 2024
1 parent 98286fc commit b8391eb
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using FwDataMiniLcmBridge.Tests.Fixtures;

namespace FwDataMiniLcmBridge.Tests.MiniLcmTests;

[Collection(ProjectLoaderFixture.Name)]
public class ComplexFormComponentTests(ProjectLoaderFixture fixture): ComplexFormComponentTestsBase
{
protected override Task<IMiniLcmApi> NewApi()
{
return Task.FromResult<IMiniLcmApi>(fixture.NewProjectApi("complex-form-component-test", "en", "en"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@
DerivedType: RemoveComplexFormTypeChange,
TypeDiscriminator: RemoveComplexFormTypeChange
},
{
DerivedType: SetComplexFormComponentChange,
TypeDiscriminator: SetComplexFormComponentChange
},
{
DerivedType: CreateComplexFormType,
TypeDiscriminator: CreateComplexFormType
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace LcmCrdt.Tests.MiniLcmTests;

public class ComplexFormComponentTests : ComplexFormComponentTestsBase
{
private readonly MiniLcmApiFixture _fixture = new();

protected override async Task<IMiniLcmApi> NewApi()
{
await _fixture.InitializeAsync();
var api = _fixture.Api;
return api;
}

public override async Task DisposeAsync()
{
await base.DisposeAsync();
await _fixture.DisposeAsync();
}
}
77 changes: 77 additions & 0 deletions backend/FwLite/MiniLcm.Tests/ComplexFormComponentTestsBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using MiniLcm.Models;

namespace MiniLcm.Tests;

public abstract class ComplexFormComponentTestsBase : MiniLcmTestBase
{
private readonly Guid _complexFormEntryId = Guid.NewGuid();
private readonly Guid _componentEntryId = Guid.NewGuid();
private readonly Guid _componentSenseId1 = Guid.NewGuid();
private readonly Guid _componentSenseId2 = Guid.NewGuid();
private Entry _complexFormEntry = null!;
private Entry _componentEntry = null!;

public override async Task InitializeAsync()
{
await base.InitializeAsync();
_complexFormEntry = await Api.CreateEntry(new()
{
Id = _complexFormEntryId,
LexemeForm = { { "en", "complex form" } }
});
_componentEntry = await Api.CreateEntry(new()
{
Id = _componentEntryId,
LexemeForm = { { "en", "component" } },
Senses =
[
new Sense
{
Id = _componentSenseId1,
Gloss = { { "en", "component sense 1" } }
},
new Sense
{
Id = _componentSenseId2,
Gloss = { { "en", "component sense 2" } }
}
]
});
}

[Fact]
public async Task CreateComplexFormComponent_Works()
{
var component = await Api.CreateComplexFormComponent(ComplexFormComponent.FromEntries(_complexFormEntry, _componentEntry));
component.ComplexFormEntryId.Should().Be(_complexFormEntryId);
component.ComponentEntryId.Should().Be(_componentEntryId);
component.ComponentSenseId.Should().BeNull();
component.ComplexFormHeadword.Should().Be("complex form");
component.ComponentHeadword.Should().Be("component");
}

[Fact]
public async Task CreateComplexFormComponent_WorksWithSense()
{
var component = await Api.CreateComplexFormComponent(ComplexFormComponent.FromEntries(_complexFormEntry, _componentEntry, _componentSenseId1));
component.ComplexFormEntryId.Should().Be(_complexFormEntryId);
component.ComponentEntryId.Should().Be(_componentEntryId);
component.ComponentSenseId.Should().Be(_componentSenseId1);
component.ComplexFormHeadword.Should().Be("complex form");
component.ComponentHeadword.Should().Be("component");
}

[Fact]
public async Task CreateComplexFormComponent_CanCreateMultipleComponentSenses()
{
var component1 = await Api.CreateComplexFormComponent(ComplexFormComponent.FromEntries(_complexFormEntry, _componentEntry, _componentSenseId1));
component1.ComplexFormEntryId.Should().Be(_complexFormEntryId);
component1.ComponentEntryId.Should().Be(_componentEntryId);
component1.ComponentSenseId.Should().Be(_componentSenseId1);

var component2 = await Api.CreateComplexFormComponent(ComplexFormComponent.FromEntries(_complexFormEntry, _componentEntry, _componentSenseId2));
component2.ComplexFormEntryId.Should().Be(_complexFormEntryId);
component2.ComponentEntryId.Should().Be(_componentEntryId);
component2.ComponentSenseId.Should().Be(_componentSenseId2);
}
}

0 comments on commit b8391eb

Please sign in to comment.