use of teammates.ui.pagedata.InstructorCourseEditPageData in project teammates by TEAMMATES.
the class InstructorCourseEditPageActionTest method testExecuteAndPostProcess.
@Override
@Test
public void testExecuteAndPostProcess() {
InstructorAttributes instructor1OfCourse1 = typicalBundle.instructors.get("instructor1OfCourse1");
String instructorId = instructor1OfCourse1.googleId;
String courseId = instructor1OfCourse1.courseId;
gaeSimulation.loginAsInstructor(instructorId);
______TS("Not enough parameters");
verifyAssumptionFailure();
______TS("Typical case: open the course edit page");
String[] submissionParams = new String[] { Const.ParamsNames.COURSE_ID, courseId };
InstructorCourseEditPageAction editAction = getAction(submissionParams);
ShowPageResult pageResult = getShowPageResult(editAction);
assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_COURSE_EDIT, false, "idOfInstructor1OfCourse1"), pageResult.getDestinationWithParams());
assertFalse(pageResult.isError);
assertEquals("", pageResult.getStatusMessage());
InstructorCourseEditPageData data = (InstructorCourseEditPageData) pageResult.data;
assertEquals(CoursesLogic.inst().getCourse(courseId).toString(), data.getCourse().toString());
verifySameInstructorList(InstructorsLogic.inst().getInstructorsForCourse(courseId), data.getInstructorPanelList());
String expectedLogSegment = "instructorCourseEdit Page Load<br>" + "Editing information for Course <span class=\"bold\">[" + courseId + "]</span>";
AssertHelper.assertContains(expectedLogSegment, editAction.getLogMessage());
______TS("Typical case: open the course edit page with instructor's email");
submissionParams = new String[] { Const.ParamsNames.COURSE_ID, courseId, Const.ParamsNames.INSTRUCTOR_EMAIL, "instr1@course1.tmt", Const.ParamsNames.COURSE_EDIT_MAIN_INDEX, "1" };
editAction = getAction(submissionParams);
pageResult = getShowPageResult(editAction);
assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_COURSE_EDIT, false, "idOfInstructor1OfCourse1"), pageResult.getDestinationWithParams());
assertFalse(pageResult.isError);
assertEquals("", pageResult.getStatusMessage());
data = (InstructorCourseEditPageData) pageResult.data;
assertEquals(CoursesLogic.inst().getCourse(courseId).toString(), data.getCourse().toString());
assertEquals(1, data.getInstructorPanelList().size());
expectedLogSegment = "instructorCourseEdit Page Load<br>" + "Editing information for Course <span class=\"bold\">[" + courseId + "]</span>";
AssertHelper.assertContains(expectedLogSegment, editAction.getLogMessage());
______TS("Masquerade mode");
InstructorAttributes instructor = typicalBundle.instructors.get("instructor4");
instructorId = instructor.googleId;
courseId = instructor.courseId;
gaeSimulation.loginAsAdmin("admin.user");
submissionParams = new String[] { Const.ParamsNames.USER_ID, instructorId, Const.ParamsNames.COURSE_ID, courseId };
editAction = getAction(submissionParams);
pageResult = getShowPageResult(editAction);
assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_COURSE_EDIT, false, "idOfInstructor4"), pageResult.getDestinationWithParams());
assertFalse(pageResult.isError);
assertEquals("", pageResult.getStatusMessage());
data = (InstructorCourseEditPageData) pageResult.data;
assertEquals(CoursesLogic.inst().getCourse(courseId).toString(), data.getCourse().toString());
verifySameInstructorList(InstructorsLogic.inst().getInstructorsForCourse(courseId), data.getInstructorPanelList());
expectedLogSegment = "instructorCourseEdit Page Load<br>" + "Editing information for Course <span class=\"bold\">[" + courseId + "]</span>";
AssertHelper.assertContains(expectedLogSegment, editAction.getLogMessage());
______TS("Failure case: edit a non-existing course");
CoursesLogic.inst().deleteCourseCascade(courseId);
submissionParams = new String[] { Const.ParamsNames.USER_ID, instructorId, Const.ParamsNames.COURSE_ID, courseId };
try {
editAction = getAction(submissionParams);
pageResult = getShowPageResult(editAction);
signalFailureToDetectException();
} catch (UnauthorizedAccessException e) {
assertEquals("Trying to access system using a non-existent instructor entity", e.getMessage());
}
}
use of teammates.ui.pagedata.InstructorCourseEditPageData in project teammates by TEAMMATES.
the class InstructorCourseEditPageDataTest method testAll.
@Test
public void testAll() {
______TS("test typical case");
AccountAttributes account = dataBundle.accounts.get("instructor1OfCourse1");
CourseAttributes course = dataBundle.courses.get("typicalCourse1");
List<InstructorAttributes> instructorList = new ArrayList<>();
instructorList.add(dataBundle.instructors.get("instructor1OfCourse1"));
instructorList.add(dataBundle.instructors.get("instructor2OfCourse1"));
instructorList.add(dataBundle.instructors.get("helperOfCourse1"));
instructorList.add(dataBundle.instructors.get("instructorNotYetJoinCourse1"));
InstructorAttributes currentInstructor = dataBundle.instructors.get("instructor1OfCourse1");
int offset = -1;
List<String> sectionNames = new ArrayList<>();
sectionNames.add("Section 1");
sectionNames.add("Section 2");
List<String> feedbackSessionNames = new ArrayList<>();
feedbackSessionNames.add("First feedback session");
feedbackSessionNames.add("Second feedback session");
feedbackSessionNames.add("Grace Period Session");
feedbackSessionNames.add("Closed Session");
feedbackSessionNames.add("Empty session");
feedbackSessionNames.add("non visible session");
InstructorCourseEditPageData pageData = new InstructorCourseEditPageData(account, dummySessionToken, course, instructorList, currentInstructor, offset, sectionNames, feedbackSessionNames);
assertEquals("idOfTypicalCourse1", pageData.getCourse().getId());
assertEquals(-1, pageData.getInstructorToShowIndex());
assertNotNull(pageData.getDeleteCourseButton());
assertNotNull(pageData.getAddInstructorButton());
assertNotNull(pageData.getInstructorPanelList());
assertEquals(instructorList.size(), pageData.getInstructorPanelList().size());
CourseEditInstructorPanel panel = pageData.getInstructorPanelList().get(0);
assertEquals(4, panel.getPermissionInputGroup1().size());
assertEquals(1, panel.getPermissionInputGroup2().size());
assertEquals(3, panel.getPermissionInputGroup3().size());
assertEquals("idOfInstructor1OfCourse1", panel.getInstructor().googleId);
assertNotNull(panel.getDeleteButton());
assertNotNull(panel.getEditButton());
assertNull(panel.getResendInviteButton());
assertEquals(sectionNames.size(), panel.getSectionRows().size());
CourseEditSectionRow sectionRow = panel.getSectionRows().get(0);
assertEquals(1, sectionRow.getPermissionInputGroup2().size());
assertEquals(3, sectionRow.getPermissionInputGroup3().size());
assertEquals(feedbackSessionNames.size(), sectionRow.getFeedbackSessions().size());
assertFalse(sectionRow.isSectionSpecial());
/*
* Comment for below Assertion:
* These sections are separated by a group of 3 so here is the formula to get the number
* of groups.
*/
assertEquals((sectionNames.size() - 1) / 3 + 1, sectionRow.getSpecialSections().size());
assertNotNull(pageData.getAddInstructorPanel());
CourseEditInstructorPanel addInstructorPanel = pageData.getAddInstructorPanel();
assertEquals(4, addInstructorPanel.getPermissionInputGroup1().size());
assertEquals(1, addInstructorPanel.getPermissionInputGroup2().size());
assertEquals(3, addInstructorPanel.getPermissionInputGroup3().size());
assertEquals(sectionNames.size(), addInstructorPanel.getSectionRows().size());
sectionRow = addInstructorPanel.getSectionRows().get(0);
assertEquals(feedbackSessionNames.size(), sectionRow.getFeedbackSessions().size());
______TS("test case when current instructor has no privilege");
String[] privileges = { Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_COURSE, Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_INSTRUCTOR, Const.ParamsNames.INSTRUCTOR_PERMISSION_SUBMIT_SESSION_IN_SECTIONS, Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_SESSION_IN_SECTIONS, Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_SESSION_COMMENT_IN_SECTIONS };
for (String privilege : privileges) {
currentInstructor.privileges.updatePrivilege(privilege, false);
}
pageData = new InstructorCourseEditPageData(account, dummySessionToken, course, instructorList, currentInstructor, offset, sectionNames, feedbackSessionNames);
assertNull(pageData.getDeleteCourseButton().getAttributes().get("disabled"));
assertTrue(pageData.getDeleteCourseButton().getAttributes().containsKey("disabled"));
assertNull(pageData.getAddInstructorButton().getAttributes().get("disabled"));
assertTrue(pageData.getAddInstructorButton().getAttributes().containsKey("disabled"));
______TS("test showing only one instructor");
offset = 1;
pageData = new InstructorCourseEditPageData(account, dummySessionToken, course, instructorList, currentInstructor, offset, sectionNames, feedbackSessionNames);
assertNotNull(pageData.getAddInstructorPanel());
assertTrue(pageData.getInstructorPanelList().get(0).isAccessControlDisplayed());
______TS("test specialSection");
InstructorAttributes instructor = instructorList.get(0);
instructor.privileges.addSessionWithDefaultPrivileges("Section 1", "First feedback session");
pageData = new InstructorCourseEditPageData(account, dummySessionToken, course, instructorList, currentInstructor, offset, sectionNames, feedbackSessionNames);
assertTrue(pageData.getInstructorPanelList().get(0).getSectionRows().get(0).isSectionSpecial());
______TS("test empty sectionNames");
sectionNames = new ArrayList<>();
pageData = new InstructorCourseEditPageData(account, dummySessionToken, course, instructorList, currentInstructor, offset, sectionNames, feedbackSessionNames);
assertNotNull(pageData.getAddInstructorPanel());
}
use of teammates.ui.pagedata.InstructorCourseEditPageData in project teammates by TEAMMATES.
the class InstructorCourseEditPageAction method execute.
// TODO: display privileges in the database properly
@Override
public ActionResult execute() throws EntityDoesNotExistException {
String courseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_ID, courseId);
String instructorEmail = getRequestParamValue(Const.ParamsNames.INSTRUCTOR_EMAIL);
String index = getRequestParamValue(Const.ParamsNames.COURSE_EDIT_MAIN_INDEX);
InstructorAttributes instructor = logic.getInstructorForGoogleId(courseId, account.googleId);
CourseAttributes courseToEdit = logic.getCourse(courseId);
gateKeeper.verifyAccessible(instructor, courseToEdit);
/* Setup page data for 'Edit' page of a course for an instructor */
List<InstructorAttributes> instructorList = new ArrayList<>();
// -1 means showing all instructors
int instructorToShowIndex = -1;
if (instructorEmail == null) {
instructorList = logic.getInstructorsForCourse(courseId);
} else {
instructorList.add(logic.getInstructorForEmail(courseId, instructorEmail));
instructorToShowIndex = Integer.parseInt(index);
}
List<String> sectionNames = logic.getSectionNamesForCourse(courseId);
List<String> feedbackNames = new ArrayList<>();
List<FeedbackSessionAttributes> feedbacks = logic.getFeedbackSessionsForCourse(courseId);
for (FeedbackSessionAttributes feedback : feedbacks) {
feedbackNames.add(feedback.getFeedbackSessionName());
}
InstructorCourseEditPageData data = new InstructorCourseEditPageData(account, sessionToken, courseToEdit, instructorList, instructor, instructorToShowIndex, sectionNames, feedbackNames);
statusToAdmin = "instructorCourseEdit Page Load<br>" + "Editing information for Course <span class=\"bold\">[" + courseId + "]</span>";
return createShowPageResult(Const.ViewURIs.INSTRUCTOR_COURSE_EDIT, data);
}
Aggregations