diff --git a/plugins/course-apps/teams/GroupEditor.jsx b/plugins/course-apps/teams/GroupEditor.jsx index 78e01b7c3..0e96d6ad6 100644 --- a/plugins/course-apps/teams/GroupEditor.jsx +++ b/plugins/course-apps/teams/GroupEditor.jsx @@ -7,6 +7,7 @@ import { GroupTypes, TeamSizes } from 'CourseAuthoring/data/constants'; import CollapsableEditor from 'CourseAuthoring/generic/CollapsableEditor'; import FormikControl from 'CourseAuthoring/generic/FormikControl'; import messages from './messages'; +import { isGroupTypeEnabled } from './utils'; // Maps a team type to its corresponding intl message const TeamTypeNameMessage = { @@ -109,7 +110,7 @@ const GroupEditor = ({ onChange={onChange} onBlur={onBlur} > - {Object.values(GroupTypes).map(groupType => ( + {Object.values(GroupTypes).map(groupType => isGroupTypeEnabled(groupType) && ( ({ + ...jest.requireActual('formik'), + useFormikContext: jest.fn(), +})); + +describe('GroupEditor', () => { + const mockIntl = { formatMessage: jest.fn() }; + + const mockGroup = { + id: '1', + name: 'Test Group', + description: 'Test Group Description', + type: 'open', + maxTeamSize: 5, + }; + + const mockProps = { + intl: mockIntl, + fieldNameCommonBase: 'test', + group: mockGroup, + onDelete: jest.fn(), + onChange: jest.fn(), + onBlur: jest.fn(), + errors: {}, + }; + + const renderComponent = (overrideProps = {}) => render( + + + , + ); + + beforeEach(() => { + useFormikContext.mockReturnValue({ + touched: {}, + errors: {}, + handleChange: jest.fn(), + handleBlur: jest.fn(), + setFieldError: jest.fn(), + }); + + jest.clearAllMocks(); + }); + + test('renders without errors', () => { + renderComponent(); + }); + + test('renders the group name and description', () => { + const { getByText } = renderComponent(); + expect(getByText('Test Group')).toBeInTheDocument(); + expect(getByText('Test Group Description')).toBeInTheDocument(); + }); + + describe('group types messages', () => { + test('group type open message', () => { + const { getByLabelText, getByText } = renderComponent(); + const expandButton = getByLabelText('Expand group editor'); + expect(expandButton).toBeInTheDocument(); + fireEvent.click(expandButton); + expect(getByText(messages.groupTypeOpenDescription.defaultMessage)).toBeInTheDocument(); + }); + + test('group type public_managed message', () => { + const publicManagedGroupMock = { + id: '2', + name: 'Test Group', + description: 'Test Group Description', + type: 'public_managed', + maxTeamSize: 5, + }; + const { getByLabelText, getByText } = renderComponent({ group: publicManagedGroupMock }); + const expandButton = getByLabelText('Expand group editor'); + expect(expandButton).toBeInTheDocument(); + fireEvent.click(expandButton); + expect(getByText(messages.groupTypePublicManagedDescription.defaultMessage)).toBeInTheDocument(); + }); + + test('group type private_managed message', () => { + const privateManagedGroupMock = { + id: '3', + name: 'Test Group', + description: 'Test Group Description', + type: 'private_managed', + maxTeamSize: 5, + }; + const { getByLabelText, getByText } = renderComponent({ group: privateManagedGroupMock }); + const expandButton = getByLabelText('Expand group editor'); + expect(expandButton).toBeInTheDocument(); + fireEvent.click(expandButton); + expect(getByText(messages.groupTypePrivateManagedDescription.defaultMessage)).toBeInTheDocument(); + }); + }); +}); diff --git a/plugins/course-apps/teams/utils.js b/plugins/course-apps/teams/utils.js new file mode 100644 index 000000000..32e9ce3da --- /dev/null +++ b/plugins/course-apps/teams/utils.js @@ -0,0 +1,23 @@ +/* eslint-disable import/prefer-default-export */ +import { getConfig } from '@edx/frontend-platform'; + +import { GroupTypes } from '../../data/constants'; + +/** + * Check if a group type is enabled by the current configuration. + * This is a temporary workaround to disable the OPEN MANAGED team type until it is fully adopted. + * For more information, see: https://openedx.atlassian.net/wiki/spaces/COMM/pages/3885760525/Open+Managed+Group+Type + * @param {string} groupType - the group type to check + * @returns {boolean} - true if the group type is enabled + */ +export const isGroupTypeEnabled = (groupType) => { + const enabledTypesByDefault = [ + GroupTypes.OPEN, + GroupTypes.PUBLIC_MANAGED, + GroupTypes.PRIVATE_MANAGED, + ]; + const enabledTypesByConfig = { + [GroupTypes.OPEN_MANAGED]: getConfig().ENABLE_OPEN_MANAGED_TEAM_TYPE, + }; + return enabledTypesByDefault.includes(groupType) || enabledTypesByConfig[groupType] || false; +}; diff --git a/plugins/course-apps/teams/utils.test.js b/plugins/course-apps/teams/utils.test.js new file mode 100644 index 000000000..20f29a53e --- /dev/null +++ b/plugins/course-apps/teams/utils.test.js @@ -0,0 +1,39 @@ +import { getConfig } from '@edx/frontend-platform'; +import { GroupTypes } from '../../data/constants'; +import { isGroupTypeEnabled } from './utils'; + +jest.mock('@edx/frontend-platform', () => ({ getConfig: jest.fn() })); + +describe('teams utils', () => { + describe('isGroupTypeEnabled', () => { + beforeEach(() => { + jest.clearAllMocks(); + }); + + test('returns true if the group type is enabled', () => { + getConfig.mockReturnValue({ ENABLE_OPEN_MANAGED_TEAM_TYPE: false }); + expect(isGroupTypeEnabled(GroupTypes.OPEN)).toBe(true); + expect(isGroupTypeEnabled(GroupTypes.PUBLIC_MANAGED)).toBe(true); + expect(isGroupTypeEnabled(GroupTypes.PRIVATE_MANAGED)).toBe(true); + }); + test('returns false if the OPEN_MANAGED group is not enabled', () => { + getConfig.mockReturnValue({ ENABLE_OPEN_MANAGED_TEAM_TYPE: false }); + expect(isGroupTypeEnabled(GroupTypes.OPEN_MANAGED)).toBe(false); + }); + + test('returns true if the OPEN_MANAGED group is enabled', () => { + getConfig.mockReturnValue({ ENABLE_OPEN_MANAGED_TEAM_TYPE: true }); + expect(isGroupTypeEnabled(GroupTypes.OPEN_MANAGED)).toBe(true); + }); + + test('returns false if the group is invalid', () => { + getConfig.mockReturnValue({ ENABLE_OPEN_MANAGED_TEAM_TYPE: true }); + expect(isGroupTypeEnabled('')).toBe(false); + }); + + test('returns false if the group is null', () => { + getConfig.mockReturnValue({ ENABLE_OPEN_MANAGED_TEAM_TYPE: true }); + expect(isGroupTypeEnabled(null)).toBe(false); + }); + }); +}); diff --git a/src/index.jsx b/src/index.jsx index 57db4eb38..725cdea0b 100755 --- a/src/index.jsx +++ b/src/index.jsx @@ -112,6 +112,7 @@ initialize({ CALCULATOR_HELP_URL: process.env.CALCULATOR_HELP_URL || null, ENABLE_PROGRESS_GRAPH_SETTINGS: process.env.ENABLE_PROGRESS_GRAPH_SETTINGS || 'false', ENABLE_TEAM_TYPE_SETTING: process.env.ENABLE_TEAM_TYPE_SETTING === 'true', + ENABLE_OPEN_MANAGED_TEAM_TYPE: process.env.ENABLE_OPEN_MANAGED_TEAM_TYPE === 'true', BBB_LEARN_MORE_URL: process.env.BBB_LEARN_MORE_URL || '', STUDIO_BASE_URL: process.env.STUDIO_BASE_URL || null, STUDIO_SHORT_NAME: process.env.STUDIO_SHORT_NAME || null,