-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
19279ed
commit 72f445d
Showing
20 changed files
with
974 additions
and
65 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 |
---|---|---|
|
@@ -548,5 +548,5 @@ | |
"translation": null | ||
} | ||
], | ||
"lastKey": "dJiBHLZjYWs6iSqb" | ||
"lastKey": null | ||
} |
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 @@ | ||
{} |
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,34 @@ | ||
{ | ||
"doctors": | ||
{ | ||
"id": 123456789, | ||
"name": "Dr. med. Mario Voss", | ||
"photoId": null, | ||
"rating": "2.5", | ||
"address": "Friedrichstraße 115, 10117 Berlin, Germany", | ||
"lat": "52.526779", | ||
"lng": "13.387201", | ||
"highlighted": false, | ||
"reviewCount": 5, | ||
"specialityIds": [ | ||
1 | ||
], | ||
"source": "google", | ||
"phoneNumber": "+29 30 28391555", | ||
"email": null, | ||
"website": "http://www.vivy-doc.de/", | ||
"openingHours": [ | ||
"D1T08:00/D1T12:00", | ||
"D1T15:00/D1T18:00", | ||
"D2T08:00/D2T12:00", | ||
"D3T08:00/D3T12:00", | ||
"D2T08:00/D2T12:00", | ||
"D2T15:00/D2T18:00", | ||
"D5T08:00/D5T12:00" | ||
], | ||
"integration": null, | ||
"translation": null | ||
} | ||
, | ||
"lastKey": "CvQD7gEAAKjcb" | ||
} |
104 changes: 104 additions & 0 deletions
104
app/src/androidTest/java/com/codechallenge/doctorscatalog/ClickOnItems.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,104 @@ | ||
package com.codechallenge.doctorscatalog | ||
|
||
import androidx.test.espresso.Espresso.onView | ||
import androidx.test.espresso.Espresso.pressBack | ||
import androidx.test.espresso.action.ViewActions.click | ||
import androidx.test.espresso.contrib.RecyclerViewActions | ||
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed | ||
import androidx.test.espresso.matcher.ViewMatchers.withId | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import androidx.test.filters.LargeTest | ||
import androidx.test.rule.ActivityTestRule | ||
import com.codechallenge.doctorscatalog.di.NetworkModule | ||
import com.codechallenge.doctorscatalog.ui.main.ItemViewHolder | ||
import com.codechallenge.doctorscatalog.utils.getStringFrom | ||
import com.codechallenge.doctorscatalog.utils.waitUntilViewWithId | ||
import com.codechallenge.doctorscatalog.utils.waitUntilViewWithText | ||
import dagger.hilt.android.testing.HiltAndroidRule | ||
import dagger.hilt.android.testing.HiltAndroidTest | ||
import dagger.hilt.android.testing.UninstallModules | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.InternalCoroutinesApi | ||
import okhttp3.mockwebserver.Dispatcher | ||
import okhttp3.mockwebserver.MockResponse | ||
import okhttp3.mockwebserver.MockWebServer | ||
import okhttp3.mockwebserver.RecordedRequest | ||
import org.junit.After | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
@UninstallModules(NetworkModule::class) | ||
@HiltAndroidTest | ||
class ClickOnItems { | ||
|
||
@get:Rule | ||
val hiltRule = HiltAndroidRule(this) | ||
|
||
@get:Rule | ||
val activityTestRule = ActivityTestRule(MainActivity::class.java, true, false) | ||
|
||
private lateinit var mockServer: MockWebServer | ||
|
||
@Before | ||
fun setUp() { | ||
hiltRule.inject() | ||
mockServer = MockWebServer() | ||
mockServer.start(8080) | ||
} | ||
|
||
@ExperimentalCoroutinesApi | ||
@InternalCoroutinesApi | ||
@Test | ||
fun clickOnVivyDoctors_shouldOpenDetails() { | ||
setDispatcher("doctors.json", 200) | ||
activityTestRule.launchActivity(null) | ||
|
||
waitUntilViewWithId(R.id.doctors_list_rv, 5, isDisplayed()) | ||
waitUntilViewWithText("Gemeinschaftspraxis Dr. Hintsche und Dr. Klausen", 5, isDisplayed()) | ||
onView(withId(R.id.doctors_list_rv)).perform(RecyclerViewActions.actionOnItemAtPosition<ItemViewHolder>(3, click())) | ||
waitUntilViewWithId(R.id.name_tv, 5, isDisplayed()) | ||
waitUntilViewWithText("Gemeinschaftspraxis Dr. Hintsche und Dr. Klausen", 5, isDisplayed()) | ||
} | ||
|
||
@ExperimentalCoroutinesApi | ||
@InternalCoroutinesApi | ||
@LargeTest | ||
@Test | ||
fun clickOnRecentDoctors_shouldOpenDetails() { | ||
setDispatcher("doctors.json", 200) | ||
activityTestRule.launchActivity(null) | ||
|
||
waitUntilViewWithId(R.id.doctors_list_rv, 5, isDisplayed()) | ||
waitUntilViewWithText("Gemeinschaftspraxis Dr. Hintsche und Dr. Klausen", 15, isDisplayed()) | ||
onView(withId(R.id.doctors_list_rv)).perform(RecyclerViewActions.actionOnItemAtPosition<ItemViewHolder>(3, click())) | ||
waitUntilViewWithId(R.id.name_tv, 15, isDisplayed()) | ||
waitUntilViewWithText("Gemeinschaftspraxis Dr. Hintsche und Dr. Klausen", 15, isDisplayed()) | ||
pressBack() | ||
onView(withId(R.id.doctor_1_iv)).perform(click()) | ||
waitUntilViewWithText("Gemeinschaftspraxis Dr. Hintsche und Dr. Klausen", 15, isDisplayed()) | ||
} | ||
|
||
private fun setDispatcher(fileName: String, responseCode: Int) { | ||
mockServer.dispatcher = object : Dispatcher() { | ||
override fun dispatch(request: RecordedRequest): MockResponse { | ||
val path = request.path | ||
if (!path.isNullOrEmpty() && path.contains("doctors-CvQD7gEAAKjcb.json")) { | ||
return MockResponse() | ||
.setResponseCode(responseCode) | ||
.setBody(getStringFrom("doctors-CvQD7gEAAKjcb.json")) | ||
} | ||
return MockResponse() | ||
.setResponseCode(responseCode) | ||
.setBody(getStringFrom(fileName)) | ||
} | ||
} | ||
} | ||
|
||
@After | ||
fun tearDown() { | ||
mockServer.shutdown() | ||
} | ||
} |
103 changes: 103 additions & 0 deletions
103
app/src/androidTest/java/com/codechallenge/doctorscatalog/ErrorsTest.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,103 @@ | ||
package com.codechallenge.doctorscatalog | ||
|
||
import androidx.test.espresso.Espresso | ||
import androidx.test.espresso.assertion.ViewAssertions | ||
import androidx.test.espresso.matcher.RootMatchers | ||
import androidx.test.espresso.matcher.ViewMatchers | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.rule.ActivityTestRule | ||
import androidx.test.uiautomator.UiDevice | ||
import com.codechallenge.doctorscatalog.di.NetworkModule | ||
import com.codechallenge.doctorscatalog.utils.getStringFrom | ||
import dagger.hilt.android.testing.HiltAndroidRule | ||
import dagger.hilt.android.testing.HiltAndroidTest | ||
import dagger.hilt.android.testing.UninstallModules | ||
import okhttp3.mockwebserver.Dispatcher | ||
import okhttp3.mockwebserver.MockResponse | ||
import okhttp3.mockwebserver.MockWebServer | ||
import okhttp3.mockwebserver.RecordedRequest | ||
import org.hamcrest.Matchers | ||
import org.junit.After | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
@UninstallModules(NetworkModule::class) | ||
@HiltAndroidTest | ||
class ErrorsTest { | ||
|
||
@get:Rule | ||
val hiltRule = HiltAndroidRule(this) | ||
|
||
@get:Rule | ||
val activityTestRule = ActivityTestRule(MainActivity::class.java, true, false) | ||
|
||
private lateinit var mockServer: MockWebServer | ||
|
||
@Before | ||
fun setUp() { | ||
hiltRule.inject() | ||
mockServer = MockWebServer() | ||
mockServer.start(8080) | ||
} | ||
|
||
@Test | ||
fun emptyJson_shouldShowErrorMessage() { | ||
setDispatcher("empty.json", 200) | ||
activityTestRule.launchActivity(null) | ||
checkToast("Result can not be parsed") | ||
} | ||
|
||
@Test | ||
fun malformedJson_shouldShowErrorMessage() { | ||
setDispatcher("malformed_doctors.json", 200) | ||
activityTestRule.launchActivity(null) | ||
checkToast("Result can not be parsed") | ||
} | ||
|
||
@Test | ||
fun networkError_shouldShowErrorMessage() { | ||
setDispatcher("doctors.json", 404) | ||
activityTestRule.launchActivity(null) | ||
checkToast("Network error") | ||
} | ||
|
||
private fun setDispatcher(fileName: String, responseCode: Int) { | ||
mockServer.dispatcher = object : Dispatcher() { | ||
override fun dispatch(request: RecordedRequest): MockResponse { | ||
val path = request.path | ||
if (!path.isNullOrEmpty() && path.contains("doctors-CvQD7gEAAKjcb.json")) { | ||
return MockResponse() | ||
.setResponseCode(responseCode) | ||
.setBody(getStringFrom("doctors-CvQD7gEAAKjcb.json")) | ||
} | ||
return MockResponse() | ||
.setResponseCode(responseCode) | ||
.setBody(getStringFrom(fileName)) | ||
} | ||
} | ||
} | ||
|
||
private fun checkToast(message: String) { | ||
Espresso.onView(ViewMatchers.withText(message)) | ||
.inRoot( | ||
RootMatchers.withDecorView( | ||
Matchers.not( | ||
Matchers.`is`( | ||
activityTestRule.activity.window.decorView | ||
) | ||
) | ||
) | ||
) | ||
.check(ViewAssertions.matches(ViewMatchers.isDisplayed())) | ||
} | ||
|
||
@After | ||
fun tearDown() { | ||
UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()).setOrientationNatural() | ||
mockServer.shutdown() | ||
} | ||
} |
24 changes: 0 additions & 24 deletions
24
app/src/androidTest/java/com/codechallenge/doctorscatalog/ExampleInstrumentedTest.kt
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
app/src/androidTest/java/com/codechallenge/doctorscatalog/MainTestRunner.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,16 @@ | ||
package com.codechallenge.doctorscatalog | ||
|
||
import android.app.Application | ||
import android.content.Context | ||
import androidx.test.runner.AndroidJUnitRunner | ||
import dagger.hilt.android.testing.HiltTestApplication | ||
|
||
class MainTestRunner : AndroidJUnitRunner() { | ||
override fun newApplication( | ||
cl: ClassLoader?, | ||
className: String?, | ||
context: Context? | ||
): Application { | ||
return super.newApplication(cl, HiltTestApplication::class.java.name, context) | ||
} | ||
} |
Oops, something went wrong.