Skip to content

Commit 589a34b

Browse files
authored
Only use 'main' Parts of speech. Like FLEx. (#2084)
* Only use 'main' Parts of speech. Like FLEx. This excludes e.g. Reversel index parts of speech. * Fix tests that create duplicate parts-of-speech * Add test that reversal index Parts of speech are excluded
1 parent 0aeeae9 commit 589a34b

3 files changed

Lines changed: 37 additions & 2 deletions

File tree

backend/FwLite/FwDataMiniLcmBridge.Tests/MiniLcmTests/PartOfSpeechTests.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using FwDataMiniLcmBridge.Api;
22
using FwDataMiniLcmBridge.Tests.Fixtures;
33
using MiniLcm.Models;
4+
using SIL.LCModel;
45
using SIL.LCModel.Infrastructure;
56

67
namespace FwDataMiniLcmBridge.Tests.MiniLcmTests;
@@ -81,4 +82,31 @@ public async Task SetPartOfSpeech_WithNullMorphoSyntaxAnalysisRA_ToNull()
8182
retrievedEntry.Should().NotBeNull();
8283
retrievedEntry!.PartOfSpeechId.Should().BeNull();
8384
}
85+
86+
[Fact]
87+
public async Task GetPartsOfSpeech_DoesNotReturnReversalIndexPos()
88+
{
89+
// Arrange
90+
var fwApi = (FwDataMiniLcmApi)BaseApi;
91+
var reversalIndexRepository = fwApi.Cache.ServiceLocator.GetInstance<IReversalIndexRepository>();
92+
var analysisWs = fwApi.Cache.DefaultAnalWs;
93+
94+
var reversalPosGuid = Guid.NewGuid();
95+
UndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW("Create Reversal Index POS",
96+
"Remove Reversal Index POS",
97+
fwApi.Cache.ServiceLocator.ActionHandler,
98+
() =>
99+
{
100+
var reversalIndex = reversalIndexRepository.FindOrCreateIndexForWs(analysisWs);
101+
var posFactory = fwApi.Cache.ServiceLocator.GetInstance<IPartOfSpeechFactory>();
102+
var reversalPos = posFactory.Create(reversalPosGuid, reversalIndex.PartsOfSpeechOA);
103+
reversalPos.Name.set_String(analysisWs, "Reversal Test POS");
104+
});
105+
106+
// Act
107+
var partsOfSpeech = await Api.GetPartsOfSpeech().ToArrayAsync();
108+
109+
// Assert
110+
partsOfSpeech.Should().NotContain(pos => pos.Id == reversalPosGuid);
111+
}
84112
}

backend/FwLite/FwDataMiniLcmBridge/Api/FwDataMiniLcmApi.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,7 @@ void MoveWs(CoreWritingSystemDefinition ws,
271271

272272
public IAsyncEnumerable<PartOfSpeech> GetPartsOfSpeech()
273273
{
274-
return PartOfSpeechRepository
275-
.AllInstances()
274+
return Cache.LangProject.AllPartsOfSpeech
276275
.OrderBy(p => p.Name.BestAnalysisAlternative.Text)
277276
.ToAsyncEnumerable()
278277
.Select(FromLcmPartOfSpeech);

backend/FwLite/FwLiteProjectSync.Tests/SyncTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ public async Task DisposeAsync()
6464
{
6565
await _fixture.CrdtApi.DeleteEntry(entry.Id);
6666
}
67+
await foreach (var pos in _fixture.FwDataApi.GetPartsOfSpeech())
68+
{
69+
await _fixture.FwDataApi.DeletePartOfSpeech(pos.Id);
70+
}
71+
foreach (var pos in await _fixture.CrdtApi.GetPartsOfSpeech().ToArrayAsync())
72+
{
73+
await _fixture.CrdtApi.DeletePartOfSpeech(pos.Id);
74+
}
6775
}
6876

6977
public SyncTests(SyncFixture fixture)

0 commit comments

Comments
 (0)