Skip to content

Commit

Permalink
[MBL-17621][Parent] Course details - Grades
Browse files Browse the repository at this point in the history
refs: MBL-17621
affects: Parent
release note: none
  • Loading branch information
kristofnemere authored Oct 4, 2024
1 parent e9f26a0 commit 7cbf649
Show file tree
Hide file tree
Showing 82 changed files with 5,916 additions and 248 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.instructure.canvasapi2.models.AlertType
import com.instructure.composeTest.hasDrawable
import com.instructure.parentapp.R
import com.instructure.parentapp.features.alerts.list.AlertsItemUiState
import com.instructure.parentapp.features.alerts.list.AlertsListItem
import com.instructure.parentapp.utils.hasDrawable
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import java.util.Date
import com.instructure.parentapp.R
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale

@RunWith(AndroidJUnit4::class)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/*
* Copyright (C) 2024 - 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.parentapp.ui.compose.courses.details

import androidx.compose.ui.test.assertHasClickAction
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertIsNotDisplayed
import androidx.compose.ui.test.hasContentDescription
import androidx.compose.ui.test.hasParent
import androidx.compose.ui.test.hasTestTag
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.instructure.parentapp.features.courses.details.CourseDetailsScreen
import com.instructure.parentapp.features.courses.details.CourseDetailsUiState
import com.instructure.parentapp.features.courses.details.TabType
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith


@RunWith(AndroidJUnit4::class)
class CourseDetailsScreenTest {

@get:Rule
val composeTestRule = createComposeRule()

@Test
fun assertLoadingContent() {
composeTestRule.setContent {
CourseDetailsScreen(
uiState = CourseDetailsUiState(
isLoading = true
),
actionHandler = {},
navigationActionClick = {}
)
}

composeTestRule.onNodeWithTag("loading")
.assertIsDisplayed()
}

@Test
fun assertErrorContent() {
composeTestRule.setContent {
CourseDetailsScreen(
uiState = CourseDetailsUiState(
isLoading = false,
isError = true
),
actionHandler = {},
navigationActionClick = {}
)
}

composeTestRule.onNodeWithText("We're having trouble loading your student's course details. Please try reloading the page or check back later.")
.assertIsDisplayed()
composeTestRule.onNodeWithText("Retry")
.assertIsDisplayed()
.assertHasClickAction()
}

@Test
fun assertCourseDetailsContent() {
composeTestRule.setContent {
CourseDetailsScreen(
uiState = CourseDetailsUiState(
isLoading = false,
isError = false,
courseName = "Course 1",
tabs = listOf(TabType.SYLLABUS, TabType.SUMMARY)
),
actionHandler = {},
navigationActionClick = {}
)
}

composeTestRule.onNodeWithTag("toolbar")
.assertIsDisplayed()
composeTestRule.onNode(hasParent(hasTestTag("toolbar")).and(hasContentDescription("Back")))
.assertIsDisplayed()
.assertHasClickAction()
composeTestRule.onNodeWithText("Course 1")
.assertIsDisplayed()
composeTestRule.onNodeWithText("SYLLABUS")
.assertIsDisplayed()
composeTestRule.onNodeWithText("SUMMARY")
.assertIsDisplayed()
composeTestRule.onNodeWithTag("courseDetailsTabRow")
.assertIsDisplayed()
composeTestRule.onNodeWithTag("courseDetailsPager")
.assertIsDisplayed()
composeTestRule.onNodeWithContentDescription("Send a message about this course")
.assertIsDisplayed()
.assertHasClickAction()
}

@Test
fun assertCourseDetailsContentWithJustOnTab() {
composeTestRule.setContent {
CourseDetailsScreen(
uiState = CourseDetailsUiState(
isLoading = false,
isError = false,
courseName = "Course 1",
tabs = listOf(TabType.SYLLABUS)
),
actionHandler = {},
navigationActionClick = {}
)
}

composeTestRule.onNodeWithText("Course 1")
.assertIsDisplayed()
composeTestRule.onNodeWithTag("courseDetailsTabRow")
.assertIsNotDisplayed()
composeTestRule.onNodeWithTag("courseDetailsPager")
.assertIsDisplayed()
composeTestRule.onNodeWithContentDescription("Send a message about this course")
.assertIsDisplayed()
.assertHasClickAction()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
*/

package com.instructure.parentapp.ui.compose
package com.instructure.parentapp.ui.compose.courses.list

import androidx.compose.ui.graphics.Color
import androidx.compose.ui.test.assertHasClickAction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
*/

package com.instructure.parentapp.ui.compose
package com.instructure.parentapp.ui.compose.managestudents

import androidx.compose.ui.test.assertHasClickAction
import androidx.compose.ui.test.assertIsDisplayed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
*/

package com.instructure.parentapp.ui.compose
package com.instructure.parentapp.ui.compose.notaparent

import androidx.compose.ui.test.assertHasClickAction
import androidx.compose.ui.test.assertIsDisplayed
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright (C) 2024 - present Instructure, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

package com.instructure.parentapp.ui.interaction

import com.instructure.canvas.espresso.mockCanvas.MockCanvas
import com.instructure.canvas.espresso.mockCanvas.init
import com.instructure.canvasapi2.models.Course
import com.instructure.canvasapi2.models.CourseSettings
import com.instructure.canvasapi2.models.Tab
import com.instructure.parentapp.utils.ParentComposeTest
import com.instructure.parentapp.utils.tokenLogin
import dagger.hilt.android.testing.HiltAndroidTest
import org.junit.Test


@HiltAndroidTest
class CourseDetailsInteractionTest : ParentComposeTest() {

@Test
fun courseDetailsDisplayed() {
val data = initData()
val course = data.courses.values.first()
setupTabs(data, course)

goToCourseDetails(data, course.name)

composeTestRule.waitForIdle()
courseDetailsPage.assertCourseDetailsDisplayed(course)
}

@Test
fun changeTab() {
val data = initData()
val course = data.courses.values.first()
setupTabs(data, course)

goToCourseDetails(data, course.name)

composeTestRule.waitForIdle()
courseDetailsPage.selectTab("SYLLABUS")
courseDetailsPage.assertTabSelected("SYLLABUS")
}

private fun initData(): MockCanvas {
return MockCanvas.init(
parentCount = 1,
studentCount = 1,
courseCount = 1
)
}

private fun setupTabs(data: MockCanvas, course: Course) {
course.homePage = Course.HomePage.HOME_SYLLABUS
course.syllabusBody = "This is the syllabus"
data.courseTabs[course.id]?.add(Tab(tabId = Tab.SYLLABUS_ID))
data.courseSettings[course.id] = CourseSettings(
courseSummary = true
)
}

private fun goToCourseDetails(data: MockCanvas, courseName: String) {
val parent = data.parents.first()
val token = data.tokenFor(parent)!!
tokenLogin(data.domain, token, parent)
coursesPage.tapCurseItem(courseName)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (C) 2024 - present Instructure, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

package com.instructure.parentapp.ui.interaction

import com.instructure.canvas.espresso.common.interaction.GradesInteractionTest
import com.instructure.canvas.espresso.mockCanvas.MockCanvas
import com.instructure.canvas.espresso.mockCanvas.addAssignmentsToGroups
import com.instructure.canvas.espresso.mockCanvas.init
import com.instructure.parentapp.BuildConfig
import com.instructure.parentapp.features.login.LoginActivity
import com.instructure.parentapp.ui.pages.CoursesPage
import com.instructure.parentapp.utils.ParentActivityTestRule
import com.instructure.parentapp.utils.tokenLogin
import dagger.hilt.android.testing.HiltAndroidTest


@HiltAndroidTest
class ParentGradesInteractionTest : GradesInteractionTest() {

private val coursesPage = CoursesPage(composeTestRule)

override val isTesting = BuildConfig.IS_TESTING

override val activityRule = ParentActivityTestRule(LoginActivity::class.java)

override fun initData(addAssignmentGroups: Boolean): MockCanvas {
return MockCanvas.init(
parentCount = 1,
studentCount = 1,
courseCount = 1,
withGradingPeriods = true
).apply {
if (addAssignmentGroups) {
addAssignmentsToGroups(this.courses.values.first(), 3)
}
}
}

override fun goToGrades(data: MockCanvas, courseName: String) {
val parent = data.parents.first()
val token = data.tokenFor(parent)!!
tokenLogin(data.domain, token, parent)
coursesPage.tapCurseItem(courseName)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (C) 2024 - 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.parentapp.ui.pages

import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertIsSelected
import androidx.compose.ui.test.junit4.ComposeTestRule
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import com.instructure.canvasapi2.models.Course


class CourseDetailsPage(private val composeTestRule: ComposeTestRule) {

fun assertCourseDetailsDisplayed(course: Course) {
composeTestRule.onNodeWithText(course.name).assertIsDisplayed()
composeTestRule.onNodeWithText("GRADES")
.assertIsDisplayed()
.assertIsSelected()
composeTestRule.onNodeWithText("SYLLABUS").assertIsDisplayed()
composeTestRule.onNodeWithText("SUMMARY").assertIsDisplayed()
}

fun selectTab(tabName: String) {
composeTestRule.onNodeWithText(tabName).performClick()
}

fun assertTabSelected(tabName: String) {
composeTestRule.onNodeWithText(tabName).assertIsSelected()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.instructure.parentapp.features.login.LoginActivity
import com.instructure.parentapp.ui.pages.AddStudentPage
import com.instructure.parentapp.ui.pages.AlertSettingsPage
import com.instructure.parentapp.ui.pages.AlertsPage
import com.instructure.parentapp.ui.pages.CourseDetailsPage
import com.instructure.parentapp.ui.pages.CoursesPage
import com.instructure.parentapp.ui.pages.ManageStudentsPage
import com.instructure.parentapp.ui.pages.NotAParentPage
Expand All @@ -43,6 +44,7 @@ abstract class ParentComposeTest : ParentTest() {
protected val qrPairingPage = QrPairingPage(composeTestRule)
protected val coursesPage = CoursesPage(composeTestRule)
protected val notAParentPage = NotAParentPage(composeTestRule)
protected val courseDetailsPage = CourseDetailsPage(composeTestRule)

override fun displaysPageObjects() = Unit
}
Loading

0 comments on commit 7cbf649

Please sign in to comment.