Skip to content

Commit

Permalink
[MBL-14901][Teacher] Created speedgrader e2e tests (#1117)
Browse files Browse the repository at this point in the history
* refs: MBL-14901
affects: Teacher
release note: Extended test matrix

test plan:

* Removed unused dependencies

refs: MBL-14901
affects: Teacher
release note: Extended test matrix

test plan:

* Added E2E test for speedgrader, removed accessibility checks

refs: MBL-14901
affects: Teacher
release note: Extended test matrix

test plan:
  • Loading branch information
davidvarga93 authored Dec 1, 2020
1 parent 53a0e22 commit 8340504
Show file tree
Hide file tree
Showing 8 changed files with 206 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/*
* Copyright (C) 2020 - present Instructure, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.instructure.teacher.ui.e2e

import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.matcher.ViewMatchers.isDisplayingAtLeast
import androidx.test.espresso.matcher.ViewMatchers.withText
import com.instructure.canvas.espresso.E2E
import com.instructure.canvas.espresso.refresh
import com.instructure.canvas.espresso.withCustomConstraints
import com.instructure.dataseeding.api.SubmissionsApi
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.teacher.R
import com.instructure.teacher.ui.utils.*
import org.junit.Test

class SpeedGraderE2ETest : TeacherTest() {
override fun displaysPageObjects() = Unit

override fun enableAndConfigureAccessibilityChecks() {
//We dont want to see accessibility errors on E2E tests
}

@E2E
@Test
@TestMetaData(Priority.P0, FeatureCategory.GRADES, TestCategory.E2E)
fun testSpeedGraderE2E() {
val data = seedData(teachers = 1, courses = 1, students = 3, favoriteCourses = 1)
val teacher = data.teachersList[0]
val course = data.coursesList[0]
val student = data.studentsList[0]
val gradedStudent = data.studentsList[1]
val noSubStudent = data.studentsList[2]

val assignment = seedAssignments(
courseId = course.id,
dueAt = 1.days.fromNow.iso8601,
submissionTypes = listOf(SubmissionType.ONLINE_TEXT_ENTRY),
teacherToken = teacher.token,
pointsPossible = 15.0
)
val sub = seedAssignmentSubmission(
submissionSeeds = listOf(SubmissionsApi.SubmissionSeedInfo(
amount = 1,
submissionType = SubmissionType.ONLINE_TEXT_ENTRY
)),
assignmentId = assignment[0].id,
courseId = course.id,
studentToken = student.token
)

val gradedSubmission = seedAssignmentSubmission(
submissionSeeds = listOf(SubmissionsApi.SubmissionSeedInfo(
amount = 1,
submissionType = SubmissionType.ONLINE_TEXT_ENTRY
)),
assignmentId = assignment[0].id,
courseId = course.id,
studentToken = gradedStudent.token
)

SubmissionsApi.gradeSubmission(
teacherToken = teacher.token,
courseId = course.id,
assignmentId = assignment[0].id,
studentId = gradedStudent.id,
postedGrade = "15",
excused = false
)

tokenLogin(teacher)

coursesListPage.openCourse(course)
courseBrowserPage.openAssignmentsTab()

assignmentListPage.clickAssignment(assignment[0])
assignmentDetailsPage.assertHasSubmitted(actual = 1, outOf = 3)
assignmentDetailsPage.assertNotSubmitted(actual = 1, outOf = 3)
assignmentDetailsPage.openNotSubmittedSubmissions()
assignmentSubmissionListPage.assertHasStudentSubmission(canvasUser = noSubStudent)
assignmentSubmissionListPage.navigateBack()
assignmentDetailsPage.openGradedSubmissions()
assignmentSubmissionListPage.assertHasStudentSubmission(canvasUser = gradedStudent)
assignmentSubmissionListPage.navigateBack()
assignmentDetailsPage.openSubmissionsPage()
assignmentSubmissionListPage.clickSubmission(student)
speedGraderPage.assertDisplaysTextSubmissionViewWithStudentName(studentName = student.name)
speedGraderPage.selectGradesTab()
speedGraderGradePage.openGradeDialog()
val grade = "10"
speedGraderGradePage.enterNewGrade(grade)
speedGraderGradePage.assertHasGrade(grade)
speedGraderGradePage.navigateBack()
refresh()

assignmentSubmissionListPage.clickFilterButton()
assignmentSubmissionListPage.clickFilterSubmissions()
assignmentSubmissionListPage.clickFilterUngraded()
assignmentSubmissionListPage.clickFilterDialogOk()
assignmentSubmissionListPage.assertHasNoSubmission()

assignmentSubmissionListPage.clickFilterButton()
assignmentSubmissionListPage.clickFilterSubmissions()
onView(withText(R.string.not_submitted)).perform(withCustomConstraints(click(), isDisplayingAtLeast(10)))
assignmentSubmissionListPage.clickFilterDialogOk()
assignmentSubmissionListPage.assertHasSubmission(1)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@ class AssignmentDetailsPage : BasePage(pageResId = R.id.assignmentDetailsPage) {
viewAllSubmissions.click()
}

fun openGradedSubmissions() {
gradedDonutWrapper.click()
}

fun openUngradedSubmissions() {
ungradedDonutWrapper.click()
}

fun openNotSubmittedSubmissions() {
notSubmittedDonutWrapper.click()
}

fun assertAssignmentDetails(assignment: Assignment) {
assignmentNameTextView.assertHasText(assignment.name!!)
if (assignment.published) {
Expand Down Expand Up @@ -139,14 +151,14 @@ class AssignmentDetailsPage : BasePage(pageResId = R.id.assignmentDetailsPage) {
pointsTextView.assertContainsText(newAssignmentPoints)
}

fun assertHasSubmitted() {
fun assertHasSubmitted(actual: Int = 1, outOf: Int = 1) {
val resources = InstrumentationRegistry.getTargetContext()
ungradedDonutWrapper.assertHasContentDescription(resources.getString(R.string.content_description_submission_donut_needs_grading).format(1, 1))
ungradedDonutWrapper.assertHasContentDescription(resources.getString(R.string.content_description_submission_donut_needs_grading).format(actual, outOf))
}

fun assertNotSubmitted() {
fun assertNotSubmitted(actual: Int = 1, outOf: Int = 1) {
val resources = InstrumentationRegistry.getTargetContext()
notSubmittedDonutWrapper.assertHasContentDescription(resources.getString(R.string.content_description_submission_donut_unsubmitted).format(1, 1))
notSubmittedDonutWrapper.assertHasContentDescription(resources.getString(R.string.content_description_submission_donut_unsubmitted).format(actual, outOf))
}

fun waitForRender() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,16 @@
*/
package com.instructure.teacher.ui.pages

import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.espresso.matcher.ViewMatchers
import com.instructure.canvas.espresso.waitForMatcherWithRefreshes
import com.instructure.canvasapi2.models.User
import com.instructure.dataseeding.model.CanvasUserApiModel
import com.instructure.espresso.*
import com.instructure.espresso.page.BasePage
import com.instructure.espresso.page.*


import com.instructure.espresso.page.onViewWithText
import com.instructure.espresso.page.waitForViewWithId
import com.instructure.espresso.page.waitForViewWithText
import com.instructure.teacher.R
import org.hamcrest.Matchers

class AssignmentSubmissionListPage : BasePage() {

Expand All @@ -38,7 +36,7 @@ class AssignmentSubmissionListPage : BasePage() {

private val assignmentSubmissionClearFilter by OnViewWithId(R.id.clearFilterTextView, false)

private val assignmentSubmissionFilterButton by OnViewWithId(R.id.submissionFilter)
private val assignmentSubmissionFilterButton by OnViewWithId(R.id.submissionFilter, false)

private val assignmentSubmissionFilterBySubmissionsButton by WaitForViewWithText(R.string.filterSubmissionsLowercase)

Expand Down Expand Up @@ -75,6 +73,10 @@ class AssignmentSubmissionListPage : BasePage() {
assignmentSubmissionClearFilter.assertGone()
}

fun assertStudentHasGrade(grade: String) {
onView(withId(R.id.submissionGrade)).assertHasText(grade)
}

fun clickFilterButton() {
assignmentSubmissionFilterButton.click()
}
Expand Down Expand Up @@ -105,8 +107,8 @@ class AssignmentSubmissionListPage : BasePage() {
assignmentSubmissionListFilterLabel.assertHasText(text)
}

fun assertHasSubmission() {
assignmentSubmissionRecyclerView.check(RecyclerViewItemCountAssertion(1))
fun assertHasSubmission(expectedCount: Int = 1) {
assignmentSubmissionRecyclerView.check(RecyclerViewItemCountAssertion(expectedCount))
}

fun assertHasNoSubmission() {
Expand Down Expand Up @@ -156,4 +158,9 @@ class AssignmentSubmissionListPage : BasePage() {
fun clickFilterDialogOk() {
waitForViewWithText(android.R.string.ok).click()
}

fun navigateBack() {
onView(Matchers.allOf((withParent(R.id.assignmentSubmissionListToolbar) + ViewMatchers.withContentDescription("Navigate up")), ViewMatchers.isDisplayed())).click()

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
*/
package com.instructure.teacher.ui.pages

import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
import com.instructure.espresso.*
import com.instructure.espresso.page.BasePage
import com.instructure.espresso.page.getStringFromResource
import com.instructure.espresso.page.onViewWithId
import com.instructure.espresso.page.*
import com.instructure.teacher.R
import org.hamcrest.Matchers

class SpeedGraderGradePage : BasePage() {

Expand All @@ -38,21 +39,25 @@ class SpeedGraderGradePage : BasePage() {


fun openGradeDialog() {
gradeTextContainer.click()
onView(Matchers.allOf((withId(R.id.gradeTextContainer)), ViewMatchers.isDisplayed())).click()
}

fun enterNewGrade(grade: String) {
gradeEditText.replaceText(grade)
confirmDialogButton.click()
}

fun navigateBack() {
onView(Matchers.allOf((withParent(R.id.speedGraderToolbar) + withContentDescription("Navigate up")), ViewMatchers.isDisplayed())).click()
}

fun assertGradeDialog() {
customizeGradeTitle.assertDisplayed()
excuseStudentCheckbox.assertDisplayed()
}

fun assertHasGrade(grade: String) {
gradeValueText.assertContainsText(grade)
onView(Matchers.allOf((withId(R.id.gradeValueText)), ViewMatchers.isDisplayed())).assertContainsText(grade)
}

fun assertRubricHidden() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import androidx.annotation.StringRes
import androidx.test.espresso.Espresso
import androidx.test.espresso.NoMatchingViewException
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import com.instructure.canvasapi2.models.Submission
import com.instructure.canvasapi2.models.User
import com.instructure.dataseeding.model.CanvasUserApiModel
Expand All @@ -27,6 +28,7 @@ import com.instructure.espresso.*
import com.instructure.espresso.page.*
import com.instructure.teacher.R
import org.hamcrest.Matchers
import org.hamcrest.Matchers.allOf

@Suppress("unused")
class SpeedGraderPage : BasePage() {
Expand Down Expand Up @@ -57,7 +59,8 @@ class SpeedGraderPage : BasePage() {
}

fun selectGradesTab() {
gradeTab.click()
val gradesTabText = getStringFromResource(R.string.sg_tab_grade).toUpperCase()
onView(allOf((withText(gradesTabText)), isDisplayed())).click()
}

fun selectCommentsTab() {
Expand Down Expand Up @@ -101,6 +104,10 @@ class SpeedGraderPage : BasePage() {
waitForViewWithId(R.id.textSubmissionWebView).assertVisible()
}

fun assertDisplaysTextSubmissionViewWithStudentName(studentName: String) {
onView(allOf(withText(studentName), isDisplayed()))
}

fun assertDisplaysEmptyState(@StringRes stringRes: Int) {
waitForViewWithText(stringRes).assertCompletelyDisplayed()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ fun TeacherTest.seedAssignments(
lockAt: String = "",
unlockAt: String = "",
dueAt: String = "",
pointsPossible: Double? = null,
submissionTypes: List<SubmissionType> = emptyList(),
teacherToken: String): List<AssignmentApiModel> {

Expand All @@ -139,7 +140,8 @@ fun TeacherTest.seedAssignments(
unlockAt = unlockAt,
dueAt = dueAt,
submissionTypes = submissionTypes,
teacherToken = teacherToken
teacherToken = teacherToken,
pointsPossible = pointsPossible
)

return AssignmentsApi.seedAssignments(request, assignments)
Expand Down
Loading

0 comments on commit 8340504

Please sign in to comment.