Skip to content
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
16 changes: 10 additions & 6 deletions app/unit-tests/src/org/commcare/l10n/BaseConnectScreenshotTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,27 @@ import org.junit.rules.TestRule

/**
* The showcase user signed in to Connect, whose screens read seeded data from the local database, with every
* network call answered empty so none of it is pruned.
* network call answered by [responseBody], empty unless a test says otherwise, so none of it is pruned.
*/
abstract class BaseConnectScreenshotTest(
protected val target: ScreenshotTarget,
) {
@get:Rule
val localeRule: TestRule = L10nScreenshots.localeRule(target)

private val mockApi = ConnectMockApiServer()
protected val mockApi = ConnectMockApiServer()

@Before
fun setUpConnect() {
mockApi.start()
mockApi.server.dispatcher = emptyJsonDispatcher()
mockApi.server.dispatcher = showcaseDispatcher()
ConnectRepository.resetInstance()
ConnectRequestManager.cancelAll()
mockOutsideWorld()

ConnectTestUtils.createConnectDbFile()
ConnectUserDatabaseUtil.storeUser(
ConnectScreenshotData.user(hasConnectAccess = true).apply {
ConnectScreenshotData.buildUser(hasConnectAccess = true).apply {
updateConnectToken("showcase-connect-token", ConnectTestUtils.daysFromNow(1))
},
)
Expand Down Expand Up @@ -86,8 +86,12 @@ abstract class BaseConnectScreenshotTest(
every { AppUtils.isAppInstalled(any()) } returns true
}

private fun emptyJsonDispatcher(): Dispatcher =
/** The JSON body the mock Connect server answers a request for [path] with. */
protected open fun responseBody(path: String): String = "{}"

private fun showcaseDispatcher(): Dispatcher =
object : Dispatcher() {
override fun dispatch(request: RecordedRequest): MockResponse = MockResponse().setResponseCode(200).setBody("{}")
override fun dispatch(request: RecordedRequest): MockResponse =
MockResponse().setResponseCode(200).setBody(responseBody(request.requestUrl?.encodedPath.orEmpty()))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class ChannelListScreenshotTest(
@Before
fun seedMessaging() {
val context = ApplicationProvider.getApplicationContext<CommCareTestApplication>()
ConnectScreenshotData.channels().forEach { ConnectMessagingDatabaseHelper.storeMessagingChannel(context, it) }
ConnectScreenshotData.messages().forEach { ConnectMessagingDatabaseHelper.storeMessagingMessage(context, it) }
ConnectScreenshotData.buildChannels().forEach { ConnectMessagingDatabaseHelper.storeMessagingChannel(context, it) }
ConnectScreenshotData.buildMessages().forEach { ConnectMessagingDatabaseHelper.storeMessagingMessage(context, it) }
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class ChannelMessagesScreenshotTest(
@Before
fun seedMessaging() {
val context = ApplicationProvider.getApplicationContext<CommCareTestApplication>()
ConnectScreenshotData.channels().forEach { ConnectMessagingDatabaseHelper.storeMessagingChannel(context, it) }
ConnectScreenshotData.messages().forEach { ConnectMessagingDatabaseHelper.storeMessagingMessage(context, it) }
ConnectScreenshotData.buildChannels().forEach { ConnectMessagingDatabaseHelper.storeMessagingChannel(context, it) }
ConnectScreenshotData.buildMessages().forEach { ConnectMessagingDatabaseHelper.storeMessagingMessage(context, it) }
}

@Test
Expand Down
Loading
Loading