forked from openedx/frontend-app-communications
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: send emails by teams pluggable
- Loading branch information
Showing
15 changed files
with
755 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,56 @@ | ||
import PropTypes from 'prop-types'; | ||
import { Form } from '@edx/paragon'; | ||
import { FormattedMessage } from '@edx/frontend-platform/i18n'; | ||
|
||
import './ListTeams.scss'; | ||
|
||
const recipientsTeamFormDescription = 'A selectable choice from a list of potential email team recipients'; | ||
|
||
const ListTeams = ({ teams, onChangeCheckBox, teamsSelected }) => ( | ||
<div className="flex-wrap flex-row w-100"> | ||
{teams.map(({ id, name }) => ( | ||
<Form.Checkbox | ||
key={`team:${name}_${id}`} | ||
value={id} | ||
className="mr-2 team-checkbox" | ||
data-testid={`team:${id}`} | ||
onChange={onChangeCheckBox} | ||
checked={teamsSelected.includes(id)} | ||
> | ||
<FormattedMessage | ||
id={`bulk.email.form.recipients.teams.${name}`} | ||
defaultMessage={name} | ||
description={recipientsTeamFormDescription} | ||
/> | ||
</Form.Checkbox> | ||
))} | ||
</div> | ||
); | ||
|
||
ListTeams.defaultProps = { | ||
onChangeCheckBox: () => {}, | ||
teamsSelected: [], | ||
}; | ||
|
||
ListTeams.propTypes = { | ||
onChangeCheckBox: PropTypes.func, | ||
teamsSelected: PropTypes.arrayOf(PropTypes.string), | ||
teams: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
id: PropTypes.string.isRequired, | ||
discussionTopicId: PropTypes.string.isRequired, | ||
name: PropTypes.string.isRequired, | ||
courseId: PropTypes.string.isRequired, | ||
topicId: PropTypes.string.isRequired, | ||
dateCreated: PropTypes.string.isRequired, | ||
description: PropTypes.string.isRequired, | ||
country: PropTypes.string.isRequired, | ||
language: PropTypes.string.isRequired, | ||
lastActivityAt: PropTypes.string.isRequired, | ||
membership: PropTypes.arrayOf(PropTypes.shape()), | ||
organizationProtected: PropTypes.bool.isRequired, | ||
}), | ||
).isRequired, | ||
}; | ||
|
||
export default ListTeams; |
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,7 @@ | ||
.team-checkbox { | ||
label { | ||
overflow-wrap: break-word; | ||
display: block !important; | ||
max-width: 300px; | ||
} | ||
} |
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,85 @@ | ||
import React from 'react'; | ||
import { render, fireEvent } from '@testing-library/react'; | ||
import { IntlProvider } from 'react-intl'; | ||
|
||
import ListTeams from './ListTeams'; | ||
|
||
describe('ListTeams component', () => { | ||
// eslint-disable-next-line no-unused-vars, react/prop-types | ||
const IntlProviderWrapper = ({ children }) => ( | ||
<IntlProvider locale="en" messages={{}}> | ||
{children} | ||
</IntlProvider> | ||
); | ||
const teamsData = [ | ||
{ | ||
id: '1', | ||
discussionTopicId: 'topic1', | ||
name: 'Team 1', | ||
courseId: 'course1', | ||
topicId: 'topic1', | ||
dateCreated: '2024-01-02T23:21:16.321434Z', | ||
description: 'Description 1', | ||
country: '', | ||
language: '', | ||
lastActivityAt: '2024-01-02T23:20:13Z', | ||
membership: [], | ||
organizationProtected: false, | ||
}, | ||
]; | ||
|
||
test('renders checkboxes for each team', () => { | ||
const { getAllByTestId } = render( | ||
<IntlProviderWrapper> | ||
<ListTeams teams={teamsData} /> | ||
</IntlProviderWrapper>, | ||
); | ||
const teamCheckboxes = getAllByTestId(/team:/i); | ||
expect(teamCheckboxes).toHaveLength(teamsData.length); | ||
}); | ||
|
||
test('displays team names in checkboxes', () => { | ||
const { getByText } = render( | ||
<IntlProviderWrapper> | ||
<ListTeams teams={teamsData} /> | ||
</IntlProviderWrapper>, | ||
); | ||
teamsData.forEach(({ name }) => { | ||
const teamNameElement = getByText(name); | ||
expect(teamNameElement).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
test('renders no checkboxes when teams array is empty', () => { | ||
const { queryByTestId } = render(<ListTeams teams={[]} />); | ||
const teamCheckboxes = queryByTestId(/team:/i); | ||
expect(teamCheckboxes).toBeNull(); | ||
}); | ||
|
||
test('calls onChangeCheckBox function when a checkbox is clicked', () => { | ||
const onChangeMock = jest.fn(); | ||
const { getByTestId } = render( | ||
<IntlProviderWrapper> | ||
<ListTeams teams={teamsData} onChangeCheckBox={onChangeMock} /> | ||
</IntlProviderWrapper>, | ||
); | ||
|
||
const checkbox = getByTestId('team:1'); | ||
fireEvent.click(checkbox); | ||
|
||
expect(onChangeMock).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
test('renders checkboxes with checked status for selected teams', () => { | ||
const selectedTeams = ['1']; | ||
const { getByTestId } = render( | ||
<IntlProviderWrapper> | ||
<ListTeams teams={teamsData} teamsSelected={selectedTeams} /> | ||
</IntlProviderWrapper>, | ||
); | ||
|
||
const checkbox = getByTestId('team:1'); | ||
expect(checkbox).toBeInTheDocument(); | ||
expect(checkbox).toBeChecked(); | ||
}); | ||
}); |
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,14 @@ | ||
import { getConfig } from '@edx/frontend-platform'; | ||
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth'; | ||
|
||
export async function getTeamsList(courseId, page = 1, pageSize = 100) { | ||
const endpointUrl = `${ | ||
getConfig().LMS_BASE_URL | ||
}/platform-plugin-teams/${courseId}/api/topics/?page=${page}&pageSize=${pageSize}`; | ||
try { | ||
const response = await getAuthenticatedHttpClient().get(endpointUrl); | ||
return response; | ||
} catch (error) { | ||
throw new Error(error); | ||
} | ||
} |
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,52 @@ | ||
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth'; | ||
import { getConfig } from '@edx/frontend-platform'; | ||
|
||
import { getTeamsList } from './api'; | ||
|
||
jest.mock('@edx/frontend-platform/auth', () => ({ | ||
getAuthenticatedHttpClient: jest.fn(), | ||
})); | ||
jest.mock('@edx/frontend-platform', () => ({ | ||
getConfig: jest.fn(), | ||
})); | ||
|
||
describe('getTeamsList function', () => { | ||
const mockCourseId = 'course123'; | ||
const mockResponseData = { data: 'someData' }; | ||
const mockConfig = { LMS_BASE_URL: 'http://localhost' }; | ||
|
||
beforeEach(() => { | ||
getConfig.mockReturnValue(mockConfig); | ||
getAuthenticatedHttpClient.mockReturnValue({ | ||
get: jest.fn().mockResolvedValue(mockResponseData), | ||
}); | ||
}); | ||
|
||
test('successfully fetches teams list with default parameters', async () => { | ||
const response = await getTeamsList(mockCourseId); | ||
|
||
expect(response).toEqual(mockResponseData); | ||
expect(getAuthenticatedHttpClient().get).toHaveBeenCalledWith( | ||
`http://localhost/platform-plugin-teams/${mockCourseId}/api/topics/?page=1&pageSize=100`, | ||
); | ||
}); | ||
|
||
test('successfully fetches teams list with custom page and pageSize', async () => { | ||
const customPage = 2; | ||
const customPageSize = 50; | ||
|
||
const response = await getTeamsList(mockCourseId, customPage, customPageSize); | ||
|
||
expect(response).toEqual(mockResponseData); | ||
expect(getAuthenticatedHttpClient().get).toHaveBeenCalledWith( | ||
`http://localhost/platform-plugin-teams/${mockCourseId}/api/topics/?page=${customPage}&pageSize=${customPageSize}`, | ||
); | ||
}); | ||
|
||
test('handles an error', async () => { | ||
const errorMessage = 'Network error'; | ||
getAuthenticatedHttpClient().get.mockRejectedValue(new Error(errorMessage)); | ||
|
||
await expect(getTeamsList(mockCourseId)).rejects.toThrow(errorMessage); | ||
}); | ||
}); |
Oops, something went wrong.