-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Student][E2E][MBL-12978] | E2E tests for assignments (#234)
* MBL-12978: Initial effort towards AssignmentsE2ETest * MBL-12978: More logic for AssignmentsE2E test * MBL-12978: More tweaks * MBL-12978: Addressed PR feedback Removed commented-out println
- Loading branch information
Showing
9 changed files
with
347 additions
and
7 deletions.
There are no files selected for viewing
174 changes: 171 additions & 3 deletions
174
apps/student/src/androidTest/java/com/instructure/student/ui/e2e/AssignmentsE2ETest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,192 @@ | ||
package com.instructure.student.ui.e2e | ||
|
||
import android.os.SystemClock.sleep | ||
import androidx.test.espresso.Espresso | ||
import com.instructure.canvas.espresso.E2E | ||
import com.instructure.canvas.espresso.Stub | ||
import com.instructure.dataseeding.api.AssignmentsApi | ||
import com.instructure.dataseeding.api.SubmissionsApi | ||
import com.instructure.dataseeding.model.FileUploadType | ||
import com.instructure.dataseeding.model.GradingType | ||
import com.instructure.dataseeding.model.SubmissionType | ||
import com.instructure.dataseeding.util.days | ||
import com.instructure.dataseeding.util.fromNow | ||
import com.instructure.dataseeding.util.iso8601 | ||
import com.instructure.panda_annotations.FeatureCategory | ||
import com.instructure.panda_annotations.Priority | ||
import com.instructure.panda_annotations.TestCategory | ||
import com.instructure.panda_annotations.TestMetaData | ||
import com.instructure.student.ui.utils.StudentTest | ||
import com.instructure.student.ui.utils.seedData | ||
import com.instructure.student.ui.utils.tokenLogin | ||
import com.instructure.student.ui.utils.uploadTextFile | ||
import org.junit.Test | ||
|
||
class AssignmentsE2ETest: StudentTest() { | ||
override fun displaysPageObjects() { | ||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. | ||
} | ||
|
||
@Stub | ||
@E2E | ||
@Test | ||
@TestMetaData(Priority.P0, FeatureCategory.ASSIGNMENTS, TestCategory.E2E, true) | ||
@TestMetaData(Priority.P0, FeatureCategory.ASSIGNMENTS, TestCategory.E2E) | ||
fun testAssignmentsE2E() { | ||
// Seed basic student/teacher/course data | ||
val data = seedData(students = 1, teachers = 1, courses = 1) | ||
val student = data.studentsList[0] | ||
val teacher = data.teachersList[0] | ||
val course = data.coursesList[0] | ||
|
||
// Seed some assignments | ||
val pointsTextAssignment = AssignmentsApi.createAssignment(AssignmentsApi.CreateAssignmentRequest( | ||
courseId = course.id, | ||
submissionTypes = listOf(SubmissionType.ONLINE_TEXT_ENTRY), | ||
gradingType = GradingType.POINTS, | ||
teacherToken = teacher.token, | ||
pointsPossible = 15.0, | ||
dueAt = 1.days.fromNow.iso8601 | ||
)) | ||
|
||
val letterGradeTextAssignment = AssignmentsApi.createAssignment(AssignmentsApi.CreateAssignmentRequest( | ||
courseId = course.id, | ||
submissionTypes = listOf(SubmissionType.ONLINE_TEXT_ENTRY), | ||
gradingType = GradingType.LETTER_GRADE, | ||
teacherToken = teacher.token, | ||
pointsPossible = 20.0 | ||
)) | ||
|
||
val percentageFileAssignment = AssignmentsApi.createAssignment(AssignmentsApi.CreateAssignmentRequest( | ||
courseId = course.id, | ||
submissionTypes = listOf(SubmissionType.ONLINE_UPLOAD), | ||
gradingType = GradingType.PERCENT, | ||
teacherToken = teacher.token, | ||
pointsPossible = 25.0, | ||
allowedExtensions = listOf("txt", "pdf", "jpg") | ||
)) | ||
|
||
// Pre-seed a submission and a grade for the letter grade assignment | ||
SubmissionsApi.seedAssignmentSubmission(SubmissionsApi.SubmissionSeedRequest( | ||
assignmentId = letterGradeTextAssignment.id, | ||
courseId = course.id, | ||
studentToken = student.token, | ||
submissionSeedsList = listOf(SubmissionsApi.SubmissionSeedInfo( | ||
amount = 1, | ||
submissionType = SubmissionType.ONLINE_TEXT_ENTRY | ||
)) | ||
)) | ||
|
||
val submissionGrade = SubmissionsApi.gradeSubmission( | ||
teacherToken = teacher.token, | ||
courseId = course.id, | ||
assignmentId = letterGradeTextAssignment.id, | ||
studentId = student.id, | ||
postedGrade = "16", | ||
excused = false | ||
) | ||
|
||
|
||
// Sign in with lone student | ||
tokenLogin(student) | ||
|
||
// Go into our course | ||
dashboardPage.waitForRender() | ||
dashboardPage.selectCourse(course) | ||
|
||
// Select the assignments tab | ||
courseBrowserPage.selectAssignments() | ||
|
||
// Verify that our assignments are present, along with any grade/date info | ||
assignmentListPage.assertHasAssignment(pointsTextAssignment) | ||
assignmentListPage.assertHasAssignment(letterGradeTextAssignment, submissionGrade.grade) | ||
assignmentListPage.assertHasAssignment(percentageFileAssignment) | ||
|
||
// Let's submit a text assignment | ||
assignmentListPage.clickAssignment(pointsTextAssignment) | ||
|
||
SubmissionsApi.submitCourseAssignment( | ||
submissionType = SubmissionType.ONLINE_TEXT_ENTRY, | ||
courseId = course.id, | ||
assignmentId = pointsTextAssignment.id, | ||
studentToken = student.token, | ||
fileIds = emptyList<Long>().toMutableList() | ||
) | ||
|
||
assignmentDetailsPage.refresh() | ||
assignmentDetailsPage.verifyAssignmentSubmitted() | ||
|
||
// Let's grade the assignment | ||
val textGrade = SubmissionsApi.gradeSubmission( | ||
teacherToken = teacher.token, | ||
courseId = course.id, | ||
assignmentId = pointsTextAssignment.id, | ||
studentId = student.id, | ||
postedGrade = "13", | ||
excused = false | ||
) | ||
|
||
assignmentDetailsPage.refresh() | ||
assignmentDetailsPage.verifyAssignmentGraded("13") | ||
|
||
Espresso.pressBack() // Back to assignment list | ||
|
||
// Upload a text file for submission | ||
assignmentListPage.clickAssignment(percentageFileAssignment) | ||
val uploadInfo = uploadTextFile( | ||
courseId = course.id, | ||
assignmentId = percentageFileAssignment.id, | ||
token = student.token, | ||
fileUploadType = FileUploadType.ASSIGNMENT_SUBMISSION | ||
) | ||
|
||
// Submit the assignment | ||
SubmissionsApi.submitCourseAssignment( | ||
submissionType = SubmissionType.ONLINE_UPLOAD, | ||
courseId = course.id, | ||
assignmentId = percentageFileAssignment.id, | ||
fileIds = listOf(uploadInfo.id).toMutableList(), | ||
studentToken = student.token | ||
) | ||
|
||
// Verify that assignment has been submitted | ||
assignmentDetailsPage.refresh() | ||
assignmentDetailsPage.verifyAssignmentSubmitted() | ||
|
||
// Grade the assignment | ||
val fileGrade = SubmissionsApi.gradeSubmission( | ||
teacherToken = teacher.token, | ||
courseId = course.id, | ||
assignmentId = percentageFileAssignment.id, | ||
studentId = student.id, | ||
postedGrade = "22", | ||
excused = false | ||
) | ||
|
||
// Verify that the assignment has been graded | ||
assignmentDetailsPage.refresh() | ||
assignmentDetailsPage.verifyAssignmentGraded("22") | ||
|
||
// Back to assignment list page | ||
Espresso.pressBack() | ||
|
||
// Let's verify that the assignments in the list all have grades now | ||
assignmentListPage.refresh() | ||
assignmentListPage.assertHasAssignment(pointsTextAssignment, textGrade.grade) | ||
assignmentListPage.assertHasAssignment(letterGradeTextAssignment, submissionGrade.grade) | ||
assignmentListPage.assertHasAssignment(percentageFileAssignment, fileGrade.grade) | ||
|
||
// Let's make sure that comments are working | ||
assignmentListPage.clickAssignment(percentageFileAssignment) | ||
assignmentDetailsPage.goToSubmissionDetails() | ||
submissionDetailsPage.openComments() | ||
submissionDetailsPage.assertCommentDisplayed( | ||
uploadInfo.fileName, | ||
student) | ||
|
||
// Add a comment, make sure it shows up in the stream | ||
submissionDetailsPage.addAndSendComment("My comment!!") | ||
sleep(2000) // Give the comment time to propagate | ||
submissionDetailsPage.assertCommentDisplayed( | ||
"My comment!!", | ||
student | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
apps/student/src/androidTest/java/com/instructure/student/ui/pages/CourseBrowserPage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.instructure.student.ui.pages | ||
|
||
import android.view.View | ||
import androidx.recyclerview.widget.RecyclerView | ||
import androidx.test.espresso.Espresso.onView | ||
import androidx.test.espresso.contrib.RecyclerViewActions | ||
import androidx.test.espresso.matcher.ViewMatchers.hasDescendant | ||
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed | ||
import androidx.test.espresso.matcher.ViewMatchers.withId | ||
import androidx.test.espresso.matcher.ViewMatchers.withText | ||
import com.instructure.espresso.click | ||
import com.instructure.espresso.page.BasePage | ||
import com.instructure.student.R | ||
import org.hamcrest.Matcher | ||
import org.hamcrest.Matchers.allOf | ||
|
||
class CourseBrowserPage : BasePage(R.id.courseBrowserPage) { | ||
|
||
fun selectAssignments() { | ||
val matcher = allOf(withText("Assignments")) | ||
selectSection(matcher) | ||
} | ||
|
||
private fun selectSection(matcher: Matcher<View>) { | ||
// Scroll RecyclerView item into view, if necessary | ||
onView(allOf(withId(R.id.courseBrowserRecyclerView), isDisplayed())) | ||
.perform(RecyclerViewActions.scrollTo<RecyclerView.ViewHolder>(hasDescendant(matcher))) | ||
|
||
onView(matcher).click() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.