Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MBL-16952][Teacher] - Extend Quizzes E2E test with searching #2619

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ class AnnouncementsE2ETest : StudentTest() {
announcementListPage.searchable.clickOnSearchButton()
announcementListPage.searchable.typeToSearchBar(announcement.title)

Log.d(STEP_TAG,"Assert that only the matching announcement is displayed on the Discussion List Page.")
Log.d(STEP_TAG,"Assert that only the matching announcement is displayed on the Announcement List Page.")
announcementListPage.pullToUpdate()
announcementListPage.assertTopicDisplayed(announcement.title)
announcementListPage.assertTopicNotDisplayed(lockedAnnouncement.title)

Log.d(STEP_TAG,"Clear search input field value and assert if all the announcements are displayed again on the Discussion List Page.")
Log.d(STEP_TAG,"Clear search input field value and assert if all the announcements are displayed again on the Announcement List Page.")
announcementListPage.searchable.clickOnClearSearchButton()
announcementListPage.waitForDiscussionTopicToDisplay(lockedAnnouncement.title)
announcementListPage.assertTopicDisplayed(announcement.title)
Expand All @@ -117,7 +117,7 @@ class AnnouncementsE2ETest : StudentTest() {
announcementListPage.assertTopicNotDisplayed(announcement.title)
announcementListPage.assertTopicNotDisplayed(lockedAnnouncement.title)

Log.d(STEP_TAG,"Clear search input field value and assert if all the announcements are displayed again on the Discussion List Page.")
Log.d(STEP_TAG,"Clear search input field value and assert if all the announcements are displayed again on the Announcement List Page.")
announcementListPage.searchable.clickOnClearSearchButton()
announcementListPage.waitForDiscussionTopicToDisplay(lockedAnnouncement.title)
announcementListPage.assertTopicDisplayed(announcement.title)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
package com.instructure.student.ui.pages

import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.espresso.matcher.ViewMatchers.hasSibling
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
import androidx.test.espresso.matcher.ViewMatchers.withParent
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.platform.app.InstrumentationRegistry
import com.instructure.canvas.espresso.DirectlyPopulateEditText
import com.instructure.canvas.espresso.explicitClick
Expand Down Expand Up @@ -56,7 +60,7 @@ open class DiscussionListPage(val searchable: Searchable) : BasePage(R.id.discus

fun waitForDiscussionTopicToDisplay(topicTitle: String) {
val matcher = allOf(withText(topicTitle), withId(R.id.discussionTitle))
waitForView(matcher)
waitForView(matcher).assertDisplayed()
}

fun assertTopicDisplayed(topicTitle: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ class QuizListPageTest : TeacherTest() {
fun searchesQuizzes() {
val quizzes = getToQuizzesPage(quizCount = 3)
val searchQuiz = quizzes[2]
quizListPage.assertQuizCount(quizzes.size + 1) // +1 to account for header
quizListPage.assertQuizCount(quizzes.size)
quizListPage.searchable.clickOnSearchButton()
quizListPage.searchable.typeToSearchBar(searchQuiz.title!!.take(searchQuiz.title!!.length / 2))
quizListPage.assertQuizCount(2) // header + single search result
quizListPage.assertQuizCount(1)
quizListPage.assertHasQuiz(searchQuiz)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.instructure.teacher.ui.e2e

import android.util.Log
import androidx.test.espresso.Espresso
import com.instructure.canvas.espresso.E2E
import com.instructure.canvas.espresso.FeatureCategory
import com.instructure.canvas.espresso.Priority
Expand Down Expand Up @@ -44,7 +45,7 @@ class QuizE2ETest: TeacherTest() {
@E2E
@Test
@TestMetaData(Priority.MANDATORY, FeatureCategory.QUIZZES, TestCategory.E2E)
fun testQuizE2E() {
fun testQuizzesE2E() {

Log.d(PREPARATION_TAG, "Seeding data.")
val data = seedData(students = 1, teachers = 1, courses = 1)
Expand All @@ -63,20 +64,28 @@ class QuizE2ETest: TeacherTest() {
Log.d(STEP_TAG,"Assert that there is no quiz displayed on the page.")
quizListPage.assertDisplaysNoQuizzesView()

Log.d(PREPARATION_TAG,"Seed a quiz for the '${course.name}' course. Also, seed a question into the quiz and publish it.")
val testQuizList = seedQuizzes(courseId = course.id, withDescription = true, dueAt = 3.days.fromNow.iso8601, teacherToken = teacher.token, published = false)
Log.d(PREPARATION_TAG,"Seed two quizzes for the '${course.name}' course. Also, seed a question into both the quizzes and publish them.")
val testQuizList = seedQuizzes(courseId = course.id, quizzes = 2, withDescription = true, dueAt = 3.days.fromNow.iso8601, teacherToken = teacher.token, published = false)
seedQuizQuestion(courseId = course.id, quizId = testQuizList.quizList[0].id, teacherToken = teacher.token)
seedQuizQuestion(courseId = course.id, quizId = testQuizList.quizList[1].id, teacherToken = teacher.token)

Log.d(STEP_TAG,"Refresh the page. Assert that the quiz is there and click on the previously seeded quiz: '${testQuizList.quizList[0].title}'.")
Log.d(STEP_TAG,"Refresh the page.")
quizListPage.refresh()
quizListPage.clickQuiz(testQuizList.quizList[0].title)

Log.d(STEP_TAG,"Assert that '${testQuizList.quizList[0].title}' quiz is 'Not Submitted' and it is unpublished.")
Log.d(ASSERTION_TAG, "Assert that both of the quizzes are displayed on the Quiz List Page so the number of quizzes is 2.")
quizListPage.assertQuizCount(2)

val firstQuiz = testQuizList.quizList[0]
val secondQuiz = testQuizList.quizList[1]
Log.d(ASSERTION_TAG, "Assert that the quiz is there and click on the previously seeded quiz: '${firstQuiz.title}'.")
quizListPage.clickQuiz(firstQuiz.title)

Log.d(STEP_TAG,"Assert that '${firstQuiz.title}' quiz is 'Not Submitted' and it is unpublished.")
quizDetailsPage.assertNotSubmitted()
quizDetailsPage.assertQuizUnpublished()

val newQuizTitle = "This is a new quiz"
Log.d(STEP_TAG,"Open 'Edit' page and edit the '${testQuizList.quizList[0].title}' quiz's title to: '$newQuizTitle'.")
Log.d(STEP_TAG,"Open 'Edit' page and edit the '${firstQuiz.title}' quiz's title to: '$newQuizTitle'.")
quizDetailsPage.openEditPage()
editQuizDetailsPage.editQuizTitle(newQuizTitle)

Expand All @@ -92,12 +101,41 @@ class QuizE2ETest: TeacherTest() {
quizDetailsPage.refresh()
quizDetailsPage.assertQuizPublished()

Log.d(PREPARATION_TAG,"Submit the '${testQuizList.quizList[0].title}' quiz.")
Log.d(PREPARATION_TAG,"Submit the '${firstQuiz.title}' quiz.")
seedQuizSubmission(courseId = course.id, quizId = testQuizList.quizList[0].id, studentToken = student.token)

Log.d(STEP_TAG,"Refresh the page. Assert that it needs grading because of the previous submission.")
quizListPage.refresh()
quizDetailsPage.assertNeedsGrading()

Log.d(STEP_TAG,"Click on Search button and type '$newQuizTitle' to the search input field.")
Espresso.pressBack()
quizListPage.searchable.clickOnSearchButton()
quizListPage.searchable.typeToSearchBar(newQuizTitle)

Log.d(STEP_TAG,"Assert that only the matching quiz, which is '$newQuizTitle' is displayed on the Quiz List Page.")
quizListPage.assertQuizCount(1)
quizListPage.assertHasQuiz(newQuizTitle)
quizListPage.assertQuizNotDisplayed(secondQuiz.title)

Log.d(STEP_TAG,"Clear search input field value and assert if both of the quizzes are displayed again on the Quiz List Page.")
quizListPage.searchable.clickOnClearSearchButton()
quizListPage.assertQuizCount(2)
quizListPage.assertHasQuiz(newQuizTitle)
quizListPage.assertHasQuiz(secondQuiz.title)

Log.d(STEP_TAG,"Type a search value to the search input field which does not much with any of the existing quizzes.")
quizListPage.searchable.typeToSearchBar("Non existing quiz")
Thread.sleep(1000) //We need this wait here to let make sure the search process has finished.

Log.d(STEP_TAG,"Assert that the empty view is displayed.")
quizListPage.assertDisplaysNoQuizzesView()

Log.d(STEP_TAG,"Clear search input field value and assert if both of the quizzes are displayed on the Quiz List Page.")
quizListPage.searchable.clickOnClearSearchButton()
quizListPage.assertQuizCount(2)
quizListPage.assertHasQuiz(newQuizTitle)
quizListPage.assertHasQuiz(secondQuiz.title)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.instructure.teacher.ui.pages

import com.instructure.canvasapi2.models.Quiz
import com.instructure.espresso.DoesNotExistAssertion
import com.instructure.espresso.OnViewWithId
import com.instructure.espresso.RecyclerViewItemCountAssertion
import com.instructure.espresso.Searchable
Expand All @@ -25,11 +26,15 @@ import com.instructure.espresso.assertDisplayed
import com.instructure.espresso.click
import com.instructure.espresso.page.BasePage
import com.instructure.espresso.page.onView
import com.instructure.espresso.page.plus
import com.instructure.espresso.page.waitForView
import com.instructure.espresso.page.waitForViewWithText
import com.instructure.espresso.page.withId
import com.instructure.espresso.page.withText
import com.instructure.espresso.swipeDown
import com.instructure.espresso.waitForCheck
import com.instructure.teacher.R
import org.hamcrest.Matchers.allOf

/**
* Represents the Quiz List Page.
Expand Down Expand Up @@ -82,6 +87,24 @@ class QuizListPage(val searchable: Searchable) : BasePage() {
waitForViewWithText(quiz.title!!).assertDisplayed()
}

/**
* Asserts the presence of a quiz on the page.
*
* @param quizTitle The quiz title to check.
*/
fun assertHasQuiz(quizTitle: String) {
waitForView(withId(R.id.quizTitle) + withText(quizTitle)).assertDisplayed()
}

/**
* Asserts the non-existence of a quiz on the page.
*
* @param quizTitle The quiz title to check.
*/
fun assertQuizNotDisplayed(quizTitle: String) {
onView(allOf(withText(quizTitle) + withId(R.id.quizTitle))).check(DoesNotExistAssertion(5))
}

/**
* Clicks on a quiz.
*
Expand All @@ -106,7 +129,7 @@ class QuizListPage(val searchable: Searchable) : BasePage() {
* @param count The expected count of quizzes.
*/
fun assertQuizCount(count: Int) {
quizRecyclerView.waitForCheck(RecyclerViewItemCountAssertion(count))
quizRecyclerView.waitForCheck(RecyclerViewItemCountAssertion(count + 1)) // +1 needed because we don't want to count the 'Assignment Quizzes' group label.
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ abstract class TeacherTest : CanvasTest() {
val pageListPage = PageListPage(Searchable(R.id.search, R.id.search_src_text, R.id.search_close_btn))
val peopleListPage = PeopleListPage(Searchable(R.id.search, R.id.search_src_text, R.id.search_close_btn))
val quizDetailsPage = QuizDetailsPage(ModuleItemInteractions(R.id.moduleName, R.id.next, R.id.previous))
val quizListPage = QuizListPage(Searchable(R.id.search, R.id.search_src_text, R.id.clearButton, R.id.backButton))
val quizListPage = QuizListPage(Searchable(R.id.search, R.id.search_src_text, R.id.search_close_btn, R.id.backButton))
val quizSubmissionListPage = QuizSubmissionListPage()
val speedGraderCommentsPage = SpeedGraderCommentsPage()
val speedGraderFilesPage = SpeedGraderFilesPage()
Expand Down