Search in sources :

Example 11 with Account

use of org.edx.mobile.user.Account in project edx-app-android by edx.

the class UserProfileInteractorTest method whenProfileImageObserved_withProfileImage_emitsFullImageUrl.

@Test
public void whenProfileImageObserved_withProfileImage_emitsFullImageUrl() {
    final Account account = configureBareMockAccount();
    final ProfileImage profileImage = account.getProfileImage();
    when(profileImage.hasImage()).thenReturn(true);
    when(profileImage.getImageUrlFull()).thenReturn(ProfileValues.ABSOLUTE_URL);
    createAndObserveInteractor();
    verify(imageObserver).onData(refEq(new UserProfileImageViewModel(Uri.parse(ProfileValues.ABSOLUTE_URL), true)));
}
Also used : Account(org.edx.mobile.user.Account) ProfileImage(org.edx.mobile.user.ProfileImage) BaseTest(org.edx.mobile.test.BaseTest) Test(org.junit.Test)

Example 12 with Account

use of org.edx.mobile.user.Account 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)

Example 13 with Account

use of org.edx.mobile.user.Account in project edx-app-android by edx.

the class NavigationFragmentTest method configureMockAccount.

@NonNull
private Account configureMockAccount(String username) {
    final ProfileImage profileImage = mock(ProfileImage.class);
    when(profileImage.hasImage()).thenReturn(true);
    when(profileImage.getImageUrlLarge()).thenReturn("file:///mnt/sdcard/dummy.jpg");
    final Account account = mock(Account.class);
    when(account.getUsername()).thenReturn(username);
    when(account.getProfileImage()).thenReturn(profileImage);
    return account;
}
Also used : Account(org.edx.mobile.user.Account) ProfileImage(org.edx.mobile.user.ProfileImage) NonNull(android.support.annotation.NonNull)

Example 14 with Account

use of org.edx.mobile.user.Account in project edx-app-android by edx.

the class EditUserProfileFragment method executeUpdate.

private void executeUpdate(FormField field, String fieldValue) {
    final Object valueObject;
    if (field.getDataType() == DataType.LANGUAGE) {
        if (TextUtils.isEmpty(fieldValue)) {
            valueObject = Collections.emptyList();
        } else {
            valueObject = Collections.singletonList(new LanguageProficiency(fieldValue));
        }
    } else {
        valueObject = fieldValue;
    }
    userService.updateAccount(username, Collections.singletonMap(field.getName(), valueObject)).enqueue(new AccountDataUpdatedCallback(getActivity(), username, new DialogErrorNotification(this)) {

        @Override
        protected void onResponse(@NonNull final Account account) {
            super.onResponse(account);
            EditUserProfileFragment.this.account = account;
            setData(account, formDescription);
        }
    });
}
Also used : LanguageProficiency(org.edx.mobile.user.LanguageProficiency) AccountDataUpdatedCallback(org.edx.mobile.user.UserAPI.AccountDataUpdatedCallback) Account(org.edx.mobile.user.Account) JsonObject(com.google.gson.JsonObject) DialogErrorNotification(org.edx.mobile.http.notifications.DialogErrorNotification)

Aggregations

Account (org.edx.mobile.user.Account)14 Test (org.junit.Test)11 BaseTest (org.edx.mobile.test.BaseTest)10 AccountDataLoadedEvent (org.edx.mobile.event.AccountDataLoadedEvent)3 LanguageProficiency (org.edx.mobile.user.LanguageProficiency)3 ProfileImage (org.edx.mobile.user.ProfileImage)3 NonNull (android.support.annotation.NonNull)2 Drawable (android.graphics.drawable.Drawable)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 JsonObject (com.google.gson.JsonObject)1 DialogErrorNotification (org.edx.mobile.http.notifications.DialogErrorNotification)1 UserPrefs (org.edx.mobile.module.prefs.UserPrefs)1 AccountDataUpdatedCallback (org.edx.mobile.user.UserAPI.AccountDataUpdatedCallback)1