diff --git a/backend/app/src/test/kotlin/io/tolgee/service/dataImport/StoredDataImporterTest.kt b/backend/app/src/test/kotlin/io/tolgee/service/dataImport/StoredDataImporterTest.kt index fcc373cb28..e3a9221ece 100644 --- a/backend/app/src/test/kotlin/io/tolgee/service/dataImport/StoredDataImporterTest.kt +++ b/backend/app/src/test/kotlin/io/tolgee/service/dataImport/StoredDataImporterTest.kt @@ -164,4 +164,48 @@ class StoredDataImporterTest : AbstractSpringTest() { assertThat(overriddenTranslation.text).isEqualTo(importTestData.translationWithConflict.text) assertThat(forceKeptTranslation.text).isEqualTo("What a text") } + + @Test + fun `only updates old keys but does not add new ones when option enabled`() { + defaultImportSettings.onlyUpdateWithoutAdd = true + storedDataImporter = + StoredDataImporter( + applicationContext, + importTestData.import, + ForceMode.OVERRIDE, + importSettings = defaultImportSettings, + ) + importTestData.addImportKeyThatDoesntExistInProject() + testDataService.saveTestData(importTestData.root) + login() + + storedDataImporter.doImport() + val projectId = importTestData.root.data.projects[0].self.id + val importedKey = keyService.find(projectId, "I'm new key in project", null) + assertThat(importedKey).isNull() + + val forceOverriddenTranslationId = importTestData.root.data.projects[0].data.translations[1].self.id + val forceOverriddenTranslation = translationService.find(forceOverriddenTranslationId)!! + assertThat(forceOverriddenTranslation.text).isEqualTo("Imported text") + } + + @Test + fun `add new key when option disabled`() { + defaultImportSettings.onlyUpdateWithoutAdd = false + storedDataImporter = + StoredDataImporter( + applicationContext, + importTestData.import, + ForceMode.OVERRIDE, + importSettings = defaultImportSettings, + ) + importTestData.addImportKeyThatDoesntExistInProject() + testDataService.saveTestData(importTestData.root) + login() + + storedDataImporter.doImport() + val projectId = importTestData.root.data.projects[0].self.id + val importedKey = keyService.find(projectId, "I'm new key in project", null) + assertThat(importedKey).isNotNull() + } } diff --git a/backend/data/src/main/kotlin/io/tolgee/development/testDataBuilder/data/dataImport/ImportTestData.kt b/backend/data/src/main/kotlin/io/tolgee/development/testDataBuilder/data/dataImport/ImportTestData.kt index d448c70c5b..83941d286d 100644 --- a/backend/data/src/main/kotlin/io/tolgee/development/testDataBuilder/data/dataImport/ImportTestData.kt +++ b/backend/data/src/main/kotlin/io/tolgee/development/testDataBuilder/data/dataImport/ImportTestData.kt @@ -431,6 +431,20 @@ class ImportTestData { } } + fun addImportKeyThatDoesntExistInProject() { + importBuilder.data.importFiles[0].build { + val key = + addImportKey { + name = "I'm new key in project" + } + addImportTranslation { + text = "Hey!" + this.key = key.self + language = importEnglish + } + } + } + data class AddFilesWithNamespacesResult( val importFrenchInNs: ImportLanguage, ) diff --git a/webapp/src/views/projects/import/component/ImportSettingsPanel.tsx b/webapp/src/views/projects/import/component/ImportSettingsPanel.tsx index 595e8f9b80..69bfa150c3 100644 --- a/webapp/src/views/projects/import/component/ImportSettingsPanel.tsx +++ b/webapp/src/views/projects/import/component/ImportSettingsPanel.tsx @@ -133,16 +133,15 @@ export const ImportSettingsPanel: FC = (props) => { {...additionalCheckboxProps} /> { - onChange('onlyUpdateWithoutAdd', e.target.checked); - }} - data-cy={''} - hint={t('import_only_update_without_add_key_label_hint')} - label={t('import_only_update_without_add_key_label')} - checked={state?.onlyUpdateWithoutAdd} - - {...additionalCheckboxProps} + loading={loadingItems.has('onlyUpdateWithoutAdd')} + onChange={(e) => { + onChange('onlyUpdateWithoutAdd', e.target.checked); + }} + data-cy={''} + hint={t('import_only_update_without_add_key_label_hint')} + label={t('import_only_update_without_add_key_label')} + checked={state?.onlyUpdateWithoutAdd} + {...additionalCheckboxProps} /> );