Skip to content
This repository has been archived by the owner on May 8, 2019. It is now read-only.

Commit

Permalink
Merge pull request #1137 from 47deg/am-test-navigationJobs-collections
Browse files Browse the repository at this point in the history
Test navigation jobs collections
  • Loading branch information
Javi Pacheco authored Nov 24, 2016
2 parents ac70a9a + cc162da commit f435321
Show file tree
Hide file tree
Showing 2 changed files with 147 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
package cards.nine.app.ui.collections.jobs

import android.os.Bundle
import cards.nine.app.ui.collections.jobs.uiactions.{GroupCollectionsDOM, GroupCollectionsUiActions, NavigationUiActions}
import cards.nine.commons.test.TaskServiceSpecification
import cards.nine.commons.test.data.CollectionTestData
import macroid.ActivityContextWrapper
import org.specs2.mock.Mockito
import org.specs2.specification.Scope


trait NavigationJobsSpecification extends TaskServiceSpecification
with Mockito
with CollectionTestData {


trait NavigationJobsScope
extends Scope {

implicit val contextWrapper = mock[ActivityContextWrapper]

implicit val mockGroupCollectionsJobs = mock[GroupCollectionsJobs]

implicit val mockSingleCollectionJobs = mock[SingleCollectionJobs]

val mockGroupCollectionsDOM = mock[GroupCollectionsDOM]

val mockGroupCollectionsUiActions = mock[GroupCollectionsUiActions]

val mockNavigationUiActions = mock[NavigationUiActions]

mockNavigationUiActions.dom returns mockGroupCollectionsDOM

val mockBundle = mock[Bundle]

val navigationJobs = new NavigationJobs(mockGroupCollectionsUiActions, mockNavigationUiActions)(contextWrapper)

}
}

class NavigationJobsSpec
extends NavigationJobsSpecification {

"showAppDialog" should {
"call to openApps" in new NavigationJobsScope {

mockGroupCollectionsDOM.getCurrentCollection returns Option(collection)
mockNavigationUiActions.openApps(any)(any, any) returns serviceRight(Unit)

navigationJobs.showAppDialog()(mockGroupCollectionsJobs, Option(mockSingleCollectionJobs)).mustRightUnit

there was two(mockGroupCollectionsDOM).getCurrentCollection
there was one(mockNavigationUiActions).openApps(any)(===(mockGroupCollectionsJobs), ===(Option(mockSingleCollectionJobs)))
}

"call to openApps when current collection is None" in new NavigationJobsScope {

mockGroupCollectionsDOM.getCurrentCollection returns None
mockNavigationUiActions.openApps(any)(any, any) returns serviceRight(Unit)

navigationJobs.showAppDialog()(mockGroupCollectionsJobs, Option(mockSingleCollectionJobs)).mustRightUnit

there was two(mockGroupCollectionsDOM).getCurrentCollection
there was one(mockNavigationUiActions).openApps(any)(===(mockGroupCollectionsJobs), ===(Option(mockSingleCollectionJobs)))
}
}

"showRecommendationDialog" should {

"call to openRecommendations" in new NavigationJobsScope {

mockGroupCollectionsDOM.getCurrentCollection returns Option(collection)
mockNavigationUiActions.openRecommendations(any)(any, any) returns serviceRight(Unit)

navigationJobs.showRecommendationDialog()(mockGroupCollectionsJobs, Option(mockSingleCollectionJobs)).mustRightUnit

there was two(mockGroupCollectionsDOM).getCurrentCollection
there was one(mockNavigationUiActions).openRecommendations(any)(===(mockGroupCollectionsJobs), ===(Option(mockSingleCollectionJobs)))
}

"shows a message of ContactUsError when current collection doesn't have appCategory and their cards doesn't have packageName" in new NavigationJobsScope {

mockGroupCollectionsDOM.getCurrentCollection returns Option(collection.copy(appsCategory = None, cards = collection.cards.map (_.copy(packageName = None))))
mockGroupCollectionsUiActions.showContactUsError() returns serviceRight(Unit)

navigationJobs.showRecommendationDialog()(mockGroupCollectionsJobs, Option(mockSingleCollectionJobs)).mustRightUnit

there was one(mockGroupCollectionsDOM).getCurrentCollection
there was one(mockGroupCollectionsUiActions).showContactUsError()
}

"shows a message of ContactUsError when current collection is None" in new NavigationJobsScope {

mockGroupCollectionsDOM.getCurrentCollection returns None
mockGroupCollectionsUiActions.showContactUsError() returns serviceRight(Unit)

navigationJobs.showRecommendationDialog()(mockGroupCollectionsJobs, Option(mockSingleCollectionJobs)).mustRightUnit

there was one(mockGroupCollectionsDOM).getCurrentCollection
there was one(mockGroupCollectionsUiActions).showContactUsError()
}
}

"showContactsDialog" should {
"call to openContacts" in new NavigationJobsScope {

mockNavigationUiActions.openContacts(any)(any, any) returns serviceRight(Unit)
mockGroupCollectionsDOM.getCurrentCollection returns Option(collection)

navigationJobs.showContactsDialog()(mockGroupCollectionsJobs, Option(mockSingleCollectionJobs)).mustRightUnit
there was one(mockNavigationUiActions).openContacts(any)(===(mockGroupCollectionsJobs), ===(Option(mockSingleCollectionJobs)))
}

"call to openContacts when current collection is None" in new NavigationJobsScope {

mockNavigationUiActions.openContacts(any)(any, any) returns serviceRight(Unit)
mockGroupCollectionsDOM.getCurrentCollection returns None

navigationJobs.showContactsDialog()(mockGroupCollectionsJobs, Option(mockSingleCollectionJobs)).mustRightUnit
there was one(mockNavigationUiActions).openContacts(any)(===(mockGroupCollectionsJobs), ===(Option(mockSingleCollectionJobs)))
}
}

"showShortcutDialog" should {
"call to openShortcuts" in new NavigationJobsScope {

mockNavigationUiActions.openShortcuts(any)(any, any) returns serviceRight(Unit)
mockGroupCollectionsDOM.getCurrentCollection returns Option(collection)

navigationJobs.showShortcutDialog()(mockGroupCollectionsJobs, Option(mockSingleCollectionJobs)).mustRightUnit
there was one(mockNavigationUiActions).openShortcuts(any)(===(mockGroupCollectionsJobs), ===(Option(mockSingleCollectionJobs)))
}

"call to openShortcuts when current collection is None" in new NavigationJobsScope {

mockNavigationUiActions.openShortcuts(any)(any, any) returns serviceRight(Unit)
mockGroupCollectionsDOM.getCurrentCollection returns None

navigationJobs.showShortcutDialog()(mockGroupCollectionsJobs, Option(mockSingleCollectionJobs)).mustRightUnit
there was one(mockNavigationUiActions).openShortcuts(any)(===(mockGroupCollectionsJobs), ===(Option(mockSingleCollectionJobs)))
}
}
}
8 changes: 4 additions & 4 deletions modules/mock-android/src/main/java/android/os/Bundle.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public class Bundle implements Parcelable, Cloneable {
public static final Bundle EMPTY = null;
public static final Creator<Bundle> CREATOR = null;
public Bundle() { throw new RuntimeException("Stub!"); }
public Bundle() { }
public Bundle(ClassLoader loader) { throw new RuntimeException("Stub!"); }
public Bundle(int capacity) { throw new RuntimeException("Stub!"); }
public Bundle(Bundle b) { throw new RuntimeException("Stub!"); }
Expand All @@ -27,11 +27,11 @@ public class Bundle implements Parcelable, Cloneable {
public void putByte(String key, byte value) { throw new RuntimeException("Stub!"); }
public void putChar(String key, char value) { throw new RuntimeException("Stub!"); }
public void putShort(String key, short value) { throw new RuntimeException("Stub!"); }
public void putInt(String key, int value) { throw new RuntimeException("Stub!"); }
public void putInt(String key, int value) { }
public void putLong(String key, long value) { throw new RuntimeException("Stub!"); }
public void putFloat(String key, float value) { throw new RuntimeException("Stub!"); }
public void putDouble(String key, double value) { throw new RuntimeException("Stub!"); }
public void putString(String key, String value) { throw new RuntimeException("Stub!"); }
public void putString(String key, String value) { }
public void putCharSequence(String key, CharSequence value) { throw new RuntimeException("Stub!"); }
public void putParcelable(String key, Parcelable value) { throw new RuntimeException("Stub!"); }
public void putParcelableArray(String key, Parcelable[] value) { throw new RuntimeException("Stub!"); }
Expand All @@ -49,7 +49,7 @@ public class Bundle implements Parcelable, Cloneable {
public void putLongArray(String key, long[] value) { throw new RuntimeException("Stub!"); }
public void putFloatArray(String key, float[] value) { throw new RuntimeException("Stub!"); }
public void putDoubleArray(String key, double[] value) { throw new RuntimeException("Stub!"); }
public void putStringArray(String key, String[] value) { throw new RuntimeException("Stub!"); }
public void putStringArray(String key, String[] value) { }
public void putCharSequenceArray(String key, CharSequence[] value) { throw new RuntimeException("Stub!"); }
public void putBundle(String key, Bundle value) { throw new RuntimeException("Stub!"); }
public boolean getBoolean(String key) { throw new RuntimeException("Stub!"); }
Expand Down

0 comments on commit f435321

Please sign in to comment.