use of org.edx.mobile.model.course.CourseComponent in project edx-app-android by edx.
the class CourseUnitNavigationActivityTest method getIntent.
/**
* {@inheritDoc}
*/
@Override
protected Intent getIntent() {
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);
}
List<CourseComponent> leafComponents = new ArrayList<>();
courseComponent.fetchAllLeafComponents(leafComponents, EnumSet.allOf(BlockType.class));
CourseComponent courseUnit = leafComponents.get(0);
Intent intent = super.getIntent();
Bundle extras = new Bundle();
extras.putSerializable(Router.EXTRA_COURSE_DATA, courseData);
extras.putString(Router.EXTRA_COURSE_COMPONENT_ID, courseUnit.getId());
intent.putExtra(Router.EXTRA_BUNDLE, extras);
return intent;
}
use of org.edx.mobile.model.course.CourseComponent in project edx-app-android by edx.
the class CourseUnitNavigationActivityTest method testUnitFragmentCreation.
/**
* Testing creation of various fragments in the {@link CourseUnitNavigationActivity}'s
* ViewPager, by supplying its {@link CourseUnitPagerAdapter} with all possible
* {@link CourseComponent} models.
*/
@Test
public void testUnitFragmentCreation() {
FragmentManager fragmentManager = Mockito.mock(FragmentManager.class);
EnrolledCoursesResponse courseData = Mockito.mock(EnrolledCoursesResponse.class);
CourseUnitFragment.HasComponent hasComponent = Mockito.mock(CourseUnitFragment.HasComponent.class);
List<CourseComponent> unitList = new ArrayList<>();
List<Class<? extends CourseUnitFragment>> classesList = new ArrayList<>();
VideoBlockModel encodeVideosModel = Mockito.mock(VideoBlockModel.class);
VideoData videoData = Mockito.mock(VideoData.class);
videoData.encodedVideos = Mockito.mock(EncodedVideos.class);
when(videoData.encodedVideos.getPreferredVideoInfo()).thenReturn(Mockito.mock(VideoInfo.class));
when(encodeVideosModel.getData()).thenReturn(videoData);
unitList.add(encodeVideosModel);
classesList.add(CourseUnitVideoFragment.class);
VideoBlockModel youtubeVideosModel = Mockito.mock(VideoBlockModel.class);
VideoData videoData2 = Mockito.mock(VideoData.class);
videoData2.encodedVideos = Mockito.mock(EncodedVideos.class);
when(videoData2.encodedVideos.getYoutubeVideoInfo()).thenReturn(Mockito.mock(VideoInfo.class));
when(youtubeVideosModel.getData()).thenReturn(videoData2);
unitList.add(youtubeVideosModel);
classesList.add(CourseUnitOnlyOnYoutubeFragment.class);
DiscussionBlockModel discussionModel = Mockito.mock(DiscussionBlockModel.class);
unitList.add(discussionModel);
if (config.isDiscussionsEnabled()) {
classesList.add(CourseUnitDiscussionFragment.class);
} else {
classesList.add(CourseUnitMobileNotSupportedFragment.class);
}
CourseComponent nonMultiDeviceModel = Mockito.mock(CourseComponent.class);
when(nonMultiDeviceModel.isMultiDevice()).thenReturn(false);
unitList.add(nonMultiDeviceModel);
classesList.add(CourseUnitMobileNotSupportedFragment.class);
HtmlBlockModel htmlModel = Mockito.mock(HtmlBlockModel.class);
when(htmlModel.isMultiDevice()).thenReturn(true);
when(htmlModel.getType()).thenReturn(BlockType.HTML);
unitList.add(htmlModel);
classesList.add(CourseUnitWebViewFragment.class);
CourseComponent unknownModel = Mockito.mock(CourseComponent.class);
when(unknownModel.isMultiDevice()).thenReturn(true);
when(unknownModel.getType()).thenReturn(BlockType.COURSE);
unitList.add(unknownModel);
classesList.add(CourseUnitEmptyFragment.class);
CourseComponent problemModel = Mockito.mock(CourseComponent.class);
when(problemModel.isMultiDevice()).thenReturn(true);
when(problemModel.getType()).thenReturn(BlockType.PROBLEM);
unitList.add(problemModel);
classesList.add(CourseUnitMobileNotSupportedFragment.class);
CourseComponent othersModel = Mockito.mock(CourseComponent.class);
when(othersModel.isMultiDevice()).thenReturn(true);
when(othersModel.getType()).thenReturn(BlockType.OTHERS);
unitList.add(othersModel);
classesList.add(CourseUnitMobileNotSupportedFragment.class);
CourseUnitPagerAdapter adapter = new CourseUnitPagerAdapter(fragmentManager, config, unitList, courseData, hasComponent);
for (int size = unitList.size(), i = 0; i < size; i++) {
assertThat(adapter.getItem(i)).isInstanceOf(classesList.get(i));
}
}
use of org.edx.mobile.model.course.CourseComponent 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.course.CourseComponent in project edx-app-android by edx.
the class CourseUnitNavigationActivityTest method verifyState.
/**
* Testing download progress menu visibility states and click behaviour
* (starting DownloadActivity). Only when both AppConstants.offline_flag
* is true and there is a downloading entry in the database, should the
* progress bar be visible.
*/
/**
* Generic method for verifying the state of the CourseUnitNavigationActivity
* at a specific unit.
*
* @param activity An instance of CourseUnitNavigationActivity that has been
* initialized
* @param unitIndex The index of the unit among all the leaves for the course
* @param currentUnit The selected course unit
* @param prevUnit The unit previous to the current selection
* @param nextUnit The unit next to the current selection
* @param viewPager The ViewPager instance containing the CourseUnitFragment
* instances
* @param pagerAdapter The PagerAdapter associated with the ViewPager
* @param prevButton The button for going to the previous unit
* @param nextButton The button for going to the next unit
* @param prevUnitLabel The label for the previous unit
* @param nextUnitLabel The label for the next unit
*/
private void verifyState(CourseUnitNavigationActivity activity, int unitIndex, CourseComponent currentUnit, CourseComponent prevUnit, CourseComponent nextUnit, ViewPager viewPager, PagerAdapter pagerAdapter, TextView prevButton, TextView nextButton, TextView prevUnitLabel, TextView nextUnitLabel) {
assertTitle(activity, currentUnit.getDisplayName());
Class<? extends CourseUnitFragment> fragmentClass;
if (currentUnit instanceof VideoBlockModel) {
fragmentClass = CourseUnitVideoFragment.class;
} else if (!currentUnit.isMultiDevice()) {
fragmentClass = CourseUnitMobileNotSupportedFragment.class;
} else if (currentUnit.getType() != BlockType.VIDEO && currentUnit.getType() != BlockType.HTML && currentUnit.getType() != BlockType.OTHERS && currentUnit.getType() != BlockType.DISCUSSION && currentUnit.getType() != BlockType.PROBLEM) {
fragmentClass = CourseUnitEmptyFragment.class;
} else if (currentUnit instanceof HtmlBlockModel) {
fragmentClass = CourseUnitWebViewFragment.class;
} else {
fragmentClass = CourseUnitMobileNotSupportedFragment.class;
}
Object item = pagerAdapter.instantiateItem(viewPager, unitIndex);
assertNotNull(item);
assertThat(item).isInstanceOf(fragmentClass);
Bundle args = ((Fragment) item).getArguments();
assertNotNull(args);
assertEquals(currentUnit, args.getSerializable(Router.EXTRA_COURSE_UNIT));
assertEquals(prevUnit != null, prevButton.isEnabled());
assertEquals(nextUnit != null, nextButton.isEnabled());
CourseComponent prevSection = prevUnit == null ? null : prevUnit.getParent();
CourseComponent nextSection = nextUnit == null ? null : nextUnit.getParent();
if (prevSection == null || currentUnit.getParent().equals(prevSection)) {
assertThat(prevUnitLabel).isNotVisible();
assertThat(prevButton).hasText(R.string.assessment_previous);
} else {
assertThat(prevUnitLabel).isVisible();
assertThat(prevUnitLabel).hasText(prevSection.getDisplayName());
}
if (nextSection == null || currentUnit.getParent().equals(nextSection)) {
assertThat(nextUnitLabel).isNotVisible();
assertThat(nextButton).hasText(R.string.assessment_next);
} else {
assertThat(nextUnitLabel).isVisible();
assertThat(nextUnitLabel).hasText(nextSection.getDisplayName());
}
}
use of org.edx.mobile.model.course.CourseComponent 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);
}
Aggregations