Skip to content

Commit

Permalink
Complex forms in miniLcm (#1061)
Browse files Browse the repository at this point in the history
* add LcmDebugger CLI to be able open projects and inspect LCM stuff in the debugger

* add crdt support for Complex Forms

* write tests and support creating entries with complex forms or components

* add complex form type to miniLcm API, ensure complex forms get imported

* support updating LCM entry components via the components property
  • Loading branch information
hahn-kev authored Oct 11, 2024
1 parent c7e9364 commit cbcb6a1
Show file tree
Hide file tree
Showing 37 changed files with 1,835 additions and 53 deletions.
7 changes: 7 additions & 0 deletions LexBox.sln
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FwLiteProjectSync", "backen
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FwLiteProjectSync.Tests", "backend\FwLite\FwLiteProjectSync.Tests\FwLiteProjectSync.Tests.csproj", "{5352D1CC-14C5-4589-9389-731F55E4FFDF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LcmDebugger", "backend\LfNext\LcmDebugger\LcmDebugger.csproj", "{5A9011D8-6EC1-4550-BDD7-AFF00DB2B921}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -127,6 +129,10 @@ Global
{5352D1CC-14C5-4589-9389-731F55E4FFDF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5352D1CC-14C5-4589-9389-731F55E4FFDF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5352D1CC-14C5-4589-9389-731F55E4FFDF}.Release|Any CPU.Build.0 = Release|Any CPU
{5A9011D8-6EC1-4550-BDD7-AFF00DB2B921}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5A9011D8-6EC1-4550-BDD7-AFF00DB2B921}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5A9011D8-6EC1-4550-BDD7-AFF00DB2B921}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5A9011D8-6EC1-4550-BDD7-AFF00DB2B921}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -144,6 +150,7 @@ Global
{9001FE0F-DBBF-4A78-9EB9-9B5042CF8A78} = {7B6E21C4-5AF4-4505-B7D9-59A3886C5090}
{2245BAB6-753A-48AE-B929-6D8C35CB9804} = {7B6E21C4-5AF4-4505-B7D9-59A3886C5090}
{5352D1CC-14C5-4589-9389-731F55E4FFDF} = {7B6E21C4-5AF4-4505-B7D9-59A3886C5090}
{5A9011D8-6EC1-4550-BDD7-AFF00DB2B921} = {7B6E21C4-5AF4-4505-B7D9-59A3886C5090}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {440AE83C-6DB0-4F18-B2C1-BCD33F0645B6}
Expand Down
138 changes: 138 additions & 0 deletions backend/FwLite/FwDataMiniLcmBridge.Tests/CreateEntryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
using FwDataMiniLcmBridge.Api;
using FwDataMiniLcmBridge.Tests.Fixtures;
using MiniLcm.Models;

namespace FwDataMiniLcmBridge.Tests;

[Collection(ProjectLoaderFixture.Name)]
public class CreateEntryTests(ProjectLoaderFixture fixture) : IAsyncLifetime
{
private FwDataMiniLcmApi _api = null!;

public Task InitializeAsync()
{
var projectName = "create-entry-test_" + Guid.NewGuid();
fixture.MockFwProjectLoader.NewProject(projectName, "en", "en");
_api = fixture.CreateApi(projectName);
return Task.CompletedTask;
}

public Task DisposeAsync()
{
_api.Dispose();
return Task.CompletedTask;
}

[Fact]
public async Task CanCreateEntry()
{
var entry = await _api.CreateEntry(new() { LexemeForm = { { "en", "test" } } });
entry.Should().NotBeNull();
entry!.LexemeForm.Values.Should().ContainKey("en");
entry.LexemeForm.Values["en"].Should().Be("test");
}

[Fact]
public async Task CanCreate_WithComponentsProperty()
{
var component = await _api.CreateEntry(new() { LexemeForm = { { "en", "test component" } } });
var entryId = Guid.NewGuid();
var entry = await _api.CreateEntry(new()
{
Id = entryId,
LexemeForm = { { "en", "test" } },
Components =
[
new ComplexFormComponent()
{
ComponentEntryId = component.Id,
ComponentHeadword = component.Headword(),
ComplexFormEntryId = entryId,
ComplexFormHeadword = "test"
}
]
});
entry = await _api.GetEntry(entry.Id);
entry.Should().NotBeNull();
entry!.Components.Should().ContainSingle(c => c.ComponentEntryId == component.Id);
}

[Fact]
public async Task CanCreate_WithComplexFormsProperty()
{
var complexForm = await _api.CreateEntry(new() { LexemeForm = { { "en", "test complex form" } } });
var entryId = Guid.NewGuid();
var entry = await _api.CreateEntry(new()
{
Id = entryId,
LexemeForm = { { "en", "test" } },
ComplexForms =
[
new ComplexFormComponent()
{
ComponentEntryId = entryId,
ComponentHeadword = "test",
ComplexFormEntryId = complexForm.Id,
ComplexFormHeadword = "test complex form"
}
]
});
entry = await _api.GetEntry(entry.Id);
entry.Should().NotBeNull();
entry!.ComplexForms.Should().ContainSingle(c => c.ComplexFormEntryId == complexForm.Id);
}

[Fact]
public async Task CreateEntry_WithComponentSenseDoesNotShowOnEntryComplexFormsList()
{
var componentSenseId = Guid.NewGuid();
var component = await _api.CreateEntry(new()
{
LexemeForm = { { "en", "test component" } },
Senses = [new Sense() { Id = componentSenseId, Gloss = { { "en", "test component sense" } } }]
});
var complexFormEntryId = Guid.NewGuid();
await _api.CreateEntry(new()
{
Id = complexFormEntryId,
LexemeForm = { { "en", "test" } },
Components =
[
new ComplexFormComponent()
{
ComponentEntryId = component.Id,
ComponentHeadword = component.Headword(),
ComponentSenseId = componentSenseId,
ComplexFormEntryId = complexFormEntryId,
ComplexFormHeadword = "test"
}
]
});

var entry = await _api.GetEntry(component.Id);
entry.Should().NotBeNull();
entry!.ComplexForms.Should().BeEmpty();

entry = await _api.GetEntry(complexFormEntryId);
entry.Should().NotBeNull();
entry!.Components.Should().ContainSingle(c => c.ComplexFormEntryId == complexFormEntryId && c.ComponentEntryId == component.Id && c.ComponentSenseId == componentSenseId);
}

[Fact]
public async Task CanCreate_WithComplexFormTypesProperty()
{
var complexFormType = await _api.CreateComplexFormType(new()
{
Name = new MultiString() { { "en", "test complex form type" } }
});

var entry = await _api.CreateEntry(new()
{
LexemeForm = { { "en", "test" } },
ComplexFormTypes = [complexFormType]
});
entry = await _api.GetEntry(entry.Id);
entry.Should().NotBeNull();
entry!.ComplexFormTypes.Should().ContainSingle(c => c.Id == complexFormType.Id);
}
}
Loading

0 comments on commit cbcb6a1

Please sign in to comment.