Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix environments tests #1441

Merged
merged 3 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/ci-external.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,16 @@ jobs:
assembleNoapiX64GeckoGeneric,
]
secrets: inherit

unit-tests:
name: Unit Tests
needs: [build-external]
uses: ./.github/workflows/build.yml
with:
flavour: ${{ matrix.flavour }}
strategy:
matrix:
flavour: [
testNoapiArm64GeckoGenericDebugUnitTest,
testNoapiX64GeckoGenericReleaseUnitTest,
]
63 changes: 31 additions & 32 deletions app/src/test/java/com/igalia/wolvic/EnvironmentsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@ import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
import java.io.File

// TODO: Fix all these tests or just remove all of them
@RunWith(RobolectricTestRunner::class)
@Config(manifest = Config.NONE, application = TestApplication::class)
class EnvironmentsTest {

@get:Rule
val gleanRule = GleanTestRule(ApplicationProvider.getApplicationContext())
lateinit var settingStore: SettingsStore
private lateinit var context: Context

Expand All @@ -47,101 +44,103 @@ class EnvironmentsTest {
@Test
fun `Environments for a target version`() {
settingStore.setRemoteProperties(TestFileUtils.readTextFile(javaClass.classLoader!!,"environments/targetVersionEnvs.json"))
val env = EnvironmentUtils.getExternalEnvironments(context, "11")
val env = EnvironmentUtils.getExternalEnvironments(context, "1")
assertNotNull(env)
assertEquals(env.size, 2)
}

@Test
fun `Environments do not exist for a target version, we fallback to the most recent ones`() {
settingStore.setRemoteProperties(TestFileUtils.readTextFile(javaClass.classLoader!!,"environments/previousVersionEnvs.json"))
val env = EnvironmentUtils.getExternalEnvironments(context, "12")
val env = EnvironmentUtils.getExternalEnvironments(context, "2")
assertNotNull(env)
assertEquals(env.size, 2)
}

@Test
fun `Environment exist for the target version`() {
settingStore.setRemoteProperties(TestFileUtils.readTextFile(javaClass.classLoader!!,"environments/targetVersionEnvs.json"))
val env = EnvironmentUtils.getExternalEnvironmentById(context, "space", "11")
val env = EnvironmentUtils.getExternalEnvironmentById(context, "wolvic", "1")
assertNotNull(env)
assertEquals(env?.value, "space")
assertEquals(env?.title, "Space")
assertEquals(env?.thumbnail, "https://mixedreality.mozilla.org/FirefoxReality/envs/space/thumbnail.jpg")
assertEquals(env?.payload, "https://mixedreality.mozilla.org/FirefoxReality/envs/space/space.zip")
assertEquals(env?.value, "wolvic")
assertEquals(env?.title, "Wolvic")
assertEquals(env?.thumbnail, "https://mixedreality.mozilla.org/FirefoxReality/envs/wolvic/thumbnail.jpg")
assertEquals(env?.payload, "https://mixedreality.mozilla.org/FirefoxReality/envs/wolvic/space.zip")
}

@Test
fun `Environment does not exist for the target version, we fallback to the most recent one`() {
settingStore.setRemoteProperties(TestFileUtils.readTextFile(javaClass.classLoader!!,"environments/previousVersionEnvs.json"))
val env = EnvironmentUtils.getExternalEnvironmentById(context, "space", "12")
val env = EnvironmentUtils.getExternalEnvironmentById(context, "wolvic", "2")
assertNotNull(env)
assertEquals(env?.value, "space")
assertEquals(env?.title, "Space")
assertEquals(env?.thumbnail, "https://mixedreality.mozilla.org/FirefoxReality/envs/space/thumbnail.jpg")
assertEquals(env?.payload, "https://mixedreality.mozilla.org/FirefoxReality/envs/space/space.zip")
assertEquals(env?.value, "wolvic")
assertEquals(env?.title, "Wolvic")
assertEquals(env?.thumbnail, "https://mixedreality.mozilla.org/FirefoxReality/envs/wolvic/thumbnail.jpg")
assertEquals(env?.payload, "https://mixedreality.mozilla.org/FirefoxReality/envs/wolvic/space.zip")
}

@Test
fun `Environment does not exist for any version`() {
settingStore.setRemoteProperties(TestFileUtils.readTextFile(javaClass.classLoader!!,"environments/testNoEnvs.json"))
val env = EnvironmentUtils.getExternalEnvironmentById(context, "test", "12")
val env = EnvironmentUtils.getExternalEnvironmentById(context, "test", "2")
assertNull(env)
}

@Test
fun `Environment by payload url`() {
settingStore.setRemoteProperties(TestFileUtils.readTextFile(javaClass.classLoader!!,"environments/targetVersionEnvs.json"))
val env = EnvironmentUtils.getExternalEnvironmentByPayload(context, "https://mixedreality.mozilla.org/FirefoxReality/envs/space/space.zip", "11")
val env = EnvironmentUtils.getExternalEnvironmentByPayload(context, "https://mixedreality.mozilla.org/FirefoxReality/envs/wolvic/space.zip", "11")
assertNotNull(env)
assertEquals(env?.value, "space")
assertEquals(env?.title, "Space")
assertEquals(env?.thumbnail, "https://mixedreality.mozilla.org/FirefoxReality/envs/space/thumbnail.jpg")
assertEquals(env?.payload, "https://mixedreality.mozilla.org/FirefoxReality/envs/space/space.zip")
assertEquals(env?.value, "wolvic")
assertEquals(env?.title, "Wolvic")
assertEquals(env?.thumbnail, "https://mixedreality.mozilla.org/FirefoxReality/envs/wolvic/thumbnail.jpg")
assertEquals(env?.payload, "https://mixedreality.mozilla.org/FirefoxReality/envs/wolvic/space.zip")
}

@Test
fun `Environment is builtin`() {
assertTrue(EnvironmentUtils.isBuiltinEnvironment(context, "void"))
assertTrue(EnvironmentUtils.isBuiltinEnvironment(context, "offworld"))
assertTrue(EnvironmentUtils.isBuiltinEnvironment(context, "wolvic"))
assertTrue(EnvironmentUtils.isBuiltinEnvironment(context, "cyberpunk"))
}

@Test
fun `Environment is external`() {
settingStore.setRemoteProperties(TestFileUtils.readTextFile(javaClass.classLoader!!,"environments/targetVersionEnvs.json"))
val isExternal = EnvironmentUtils.isExternalEnvironment(context, "space", "11")
val isExternal = EnvironmentUtils.isExternalEnvironment(context, "wolvic", "1")
assertTrue(isExternal)
}

@Test
fun `Environment is not external`() {
settingStore.setRemoteProperties(TestFileUtils.readTextFile(javaClass.classLoader!!,"environments/testNoEnvs.json"))
val isExternal = EnvironmentUtils.isExternalEnvironment(context, "space", "11")
val isExternal = EnvironmentUtils.isExternalEnvironment(context, "wolvic", "1")
assertFalse(isExternal)
}

@Test
fun `External environment path`() {
var path = context.getExternalFilesDir(EnvironmentUtils.ENVS_FOLDER)
assertNotNull(path)
path = File(path, "space")
val cacheDir = context.cacheDir.absolutePath
assertNotNull(cacheDir)

val path = File(cacheDir, EnvironmentUtils.ENVS_FOLDER + "/wolvic")
assertNotNull(path)

val actualPath = EnvironmentUtils.getExternalEnvPath(context, "space")
val actualPath = EnvironmentUtils.getExternalEnvPath(context, "wolvic")
assertNotNull(actualPath)

assertEquals(actualPath, path.absolutePath)
assertEquals(path.absolutePath, actualPath)
}

@Test
fun `External environment is not ready`() {
val isReady = EnvironmentUtils.isExternalEnvReady(context, "space")
val isReady = EnvironmentUtils.isExternalEnvReady(context, "wolvic")
assertFalse(isReady)
}

@Test
fun `External environment is ready`() {
val actualPath = EnvironmentUtils.getExternalEnvPath(context, "space")
val actualPath = EnvironmentUtils.getExternalEnvPath(context, "wolvic")
assertNotNull(actualPath)

// We just check that there are 6 files in the directory to determine that the env is ready
Expand All @@ -154,7 +153,7 @@ class EnvironmentsTest {
assertTrue(file.createNewFile())
}

val isReady = EnvironmentUtils.isExternalEnvReady(context, "space")
val isReady = EnvironmentUtils.isExternalEnvReady(context, "wolvic")
assertTrue(isReady)
}

Expand Down
9 changes: 9 additions & 0 deletions app/src/test/resources/environments/previousVersionEnvs.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@
{
"value": "wolvic",
"title": "Wolvic",
"thumbnail": "https://mixedreality.mozilla.org/FirefoxReality/envs/wolvic/thumbnail.jpg",
"payload": "https://mixedreality.mozilla.org/FirefoxReality/envs/wolvic/space.zip"
},
{
"value": "meadow",
"title": "Meadow",
"thumbnail": "https://mixedreality.mozilla.org/FirefoxReality/envs/meadow/thumbnail.jpg",
"payload": "https://mixedreality.mozilla.org/FirefoxReality/envs/meadow/space.zip"
}
]
},
"2": {
"whatsNewUrl": "https://blog.mozvr.com/firefox-reality-11/"
}
}
9 changes: 9 additions & 0 deletions app/src/test/resources/environments/targetVersionEnvs.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@
{
"value": "wolvic",
"title": "Wolvic",
"thumbnail": "https://mixedreality.mozilla.org/FirefoxReality/envs/wolvic/thumbnail.jpg",
"payload": "https://mixedreality.mozilla.org/FirefoxReality/envs/wolvic/space.zip"
},
{
"value": "meadow",
"title": "Meadow",
"thumbnail": "https://mixedreality.mozilla.org/FirefoxReality/envs/meadow/thumbnail.jpg",
"payload": "https://mixedreality.mozilla.org/FirefoxReality/envs/meadow/space.zip"
}
]
},
"2": {
"whatsNewUrl": "https://blog.mozvr.com/firefox-reality-11/"
}
}
2 changes: 1 addition & 1 deletion app/src/test/resources/environments/testNoEnvs.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"11": {
"1": {
"whatsNewUrl": "https://wolvic.com",
"environments": [
]
Expand Down
Loading