Search in sources :

Example 16 with EnrolledCoursesResponse

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;
        }*/
}
Also used : Bundle(android.os.Bundle) Intent(android.content.Intent) View(android.view.View) TextView(android.widget.TextView) DisableableViewPager(org.edx.mobile.view.custom.DisableableViewPager) ViewPager(android.support.v4.view.ViewPager) PagerAdapter(android.support.v4.view.PagerAdapter) CourseUnitPagerAdapter(org.edx.mobile.view.adapters.CourseUnitPagerAdapter) CourseComponent(org.edx.mobile.model.course.CourseComponent) IOException(java.io.IOException) EnrolledCoursesResponse(org.edx.mobile.model.api.EnrolledCoursesResponse) TextView(android.widget.TextView) CourseStructureV1Model(org.edx.mobile.model.course.CourseStructureV1Model) Test(org.junit.Test)

Example 17 with EnrolledCoursesResponse

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);
}
Also used : EnrolledCoursesResponse(org.edx.mobile.model.api.EnrolledCoursesResponse) CourseStructureV1Model(org.edx.mobile.model.course.CourseStructureV1Model) VideoBlockModel(org.edx.mobile.model.course.VideoBlockModel) CourseComponent(org.edx.mobile.model.course.CourseComponent)

Example 18 with EnrolledCoursesResponse

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;
}
Also used : Bundle(android.os.Bundle) EnrolledCoursesResponse(org.edx.mobile.model.api.EnrolledCoursesResponse) Intent(android.content.Intent) CourseStructureV1Model(org.edx.mobile.model.course.CourseStructureV1Model) CourseComponent(org.edx.mobile.model.course.CourseComponent)

Example 19 with EnrolledCoursesResponse

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;
}
Also used : Bundle(android.os.Bundle) EnrolledCoursesResponse(org.edx.mobile.model.api.EnrolledCoursesResponse) Intent(android.content.Intent)

Example 20 with EnrolledCoursesResponse

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));
    }
}
Also used : IBlock(org.edx.mobile.model.course.IBlock) BlockPath(org.edx.mobile.model.course.BlockPath) Bundle(android.os.Bundle) Intent(android.content.Intent) Fragment(android.support.v4.app.Fragment) CourseComponent(org.edx.mobile.model.course.CourseComponent) EnrolledCoursesResponse(org.edx.mobile.model.api.EnrolledCoursesResponse) ShadowActivity(org.robolectric.shadows.ShadowActivity) ArrayList(java.util.ArrayList) List(java.util.List) CourseStructureV1Model(org.edx.mobile.model.course.CourseStructureV1Model) Test(org.junit.Test)

Aggregations

EnrolledCoursesResponse (org.edx.mobile.model.api.EnrolledCoursesResponse)24 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)11 CourseComponent (org.edx.mobile.model.course.CourseComponent)9 CourseStructureV1Model (org.edx.mobile.model.course.CourseStructureV1Model)8 Intent (android.content.Intent)7 Bundle (android.os.Bundle)7 Ignore (org.junit.Ignore)6 View (android.view.View)4 Fragment (android.support.v4.app.Fragment)3 BlockType (org.edx.mobile.model.course.BlockType)3 IBlock (org.edx.mobile.model.course.IBlock)3 VideoBlockModel (org.edx.mobile.model.course.VideoBlockModel)3 TextView (android.widget.TextView)2 IOException (java.io.IOException)2 List (java.util.List)2 Request (okhttp3.Request)2 AuthException (org.edx.mobile.exception.AuthException)2 HttpStatusException (org.edx.mobile.http.HttpStatusException)2 SectionEntry (org.edx.mobile.model.api.SectionEntry)2