use of org.edx.mobile.model.api.EnrolledCoursesResponse in project edx-app-android by edx.
the class CourseUnitNavigationActivityTest method initializeTest.
/**
* {@inheritDoc}
*/
@Test
@Override
public void initializeTest() {
super.initializeTest();
Intent intent = getIntent();
ActivityController<? extends CourseUnitNavigationActivity> controller = Robolectric.buildActivity(getActivityClass()).withIntent(intent);
CourseUnitNavigationActivity activity = controller.get();
controller.create();
assertNotNull(activity.findViewById(R.id.course_unit_nav_bar));
View prev = activity.findViewById(R.id.goto_prev);
assertNotNull(prev);
assertThat(prev).isInstanceOf(TextView.class);
TextView prevButton = (TextView) prev;
View next = activity.findViewById(R.id.goto_next);
assertNotNull(next);
assertThat(next).isInstanceOf(TextView.class);
TextView nextButton = (TextView) next;
View prevUnitTitle = activity.findViewById(R.id.prev_unit_title);
assertNotNull(prevUnitTitle);
assertThat(prevUnitTitle).isInstanceOf(TextView.class);
TextView prevUnitLabel = (TextView) prevUnitTitle;
View nextUnitTitle = activity.findViewById(R.id.next_unit_title);
assertNotNull(nextUnitTitle);
assertThat(nextUnitTitle).isInstanceOf(TextView.class);
TextView nextUnitLabel = (TextView) nextUnitTitle;
View pager = activity.findViewById(R.id.pager);
assertNotNull(pager);
assertThat(pager).isInstanceOf(ViewPager.class);
ViewPager viewPager = (ViewPager) pager;
PagerAdapter pagerAdapter = viewPager.getAdapter();
assertNotNull(pagerAdapter);
// Text navigation through units
Bundle extras = intent.getBundleExtra(Router.EXTRA_BUNDLE);
EnrolledCoursesResponse courseData = (EnrolledCoursesResponse) extras.getSerializable(Router.EXTRA_COURSE_DATA);
assertNotNull(courseData);
String courseId = courseData.getCourse().getId();
CourseStructureV1Model model;
CourseComponent courseComponent;
try {
model = executeStrict(courseAPI.getCourseStructure(courseId));
courseComponent = (CourseComponent) CourseAPI.normalizeCourseStructure(model, courseId);
} catch (Exception e) {
throw new RuntimeException(e);
}
assertNotNull(courseComponent);
final String unitId = extras.getString(Router.EXTRA_COURSE_COMPONENT_ID);
assertNotNull(unitId);
CourseComponent currentUnit = courseComponent.find(new Filter<CourseComponent>() {
@Override
public boolean apply(CourseComponent courseComponent) {
return unitId.equals(courseComponent.getId());
}
});
assertNotNull(currentUnit);
// Since Robolectric current does not call the scroll callbacks due
// to not supporting view drawing (see
// https://github.com/robolectric/robolectric/issues/2007), we can't
// test the ViewPager navigation at the moment.
// TODO: Uncomment the following code when this issue is fixed
/*List<CourseComponent> units = new ArrayList<>();
courseComponent.fetchAllLeafComponents(units,
EnumSet.allOf(BlockType.class));
assertThat(units).isNotEmpty();
controller.start().postCreate((Bundle)null).resume().visible();
ListIterator<CourseComponent> unitIterator = units.listIterator(1);
for (CourseComponent prevUnit = null;;) {
int unitIndex = unitIterator.previousIndex();
CourseComponent nextUnit = unitIterator.hasNext() ?
unitIterator.next() : null;
verifyState(activity, unitIndex, currentUnit, prevUnit, nextUnit,
viewPager, pagerAdapter, prevButton, nextButton,
prevUnitLabel, nextUnitLabel);
if (nextUnit == null) break;
// The Scheduler needs to be paused while clicking the next button
// to enable the FragmentStatePagerAdapter to clear it's transaction
// state, and thus avoid the commit being called recursively
Scheduler foregroundScheduler = ShadowApplication.getInstance()
.getForegroundThreadScheduler();
foregroundScheduler.pause();
assertTrue(nextButton.performClick());
foregroundScheduler.unPause();
prevUnit = currentUnit;
currentUnit = nextUnit;
}
// Now iterate back in reverse order to test the previous button
unitIterator = units.listIterator(units.size() - 1);
for (CourseComponent nextUnit = null;;) {
int unitIndex = unitIterator.nextIndex();
CourseComponent prevUnit = unitIterator.hasPrevious() ?
unitIterator.previous() : null;
verifyState(activity, unitIndex, currentUnit, prevUnit, nextUnit,
viewPager, pagerAdapter, prevButton, nextButton,
prevUnitLabel, nextUnitLabel);
if (prevUnit == null) break;
Scheduler foregroundScheduler = ShadowApplication.getInstance()
.getForegroundThreadScheduler();
foregroundScheduler.pause();
assertTrue(prevButton.performClick());
foregroundScheduler.unPause();
nextUnit = currentUnit;
currentUnit = prevUnit;
}*/
}
use of org.edx.mobile.model.api.EnrolledCoursesResponse in project edx-app-android by edx.
the class CourseUnitVideoFragmentTest method getVideoUnit.
/**
* Method for iterating through the mock course response data, and
* returning the first video block leaf.
*
* @return The first {@link VideoBlockModel} leaf in the mock course data
*/
private VideoBlockModel getVideoUnit() {
EnrolledCoursesResponse courseData;
try {
courseData = executeStrict(courseAPI.getEnrolledCourses()).get(0);
} catch (Exception e) {
throw new RuntimeException(e);
}
String courseId = courseData.getCourse().getId();
CourseStructureV1Model model;
CourseComponent courseComponent;
try {
model = executeStrict(courseAPI.getCourseStructure(courseId));
courseComponent = (CourseComponent) CourseAPI.normalizeCourseStructure(model, courseId);
} catch (Exception e) {
throw new RuntimeException(e);
}
return (VideoBlockModel) courseComponent.getVideos().get(0);
}
use of org.edx.mobile.model.api.EnrolledCoursesResponse in project edx-app-android by edx.
the class CourseBaseActivityTest method getIntent.
/**
* {@inheritDoc}
*/
@Override
protected Intent getIntent() {
EnrolledCoursesResponse courseData;
try {
courseData = executeStrict(courseAPI.getEnrolledCourses()).get(0);
} catch (Exception e) {
throw new RuntimeException(e);
}
Intent intent = super.getIntent();
Bundle extras = new Bundle();
extras.putSerializable(Router.EXTRA_COURSE_DATA, courseData);
if (provideCourseId) {
String courseId = courseData.getCourse().getId();
CourseStructureV1Model model;
CourseComponent courseComponent;
try {
model = executeStrict(courseAPI.getCourseStructure(courseId));
courseComponent = (CourseComponent) CourseAPI.normalizeCourseStructure(model, courseId);
} catch (Exception e) {
throw new RuntimeException(e);
}
extras.putString(Router.EXTRA_COURSE_COMPONENT_ID, courseComponent.getId());
}
intent.putExtra(Router.EXTRA_BUNDLE, extras);
return intent;
}
use of org.edx.mobile.model.api.EnrolledCoursesResponse in project edx-app-android by edx.
the class CourseDashboardActivityTest method getIntent.
/**
* {@inheritDoc}
*/
@Override
protected Intent getIntent() {
EnrolledCoursesResponse courseData;
try {
courseData = executeStrict(courseAPI.getEnrolledCourses()).get(0);
} catch (Exception e) {
throw new RuntimeException(e);
}
Intent intent = super.getIntent();
Bundle extras = new Bundle();
extras.putSerializable(Router.EXTRA_COURSE_DATA, courseData);
intent.putExtra(Router.EXTRA_BUNDLE, extras);
return intent;
}
use of org.edx.mobile.model.api.EnrolledCoursesResponse in project edx-app-android by edx.
the class CourseOutlineActivityTest method sectionNavigationTest.
// Since Robolectric doesn't simulate actual Activity navigation, we
// can only test forward navigation, and only up to one level. This
// blocks us from testing the back stack restructuring upon switching
// to a different section from CourseUnitNavigationActivityTest.
/**
* Testing navigation to a section
*/
@Test
public void sectionNavigationTest() {
Intent intent = getIntent();
Bundle extras = intent.getBundleExtra(Router.EXTRA_BUNDLE);
EnrolledCoursesResponse courseData = (EnrolledCoursesResponse) extras.getSerializable(Router.EXTRA_COURSE_DATA);
assertNotNull(courseData);
String courseId = courseData.getCourse().getId();
CourseStructureV1Model model;
CourseComponent courseComponent;
try {
model = executeStrict(courseAPI.getCourseStructure(courseId));
courseComponent = (CourseComponent) CourseAPI.normalizeCourseStructure(model, courseId);
} catch (Exception e) {
throw new RuntimeException(e);
}
int subsectionRowIndex = -1;
String subsectionId = null;
CourseComponent subsectionUnit = null;
List<IBlock> sections = courseComponent.getChildren();
sectionIteration: for (@SuppressWarnings("unused") IBlock section : sections) {
subsectionRowIndex++;
for (IBlock subsection : section.getChildren()) {
subsectionRowIndex++;
if (((CourseComponent) subsection).isContainer()) {
subsectionId = subsection.getId();
List<CourseComponent> leafComponents = new ArrayList<>();
courseComponent.fetchAllLeafComponents(leafComponents, EnumSet.allOf(BlockType.class));
subsectionUnit = leafComponents.get(0);
break sectionIteration;
}
}
}
assertNotNull(subsectionId);
extras.putString(Router.EXTRA_COURSE_COMPONENT_ID, courseComponent.getId());
ActivityController<? extends CourseOutlineActivity> controller = initialize(intent);
CourseOutlineActivity activity = controller.get();
Fragment fragment = activity.getSupportFragmentManager().findFragmentByTag(CourseOutlineFragment.TAG);
assertThat(fragment).isInstanceOf(CourseOutlineFragment.class);
CourseOutlineFragment courseOutlineFragment = (CourseOutlineFragment) fragment;
clickRow(controller, courseOutlineFragment, subsectionRowIndex);
Intent newIntent = assertNextStartedActivity(activity, CourseOutlineActivity.class);
Bundle newData = newIntent.getBundleExtra(Router.EXTRA_BUNDLE);
assertNotNull(newData);
assertEquals(courseData, newData.getSerializable(Router.EXTRA_COURSE_DATA));
assertEquals(subsectionId, newData.getString(Router.EXTRA_COURSE_COMPONENT_ID));
// Back stack reconstruction upon receiving a specific path
Intent resultData = new Intent();
resultData.putExtra(Router.EXTRA_COURSE_COMPONENT_ID, subsectionUnit.getId());
courseOutlineFragment.onActivityResult(CourseOutlineFragment.REQUEST_SHOW_COURSE_UNIT_DETAIL, Activity.RESULT_OK, resultData);
ShadowActivity shadowActivity = Shadows.shadowOf(activity);
BlockPath outlinePath = courseComponent.getPath();
BlockPath leafPath = subsectionUnit.getPath();
int outlinePathSize = outlinePath.getPath().size();
for (int i = outlinePathSize + 1; ; i += 2) {
newIntent = shadowActivity.getNextStartedActivity();
CourseComponent nextComp = leafPath.get(i);
if (nextComp == null || !nextComp.isContainer()) {
assertNull(newIntent);
break;
}
assertNotNull(newIntent);
assertThat(newIntent).hasComponent(activity, CourseOutlineActivity.class);
newData = newIntent.getBundleExtra(Router.EXTRA_BUNDLE);
assertNotNull(newData);
assertEquals(courseData, newData.getSerializable(Router.EXTRA_COURSE_DATA));
assertEquals(nextComp.getId(), newData.getString(Router.EXTRA_COURSE_COMPONENT_ID));
}
}
Aggregations