Skip to content

Commit

Permalink
add support for changing ComplexForms collection directly
Browse files Browse the repository at this point in the history
  • Loading branch information
hahn-kev committed Oct 1, 2024
1 parent 786e20b commit 0fc946e
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 5 deletions.
36 changes: 36 additions & 0 deletions backend/FwLite/FwDataMiniLcmBridge.Tests/CreateEntryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,42 @@ public async Task CanCreate_WithComplexFormsProperty()
entry!.ComplexForms.Should().ContainSingle(c => c.ComplexFormEntryId == complexForm.Id);
}

[Fact]
public async Task CreateEntry_WithComponentSenseDoesNotShowOnComplexFormsList()
{
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()
{
Expand Down
103 changes: 98 additions & 5 deletions backend/FwLite/FwDataMiniLcmBridge.Tests/UpdateComplexFormsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ await _api.UpdateEntry(complexForm.Id,
ComplexFormComponent.FromEntries(complexForm, component)));
var entry = await _api.GetEntry(complexForm.Id);
entry.Should().NotBeNull();
entry!.Components.Should().ContainSingle(c => c.ComponentEntryId == component.Id);
entry!.Components.Should().ContainSingle(c => c.ComplexFormEntryId == complexForm.Id);
entry!.Components.Should().ContainSingle(c => c.ComponentEntryId == component.Id && c.ComplexFormEntryId == complexForm.Id);
}

[Fact]
Expand Down Expand Up @@ -124,7 +123,6 @@ public async Task CanChangeComponentSenseId()
public async Task CanChangeComponentSenseIdToNull()
{
var component2SenseId = Guid.NewGuid();
var component1 = await _api.CreateEntry(new() { LexemeForm = { { "en", "component1" } } });
var component2 = await _api.CreateEntry(new() { LexemeForm = { { "en", "component2" } }, Senses = [new Sense() { Id = component2SenseId, Gloss = { { "en", "component2" } } }] });
var complexFormId = Guid.NewGuid();
var complexForm = await _api.CreateEntry(new()
Expand All @@ -135,9 +133,9 @@ public async Task CanChangeComponentSenseIdToNull()
[
new ComplexFormComponent()
{
ComponentEntryId = component1.Id,
ComponentEntryId = component2.Id,
ComponentSenseId = component2SenseId,
ComponentHeadword = component1.Headword(),
ComponentHeadword = component2.Headword(),
ComplexFormEntryId = complexFormId,
ComplexFormHeadword = "complex form"
}
Expand Down Expand Up @@ -177,4 +175,99 @@ public async Task CanChangeComplexFormId()
entry.Should().NotBeNull();
entry!.Components.Should().ContainSingle(c => c.ComponentEntryId == component1.Id);
}

[Fact]
public async Task CanAddComplexFormToExistingEntry()
{
var complexForm = await _api.CreateEntry(new() { LexemeForm = { { "en", "complex form" } } });
var component = await _api.CreateEntry(new() { LexemeForm = { { "en", "component" } } });

await _api.UpdateEntry(component.Id,
new UpdateObjectInput<Entry>().Add(e => e.ComplexForms,
ComplexFormComponent.FromEntries(complexForm, component)));
var entry = await _api.GetEntry(component.Id);
entry.Should().NotBeNull();
entry!.ComplexForms.Should().ContainSingle(c => c.ComponentEntryId == component.Id && c.ComplexFormEntryId == complexForm.Id);
}

[Fact]
public async Task CanRemoveComplexFormFromExistingEntry()
{
var component = await _api.CreateEntry(new() { LexemeForm = { { "en", "component" } } });
var complexFormId = Guid.NewGuid();
await _api.CreateEntry(new()
{
Id = complexFormId,
LexemeForm = { { "en", "complex form" } },
Components = [new ComplexFormComponent()
{
ComponentEntryId = component.Id,
ComponentHeadword = component.Headword(),
ComplexFormEntryId = complexFormId,
ComplexFormHeadword = "complex form"
}]
});

await _api.UpdateEntry(component.Id,
new UpdateObjectInput<Entry>().Remove(e => e.ComplexForms, 0));
var entry = await _api.GetEntry(component.Id);
entry.Should().NotBeNull();
entry!.ComplexForms.Should().BeEmpty();
}

[Fact]
public async Task CanChangeComplexFormIdOnComplexFormsList()
{
var component1 = await _api.CreateEntry(new() { LexemeForm = { { "en", "component1" } } });
var complexForm2 = await _api.CreateEntry(new() { LexemeForm = { { "en", "complex form 2" } } });
var complexFormId = Guid.NewGuid();
await _api.CreateEntry(new()
{
Id = complexFormId,
LexemeForm = { { "en", "complex form" } },
Components =
[
new ComplexFormComponent()
{
ComponentEntryId = component1.Id,
ComponentHeadword = component1.Headword(),
ComplexFormEntryId = complexFormId,
ComplexFormHeadword = "complex form"
}
]
});

await _api.UpdateEntry(component1.Id, new UpdateObjectInput<Entry>().Set(e => e.ComplexForms[0].ComplexFormEntryId, complexForm2.Id));
var entry = await _api.GetEntry(component1.Id);
entry.Should().NotBeNull();
entry!.ComplexForms.Should().ContainSingle(c => c.ComplexFormEntryId == complexForm2.Id);
}

[Fact]
public async Task CanChangeComponentIdOnComplexFormsList()
{
var component1 = await _api.CreateEntry(new() { LexemeForm = { { "en", "component1" } } });
var component2 = await _api.CreateEntry(new() { LexemeForm = { { "en", "component2" } } });
var complexFormId = Guid.NewGuid();
await _api.CreateEntry(new()
{
Id = complexFormId,
LexemeForm = { { "en", "complex form" } },
Components =
[
new ComplexFormComponent()
{
ComponentEntryId = component1.Id,
ComponentHeadword = component1.Headword(),
ComplexFormEntryId = complexFormId,
ComplexFormHeadword = "complex form"
}
]
});

await _api.UpdateEntry(component1.Id, new UpdateObjectInput<Entry>().Set(e => e.ComplexForms[0].ComponentEntryId, component2.Id));
var entry = await _api.GetEntry(component2.Id);
entry.Should().NotBeNull();
entry!.ComplexForms.Should().ContainSingle(c => c.ComponentEntryId == component2.Id && c.ComplexFormEntryId == complexFormId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,21 @@ public override IList<ComplexFormComponent> Components
set => throw new NotImplementedException();
}

public override IList<ComplexFormComponent> ComplexForms
{
get =>
new UpdateListProxy<ComplexFormComponent>(
component => lexboxLcmApi.AddComplexFormComponent(lexboxLcmApi.EntriesRepository.GetObject(component.ComplexFormEntryId), component),
component => lexboxLcmApi.RemoveComplexFormComponent(lexboxLcmApi.EntriesRepository.GetObject(component.ComplexFormEntryId), component),
//todo this does not handle complex forms which reference a sense
i => new UpdateComplexFormComponentProxy(lcmEntry.ComplexFormEntries.ElementAt(i),
lcmEntry,
lexboxLcmApi),
lcmEntry.ComplexFormEntries.Count()
);
set => throw new NotImplementedException();
}

public override MultiString Note
{
get => new UpdateMultiStringProxy(lcmEntry.Comment, lexboxLcmApi);
Expand Down

0 comments on commit 0fc946e

Please sign in to comment.