From 914aba12f5233c232232985adaa74563b890bb5d Mon Sep 17 00:00:00 2001 From: Jordan Marshall Date: Fri, 13 Sep 2019 14:11:17 -0600 Subject: [PATCH] [Student][MBL-13200] Assignment details page: Fix submission status for graded-but-not-submitted assignments (#313) --- .../AssignmentDetailsRenderTest.kt | 2 +- .../details/AssignmentDetailsPresenterTest.kt | 32 ++++++++++++++----- .../canvasapi2/models/Assignment.kt | 6 ++-- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/apps/student/src/androidTest/java/com/instructure/student/ui/renderTests/AssignmentDetailsRenderTest.kt b/apps/student/src/androidTest/java/com/instructure/student/ui/renderTests/AssignmentDetailsRenderTest.kt index 56b8938a5f..318b319881 100644 --- a/apps/student/src/androidTest/java/com/instructure/student/ui/renderTests/AssignmentDetailsRenderTest.kt +++ b/apps/student/src/androidTest/java/com/instructure/student/ui/renderTests/AssignmentDetailsRenderTest.kt @@ -90,7 +90,7 @@ class AssignmentDetailsRenderTest : StudentRenderTest() { @Test @TestMetaData(Priority.P2, FeatureCategory.ASSIGNMENTS, TestCategory.RENDER) fun displaysTitleDataSubmitted() { - val submission = Submission(workflowState = "submitted") + val submission = Submission(workflowState = "submitted", submittedAt = Date()) val assignment = Assignment( name = "Test Assignment", pointsPossible = 35.0, diff --git a/apps/student/src/test/java/com/instructure/student/test/assignment/details/AssignmentDetailsPresenterTest.kt b/apps/student/src/test/java/com/instructure/student/test/assignment/details/AssignmentDetailsPresenterTest.kt index a05c1b37a1..45816c3f49 100644 --- a/apps/student/src/test/java/com/instructure/student/test/assignment/details/AssignmentDetailsPresenterTest.kt +++ b/apps/student/src/test/java/com/instructure/student/test/assignment/details/AssignmentDetailsPresenterTest.kt @@ -39,7 +39,10 @@ import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.threeten.bp.OffsetDateTime -import java.util.* +import java.util.Calendar +import java.util.Date +import java.util.GregorianCalendar +import java.util.Locale import java.util.concurrent.TimeUnit @RunWith(AndroidJUnit4::class) @@ -73,6 +76,7 @@ class AssignmentDetailsPresenterTest : Assert() { ) baseSubmission = Submission( attempt = 1, + submittedAt = Date(), workflowState = "submitted" ) baseQuiz = Quiz( @@ -200,7 +204,7 @@ class AssignmentDetailsPresenterTest : Assert() { @Test fun `Uses correct label text for submitted status when submission is graded`() { - val submission = baseSubmission.copy(grade = "8", postedAt = Date()) + val submission = baseSubmission.copy(grade = "8", postedAt = Date(), workflowState = "graded") val assignment = baseAssignment.copy(submission = submission) val model = baseModel.copy(assignmentResult = DataResult.Success(assignment)) val state = AssignmentDetailsPresenter.present(model, context) as AssignmentDetailsViewState.Loaded @@ -209,7 +213,7 @@ class AssignmentDetailsPresenterTest : Assert() { @Test fun `Uses correct label text for submitted status when submission is missing`() { - val submission = baseSubmission.copy(attempt = 0, missing = true, workflowState = "unsubmitted") + val submission = baseSubmission.copy(attempt = 0, missing = true, workflowState = "unsubmitted", submittedAt = null) val assignment = baseAssignment.copy(submission = submission) val model = baseModel.copy(assignmentResult = DataResult.Success(assignment)) val state = AssignmentDetailsPresenter.present(model, context) as AssignmentDetailsViewState.Loaded @@ -220,7 +224,7 @@ class AssignmentDetailsPresenterTest : Assert() { fun `Uses correct label text for submitted status when submission is past due`() { val calendar = Calendar.getInstance().apply { set(2000, 0, 31, 23, 59, 0) } - val submission = baseSubmission.copy(attempt = 0, workflowState = "unsubmitted") + val submission = baseSubmission.copy(attempt = 0, workflowState = "unsubmitted", submittedAt = null) val assignment = baseAssignment.copy(submission = submission, dueAt = calendar.time.toApiString(), submissionTypesRaw = listOf(Assignment.SubmissionType.ONLINE_UPLOAD.apiString)) val model = baseModel.copy(assignmentResult = DataResult.Success(assignment)) val state = AssignmentDetailsPresenter.present(model, context) as AssignmentDetailsViewState.Loaded @@ -241,7 +245,7 @@ class AssignmentDetailsPresenterTest : Assert() { fun `Uses correct label text for submitted status when submission is past due for an LTI assignment`() { val calendar = Calendar.getInstance().apply { set(2000, 0, 31, 23, 59, 0) } - val submission = baseSubmission.copy(attempt = 0, workflowState = "unsubmitted") + val submission = baseSubmission.copy(attempt = 0, workflowState = "unsubmitted", submittedAt = null) val assignment = baseAssignment.copy(submission = submission, dueAt = calendar.time.toApiString(), submissionTypesRaw = listOf("basic_lti_launch")) val model = baseModel.copy(assignmentResult = DataResult.Success(assignment)) val state = AssignmentDetailsPresenter.present(model, context) as AssignmentDetailsViewState.Loaded @@ -252,7 +256,7 @@ class AssignmentDetailsPresenterTest : Assert() { fun `Uses correct label text for submitted status when submission is past due for an external assignment`() { val calendar = Calendar.getInstance().apply { set(2000, 0, 31, 23, 59, 0) } - val submission = baseSubmission.copy(attempt = 0, workflowState = "unsubmitted") + val submission = baseSubmission.copy(attempt = 0, workflowState = "unsubmitted", submittedAt = null) val assignment = baseAssignment.copy(submission = submission, dueAt = calendar.time.toApiString(), submissionTypesRaw = listOf("external_tool")) val model = baseModel.copy(assignmentResult = DataResult.Success(assignment)) val state = AssignmentDetailsPresenter.present(model, context) as AssignmentDetailsViewState.Loaded @@ -269,7 +273,16 @@ class AssignmentDetailsPresenterTest : Assert() { @Test fun `Uses correct label text for submitted status when submission is not submitted`() { - val submission = baseSubmission.copy(attempt = 0, workflowState = "unsubmitted") + val submission = baseSubmission.copy(attempt = 0, workflowState = "unsubmitted", submittedAt = null) + val assignment = baseAssignment.copy(submission = submission) + val model = baseModel.copy(assignmentResult = DataResult.Success(assignment)) + val state = AssignmentDetailsPresenter.present(model, context) as AssignmentDetailsViewState.Loaded + assertEquals("Not Submitted", state.submittedStateLabel) + } + + @Test + fun `Uses correct label text for submitted status when submission is graded but not submitted`() { + val submission = baseSubmission.copy(attempt = 0, submittedAt = null, grade = "8", postedAt = Date(), workflowState = "graded") val assignment = baseAssignment.copy(submission = submission) val model = baseModel.copy(assignmentResult = DataResult.Success(assignment)) val state = AssignmentDetailsPresenter.present(model, context) as AssignmentDetailsViewState.Loaded @@ -529,6 +542,7 @@ class AssignmentDetailsPresenterTest : Assert() { fun `Displays grade cell when grade is not empty`() { val assignment = baseAssignment.copy( submission = baseSubmission.copy( + workflowState = "graded", enteredScore = 85.0, enteredGrade = "85", score = 85.0, @@ -559,6 +573,7 @@ class AssignmentDetailsPresenterTest : Assert() { ) val assignment = baseAssignment.copy( submission = baseSubmission.copy( + workflowState = "graded", enteredScore = 85.0, enteredGrade = "85", score = 85.0, @@ -617,7 +632,8 @@ class AssignmentDetailsPresenterTest : Assert() { ) val assignment = baseAssignment.copy( submission = baseSubmission.copy( - workflowState = "unsubmitted" + workflowState = "unsubmitted", + submittedAt = null ) ) val model = baseModel.copy(assignmentResult = DataResult.Success(assignment), databaseSubmission = submission) diff --git a/libs/canvas-api-2/src/main/java/com/instructure/canvasapi2/models/Assignment.kt b/libs/canvas-api-2/src/main/java/com/instructure/canvasapi2/models/Assignment.kt index ab34d4af80..a41755147c 100644 --- a/libs/canvas-api-2/src/main/java/com/instructure/canvasapi2/models/Assignment.kt +++ b/libs/canvas-api-2/src/main/java/com/instructure/canvasapi2/models/Assignment.kt @@ -22,7 +22,7 @@ import com.google.gson.annotations.SerializedName import com.instructure.canvasapi2.R import com.instructure.canvasapi2.utils.toDate import kotlinx.android.parcel.Parcelize -import java.util.* +import java.util.Date @Parcelize data class Assignment( @@ -105,10 +105,10 @@ data class Assignment( /** * Whether or not the user has submitted this assignment. If the user has not submitted anything, Canvas generates - * an empty submission with an "unsubmitted" workflow state. For very old assignments, canvas might not + * an empty submission with a null value for "submittedAt". For very old assignments, canvas might not * return a submission at all. */ - val isSubmitted: Boolean get() = submission != null && submission!!.workflowState != "unsubmitted" + val isSubmitted: Boolean get() = submission?.submittedAt != null val isAllowedToSubmit: Boolean get() {