use of org.edx.mobile.model.course.HtmlBlockModel in project edx-app-android by edx.
the class CourseUnitWebViewFragmentTest method getHtmlUnit.
/**
* Method for iterating through the mock course response data, and
* returning the first video block leaf.
*
* @return The first {@link HtmlBlockModel} leaf in the mock course data
*/
private HtmlBlockModel getHtmlUnit() throws CourseContentNotValidException {
EnrolledCoursesResponse courseData;
try {
courseData = executeStrict(courseAPI.getEnrolledCourses()).get(0);
} catch (Exception e) {
throw new RuntimeException(e);
}
String courseId = courseData.getCourse().getId();
CourseStructureV1Model model;
try {
model = executeStrict(courseAPI.getCourseStructure(courseId));
} catch (Exception e) {
throw new RuntimeException(e);
}
CourseComponent courseComponent = (CourseComponent) CourseAPI.normalizeCourseStructure(model, courseId);
List<CourseComponent> htmlBlockUnits = new ArrayList<>();
courseComponent.fetchAllLeafComponents(htmlBlockUnits, EnumSet.of(BlockType.HTML));
return (HtmlBlockModel) htmlBlockUnits.get(0);
}
use of org.edx.mobile.model.course.HtmlBlockModel in project edx-app-android by edx.
the class CourseUnitPagerAdapter method getItem.
@Override
public Fragment getItem(int pos) {
CourseComponent unit = getUnit(pos);
CourseUnitFragment unitFragment;
// FIXME - for the video, let's ignore studentViewMultiDevice for now
if (isCourseUnitVideo(unit)) {
unitFragment = CourseUnitVideoFragment.newInstance((VideoBlockModel) unit, (pos < unitList.size()), (pos > 0));
} else if (unit instanceof VideoBlockModel && ((VideoBlockModel) unit).getData().encodedVideos.getYoutubeVideoInfo() != null) {
unitFragment = CourseUnitOnlyOnYoutubeFragment.newInstance(unit);
} else if (config.isDiscussionsEnabled() && unit instanceof DiscussionBlockModel) {
unitFragment = CourseUnitDiscussionFragment.newInstance(unit, courseData);
} else if (!unit.isMultiDevice()) {
unitFragment = CourseUnitMobileNotSupportedFragment.newInstance(unit);
} else if (unit.getType() != BlockType.VIDEO && unit.getType() != BlockType.HTML && unit.getType() != BlockType.OTHERS && unit.getType() != BlockType.DISCUSSION && unit.getType() != BlockType.PROBLEM) {
unitFragment = CourseUnitEmptyFragment.newInstance(unit);
} else if (unit instanceof HtmlBlockModel) {
unitFragment = CourseUnitWebViewFragment.newInstance((HtmlBlockModel) unit);
} else // fallback
{
unitFragment = CourseUnitMobileNotSupportedFragment.newInstance(unit);
}
unitFragment.setHasComponentCallback(callback);
return unitFragment;
}
use of org.edx.mobile.model.course.HtmlBlockModel 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.HtmlBlockModel 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());
}
}
Aggregations