Search in sources :

Example 1 with AccountDataLoadedEvent

use of org.edx.mobile.event.AccountDataLoadedEvent in project edx-app-android by edx.

the class UserProfileInteractorTest method onAccountUpdatedEvent_withMatchingUsername_emitsUpdatedProfileContent.

@Test
public void onAccountUpdatedEvent_withMatchingUsername_emitsUpdatedProfileContent() throws Exception {
    final Account account = configureBareMockAccount();
    createAndObserveInteractor();
    verify(profileObserver).onData(refEq(new UserProfileViewModel(UserProfileViewModel.LimitedProfileMessage.NONE, null, null, new UserProfileBioModel(UserProfileBioModel.ContentType.NO_ABOUT_ME, null))));
    when(account.getBio()).thenReturn(ProfileValues.ABOUT_ME);
    eventBus.post(new AccountDataLoadedEvent(account));
    verify(profileObserver).onData(refEq(new UserProfileViewModel(UserProfileViewModel.LimitedProfileMessage.NONE, null, null, new UserProfileBioModel(UserProfileBioModel.ContentType.ABOUT_ME, ProfileValues.ABOUT_ME))));
}
Also used : Account(org.edx.mobile.user.Account) AccountDataLoadedEvent(org.edx.mobile.event.AccountDataLoadedEvent) BaseTest(org.edx.mobile.test.BaseTest) Test(org.junit.Test)

Example 2 with AccountDataLoadedEvent

use of org.edx.mobile.event.AccountDataLoadedEvent in project edx-app-android by edx.

the class UserProfileInteractorTest method onAccountUpdatedEvent_withUnrelatedUsername_emitsUpdatedProfileContent.

@Test
public void onAccountUpdatedEvent_withUnrelatedUsername_emitsUpdatedProfileContent() throws Exception {
    final Account account = configureBareMockAccount();
    createAndObserveInteractor();
    verify(profileObserver).onData(refEq(new UserProfileViewModel(UserProfileViewModel.LimitedProfileMessage.NONE, null, null, new UserProfileBioModel(UserProfileBioModel.ContentType.NO_ABOUT_ME, null))));
    when(account.getUsername()).thenReturn(ProfileValues.ALTERNATE_USERNAME);
    when(account.getBio()).thenReturn(ProfileValues.ABOUT_ME);
    eventBus.post(new AccountDataLoadedEvent(account));
    verifyNoMoreInteractions(profileObserver);
}
Also used : Account(org.edx.mobile.user.Account) AccountDataLoadedEvent(org.edx.mobile.event.AccountDataLoadedEvent) BaseTest(org.edx.mobile.test.BaseTest) Test(org.junit.Test)

Example 3 with AccountDataLoadedEvent

use of org.edx.mobile.event.AccountDataLoadedEvent in project edx-app-android by edx.

the class NavigationFragmentTest method testProfileImageUpdation_onGlobalAccountEvent.

@Test
public void testProfileImageUpdation_onGlobalAccountEvent() {
    final NavigationFragment fragment = new NavigationFragment();
    SupportFragmentTestUtil.startVisibleFragment(fragment);
    final View view = fragment.getView();
    assertNotNull(view);
    final ImageView profileImage = (ImageView) view.findViewById(R.id.profile_image);
    assertNotNull(profileImage);
    // Assert: Profile pic not updated when a non-logged in user's account object is broadcasted
    Drawable previousDrawable = profileImage.getDrawable();
    Account account = configureMockAccount("not_logged_in_user");
    EventBus.getDefault().post(new AccountDataLoadedEvent(account));
    assertEquals(previousDrawable, profileImage.getDrawable());
    // Assert: Profile pic is updated when a logged-in user's account object is broadcasted
    UserPrefs userPrefs = RoboGuice.getInjector(context).getInstance(UserPrefs.class);
    final String loggedInUser = userPrefs.getProfile().username;
    account = configureMockAccount(loggedInUser);
    EventBus.getDefault().post(new AccountDataLoadedEvent(account));
    assertNotEquals(previousDrawable, profileImage.getDrawable());
}
Also used : Account(org.edx.mobile.user.Account) Drawable(android.graphics.drawable.Drawable) ImageView(android.widget.ImageView) AccountDataLoadedEvent(org.edx.mobile.event.AccountDataLoadedEvent) ImageView(android.widget.ImageView) View(android.view.View) UserPrefs(org.edx.mobile.module.prefs.UserPrefs) Test(org.junit.Test)

Aggregations

AccountDataLoadedEvent (org.edx.mobile.event.AccountDataLoadedEvent)3 Account (org.edx.mobile.user.Account)3 Test (org.junit.Test)3 BaseTest (org.edx.mobile.test.BaseTest)2 Drawable (android.graphics.drawable.Drawable)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 UserPrefs (org.edx.mobile.module.prefs.UserPrefs)1