Skip to content

Commit

Permalink
memindahkan fungsi addtofavorite dan removefavorite ke detailpresenter
Browse files Browse the repository at this point in the history
  • Loading branch information
andremw96 committed Oct 26, 2018
1 parent a47af0f commit df11f18
Show file tree
Hide file tree
Showing 22 changed files with 656 additions and 188 deletions.
2 changes: 1 addition & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,23 @@ androidExtensions {
experimental = true
}

kotlin {
experimental {
coroutines "enable"
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:0.25.3"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-v4:28.0.0'
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.22.0'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

Expand All @@ -45,11 +54,26 @@ dependencies {
//anko
implementation "org.jetbrains.anko:anko:$anko_version"
implementation "org.jetbrains.anko:anko-design:$anko_version"
implementation "org.jetbrains.anko:anko-coroutines:$anko_version"
implementation "org.jetbrains.anko:anko-sdk15-coroutines:$anko_version"
implementation "org.jetbrains.anko:anko-appcompat-v7-coroutines:$anko_version"
implementation "org.jetbrains.anko:anko-design-coroutines:$anko_version"

// RecyclerView-v7
implementation "org.jetbrains.anko:anko-recyclerview-v7:$anko_version"
implementation "org.jetbrains.anko:anko-recyclerview-v7-coroutines:$anko_version"

implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.google.code.gson:gson:2.8.5'

//mockito
testImplementation 'org.mockito:mockito-core:2.22.0'
testImplementation "org.mockito:mockito-inline:2.22.0"

androidTestImplementation("com.android.support.test.espresso:espresso-contrib:2.2.2") {
exclude group: 'com.android.support', module: 'appcompat-v7'
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.android.support', module: 'design'
exclude group: 'com.android.support', module: 'recyclerview-v7'
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
package com.example.wijaya_pc.eplmatchschedule

import android.support.test.espresso.Espresso
import android.support.test.espresso.Espresso.onView
import android.support.test.espresso.Espresso.pressBack
import android.support.test.espresso.action.ViewActions.click
import android.support.test.espresso.assertion.ViewAssertions.matches
import android.support.test.espresso.contrib.RecyclerViewActions
import android.support.test.espresso.matcher.ViewMatchers
import android.support.test.espresso.matcher.ViewMatchers.isDisplayed
import android.support.test.espresso.matcher.ViewMatchers.withId
import android.support.test.rule.ActivityTestRule
import android.support.test.runner.AndroidJUnit4
import android.support.v7.widget.RecyclerView
import com.example.wijaya_pc.eplmatchschedule.R.id.*
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class MainActivityTest {
@Rule
@JvmField var activityRule = ActivityTestRule(MainActivity::class.java)

@Test
fun testRecyclerViewLastMatchBehaviour() {
Thread.sleep(1000)

onView(withId(listMatch)).check(matches(isDisplayed()))
Thread.sleep(1000)
onView(withId(listMatch)).perform(RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(14))
Thread.sleep(1000)
onView(withId(listMatch)).perform(RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(1))
Thread.sleep(1000)
onView(withId(listMatch)).perform(RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(1, click()))
}

@Test
fun testRecyclerViewNextMatchBehaviour() {
Thread.sleep(1000)

onView(withId(bottom_navigation)).check(matches(isDisplayed()))
onView(withId(tab_next_match)).perform(click())
Thread.sleep(1000)

onView(withId(listMatch)).check(matches(isDisplayed()))
Thread.sleep(1000)
onView(withId(listMatch)).perform(RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(7))
Thread.sleep(1000)
onView(withId(listMatch)).perform(RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(3))
Thread.sleep(1000)
onView(withId(listMatch)).perform(RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(3, click()))
}

@Test
fun testRecyclerViewFavoritesBehaviour() {
Thread.sleep(1000)

onView(withId(bottom_navigation)).check(matches(isDisplayed()))
onView(withId(favorites)).perform(click())
Thread.sleep(1000)

onView(withId(listFav)).check(matches(isDisplayed()))
Thread.sleep(1000)
onView(withId(listFav)).perform(RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(14))
Thread.sleep(1000)
onView(withId(listFav)).perform(RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(0))
Thread.sleep(1000)
onView(withId(listFav)).perform(RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(0, click()))
}


@Test
fun testAddFavoriteFromLastMatchBehaviour() {
Thread.sleep(1000)

onView(withId(listMatch)).check(matches(isDisplayed()))
onView(ViewMatchers.withText("Crystal Palace")).perform(click())
Thread.sleep(1000)

onView(withId(add_to_favorite)).check(matches(isDisplayed()))
onView(withId(add_to_favorite)).perform(click())
onView(ViewMatchers.withText("Added to FavoriteMatches")).check(matches(isDisplayed()))
Thread.sleep(1000)

onView(withId(add_to_favorite)).check(matches(isDisplayed()))
Thread.sleep(1000)
onView(withId(add_to_favorite)).perform(click())
Thread.sleep(1000)
onView(ViewMatchers.withText("Removed from FavoriteMatches")).check(matches(isDisplayed()))
Thread.sleep(1000)

onView(withId(add_to_favorite)).check(matches(isDisplayed()))
Thread.sleep(1000)
onView(withId(add_to_favorite)).perform(click())
Thread.sleep(1000)
onView(ViewMatchers.withText("Added to FavoriteMatches")).check(matches(isDisplayed()))
Thread.sleep(1000)

pressBack()

onView(withId(listMatch)).check(matches(isDisplayed()))
Thread.sleep(1000)

onView(withId(listMatch)).perform(RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(5))
Thread.sleep(1000)
onView(withId(listMatch)).perform(RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(5, click()))
Thread.sleep(1000)

onView(withId(add_to_favorite)).check(matches(isDisplayed()))
onView(withId(add_to_favorite)).perform(click())
onView(ViewMatchers.withText("Added to FavoriteMatches")).check(matches(isDisplayed()))

pressBack()

onView(withId(bottom_navigation)).check(matches(isDisplayed()))
onView(withId(favorites)).perform(click())
Thread.sleep(1000)
}

@Test
fun testAddFavoriteFromNextMatchBehaviour() {
Thread.sleep(1000)

onView(withId(listMatch)).check(matches(isDisplayed()))
Thread.sleep(1000)

onView(withId(bottom_navigation)).check(matches(isDisplayed()))
onView(withId(tab_next_match)).perform(click())
Thread.sleep(1000)

onView(withId(listMatch)).check(matches(isDisplayed()))
onView(ViewMatchers.withText("Liverpool")).perform(click())
Thread.sleep(1000)

onView(withId(add_to_favorite)).check(matches(isDisplayed()))
onView(withId(add_to_favorite)).perform(click())
onView(ViewMatchers.withText("Added to FavoriteMatches")).check(matches(isDisplayed()))
Thread.sleep(1000)

onView(withId(add_to_favorite)).check(matches(isDisplayed()))
Thread.sleep(1000)
onView(withId(add_to_favorite)).perform(click())
Thread.sleep(1000)
onView(ViewMatchers.withText("Removed from FavoriteMatches")).check(matches(isDisplayed()))
Thread.sleep(1000)

onView(withId(add_to_favorite)).check(matches(isDisplayed()))
Thread.sleep(1000)
onView(withId(add_to_favorite)).perform(click())
Thread.sleep(1000)
onView(ViewMatchers.withText("Added to FavoriteMatches")).check(matches(isDisplayed()))
Thread.sleep(1000)

pressBack()

onView(withId(listMatch)).check(matches(isDisplayed()))
Thread.sleep(1000)

onView(withId(listMatch)).perform(RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(8))
Thread.sleep(1000)
onView(withId(listMatch)).perform(RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(8, click()))
Thread.sleep(1000)

onView(withId(add_to_favorite)).check(matches(isDisplayed()))
onView(withId(add_to_favorite)).perform(click())
onView(ViewMatchers.withText("Added to FavoriteMatches")).check(matches(isDisplayed()))

pressBack()

onView(withId(bottom_navigation)).check(matches(isDisplayed()))
onView(withId(favorites)).perform(click())
Thread.sleep(1000)
}

@Test
fun testDeleteFavoriteFromFavoritesFragmentBehaviour() {
Thread.sleep(1000)

onView(withId(listMatch)).check(matches(isDisplayed()))
Thread.sleep(1000)

onView(withId(bottom_navigation)).check(matches(isDisplayed()))
onView(withId(favorites)).perform(click())
Thread.sleep(1000)

onView(withId(listFav)).check(matches(isDisplayed()))
Thread.sleep(1000)
onView(withId(listFav)).perform(RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(0))
Thread.sleep(1000)
onView(withId(listFav)).perform(RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(0, click()))

onView(withId(add_to_favorite)).check(matches(isDisplayed()))
onView(withId(add_to_favorite)).perform(click())
onView(ViewMatchers.withText("Removed from FavoriteMatches")).check(matches(isDisplayed()))
Thread.sleep(1000)
}
}
Loading

0 comments on commit df11f18

Please sign in to comment.