aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-android/app/src/test/kotlin/org/meshbay/client/NativeTextTest.kt
blob: 9e0bc7e2555d82b05e387031fae95fe8b70b8c46 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package org.meshbay.client

import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotEquals
import org.junit.Test
import org.meshbay.client.shell.NativeText
import java.io.File

/** The application's own dialogs, worded from the real catalogues in every language. */
class NativeTextTest {
    private val locales = File("../../meshbay-hub/src/meshbay_hub/static/locales")
    private val text = NativeText { code -> File(locales, "$code.js").takeIf { it.exists() }?.readText() }

    @Test fun `every catalogue words the native dialogs`() {
        val codes = locales.listFiles()!!.map { it.nameWithoutExtension }
        assertEquals(10, codes.size)
        for (code in codes) for (key in listOf("native.browser_access_confirm", "native.declined", "dialog.ok", "dialog.cancel")) {
            assertNotEquals("$code $key", key, text.get(key, code))
        }
    }

    @Test fun `escapes are read as the page reads them`() {
        assertEquals("Annulé — rien n'a été modifié.", text.get("native.declined", "fr"))
    }

    @Test fun `an unknown language falls back to English, an unknown key to itself`() {
        assertEquals("Cancel", text.get("dialog.cancel", "xx"))
        assertEquals("no.such.key", text.get("no.such.key", "fr"))
    }

    @Test fun `plural entries give their other form and parameters are filled`() {
        assertEquals("Use at least 12 characters", text.get("register.err_min_len", "en", mapOf("n" to "12")))
    }
}