From fa23a4da110ba214e0736ad51170b0e145ac03b5 Mon Sep 17 00:00:00 2001 From: Wadim Wawrzenczak Date: Thu, 4 Jan 2024 17:34:39 +0100 Subject: [PATCH 1/2] Add test for 0 word drop exports --- .../cli/command/DropExportCommandTest.java | 21 +++++++++++++++++++ .../input/source/source-xliff.xliff | 10 +++++++++ 2 files changed, 31 insertions(+) create mode 100644 cli/src/test/resources/com/box/l10n/mojito/cli/command/DropExportCommandTest/exportZeroWords/input/source/source-xliff.xliff diff --git a/cli/src/test/java/com/box/l10n/mojito/cli/command/DropExportCommandTest.java b/cli/src/test/java/com/box/l10n/mojito/cli/command/DropExportCommandTest.java index 7e85273ac9..6536fa12e0 100644 --- a/cli/src/test/java/com/box/l10n/mojito/cli/command/DropExportCommandTest.java +++ b/cli/src/test/java/com/box/l10n/mojito/cli/command/DropExportCommandTest.java @@ -81,6 +81,27 @@ public void exportFullyTranslated() throws Exception { assertEquals("A Drop should not have been added", findAllBefore.getTotalElements(), findAllAfter.getTotalElements()); } + @Test + public void exportZeroWords() throws Exception { + + Repository repository = createTestRepoUsingRepoService(); + + getL10nJCommander().run("push", "-r", repository.getName(), + "-s", getInputResourcesTestDir("source").getAbsolutePath()); + + // there should be a single string for translation, but with 0 words in it + waitForRepositoryToHaveStringsForTranslations(repository.getId()); + + Page findAllBefore = dropClient.getDrops(repository.getId(), null, null, null); + + getL10nJCommander().run("drop-export", "-r", repository.getName()); + + Page findAllAfter = dropClient.getDrops(repository.getId(), null, null, null); + + // drop export command should not trigger an export when there are 0 words for translation + assertEquals("A Drop should not have been added", findAllBefore.getTotalElements(), findAllAfter.getTotalElements()); + } + @Test public void exportSelectFullyTranslatedLocales() throws Exception { diff --git a/cli/src/test/resources/com/box/l10n/mojito/cli/command/DropExportCommandTest/exportZeroWords/input/source/source-xliff.xliff b/cli/src/test/resources/com/box/l10n/mojito/cli/command/DropExportCommandTest/exportZeroWords/input/source/source-xliff.xliff new file mode 100644 index 0000000000..871bb72cfa --- /dev/null +++ b/cli/src/test/resources/com/box/l10n/mojito/cli/command/DropExportCommandTest/exportZeroWords/input/source/source-xliff.xliff @@ -0,0 +1,10 @@ + + + + + + + + + + From b3f733844e414806d7e9fadd709885b1f2b803bb Mon Sep 17 00:00:00 2001 From: Wadim Wawrzenczak Date: Thu, 4 Jan 2024 17:36:38 +0100 Subject: [PATCH 2/2] Use word count to check if drop export is pending --- .../box/l10n/mojito/cli/command/DropExportCommand.java | 2 +- .../mojito/rest/entity/RepositoryLocaleStatistic.java | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/command/DropExportCommand.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/DropExportCommand.java index bc41b7f3da..3006fbd1d3 100644 --- a/cli/src/main/java/com/box/l10n/mojito/cli/command/DropExportCommand.java +++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/DropExportCommand.java @@ -168,7 +168,7 @@ private boolean shouldCreateDrop(Repository repository) throws CommandException RepositoryStatistic repoStat = repository.getRepositoryStatistic(); if (repoStat != null) { for (RepositoryLocaleStatistic repoLocaleStat : repoStat.getRepositoryLocaleStatistics()) { - if (bcp47TagsForTranslation.contains(repoLocaleStat.getLocale().getBcp47Tag()) && repoLocaleStat.getForTranslationCount() > 0L) { + if (bcp47TagsForTranslation.contains(repoLocaleStat.getLocale().getBcp47Tag()) && repoLocaleStat.getForTranslationWordCount() > 0L) { createDrop = true; break; } diff --git a/restclient/src/main/java/com/box/l10n/mojito/rest/entity/RepositoryLocaleStatistic.java b/restclient/src/main/java/com/box/l10n/mojito/rest/entity/RepositoryLocaleStatistic.java index de6915a77b..515f63bef4 100644 --- a/restclient/src/main/java/com/box/l10n/mojito/rest/entity/RepositoryLocaleStatistic.java +++ b/restclient/src/main/java/com/box/l10n/mojito/rest/entity/RepositoryLocaleStatistic.java @@ -9,6 +9,8 @@ public class RepositoryLocaleStatistic { private Locale locale; private Long forTranslationCount = 0L; + private Long forTranslationWordCount = 0L; + public Locale getLocale() { return locale; } @@ -25,4 +27,12 @@ public void setForTranslationCount(Long forTranslationCount) { this.forTranslationCount = forTranslationCount; } + public Long getForTranslationWordCount() { + return forTranslationWordCount; + } + + public void setForTranslationWordCount(Long forTranslationWordCount) { + this.forTranslationWordCount = forTranslationWordCount; + } + }