|
| 1 | +package com.sysadmindoc.callshield.ui |
| 2 | + |
| 3 | +import android.content.Context |
| 4 | +import android.content.res.XmlResourceParser |
| 5 | +import androidx.test.core.app.ApplicationProvider |
| 6 | +import com.sysadmindoc.callshield.R |
| 7 | +import org.junit.Assert.assertEquals |
| 8 | +import org.junit.Assert.assertNotEquals |
| 9 | +import org.junit.Test |
| 10 | +import org.junit.runner.RunWith |
| 11 | +import org.robolectric.RobolectricTestRunner |
| 12 | +import org.robolectric.annotation.Config |
| 13 | + |
| 14 | +@RunWith(RobolectricTestRunner::class) |
| 15 | +@Config(sdk = [34]) |
| 16 | +class ShippedLocalesTest { |
| 17 | + private val context: Context = ApplicationProvider.getApplicationContext() |
| 18 | + |
| 19 | + private fun registeredLocales(): List<String> { |
| 20 | + val tags = mutableListOf<String>() |
| 21 | + context.resources.getXml(R.xml.locales_config).use { parser -> |
| 22 | + while (parser.next() != XmlResourceParser.END_DOCUMENT) { |
| 23 | + if (parser.eventType == XmlResourceParser.START_TAG && parser.name == "locale") { |
| 24 | + tags += parser.getAttributeValue("http://schemas.android.com/apk/res/android", "name") |
| 25 | + } |
| 26 | + } |
| 27 | + } |
| 28 | + return tags |
| 29 | + } |
| 30 | + |
| 31 | + @Test |
| 32 | + fun `the in-app picker offers every locale Android's picker offers`() { |
| 33 | + val offered = AppLanguage.options(includePseudoLocales = false).map { it.languageTag } - AppLanguage.SYSTEM_DEFAULT_TAG |
| 34 | + |
| 35 | + assertEquals(registeredLocales().sorted(), offered.sorted()) |
| 36 | + } |
| 37 | + |
| 38 | + @Test |
| 39 | + @Config(qualifiers = "pt-rBR") |
| 40 | + fun `Brazilian Portuguese is translated`() { |
| 41 | + assertEquals("Chamada recebida", context.getString(R.string.overlay_header_incoming_call)) |
| 42 | + assertEquals( |
| 43 | + "CallShield", |
| 44 | + context.getString(R.string.app_name), |
| 45 | + ) |
| 46 | + } |
| 47 | + |
| 48 | + @Test |
| 49 | + @Config(qualifiers = "pt-rPT") |
| 50 | + fun `Portuguese from Portugal gets the Brazilian text rather than English`() { |
| 51 | + assertEquals("Chamada recebida", context.getString(R.string.overlay_header_incoming_call)) |
| 52 | + } |
| 53 | + |
| 54 | + @Test |
| 55 | + @Config(qualifiers = "es") |
| 56 | + fun `Spanish is translated`() { |
| 57 | + assertEquals("Llamada entrante", context.getString(R.string.overlay_header_incoming_call)) |
| 58 | + } |
| 59 | + |
| 60 | + @Test |
| 61 | + @Config(qualifiers = "es-rMX") |
| 62 | + fun `a regional Spanish phone gets the Spanish text`() { |
| 63 | + assertEquals("Llamada entrante", context.getString(R.string.overlay_header_incoming_call)) |
| 64 | + assertNotEquals("Incoming call", context.getString(R.string.overlay_header_incoming_call)) |
| 65 | + } |
| 66 | + |
| 67 | + @Test |
| 68 | + @Config(qualifiers = "es") |
| 69 | + fun `every language keeps its own name in the picker`() { |
| 70 | + assertEquals("简体中文", context.getString(R.string.settings_language_chinese_simplified)) |
| 71 | + assertEquals("Português (Brasil)", context.getString(R.string.settings_language_portuguese_brazil)) |
| 72 | + assertEquals("Español", context.getString(R.string.settings_language_spanish)) |
| 73 | + } |
| 74 | +} |
0 commit comments