Skip to content

Commit

Permalink
Merge branch 'main' into otdGame_design
Browse files Browse the repository at this point in the history
  • Loading branch information
dbrant committed Jan 8, 2025
2 parents 95dc74f + 3d56e17 commit c9ddd08
Show file tree
Hide file tree
Showing 308 changed files with 8,658 additions and 3,592 deletions.
18 changes: 17 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
id 'kotlin-android'
id 'kotlin-parcelize'
id 'kotlinx-serialization'
alias(libs.plugins.compose.compiler)
}

// Copy the signing.properties.sample file to ~/.sign/signing.properties and adjust the values.
Expand Down Expand Up @@ -37,7 +38,7 @@ android {
applicationId 'org.wikipedia'
minSdk 21
targetSdk 35
versionCode 50508
versionCode 50515
testApplicationId 'org.wikipedia.test'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments clearPackageData: 'true'
Expand All @@ -63,6 +64,7 @@ android {
buildFeatures {
viewBinding true
buildConfig true
compose true
}

androidResources {
Expand Down Expand Up @@ -263,6 +265,20 @@ dependencies {
androidTestImplementation libs.androidx.uiautomator
androidTestImplementation libs.room.testing
androidTestUtil libs.androidx.orchestrator

// Compose Library
def composeBom = platform(libs.composeBom)
implementation(composeBom)
implementation(libs.compose.material3)
implementation(libs.compose.ui)
implementation(libs.compose.ui.tooling.preview)
debugImplementation(libs.compose.ui.tooling)
implementation(libs.compose.activity)
implementation(libs.compose.view.model)

// Compose Test Library
androidTestImplementation(libs.compose.test)
androidTestImplementation(composeBom)
}

private setSigningConfigKey(config, Properties props) {
Expand Down
11 changes: 11 additions & 0 deletions app/src/androidTest/java/org/wikipedia/EspressoLogger.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.wikipedia

import android.util.Log

object EspressoLogger {
private const val TAG = "EspressoError"

fun logError(message: String) {
Log.e(TAG, message)
}
}
24 changes: 24 additions & 0 deletions app/src/androidTest/java/org/wikipedia/FakeData.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.wikipedia

import android.location.Location
import android.net.Uri
import org.wikipedia.dataclient.WikiSite
import org.wikipedia.history.HistoryEntry
import org.wikipedia.page.PageTitle

object FakeData {
val site = WikiSite(
uri = Uri.parse("https://en.wikipedia.org")
)
val title = PageTitle(
_displayText = "Hopf_fibration",
_text = "Hopf fibration",
description = "Fiber bundle of the 3-sphere over the 2-sphere, with 1-spheres as fibers",
thumbUrl = "https://upload.wikimedia.org/wikipedia/commons/thumb/b/b9/Hopf_Fibration.png/320px-Hopf_Fibration.png",
wikiSite = site
)
val inNewTab = false
val position = 0
val location: Location? = null
val historyEntry = HistoryEntry(title, HistoryEntry.SOURCE_SEARCH)
}
13 changes: 13 additions & 0 deletions app/src/androidTest/java/org/wikipedia/TestConstants.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.wikipedia

object TestConstants {
const val FEATURED_ARTICLE = "Featured article"
const val TODAY_ON_WIKIPEDIA_MAIN_PAGE = "Today on Wikipedia"
const val TOP_READ_ARTICLES = "Top read"
const val PICTURE_OF_DAY = "Picture of the day"
const val BECAUSE_YOU_READ = "Because you read"
const val NEWS_CARD = "In the news"
const val ON_THIS_DAY_CARD = "On this day"
const val RANDOM_CARD = "Random article"
const val SUGGESTED_EDITS = "Suggested edits"
}
33 changes: 33 additions & 0 deletions app/src/androidTest/java/org/wikipedia/TestLogRule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.wikipedia

import org.junit.rules.TestRule
import org.junit.runner.Description
import org.junit.runners.model.Statement

class TestLogRule : TestRule {
override fun apply(base: Statement, description: Description): Statement {
return object : Statement() {
override fun evaluate() {
try {
base.evaluate()
} catch (t: Throwable) {
val locationErrorLog = t.stackTrace
.filter { it.className.contains("org.wikipedia") }
.take(3)
.joinToString("\n") {
"\u2551 at ${it.fileName}:${it.lineNumber} --> ${it.methodName}()"
}
val errorLog = buildString {
appendLine("════ TEST FAILURE ════")
append(locationErrorLog)
appendLine("Stack Trace: ")
append(t.localizedMessage)
appendLine("\n══════════════════════")
}
EspressoLogger.logError(errorLog)
throw t
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package org.wikipedia.base

import android.view.View
import android.webkit.ValueCallback
import android.webkit.WebView
import androidx.test.espresso.PerformException
import androidx.test.espresso.UiController
import androidx.test.espresso.ViewAction
import androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom
import androidx.test.espresso.util.HumanReadables
import org.hamcrest.Matcher
import java.util.concurrent.atomic.AtomicBoolean

class AssertJavascriptAction(val script: String, val expectedResult: String) : ViewAction, ValueCallback<String> {
private var result: String? = null
private val evaluateFinished = AtomicBoolean(false)
private val exception = PerformException.Builder()
.withActionDescription(this.description)

override fun getConstraints(): Matcher<View> {
return isAssignableFrom(WebView::class.java)
}

override fun getDescription(): String {
return "Evaluate Javascript"
}

override fun perform(uiController: UiController, view: View) {
uiController.loopMainThreadUntilIdle()

val webView = view as WebView
exception.withViewDescription(HumanReadables.describe(view))

webView.evaluateJavascript(script, this)

val maxTime = System.currentTimeMillis() + 5000
while (!evaluateFinished.get()) {
if (System.currentTimeMillis() > maxTime) {
throw exception
.withCause(RuntimeException("Evaluating Javascript timed out."))
.build()
}
uiController.loopMainThreadForAtLeast(50)
}
}

override fun onReceiveValue(value: String) {
evaluateFinished.set(true)
if (value != expectedResult) {
throw exception
.withCause(RuntimeException("Expected: $expectedResult, but got: $value"))
.build()
}
}
}
Loading

0 comments on commit c9ddd08

Please sign in to comment.