feat: refactor date visibility (#1298)

This commit is contained in:
Alison Langston
2024-02-22 15:25:37 -05:00
committed by GitHub
parent 6def66677a
commit ff7366d42a
3 changed files with 34 additions and 26 deletions

View File

@@ -70,23 +70,6 @@ const Course = ({
const SidebarProviderComponent = enableNewSidebar === 'true' ? NewSidebarProvider : SidebarProvider;
const chatValidDates = () => {
const date = new Date();
const utcDate = date.toISOString();
const enrollmentStartDate = course.enrollmentStart || utcDate;
const startDate = course.start || enrollmentStartDate;
const enrollmentEndDate = course.enrollmentEnd || utcDate;
const endDate = course.end || enrollmentEndDate;
return (
startDate <= enrollmentStartDate
&& enrollmentStartDate <= utcDate
&& utcDate <= enrollmentEndDate
&& enrollmentEndDate <= endDate
);
};
return (
<SidebarProviderComponent courseId={courseId} unitId={unitId}>
<Helmet>
@@ -109,7 +92,6 @@ const Course = ({
courseId={courseId}
contentToolsEnabled={course.showCalculator || course.notes.enabled}
unitId={unitId}
validDates={chatValidDates()}
/>
</>
)}

View File

@@ -5,6 +5,8 @@ import PropTypes from 'prop-types';
import { Xpert } from '@edx/frontend-lib-learning-assistant';
import { injectIntl } from '@edx/frontend-platform/i18n';
import { useModel } from '../../../generic/model-store';
const Chat = ({
enabled,
enrollmentMode,
@@ -12,11 +14,11 @@ const Chat = ({
courseId,
contentToolsEnabled,
unitId,
validDates,
}) => {
const {
activeAttempt, exam,
} = useSelector(state => state.specialExams);
const course = useModel('coursewareMeta', courseId);
const VERIFIED_MODES = [
'professional',
@@ -35,10 +37,27 @@ const Chat = ({
&& [...VERIFIED_MODES].some(mode => mode === enrollmentMode)
);
const validDates = () => {
const date = new Date();
const utcDate = date.toISOString();
const enrollmentStartDate = course.enrollmentStart || utcDate;
const startDate = course.start || enrollmentStartDate;
const enrollmentEndDate = course.enrollmentEnd || utcDate;
const endDate = course.end || enrollmentEndDate;
return (
startDate <= enrollmentStartDate
&& enrollmentStartDate <= utcDate
&& utcDate <= enrollmentEndDate
&& enrollmentEndDate <= endDate
);
};
const shouldDisplayChat = (
enabled
&& (hasVerifiedEnrollment || isStaff) // display only to verified learners or staff
&& validDates
&& validDates()
// it is necessary to check both whether the user is in an exam, and whether or not they are viewing an exam
// this will prevent the learner from interacting with the tool at any point of the exam flow, even at the
// entrance interstitial.
@@ -63,7 +82,6 @@ Chat.propTypes = {
courseId: PropTypes.string.isRequired,
contentToolsEnabled: PropTypes.bool.isRequired,
unitId: PropTypes.string.isRequired,
validDates: PropTypes.bool.isRequired,
};
Chat.defaultProps = {

View File

@@ -1,5 +1,6 @@
import { BrowserRouter } from 'react-router-dom';
import React from 'react';
import { Factory } from 'rosie';
import {
initializeMockApp,
@@ -72,7 +73,6 @@ describe('Chat', () => {
enabled
courseId={courseId}
contentToolsEnabled={false}
validDates
/>
</BrowserRouter>,
{ store },
@@ -100,7 +100,6 @@ describe('Chat', () => {
enabled
courseId={courseId}
contentToolsEnabled={false}
validDates
/>
</BrowserRouter>,
{ store },
@@ -156,7 +155,6 @@ describe('Chat', () => {
enabled={test.enabled}
courseId={courseId}
contentToolsEnabled={false}
validDates
/>
</BrowserRouter>,
{ store },
@@ -173,6 +171,18 @@ describe('Chat', () => {
});
it('if course end date has passed, component should not be visible', async () => {
store = await initializeTestStore({
specialExams: {
activeAttempt: {
attempt_id: 1,
},
},
courseMetadata: Factory.build('courseMetadata', {
start: '2014-02-03T05:00:00Z',
end: '2014-02-05T05:00:00Z',
}),
});
render(
<BrowserRouter>
<Chat
@@ -181,7 +191,6 @@ describe('Chat', () => {
enabled
courseId={courseId}
contentToolsEnabled={false}
validDates={false}
/>
</BrowserRouter>,
{ store },
@@ -208,7 +217,6 @@ describe('Chat', () => {
enabled
courseId={courseId}
contentToolsEnabled={false}
validDates
/>
</BrowserRouter>,
{ store },