From 555628841667842ffa9c6e06702d705f8384af27 Mon Sep 17 00:00:00 2001 From: Ryan Norton Date: Wed, 20 Nov 2019 13:01:57 -0700 Subject: [PATCH] do not allow submissions from not current attempts in a2, we should not allow the user to submit a valid attempt unless they are viewing the current attempt Test Plan: * as a student in a2, navigate to any submission type * create and submit an attempt * click the button to create a new attempt * add a draft to this attempt but do not submit it * confirm that the submit button is visible * click the previous attempt button * confirm that the submit button is no longer visible flag=assignments_2_student fixes KNO-158 Change-Id: Icc29c3378e72382b39ee512a9f8ebf3cacc33466 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/218025 Reviewed-by: Matthew Lemon Tested-by: Service Cloud Jenkins Tested-by: Jenkins QA-Review: Steven Burnett Product-Review: Steven Burnett --- .../student/components/SubmissionManager.js | 12 +++++++++--- .../__tests__/SubmissionManager.test.js | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/app/jsx/assignments_2/student/components/SubmissionManager.js b/app/jsx/assignments_2/student/components/SubmissionManager.js index 288459adfdf..707a94a0689 100644 --- a/app/jsx/assignments_2/student/components/SubmissionManager.js +++ b/app/jsx/assignments_2/student/components/SubmissionManager.js @@ -29,6 +29,7 @@ import {Mutation} from 'react-apollo' import PropTypes from 'prop-types' import React, {Component} from 'react' import {STUDENT_VIEW_QUERY, SUBMISSION_HISTORIES_QUERY} from '../graphqlData/Queries' +import StudentViewContext from './Context' import {Submission} from '../graphqlData/Submission' import theme from '@instructure/canvas-theme' @@ -200,7 +201,7 @@ export default class SubmissionManager extends Component { this.setState({submittingAssignment: false}) } - shouldRenderSubmit = () => { + shouldRenderSubmit(context) { let activeTypeMeetsCriteria = false switch (this.state.activeSubmissionType) { case 'media_recording': @@ -221,7 +222,8 @@ export default class SubmissionManager extends Component { this.props.submission.submissionDraft && activeTypeMeetsCriteria && !this.state.uploadingFiles && - !this.state.editingDraft + !this.state.editingDraft && + !context.nextButtonEnabled ) } @@ -387,7 +389,11 @@ export default class SubmissionManager extends Component { return ( <> {this.state.submittingAssignment ? : this.renderAttemptTab()} - {this.shouldRenderSubmit() && this.renderSubmitButton()} + + {context => { + return this.shouldRenderSubmit(context) ? this.renderSubmitButton() : null + }} + ) } diff --git a/app/jsx/assignments_2/student/components/__tests__/SubmissionManager.test.js b/app/jsx/assignments_2/student/components/__tests__/SubmissionManager.test.js index 08e06a57745..6143cf76aef 100644 --- a/app/jsx/assignments_2/student/components/__tests__/SubmissionManager.test.js +++ b/app/jsx/assignments_2/student/components/__tests__/SubmissionManager.test.js @@ -22,6 +22,7 @@ import {fireEvent, render} from '@testing-library/react' import {mockAssignmentAndSubmission, mockQuery} from '../../mocks' import {MockedProvider} from '@apollo/react-testing' import React from 'react' +import StudentViewContext from '../Context' import SubmissionManager from '../SubmissionManager' import {SubmissionMocks} from '../../graphqlData/Submission' @@ -79,6 +80,21 @@ describe('SubmissionManager', () => { expect(queryByText('Submit')).not.toBeInTheDocument() }) + it('does not render the submit button if we are not on the latest submission', async () => { + const props = await mockAssignmentAndSubmission({ + Submission: SubmissionMocks.onlineUploadReadyToSubmit + }) + const {queryByText} = render( + + + + + + ) + + expect(queryByText('Submit')).not.toBeInTheDocument() + }) + it('disables the submit button after it is pressed', async () => { const props = await mockAssignmentAndSubmission({ Submission: SubmissionMocks.onlineUploadReadyToSubmit