From 4cb25ea923f5fdd6e802a3875aafdea9062df033 Mon Sep 17 00:00:00 2001 From: Zachary Hancock Date: Wed, 4 Aug 2021 09:54:32 -0400 Subject: [PATCH] feat: allow staff users to bypass exam interstitials (#39) --- src/exam/ExamWrapper.jsx | 10 ++++++++-- src/exam/ExamWrapper.test.jsx | 21 ++++++++++++++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/exam/ExamWrapper.jsx b/src/exam/ExamWrapper.jsx index 1bd7c391..2e5f4133 100644 --- a/src/exam/ExamWrapper.jsx +++ b/src/exam/ExamWrapper.jsx @@ -10,7 +10,7 @@ import ExamStateContext from '../context'; const ExamWrapper = ({ children, ...props }) => { const state = useContext(ExamStateContext); const { authenticatedUser } = useContext(AppContext); - const { sequence, courseId } = props; + const { sequence, courseId, isStaff } = props; const { getExamAttemptsData, getAllowProctoringOptOut } = state; const loadInitialData = async () => { await getExamAttemptsData(courseId, sequence.id); @@ -18,8 +18,9 @@ const ExamWrapper = ({ children, ...props }) => { }; // if the user is browsing public content (not logged in) they cannot be in an exam + // if the user is staff they may view exam content without an exam attempt // any requests for exam state will 403 so just short circuit this component here - if (!authenticatedUser) { + if (!authenticatedUser || isStaff) { return children; } @@ -42,6 +43,11 @@ ExamWrapper.propTypes = { }).isRequired, courseId: PropTypes.string.isRequired, children: PropTypes.element.isRequired, + isStaff: PropTypes.bool, +}; + +ExamWrapper.defaultProps = { + isStaff: false, }; export default ExamWrapper; diff --git a/src/exam/ExamWrapper.test.jsx b/src/exam/ExamWrapper.test.jsx index 317c256d..fe26f1fa 100644 --- a/src/exam/ExamWrapper.test.jsx +++ b/src/exam/ExamWrapper.test.jsx @@ -24,7 +24,7 @@ describe('SequenceExamWrapper', () => { }; const courseId = 'course-v1:test+test+test'; - it('is successfully rendered and shows instructions', () => { + it('is successfully rendered and shows instructions if the user is not staff', () => { store.getState = () => ({ examState: Factory.build('examState'), }); @@ -121,4 +121,23 @@ describe('SequenceExamWrapper', () => { ); expect(getByTestId('sequence-content')).toHaveTextContent('children'); }); + + it('renders exam content without an active attempt if the user is staff', () => { + store.getState = () => ({ + examState: Factory.build('examState', { + exam: Factory.build('exam', { + type: ExamType.PROCTORED, + }), + }), + }); + const { queryByTestId } = render( + + +
children
+
+
, + { store }, + ); + expect(queryByTestId('sequence-content')).toHaveTextContent('children'); + }); });