Skip to content

Commit

Permalink
feat: add BE tests for new option
Browse files Browse the repository at this point in the history
  • Loading branch information
huglx committed Jul 18, 2024
1 parent 4ce10b2 commit 1d7f7eb
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
19 changes: 9 additions & 10 deletions webapp/src/views/projects/import/component/ImportSettingsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,15 @@ export const ImportSettingsPanel: FC = (props) => {
{...additionalCheckboxProps}
/>
<LoadingCheckboxWithSkeleton
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}
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}
/>
</StyledPanelBox>
);
Expand Down

0 comments on commit 1d7f7eb

Please sign in to comment.