Search in sources :

Example 1 with StudentCourseDetailsPageData

use of teammates.ui.pagedata.StudentCourseDetailsPageData in project teammates by TEAMMATES.

the class StudentCourseDetailsPageActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() {
    StudentAttributes student1InCourse1 = typicalBundle.students.get("student1InCourse1");
    String idOfCourseOfStudent = student1InCourse1.course;
    gaeSimulation.loginAsStudent(student1InCourse1.googleId);
    String[] submissionParams = new String[] { Const.ParamsNames.COURSE_ID, idOfCourseOfStudent };
    ______TS("Invalid parameters");
    // parameters missing.
    verifyAssumptionFailure(new String[] {});
    ______TS("Typical case, student in the same course");
    StudentCourseDetailsPageAction pageAction = getAction(submissionParams);
    ShowPageResult pageResult = getShowPageResult(pageAction);
    assertEquals(getPageResultDestination(Const.ViewURIs.STUDENT_COURSE_DETAILS, false, "student1InCourse1"), pageResult.getDestinationWithParams());
    assertFalse(pageResult.isError);
    assertEquals("", pageResult.getStatusMessage());
    StudentCourseDetailsPageData pageData = (StudentCourseDetailsPageData) pageResult.data;
    assertEquals(student1InCourse1.course, pageData.getStudentCourseDetailsPanel().getCourseId());
    assertEquals(student1InCourse1.googleId, pageData.account.googleId);
    assertEquals(student1InCourse1.getIdentificationString(), pageData.student.getIdentificationString());
    assertEquals(student1InCourse1.team, pageData.getStudentCourseDetailsPanel().getStudentTeam());
    List<StudentAttributes> expectedStudentsList = StudentsLogic.inst().getStudentsForTeam(student1InCourse1.team, student1InCourse1.course);
    List<StudentAttributes> actualStudentsList = pageData.getStudentCourseDetailsPanel().getTeammates();
    AssertHelper.assertSameContentIgnoreOrder(expectedStudentsList, actualStudentsList);
    // assertEquals(StudentsLogic.inst().getStudentsForTeam(student1InCourse1.team, student1InCourse1), pageData.);
    // above comparison method failed, so use the one below
    List<InstructorAttributes> expectedInstructorsList = InstructorsLogic.inst().getInstructorsForCourse(student1InCourse1.course);
    List<InstructorAttributes> actualInstructorsList = pageData.getStudentCourseDetailsPanel().getInstructors();
    AssertHelper.assertSameContentIgnoreOrder(expectedInstructorsList, actualInstructorsList);
    String expectedLogMessage = "TEAMMATESLOG|||studentCourseDetailsPage|||studentCourseDetailsPage|||true|||" + "Student|||Student 1 in course 1|||student1InCourse1|||" + "student1InCourse1@gmail.tmt|||studentCourseDetails Page Load<br>" + "Viewing team details for <span class=\"bold\">[idOfTypicalCourse1] " + "Typical Course 1 with 2 Evals</span>|||/page/studentCourseDetailsPage";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, pageAction.getLogMessage());
    ______TS("Typical case, the student is not in the course");
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, "idOfTypicalCourse2" };
    StudentCourseDetailsPageAction redirectAction = getAction(submissionParams);
    RedirectResult redirectResult = this.getRedirectResult(redirectAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.STUDENT_HOME_PAGE, true, "student1InCourse1"), redirectResult.getDestinationWithParams());
    assertTrue(redirectResult.isError);
    assertEquals("You are not registered in the course idOfTypicalCourse2", redirectResult.getStatusMessage());
    expectedLogMessage = "TEAMMATESLOG|||studentCourseDetailsPage|||studentCourseDetailsPage|||true|||" + "Student|||Student 1 in course 1|||student1InCourse1|||" + "student1InCourse1@gmail.tmt|||studentCourseDetails Page Load<br>" + "Viewing team details for <span class=\"bold\">[idOfTypicalCourse1] " + "Typical Course 1 with 2 Evals</span>|||/page/studentCourseDetailsPage";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, pageAction.getLogMessage());
    ______TS("Typical case, student contains data requiring sanitization");
    StudentAttributes studentTestingSanitization = typicalBundle.students.get("student1InTestingSanitizationCourse");
    gaeSimulation.loginAsStudent(studentTestingSanitization.googleId);
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, studentTestingSanitization.course };
    pageAction = getAction(submissionParams);
    pageResult = getShowPageResult(pageAction);
    assertEquals(Const.ViewURIs.STUDENT_COURSE_DETAILS + "?error=false&user=" + studentTestingSanitization.googleId, pageResult.getDestinationWithParams());
    assertFalse(pageResult.isError);
    assertEquals("", pageResult.getStatusMessage());
    expectedLogMessage = "TEAMMATESLOG|||studentCourseDetailsPage|||studentCourseDetailsPage|||true|||" + "Student|||" + SanitizationHelper.sanitizeForHtml("Stud1<script> alert('hi!'); </script>") + "|||student1InTestingSanitizationCourse|||" + "normal@sanitization.tmt|||studentCourseDetails Page Load<br>" + "Viewing team details for <span class=\"bold\">[idOfTestingSanitizationCourse] " + SanitizationHelper.sanitizeForHtml("Testing<script> alert('hi!'); </script>") + "</span>|||/page/studentCourseDetailsPage";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, pageAction.getLogMessage());
}
Also used : ShowPageResult(teammates.ui.controller.ShowPageResult) RedirectResult(teammates.ui.controller.RedirectResult) StudentCourseDetailsPageData(teammates.ui.pagedata.StudentCourseDetailsPageData) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) StudentCourseDetailsPageAction(teammates.ui.controller.StudentCourseDetailsPageAction) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Test(org.testng.annotations.Test)

Example 2 with StudentCourseDetailsPageData

use of teammates.ui.pagedata.StudentCourseDetailsPageData in project teammates by TEAMMATES.

the class StudentCourseDetailsPageDataTest method test.

@Test
public void test() {
    ______TS("typical success case");
    AccountAttributes account = dataBundle.accounts.get("student1InCourse1");
    StudentCourseDetailsPageData pageData = new StudentCourseDetailsPageData(account, dummySessionToken);
    StudentAttributes student = dataBundle.students.get("student1InCourse1");
    CourseAttributes course = dataBundle.courses.get("typicalCourse1");
    CourseDetailsBundle courseDetails = new CourseDetailsBundle(course);
    List<InstructorAttributes> instructors = new ArrayList<>();
    instructors.add(dataBundle.instructors.get("instructor1OfCourse1"));
    instructors.add(dataBundle.instructors.get("instructor2OfCourse1"));
    instructors.add(dataBundle.instructors.get("helperOfCourse1"));
    TeamDetailsBundle team = new TeamDetailsBundle();
    team.name = student.team;
    // Get team members of student
    for (Entry<String, StudentAttributes> entry : dataBundle.students.entrySet()) {
        StudentAttributes currStudent = entry.getValue();
        if (currStudent.team.equals(team.name)) {
            team.students.add(currStudent);
        }
    }
    pageData.init(courseDetails, instructors, student, team);
    List<InstructorAttributes> courseInstructors = pageData.getStudentCourseDetailsPanel().getInstructors();
    List<StudentAttributes> teammates = pageData.getStudentCourseDetailsPanel().getTeammates();
    assertEquals(courseDetails.course.getName(), pageData.getStudentCourseDetailsPanel().getCourseName());
    assertEquals(courseDetails.course.getId(), pageData.getStudentCourseDetailsPanel().getCourseId());
    assertFalse(courseInstructors.isEmpty());
    assertFalse(teammates.isEmpty());
    assertEquals(student.email, pageData.getStudentCourseDetailsPanel().getStudentEmail());
    assertEquals(student.name, pageData.getStudentCourseDetailsPanel().getStudentName());
    assertEquals(team.name, pageData.getStudentCourseDetailsPanel().getStudentTeam());
    assertEquals(instructors.size(), courseInstructors.size());
    assertEquals(instructors.get(0).name, courseInstructors.get(0).name);
    assertEquals(instructors.get(1).name, courseInstructors.get(1).name);
    assertEquals(instructors.get(2).name, courseInstructors.get(2).name);
    assertEquals(instructors.get(0).displayedName, courseInstructors.get(0).displayedName);
    assertEquals(instructors.get(1).displayedName, courseInstructors.get(1).displayedName);
    assertEquals(instructors.get(2).displayedName, courseInstructors.get(2).displayedName);
    assertEquals(team.students.size(), teammates.size());
    ______TS("student in unregistered course");
    student = dataBundle.students.get("student1InUnregisteredCourse");
    course = dataBundle.courses.get("unregisteredCourse");
    courseDetails = new CourseDetailsBundle(course);
    instructors = new ArrayList<>();
    instructors.add(dataBundle.instructors.get("instructor5"));
    team = new TeamDetailsBundle();
    team.name = student.team;
    // Get team members of student
    for (Entry<String, StudentAttributes> entry : dataBundle.students.entrySet()) {
        StudentAttributes currStudent = entry.getValue();
        if (currStudent.team.equals(team.name)) {
            team.students.add(currStudent);
        }
    }
    pageData.init(courseDetails, instructors, student, team);
    courseInstructors = pageData.getStudentCourseDetailsPanel().getInstructors();
    teammates = pageData.getStudentCourseDetailsPanel().getTeammates();
    assertEquals(courseDetails.course.getName(), pageData.getStudentCourseDetailsPanel().getCourseName());
    assertEquals(courseDetails.course.getId(), pageData.getStudentCourseDetailsPanel().getCourseId());
    assertFalse(courseInstructors.isEmpty());
    assertFalse(teammates.isEmpty());
    assertEquals(student.email, pageData.getStudentCourseDetailsPanel().getStudentEmail());
    assertEquals(student.name, pageData.getStudentCourseDetailsPanel().getStudentName());
    assertEquals(team.name, pageData.getStudentCourseDetailsPanel().getStudentTeam());
    assertEquals(instructors.size(), courseInstructors.size());
    assertEquals(instructors.get(0).name, courseInstructors.get(0).name);
    assertEquals(instructors.get(0).displayedName, courseInstructors.get(0).displayedName);
    assertEquals(team.students.size(), teammates.size());
    ______TS("student in archived course");
    student = dataBundle.students.get("student1InArchivedCourse");
    course = dataBundle.courses.get("archivedCourse");
    courseDetails = new CourseDetailsBundle(course);
    instructors = new ArrayList<>();
    instructors.add(dataBundle.instructors.get("instructorOfArchivedCourse"));
    team = new TeamDetailsBundle();
    team.name = student.team;
    // Get team members of student
    for (Entry<String, StudentAttributes> entry : dataBundle.students.entrySet()) {
        StudentAttributes currStudent = entry.getValue();
        if (currStudent.team.equals(team.name)) {
            team.students.add(currStudent);
        }
    }
    pageData.init(courseDetails, instructors, student, team);
    courseInstructors = pageData.getStudentCourseDetailsPanel().getInstructors();
    teammates = pageData.getStudentCourseDetailsPanel().getTeammates();
    assertEquals(courseDetails.course.getName(), pageData.getStudentCourseDetailsPanel().getCourseName());
    assertEquals(courseDetails.course.getId(), pageData.getStudentCourseDetailsPanel().getCourseId());
    assertFalse(courseInstructors.isEmpty());
    assertFalse(teammates.isEmpty());
    assertEquals(student.email, pageData.getStudentCourseDetailsPanel().getStudentEmail());
    assertEquals(student.name, pageData.getStudentCourseDetailsPanel().getStudentName());
    assertEquals(team.name, pageData.getStudentCourseDetailsPanel().getStudentTeam());
    assertEquals(instructors.size(), courseInstructors.size());
    assertEquals(instructors.get(0).name, courseInstructors.get(0).name);
    assertEquals(instructors.get(0).displayedName, courseInstructors.get(0).displayedName);
    assertEquals(team.students.size(), teammates.size());
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) ArrayList(java.util.ArrayList) StudentCourseDetailsPageData(teammates.ui.pagedata.StudentCourseDetailsPageData) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) CourseDetailsBundle(teammates.common.datatransfer.CourseDetailsBundle) TeamDetailsBundle(teammates.common.datatransfer.TeamDetailsBundle) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) Test(org.testng.annotations.Test)

Example 3 with StudentCourseDetailsPageData

use of teammates.ui.pagedata.StudentCourseDetailsPageData in project teammates by TEAMMATES.

the class StudentCourseDetailsPageActionTest method testTeamMemberDetailsOnViewTeamPage.

@Test
public void testTeamMemberDetailsOnViewTeamPage() {
    AccountAttributes student = typicalBundle.accounts.get("student1InCourse1");
    String[] submissionParams = createValidParamsForProfile();
    StudentProfileAttributes expectedProfile = getProfileAttributesFrom(student.googleId, submissionParams);
    gaeSimulation.loginAsStudent(student.googleId);
    // adding profile picture for student1InCourse1
    StudentProfileEditSaveAction action = getStudentProfileEditSaveAction(submissionParams);
    RedirectResult result = getRedirectResult(action);
    expectedProfile.googleId = student.googleId;
    assertFalse(result.isError);
    StudentAttributes student1 = typicalBundle.students.get("student1InCourse1");
    gaeSimulation.logoutUser();
    gaeSimulation.loginAsStudent(typicalBundle.accounts.get("student2InCourse1").googleId);
    String[] submissionParam = new String[] { Const.ParamsNames.COURSE_ID, student1.course };
    StudentCourseDetailsPageAction pageAction = getAction(submissionParam);
    ShowPageResult pageResult = getShowPageResult(pageAction);
    StudentCourseDetailsPageData pageData = (StudentCourseDetailsPageData) pageResult.data;
    List<StudentAttributes> actualStudentsList = pageData.getStudentCourseDetailsPanel().getTeammates();
    boolean isStudentDisplayedOnViewTeam = false;
    for (StudentAttributes stud : actualStudentsList) {
        if (student1.email.equals(stud.email) && student1.name.equals(stud.name) && student1.getPublicProfilePictureUrl().equals(stud.getPublicProfilePictureUrl())) {
            isStudentDisplayedOnViewTeam = true;
        }
    }
    assertTrue(isStudentDisplayedOnViewTeam);
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) ShowPageResult(teammates.ui.controller.ShowPageResult) RedirectResult(teammates.ui.controller.RedirectResult) StudentProfileEditSaveAction(teammates.ui.controller.StudentProfileEditSaveAction) StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes) StudentCourseDetailsPageData(teammates.ui.pagedata.StudentCourseDetailsPageData) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) StudentCourseDetailsPageAction(teammates.ui.controller.StudentCourseDetailsPageAction) Test(org.testng.annotations.Test)

Example 4 with StudentCourseDetailsPageData

use of teammates.ui.pagedata.StudentCourseDetailsPageData in project teammates by TEAMMATES.

the class StudentCourseDetailsPageAction method execute.

@Override
public ActionResult execute() throws EntityDoesNotExistException {
    String courseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
    Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_ID, courseId);
    if (!isJoinedCourse(courseId)) {
        return createPleaseJoinCourseResponse(courseId);
    }
    CourseAttributes course = logic.getCourse(courseId);
    gateKeeper.verifyAccessible(logic.getStudentForGoogleId(courseId, account.googleId), course);
    StudentCourseDetailsPageData data = new StudentCourseDetailsPageData(account, sessionToken);
    data.init(logic.getCourseDetails(courseId), logic.getInstructorsForCourse(courseId), logic.getStudentForGoogleId(courseId, account.googleId), logic.getTeamDetailsForStudent(logic.getStudentForGoogleId(courseId, account.googleId)));
    statusToAdmin = "studentCourseDetails Page Load<br>" + "Viewing team details for <span class=\"bold\">[" + courseId + "] " + SanitizationHelper.sanitizeForHtml(course.getName()) + "</span>";
    return createShowPageResult(Const.ViewURIs.STUDENT_COURSE_DETAILS, data);
}
Also used : StudentCourseDetailsPageData(teammates.ui.pagedata.StudentCourseDetailsPageData) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes)

Aggregations

StudentCourseDetailsPageData (teammates.ui.pagedata.StudentCourseDetailsPageData)4 Test (org.testng.annotations.Test)3 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)3 AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)2 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)2 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)2 RedirectResult (teammates.ui.controller.RedirectResult)2 ShowPageResult (teammates.ui.controller.ShowPageResult)2 StudentCourseDetailsPageAction (teammates.ui.controller.StudentCourseDetailsPageAction)2 ArrayList (java.util.ArrayList)1 CourseDetailsBundle (teammates.common.datatransfer.CourseDetailsBundle)1 TeamDetailsBundle (teammates.common.datatransfer.TeamDetailsBundle)1 StudentProfileAttributes (teammates.common.datatransfer.attributes.StudentProfileAttributes)1 StudentProfileEditSaveAction (teammates.ui.controller.StudentProfileEditSaveAction)1