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)));
}
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());
}
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;
}
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);
}
});
}
Aggregations