-
-
Notifications
You must be signed in to change notification settings - Fork 647
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into otdGame_design
- Loading branch information
Showing
308 changed files
with
8,658 additions
and
3,592 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
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) | ||
} | ||
} |
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,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) | ||
} |
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,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" | ||
} |
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,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 | ||
} | ||
} | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
app/src/androidTest/java/org/wikipedia/base/AssertJavascriptAction.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,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() | ||
} | ||
} | ||
} |
Oops, something went wrong.