Skip to content

Commit

Permalink
Merge branch 'refs/heads/develop' into feat/close-fwdata-on-disconnect
Browse files Browse the repository at this point in the history
# Conflicts:
#	backend/FwDataMiniLcmBridge/FwDataBridgeKernel.cs
#	frontend/viewer/src/App.svelte
#	frontend/viewer/src/ProjectView.svelte
  • Loading branch information
hahn-kev committed Jul 5, 2024
2 parents 9d875d2 + e5074b9 commit 1b9c298
Show file tree
Hide file tree
Showing 113 changed files with 2,968 additions and 512 deletions.
7 changes: 7 additions & 0 deletions LexBox.sln
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Crdt.Core", "backend\harmon
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FwDataMiniLcmBridge", "backend\FwDataMiniLcmBridge\FwDataMiniLcmBridge.csproj", "{279197B6-EC06-4DE0-94F8-625379C3AD83}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FwDataMiniLcmBridge.Tests", "backend\FwDataMiniLcmBridge.Tests\FwDataMiniLcmBridge.Tests.csproj", "{B0299A49-C0B2-4553-A72E-1670D4CB5138}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -101,6 +103,10 @@ Global
{279197B6-EC06-4DE0-94F8-625379C3AD83}.Debug|Any CPU.Build.0 = Debug|Any CPU
{279197B6-EC06-4DE0-94F8-625379C3AD83}.Release|Any CPU.ActiveCfg = Release|Any CPU
{279197B6-EC06-4DE0-94F8-625379C3AD83}.Release|Any CPU.Build.0 = Release|Any CPU
{B0299A49-C0B2-4553-A72E-1670D4CB5138}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B0299A49-C0B2-4553-A72E-1670D4CB5138}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B0299A49-C0B2-4553-A72E-1670D4CB5138}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B0299A49-C0B2-4553-A72E-1670D4CB5138}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{E8BB768B-C3DC-4BE6-9B9F-82319E05AF86} = {7B6E21C4-5AF4-4505-B7D9-59A3886C5090}
Expand All @@ -111,5 +117,6 @@ Global
{740C8FF5-8006-4047-8C52-53873C2DD7C4} = {7B6E21C4-5AF4-4505-B7D9-59A3886C5090}
{8B54FFB5-0BDF-403E-83CC-A3B3861EC507} = {7B6E21C4-5AF4-4505-B7D9-59A3886C5090}
{279197B6-EC06-4DE0-94F8-625379C3AD83} = {7B6E21C4-5AF4-4505-B7D9-59A3886C5090}
{B0299A49-C0B2-4553-A72E-1670D4CB5138} = {7B6E21C4-5AF4-4505-B7D9-59A3886C5090}
EndGlobalSection
EndGlobal
2 changes: 2 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ tasks:
platforms: [ windows ]
cmds:
- powershell -File download.ps1 sena-3 'https://drive.google.com/uc?export=download&id=1I-hwc0RHoQqW774gbS5qR-GHa1E7BlsS' 'BEC5131799DB07BF8D84D8FC1F3169FB2574F2A1F4C37F6898EAB563A4AE95B8'
- powershell -File download.ps1 empty 'https://drive.google.com/uc?export=download&id=1p73u-AGdSwNkg_5KEv9-4iLRuN-1V-LD' 'F4EB48D2C7B3294DCA93965F14F058E56D797F38D562B86CF0372F774E1B486B'
- powershell -File download.ps1 elawa 'https://drive.usercontent.google.com/download?export=download&id=1Jk-eSDho8ATBMS-Kmfatwi-MWQth26ro&confirm=t' "E3608F1E3188CE5FDB166FBF9D5AAD06558DB68EFA079FB453881572B50CB8E3"
setup-unix:
platforms: [ linux, darwin ]
cmds:
- wget -c -O {{.DATA_DIR}}/sena-3.zip 'https://drive.google.com/uc?export=download&id=1I-hwc0RHoQqW774gbS5qR-GHa1E7BlsS'
- wget -c -O {{.DATA_DIR}}/empty.zip 'https://drive.google.com/uc?export=download&id=1p73u-AGdSwNkg_5KEv9-4iLRuN-1V-LD'
- wget -c -O {{.DATA_DIR}}/elawa.zip 'https://drive.usercontent.google.com/download?export=download&id=1Jk-eSDho8ATBMS-Kmfatwi-MWQth26ro&confirm=t'

# k8s
Expand Down
34 changes: 34 additions & 0 deletions backend/FwDataMiniLcmBridge.Tests/Fixtures/ProjectLoaderFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using FwDataMiniLcmBridge.Api;
using Microsoft.Extensions.DependencyInjection;

namespace FwDataMiniLcmBridge.Tests.Fixtures;

public class ProjectLoaderFixture : IDisposable
{
public const string Name = "ProjectLoaderCollection";
private readonly FwDataFactory _fwDataFactory;
private readonly ServiceProvider _serviceProvider;

public ProjectLoaderFixture()
{
//todo make mock of IProjectLoader so we can load from test projects
var provider = new ServiceCollection().AddFwDataBridge().BuildServiceProvider();
_serviceProvider = provider;
_fwDataFactory = provider.GetRequiredService<FwDataFactory>();
}

public FwDataMiniLcmApi CreateApi(string projectName)
{
return _fwDataFactory.GetFwDataMiniLcmApi(projectName, false);
}

public void Dispose()
{
_serviceProvider.Dispose();
}
}

[CollectionDefinition(ProjectLoaderFixture.Name)]
public class ProjectLoaderCollection : ICollectionFixture<ProjectLoaderFixture>
{
}
34 changes: 34 additions & 0 deletions backend/FwDataMiniLcmBridge.Tests/FwDataMiniLcmBridge.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/>
<PackageReference Include="FluentAssertions" Version="6.12.0"/>
<PackageReference Include="xunit" Version="2.5.3"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3"/>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
<Using Include="Xunit"/>
<Using Include="FluentAssertions"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\FwDataMiniLcmBridge\FwDataMiniLcmBridge.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="TestData\" />
</ItemGroup>

</Project>
47 changes: 47 additions & 0 deletions backend/FwDataMiniLcmBridge.Tests/PartOfSpeechTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using FwDataMiniLcmBridge.Tests.Fixtures;
using MiniLcm;

namespace FwDataMiniLcmBridge.Tests;

[Collection(ProjectLoaderFixture.Name)]
public class PartOfSpeechTests(ProjectLoaderFixture fixture)
{
[Fact]
public async Task GetPartsOfSpeech_ReturnsAllPartsOfSpeech()
{
var api = fixture.CreateApi("sena-3");
var partOfSpeeches = await api.GetPartsOfSpeech().ToArrayAsync();
partOfSpeeches.Should().AllSatisfy(po => po.Id.Should().NotBe(Guid.Empty));
}

[Fact]
public async Task Sense_HasPartOfSpeech()
{
var api = fixture.CreateApi("sena-3");
var entry = await api.GetEntries().FirstAsync(e => e.Senses.Any(s => !string.IsNullOrEmpty(s.PartOfSpeech)));
var sense = entry.Senses.First(s => !string.IsNullOrEmpty(s.PartOfSpeech));
sense.PartOfSpeech.Should().NotBeNullOrEmpty();
sense.PartOfSpeechId.Should().NotBeNull();
}

[Fact]
public async Task Sense_UpdatesPartOfSpeech()
{
var api = fixture.CreateApi("sena-3");
var entry = await api.GetEntries().FirstAsync(e => e.Senses.Any(s => !string.IsNullOrEmpty(s.PartOfSpeech)));
var sense = entry.Senses.First(s => !string.IsNullOrEmpty(s.PartOfSpeech));
var newPartOfSpeech = await api.GetPartsOfSpeech().FirstAsync(po => po.Id != sense.PartOfSpeechId);

var update = api.CreateUpdateBuilder<Sense>()
.Set(s => s.PartOfSpeech, newPartOfSpeech.Name["en"])//this won't actually update the part of speech, but it shouldn't cause an issue either.
.Set(s => s.PartOfSpeechId, newPartOfSpeech.Id)
.Build();
await api.UpdateSense(entry.Id, sense.Id, update);

entry = await api.GetEntry(entry.Id);
ArgumentNullException.ThrowIfNull(entry);
var updatedSense = entry.Senses.First(s => s.Id == sense.Id);
updatedSense.PartOfSpeechId.Should().Be(newPartOfSpeech.Id);
updatedSense.PartOfSpeech.Should().NotBe(sense.PartOfSpeech);//the part of speech here is whatever the default is for the project, not english.
}
}
75 changes: 75 additions & 0 deletions backend/FwDataMiniLcmBridge.Tests/SemanticDomainTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using FwDataMiniLcmBridge.Tests.Fixtures;
using MiniLcm;

namespace FwDataMiniLcmBridge.Tests;

[Collection(ProjectLoaderFixture.Name)]
public class SemanticDomainTests(ProjectLoaderFixture fixture)
{
[Fact]
public async Task GetSemanticDomains_ReturnsAllSemanticDomains()
{
var api = fixture.CreateApi("sena-3");
var semanticDomains = await api.GetSemanticDomains().ToArrayAsync();
semanticDomains.Should().AllSatisfy(sd =>
{
sd.Id.Should().NotBe(Guid.Empty);
sd.Name.Values.Should().NotBeEmpty();
sd.Code.Should().NotBeEmpty();
});
}

[Fact]
public async Task Sense_HasSemanticDomains()
{
var api = fixture.CreateApi("sena-3");
var entry = await api.GetEntries().FirstAsync(e => e.Senses.Any(s => s.SemanticDomains.Any()));
var sense = entry.Senses.First(s => s.SemanticDomains.Any());
sense.SemanticDomains.Should().NotBeEmpty();
sense.SemanticDomains.Should().AllSatisfy(sd =>
{
sd.Id.Should().NotBe(Guid.Empty);
sd.Name.Values.Should().NotBeEmpty();
sd.Code.Should().NotBeEmpty();
});
}

[Fact]
public async Task Sense_AddSemanticDomain()
{
var api = fixture.CreateApi("sena-3");
var entry = await api.GetEntries().FirstAsync(e => e.Senses.Any(s => s.SemanticDomains.Any()));
var sense = entry.Senses.First(s => s.SemanticDomains.Any());
var currentSemanticDomain = sense.SemanticDomains.First();
var newSemanticDomain = await api.GetSemanticDomains().FirstAsync(sd => sd.Id != currentSemanticDomain.Id);

var update = api.CreateUpdateBuilder<Sense>()
.Add(s => s.SemanticDomains, newSemanticDomain)
.Build();
await api.UpdateSense(entry.Id, sense.Id, update);

entry = await api.GetEntry(entry.Id);
ArgumentNullException.ThrowIfNull(entry);
var updatedSense = entry.Senses.First(s => s.Id == sense.Id);
updatedSense.SemanticDomains.Select(sd => sd.Id).Should().Contain(newSemanticDomain.Id);
}

[Fact]
public async Task Sense_RemoveSemanticDomain()
{
var api = fixture.CreateApi("sena-3");
var entry = await api.GetEntries().FirstAsync(e => e.Senses.Any(s => s.SemanticDomains.Any()));
var sense = entry.Senses.First(s => s.SemanticDomains.Any());
var domainToRemove = sense.SemanticDomains[0];

var update = api.CreateUpdateBuilder<Sense>()
.Remove(s => s.SemanticDomains, 0)
.Build();
await api.UpdateSense(entry.Id, sense.Id, update);

entry = await api.GetEntry(entry.Id);
ArgumentNullException.ThrowIfNull(entry);
var updatedSense = entry.Senses.First(s => s.Id == sense.Id);
updatedSense.SemanticDomains.Select(sd => sd.Id).Should().NotContain(domainToRemove.Id);
}
}
22 changes: 22 additions & 0 deletions backend/FwDataMiniLcmBridge.Tests/WritingSystemTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using FwDataMiniLcmBridge.Tests.Fixtures;

namespace FwDataMiniLcmBridge.Tests;

[Collection(ProjectLoaderFixture.Name)]
public class WritingSystemTests(ProjectLoaderFixture fixture)
{
[Fact]
public async Task GetWritingSystems_DoesNotReturnNullOrEmpty()
{
var writingSystems = await fixture.CreateApi("sena-3").GetWritingSystems();
writingSystems.Vernacular.Should().NotBeNullOrEmpty();
writingSystems.Analysis.Should().NotBeNullOrEmpty();
}

[Fact]
public async Task GetWritingSystems_ReturnsExemplars()
{
var writingSystems = await fixture.CreateApi("sena-3").GetWritingSystems();
writingSystems.Vernacular.Should().Contain(ws => ws.Exemplars.Any());
}
}
Loading

0 comments on commit 1b9c298

Please sign in to comment.