forked from openedx/frontend-app-authoring
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
443 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Stack } from '@edx/paragon'; | ||
import { FormattedMessage, injectIntl, useIntl } from '@edx/frontend-platform/i18n'; | ||
import messages from './messages'; | ||
import { DatepickerControl, DATEPICKER_TYPES } from '../../generic/datepicker-control'; | ||
|
||
const BasicTab = ({ releaseDate, setReleaseDate }) => { | ||
const intl = useIntl(); | ||
const onChange = (value) => { | ||
setReleaseDate(value); | ||
}; | ||
|
||
return ( | ||
<> | ||
<h3 className="mt-3"><FormattedMessage {...messages.releaseDateAndTime} /></h3> | ||
<hr /> | ||
<Stack direction="horizontal" gap={5}> | ||
<DatepickerControl | ||
type={DATEPICKER_TYPES.date} | ||
value={releaseDate} | ||
label={intl.formatMessage(messages.releaseDate)} | ||
controlName="state-date" | ||
onChange={(date) => onChange(date)} | ||
/> | ||
<DatepickerControl | ||
type={DATEPICKER_TYPES.time} | ||
value={releaseDate} | ||
label={intl.formatMessage(messages.releaseTimeUTC)} | ||
controlName="start-time" | ||
onChange={(date) => onChange(date)} | ||
/> | ||
</Stack> | ||
</> | ||
); | ||
}; | ||
|
||
BasicTab.propTypes = { | ||
releaseDate: PropTypes.string.isRequired, | ||
setReleaseDate: PropTypes.func.isRequired, | ||
}; | ||
|
||
export default injectIntl(BasicTab); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* eslint-disable import/named */ | ||
import React, { useEffect, useState } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { useIntl } from '@edx/frontend-platform/i18n'; | ||
import { | ||
ModalDialog, | ||
Button, | ||
ActionRow, | ||
Tab, | ||
Tabs, | ||
} from '@edx/paragon'; | ||
import { useSelector } from 'react-redux'; | ||
|
||
import { VisibilityTypes } from '../../data/constants'; | ||
import { getCurrentSection } from '../data/selectors'; | ||
import messages from './messages'; | ||
import BasicTab from './BasicTab'; | ||
import VisibilityTab from './VisibilityTab'; | ||
|
||
const ConfigureModal = ({ | ||
isOpen, | ||
onClose, | ||
onConfigureSubmit, | ||
}) => { | ||
const intl = useIntl(); | ||
const { displayName, start: sectionStartDate, visibilityState } = useSelector(getCurrentSection); | ||
const [releaseDate, setReleaseDate] = useState(sectionStartDate); | ||
const [isVisibleToStaffOnly, setIsVisibleToStaffOnly] = useState(visibilityState === VisibilityTypes.STAFF_ONLY); | ||
const [saveButtonDisabled, setSaveButtonDisabled] = useState(true); | ||
|
||
useEffect(() => { | ||
setReleaseDate(sectionStartDate); | ||
}, [sectionStartDate]); | ||
|
||
useEffect(() => { | ||
setIsVisibleToStaffOnly(visibilityState === VisibilityTypes.STAFF_ONLY); | ||
}, [visibilityState]); | ||
|
||
useEffect(() => { | ||
const visibilityUnchanged = isVisibleToStaffOnly === (visibilityState === VisibilityTypes.STAFF_ONLY); | ||
setSaveButtonDisabled(visibilityUnchanged && releaseDate === sectionStartDate); | ||
}, [releaseDate, isVisibleToStaffOnly]); | ||
|
||
const handleSave = () => { | ||
onConfigureSubmit(isVisibleToStaffOnly, releaseDate); | ||
}; | ||
|
||
return ( | ||
<ModalDialog | ||
className="configure-modal" | ||
isOpen={isOpen} | ||
onClose={onClose} | ||
hasCloseButton | ||
isFullscreenOnMobile | ||
> | ||
<ModalDialog.Header className="configure-modal__header"> | ||
<ModalDialog.Title> | ||
{intl.formatMessage(messages.title, { title: displayName })} | ||
</ModalDialog.Title> | ||
</ModalDialog.Header> | ||
<ModalDialog.Body className="configure-modal__body"> | ||
<Tabs> | ||
<Tab eventKey="basic" title={intl.formatMessage(messages.basicTabTitle)}> | ||
<BasicTab releaseDate={releaseDate} setReleaseDate={setReleaseDate} /> | ||
</Tab> | ||
<Tab eventKey="visibility" title={intl.formatMessage(messages.visibilityTabTitle)}> | ||
<VisibilityTab | ||
isVisibleToStaffOnly={isVisibleToStaffOnly} | ||
setIsVisibleToStaffOnly={setIsVisibleToStaffOnly} | ||
showWarning={visibilityState === VisibilityTypes.STAFF_ONLY} | ||
/> | ||
</Tab> | ||
</Tabs> | ||
</ModalDialog.Body> | ||
<ModalDialog.Footer className="pt-1"> | ||
<ActionRow> | ||
<ModalDialog.CloseButton variant="tertiary"> | ||
{intl.formatMessage(messages.cancelButton)} | ||
</ModalDialog.CloseButton> | ||
<Button onClick={handleSave} disabled={saveButtonDisabled}> | ||
{intl.formatMessage(messages.saveButton)} | ||
</Button> | ||
</ActionRow> | ||
</ModalDialog.Footer> | ||
</ModalDialog> | ||
); | ||
}; | ||
|
||
ConfigureModal.propTypes = { | ||
isOpen: PropTypes.bool.isRequired, | ||
onClose: PropTypes.func.isRequired, | ||
onConfigureSubmit: PropTypes.func.isRequired, | ||
}; | ||
|
||
export default ConfigureModal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.configure-modal { | ||
max-width: 33.6875rem; | ||
overflow: visible; | ||
|
||
.configure-modal__header { | ||
padding-top: 1.5rem; | ||
} | ||
|
||
.configure-modal__body { | ||
overflow: visible; | ||
} | ||
} |
131 changes: 131 additions & 0 deletions
131
src/course-outline/configure-modal/ConfigureModal.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
import React from 'react'; | ||
import { render, fireEvent } from '@testing-library/react'; | ||
import { IntlProvider } from '@edx/frontend-platform/i18n'; | ||
import { useSelector } from 'react-redux'; | ||
import { initializeMockApp } from '@edx/frontend-platform'; | ||
import MockAdapter from 'axios-mock-adapter'; | ||
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth'; | ||
import { AppProvider } from '@edx/frontend-platform/react'; | ||
|
||
import initializeStore from '../../store'; | ||
import ConfigureModal from './ConfigureModal'; | ||
import messages from './messages'; | ||
|
||
// eslint-disable-next-line no-unused-vars | ||
let axiosMock; | ||
let store; | ||
const mockPathname = '/foo-bar'; | ||
|
||
jest.mock('react-redux', () => ({ | ||
...jest.requireActual('react-redux'), | ||
useSelector: jest.fn(), | ||
})); | ||
|
||
jest.mock('react-router-dom', () => ({ | ||
...jest.requireActual('react-router-dom'), | ||
useLocation: () => ({ | ||
pathname: mockPathname, | ||
}), | ||
})); | ||
|
||
const currentSectionMock = { | ||
displayName: 'Section1', | ||
childInfo: { | ||
displayName: 'Subsection', | ||
children: [ | ||
{ | ||
displayName: 'Subsection 1', | ||
id: 1, | ||
childInfo: { | ||
displayName: 'Unit', | ||
children: [ | ||
{ | ||
id: 11, | ||
displayName: 'Subsection_1 Unit 1', | ||
}, | ||
], | ||
}, | ||
}, | ||
{ | ||
displayName: 'Subsection 2', | ||
id: 2, | ||
childInfo: { | ||
displayName: 'Unit', | ||
children: [ | ||
{ | ||
id: 21, | ||
displayName: 'Subsection_2 Unit 1', | ||
}, | ||
], | ||
}, | ||
}, | ||
{ | ||
displayName: 'Subsection 3', | ||
id: 3, | ||
childInfo: { | ||
children: [], | ||
}, | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
const onCloseMock = jest.fn(); | ||
const onConfigureSubmitMock = jest.fn(); | ||
|
||
const renderComponent = () => render( | ||
<AppProvider store={store}> | ||
<IntlProvider locale="en"> | ||
<ConfigureModal | ||
isOpen | ||
onClose={onCloseMock} | ||
onConfigureSubmit={onConfigureSubmitMock} | ||
/> | ||
</IntlProvider>, | ||
</AppProvider>, | ||
); | ||
|
||
describe('<ConfigureModal />', () => { | ||
beforeEach(() => { | ||
initializeMockApp({ | ||
authenticatedUser: { | ||
userId: 3, | ||
username: 'abc123', | ||
administrator: true, | ||
roles: [], | ||
}, | ||
}); | ||
|
||
store = initializeStore(); | ||
axiosMock = new MockAdapter(getAuthenticatedHttpClient()); | ||
useSelector.mockReturnValue(currentSectionMock); | ||
}); | ||
|
||
it('renders ConfigureModal component correctly', () => { | ||
const { getByText, getByRole } = renderComponent(); | ||
expect(getByText(`${currentSectionMock.displayName} Settings`)).toBeInTheDocument(); | ||
expect(getByText(messages.basicTabTitle.defaultMessage)).toBeInTheDocument(); | ||
expect(getByText(messages.visibilityTabTitle.defaultMessage)).toBeInTheDocument(); | ||
expect(getByText(messages.releaseDate.defaultMessage)).toBeInTheDocument(); | ||
expect(getByText(messages.releaseTimeUTC.defaultMessage)).toBeInTheDocument(); | ||
expect(getByRole('button', { name: messages.cancelButton.defaultMessage })).toBeInTheDocument(); | ||
expect(getByRole('button', { name: messages.saveButton.defaultMessage })).toBeInTheDocument(); | ||
}); | ||
|
||
it('switches to the Visibility tab and renders correctly', () => { | ||
const { getByRole, getByText } = renderComponent(); | ||
|
||
const visibilityTab = getByRole('tab', { name: messages.visibilityTabTitle.defaultMessage }); | ||
fireEvent.click(visibilityTab); | ||
expect(getByText(messages.sectionVisibility.defaultMessage)).toBeInTheDocument(); | ||
expect(getByText(messages.hideFromLearners.defaultMessage)).toBeInTheDocument(); | ||
}); | ||
|
||
it('calls the onClose function when the cancel button is clicked', () => { | ||
const { getByRole } = renderComponent(); | ||
|
||
const cancelButton = getByRole('button', { name: messages.cancelButton.defaultMessage }); | ||
fireEvent.click(cancelButton); | ||
expect(onCloseMock).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
Oops, something went wrong.