+ {intl.formatMessage(get( + messages, + `profile.learningGoal.options.${learningGoal}`, + messages['profile.learningGoal.options.something_else'], + ))} +
+ > + ), + static: ( + <> ++ {intl.formatMessage(get( + messages, + `profile.learningGoal.options.${learningGoal}`, + messages['profile.learningGoal.options.something_else'], + ))} +
+ > + ), + }} + /> + ); +}; + +LearningGoal.propTypes = { + // From Selector + learningGoal: PropTypes.oneOf(['advance_career', 'start_career', 'learn_something_new', 'something_else']), + visibilityLearningGoal: PropTypes.oneOf(['private', 'all_users']), + editMode: PropTypes.oneOf(['editable', 'static']), + + // i18n + intl: intlShape.isRequired, +}; + +LearningGoal.defaultProps = { + editMode: 'static', + learningGoal: null, + visibilityLearningGoal: 'private', +}; + +export default connect( + editableFormSelector, + {}, +)(injectIntl(LearningGoal)); diff --git a/src/profile/forms/LearningGoal.messages.jsx b/src/profile/forms/LearningGoal.messages.jsx new file mode 100644 index 0000000..181fbb3 --- /dev/null +++ b/src/profile/forms/LearningGoal.messages.jsx @@ -0,0 +1,31 @@ +import { defineMessages } from '@edx/frontend-platform/i18n'; + +const messages = defineMessages({ + 'profile.learningGoal.learningGoal': { + id: 'profile.learningGoal.learningGoal', + defaultMessage: 'Learning Goal', + description: 'A section of a user profile that displays their current learning goal.', + }, + 'profile.learningGoal.options.start_career': { + id: 'profile.learningGoal.options.start_career', + defaultMessage: 'I want to start my career', + description: 'Selected by user if their goal is to start their career.', + }, + 'profile.learningGoal.options.advance_career': { + id: 'profile.learningGoal.options.advance_career', + defaultMessage: 'I want to advance my career', + description: 'Selected by user if their goal is to advance their career.', + }, + 'profile.learningGoal.options.learn_something_new': { + id: 'profile.learningGoal.options.learn_something_new', + defaultMessage: 'I want to learn something new', + description: 'Selected by user if their goal is to learn something new.', + }, + 'profile.learningGoal.options.something_else': { + id: 'profile.learningGoal.options.something_else', + defaultMessage: 'Something else', + description: 'Selected by user if their goal is not described by the other choices.', + }, +}); + +export default messages; diff --git a/src/profile/forms/LearningGoal.test.jsx b/src/profile/forms/LearningGoal.test.jsx new file mode 100644 index 0000000..1143aff --- /dev/null +++ b/src/profile/forms/LearningGoal.test.jsx @@ -0,0 +1,122 @@ +import PropTypes from 'prop-types'; +import React, { useMemo } from 'react'; +import { Provider } from 'react-redux'; +import renderer from 'react-test-renderer'; +import configureMockStore from 'redux-mock-store'; +import thunk from 'redux-thunk'; +import { configure as configureI18n, IntlProvider } from '@edx/frontend-platform/i18n'; +import { getConfig } from '@edx/frontend-platform'; +import { AppContext } from '@edx/frontend-platform/react'; +import messages from '../../i18n'; + +import viewOwnProfileMockStore from '../__mocks__/viewOwnProfile.mockStore'; +import savingEditedBioMockStore from '../__mocks__/savingEditedBio.mockStore'; + +import LearningGoal from './LearningGoal'; + +const mockStore = configureMockStore([thunk]); + +// props to be passed down to LearningGoal component +const requiredLearningGoalProps = { + formId: 'learningGoal', + learningGoal: 'advance_career', + drafts: {}, + visibilityLearningGoal: 'private', + editMode: 'static', + saveState: null, + error: null, + openHandler: jest.fn(), +}; + +configureI18n({ + loggingService: { logError: jest.fn() }, + config: { + ENVIRONMENT: 'production', + LANGUAGE_PREFERENCE_COOKIE_NAME: 'yum', + }, + messages, +}); + +const LearningGoalWrapper = (props) => { + const contextValue = useMemo(() => ({ + authenticatedUser: { userId: null, username: null, administrator: false }, + config: getConfig(), + }), []); + return ( +