Skip to content

Commit

Permalink
feat: support for content gating (#41)
Browse files Browse the repository at this point in the history
* feat: support content gating

* fix: minor HTML validation issues
  • Loading branch information
zacharis278 authored Aug 31, 2021
1 parent c15296d commit d2d6bbf
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 7 deletions.
7 changes: 5 additions & 2 deletions src/exam/Exam.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import { ExamStatus, ExamType } from '../constants';
* @returns {JSX.Element}
* @constructor
*/
const Exam = ({ isTimeLimited, originalUserIsStaff, children }) => {
const Exam = ({
isGated, isTimeLimited, originalUserIsStaff, children,
}) => {
const state = useContext(ExamStateContext);
const {
isLoading, activeAttempt, showTimer, stopExam, exam,
Expand Down Expand Up @@ -93,7 +95,7 @@ const Exam = ({ isTimeLimited, originalUserIsStaff, children }) => {
/>
)}
{apiErrorMsg && <ExamAPIError />}
{isTimeLimited && !originalUserIsStaff
{isTimeLimited && !originalUserIsStaff && !isGated
? <Instructions>{sequenceContent}</Instructions>
: sequenceContent}
</div>
Expand All @@ -102,6 +104,7 @@ const Exam = ({ isTimeLimited, originalUserIsStaff, children }) => {

Exam.propTypes = {
isTimeLimited: PropTypes.bool.isRequired,
isGated: PropTypes.bool.isRequired,
originalUserIsStaff: PropTypes.bool.isRequired,
children: PropTypes.element.isRequired,
};
Expand Down
7 changes: 6 additions & 1 deletion src/exam/ExamWrapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const ExamWrapper = ({ children, ...props }) => {
await getAllowProctoringOptOut(sequence.allowProctoringOptOut);
};

const isGated = sequence && sequence.gatedContent !== undefined && sequence.gatedContent.gated;

// 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
Expand All @@ -34,7 +36,7 @@ const ExamWrapper = ({ children, ...props }) => {
}, []);

return (
<Exam isTimeLimited={sequence.isTimeLimited} originalUserIsStaff={originalUserIsStaff}>
<Exam isGated={isGated} isTimeLimited={sequence.isTimeLimited} originalUserIsStaff={originalUserIsStaff}>
{children}
</Exam>
);
Expand All @@ -45,6 +47,9 @@ ExamWrapper.propTypes = {
id: PropTypes.string.isRequired,
isTimeLimited: PropTypes.bool,
allowProctoringOptOut: PropTypes.bool,
gatedContent: PropTypes.shape({
gated: PropTypes.bool,
}),
}).isRequired,
courseId: PropTypes.string.isRequired,
children: PropTypes.element.isRequired,
Expand Down
22 changes: 22 additions & 0 deletions src/exam/ExamWrapper.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,28 @@ describe('SequenceExamWrapper', () => {
expect(queryByTestId('masquerade-alert')).toBeInTheDocument();
});

it('allows default content rendering for gated sections even for exams', () => {
sequence.gatedContent = {
gated: true,
};
store.getState = () => ({
examState: Factory.build('examState', {
exam: Factory.build('exam', {
type: ExamType.PROCTORED,
}),
}),
});
const { queryByTestId } = render(
<ExamStateProvider>
<SequenceExamWrapper sequence={sequence} courseId={courseId}>
<div data-testid="sequence-content">children</div>
</SequenceExamWrapper>
</ExamStateProvider>,
{ store },
);
expect(queryByTestId('sequence-content')).toHaveTextContent('children');
});

it('does not display masquerade alert if specified learner is in the middle of the exam', () => {
store.getState = () => ({
examState: Factory.build('examState', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ const DefaultInstructions = ({ code }) => (
defaultMessage="Step 1."
/>
</div>
<p>
<div>
<ExamCode code={code} />
</p>
</div>
<p>
<FormattedMessage
id="exam.DefaultDownloadSoftwareProctoredExamInstructions.step1.body"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const DownloadSoftwareProctoredExamInstructions = ({ intl, skipProctoredExam })
downloadClicked={downloadClicked}
/>
{!withProviderInstructions && (
<p className="pt-3">
<div className="pt-3">
<div className="h4">
<FormattedMessage
id="exam.DefaultDownloadSoftwareProctoredExamInstructions.step3.title"
Expand All @@ -120,7 +120,7 @@ const DownloadSoftwareProctoredExamInstructions = ({ intl, skipProctoredExam })
+ 'direct you to the RPNow proctoring experience.'}
/>
</p>
</p>
</div>
)}
</Container>
{allowProctoringOptOut && <SkipProctoredExamButton handleClick={skipProctoredExam} />}
Expand Down

0 comments on commit d2d6bbf

Please sign in to comment.