-
Notifications
You must be signed in to change notification settings - Fork 127
refactor: replaced injectIntl with useIntl #1239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
brian-smith-tcril
merged 8 commits into
openedx:master
from
Simoblaster:refactor/use-intl-hook
Aug 18, 2025
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2610def
refactor: replaced injectIntl with useIntl
Simoblaster c01b9af
test: update tests for useIntl hook implementation
Simoblaster 99b2133
fix: add missing trailing comma
Simoblaster 1cfc047
Merge branch 'master' into refactor/use-intl-hook
Simoblaster 0ebe870
Merge branch 'openedx:master' into refactor/use-intl-hook
Simoblaster abc0686
test: fix failing component tests and remove deprecated defaultProps
Simoblaster b118319
Merge branch 'refactor/use-intl-hook' of https://github.com/Simoblast…
Simoblaster 7fd14e4
fix: add missing trailing comma
Simoblaster File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
@@ -1,21 +1,26 @@ | ||
import React from 'react'; | ||
import { Helmet } from 'react-helmet'; | ||
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n'; | ||
import { useIntl } from '@edx/frontend-platform/i18n'; | ||
import { getConfig } from '@edx/frontend-platform'; | ||
|
||
import messages from './messages'; | ||
|
||
const Head = ({ intl }) => ( | ||
<Helmet> | ||
<title> | ||
{intl.formatMessage(messages['profile.page.title'], { siteName: getConfig().SITE_NAME })} | ||
</title> | ||
<link rel="shortcut icon" href={getConfig().FAVICON_URL} type="image/x-icon" /> | ||
</Helmet> | ||
); | ||
|
||
Head.propTypes = { | ||
intl: intlShape.isRequired, | ||
const Head = () => { | ||
const intl = useIntl(); | ||
return ( | ||
<Helmet> | ||
<title> | ||
{intl.formatMessage(messages['profile.page.title'], { | ||
siteName: getConfig().SITE_NAME, | ||
})} | ||
</title> | ||
<link | ||
rel="shortcut icon" | ||
href={getConfig().FAVICON_URL} | ||
type="image/x-icon" | ||
/> | ||
</Helmet> | ||
); | ||
}; | ||
|
||
export default injectIntl(Head); | ||
export default Head; |
This file contains hidden or 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 hidden or 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,22 @@ | ||
import React from 'react'; | ||
import { render, fireEvent } from '@testing-library/react'; | ||
import { IntlProvider } from '@edx/frontend-platform/i18n'; | ||
import EditButton from './EditButton'; | ||
|
||
const messages = { | ||
'profile.editbutton.edit': { defaultMessage: 'Edit' }, | ||
}; | ||
|
||
describe('EditButton', () => { | ||
it('renders and calls onClick when clicked', () => { | ||
const onClick = jest.fn(); | ||
const { getByRole } = render( | ||
<IntlProvider locale="en" messages={messages}> | ||
<EditButton onClick={onClick} /> | ||
</IntlProvider>, | ||
); | ||
const button = getByRole('button'); | ||
fireEvent.click(button); | ||
expect(onClick).toHaveBeenCalled(); | ||
}); | ||
}); |
This file contains hidden or 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 hidden or 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,25 @@ | ||
import React from 'react'; | ||
import { render, fireEvent } from '@testing-library/react'; | ||
import { IntlProvider } from '@edx/frontend-platform/i18n'; | ||
import FormControls from './FormControls'; | ||
import messages from './FormControls.messages'; | ||
|
||
describe('FormControls', () => { | ||
it('renders and triggers cancelHandler', () => { | ||
const cancelHandler = jest.fn(); | ||
const changeHandler = jest.fn(); | ||
const { getByText } = render( | ||
<IntlProvider locale="en" messages={messages}> | ||
<FormControls | ||
cancelHandler={cancelHandler} | ||
changeHandler={changeHandler} | ||
visibilityId="test-visibility" | ||
/> | ||
</IntlProvider>, | ||
); | ||
// Use the actual label from the messages file | ||
const cancelLabel = messages['profile.formcontrols.button.cancel'].defaultMessage; | ||
fireEvent.click(getByText(cancelLabel)); | ||
expect(cancelHandler).toHaveBeenCalled(); | ||
}); | ||
}); |
This file contains hidden or 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 hidden or 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 { render } from '@testing-library/react'; | ||
import { IntlProvider } from '@edx/frontend-platform/i18n'; | ||
import { Visibility, VisibilitySelect } from './Visibility'; | ||
import '@testing-library/jest-dom'; | ||
|
||
const messages = { | ||
'profile.visibility.who.just.me': { defaultMessage: 'Just me' }, | ||
'profile.visibility.who.everyone': { defaultMessage: 'Everyone' }, | ||
}; | ||
|
||
describe('Visibility', () => { | ||
it('shows the correct icon and label for private', () => { | ||
const { getByText } = render( | ||
<IntlProvider locale="en" messages={messages}> | ||
<Visibility to="private" /> | ||
</IntlProvider>, | ||
); | ||
expect(getByText(/just me/i)).toBeInTheDocument(); | ||
}); | ||
it('shows the correct icon and label for all_users', () => { | ||
const { getByText } = render( | ||
<IntlProvider locale="en" messages={messages}> | ||
<Visibility to="all_users" /> | ||
</IntlProvider>, | ||
); | ||
expect(getByText(/everyone/i)).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
describe('VisibilitySelect', () => { | ||
it('renders both options', () => { | ||
const { getByRole, getAllByRole } = render( | ||
<IntlProvider locale="en" messages={messages}> | ||
<VisibilitySelect value="private" onChange={() => {}} /> | ||
</IntlProvider>, | ||
); | ||
const select = getByRole('combobox'); | ||
const options = getAllByRole('option'); | ||
expect(select).toBeInTheDocument(); | ||
expect(options.length).toBe(2); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment seems to provide some helpful context. I don't think it should be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took it back!