-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MOBC-471 || use values-in folder for Indonesian locale (#3)
* Make API url injectable to run GradleRunner-based tests * Use values-in folder for "id" locale * Ensure line breaks at the end of files * Use better name * Make overriding default OneSky API url more explicit
- Loading branch information
Showing
12 changed files
with
148 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
plugin/src/test/java/co/brainly/onesky/task/DownloadTranslationsTaskTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package co.brainly.onesky.task | ||
|
||
import co.brainly.onesky.client.util.enqueueResponseWithFilesContent | ||
import co.brainly.onesky.util.buildFile | ||
import co.brainly.onesky.util.settingsFile | ||
import okhttp3.mockwebserver.MockWebServer | ||
import org.gradle.testkit.runner.GradleRunner | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.io.TempDir | ||
import java.io.File | ||
import org.junit.jupiter.api.Assertions.assertEquals as assertEquals | ||
|
||
class DownloadTranslationsTaskTest { | ||
|
||
private val server = MockWebServer() | ||
|
||
@Test | ||
fun `uses values-in directory for Indonesian locale (id) `(@TempDir tempDir: File) { | ||
val projectDir = tempDir.resolve("onesky-project").apply { mkdirs() } | ||
val moduleDir = projectDir.resolve("my-module").apply { mkdirs() } | ||
|
||
projectDir.settingsFile().writeText( | ||
""" | ||
include ":my-module" | ||
""".trimIndent() | ||
) | ||
|
||
moduleDir.buildFile().writeText( | ||
""" | ||
import co.brainly.onesky.OneSkyPluginExtension | ||
buildscript { | ||
repositories { | ||
mavenLocal() | ||
mavenCentral() | ||
gradlePluginPortal() | ||
} | ||
} | ||
plugins { | ||
id("co.brainly.onesky") | ||
} | ||
configure<OneSkyPluginExtension> { | ||
apiKey = "???" | ||
apiSecret = "???" | ||
projectId = 378760 | ||
sourceStringFiles = listOf("strings.xml") | ||
overrideOneSkyApiUrl("${server.url("/")}") | ||
} | ||
""".trimIndent() | ||
) | ||
|
||
server.enqueueResponseWithFilesContent("project_languages_response_just_id.json") | ||
server.enqueueResponseWithFilesContent("example_translation_file.xml") | ||
|
||
GradleRunner.create() | ||
.withProjectDir(projectDir) | ||
.withPluginClasspath() | ||
.withArguments(":my-module:downloadTranslations") | ||
.build() | ||
|
||
assertEquals( | ||
false, | ||
moduleDir.resolve("src/main/res/values-id/strings.xml").exists(), | ||
"files not created in values-id directory" | ||
) | ||
|
||
assertEquals( | ||
true, | ||
moduleDir.resolve("src/main/res/values-in/strings.xml").exists(), | ||
"files created in values-in directory" | ||
) | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
plugin/src/test/java/co/brainly/onesky/util/GradleTestExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package co.brainly.onesky.util | ||
|
||
import java.io.File | ||
|
||
fun File.buildFile() = resolve("build.gradle.kts") | ||
fun File.settingsFile() = resolve("settings.gradle") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -400,4 +400,4 @@ | |
"last_updated_at": "2020-10-28T04:19:09+0000", | ||
"last_updated_at_timestamp": 1603858749 | ||
}] | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
plugin/src/test/resources/project_languages_response_just_id.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"meta": { | ||
"status": 200, | ||
"record_count": 33 | ||
}, | ||
"data": [{ | ||
"code": "id", | ||
"english_name": "Indonesian", | ||
"local_name": "Bahasa Indonesia", | ||
"custom_locale": null, | ||
"locale": "id", | ||
"region": "", | ||
"is_base_language": false, | ||
"is_ready_to_publish": false, | ||
"translation_progress": "99.8%", | ||
"last_updated_at": "2020-11-09T03:34:42+0000", | ||
"last_updated_at_timestamp": 1604892882 | ||
}] | ||
} |