Skip to content

Commit

Permalink
[Student][MBL-13200] Assignment details page: Fix submission status f…
Browse files Browse the repository at this point in the history
…or graded-but-not-submitted assignments (#313)
  • Loading branch information
JordanMarshall authored Sep 13, 2019
1 parent 75adc53 commit 914aba1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -73,6 +76,7 @@ class AssignmentDetailsPresenterTest : Assert() {
)
baseSubmission = Submission(
attempt = 1,
submittedAt = Date(),
workflowState = "submitted"
)
baseQuiz = Quiz(
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -559,6 +573,7 @@ class AssignmentDetailsPresenterTest : Assert() {
)
val assignment = baseAssignment.copy(
submission = baseSubmission.copy(
workflowState = "graded",
enteredScore = 85.0,
enteredGrade = "85",
score = 85.0,
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 914aba1

Please sign in to comment.