generated from openedx/frontend-template-application
-
Notifications
You must be signed in to change notification settings - Fork 11
feat: [FC-86] Updated Header links #24
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 10 commits into
openedx:master
from
raccoongang:Peter_Kulko/header-links
Oct 3, 2025
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7e88d0c
feat: updated Header links
PKulkoRaccoonGang cda6af9
refactor: some refactoring
PKulkoRaccoonGang 36660d8
refactor: code refactoring
PKulkoRaccoonGang 44ae8b5
refactor: added some tests
PKulkoRaccoonGang 3b8b761
refactor: after review
PKulkoRaccoonGang 5531de1
refactor: removed logo url logic
PKulkoRaccoonGang 3ae7136
refactor: after review
PKulkoRaccoonGang 50e8925
refactor: corrected header tests
PKulkoRaccoonGang afa6c70
refactor: corrected tests
PKulkoRaccoonGang 95ec797
refactor: after rebase
PKulkoRaccoonGang 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
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
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
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,184 @@ | ||
| import { getConfig } from '@edx/frontend-platform'; | ||
|
|
||
| import { render, screen } from '../setupTest'; | ||
| import { ROUTES } from '../routes'; | ||
| import CatalogHeader from './CatalogHeader'; | ||
| import { useMenuItems } from './hooks/useMenuItems'; | ||
| import messages from './messages'; | ||
|
|
||
| jest.mock('@edx/frontend-platform', () => ({ | ||
| getConfig: jest.fn(() => ({ | ||
| LMS_BASE_URL: process.env.LMS_BASE_URL, | ||
| ENABLE_PROGRAMS: process.env.ENABLE_PROGRAMS, | ||
| ENABLE_COURSE_DISCOVERY: process.env.ENABLE_COURSE_DISCOVERY, | ||
| SUPPORT_URL: process.env.SUPPORT_URL, | ||
| })), | ||
| mergeConfig: jest.fn(), | ||
| ensureConfig: jest.fn(), | ||
| subscribe: jest.fn(), | ||
| })); | ||
|
|
||
| jest.mock('./hooks/useMenuItems', () => ({ | ||
| useMenuItems: jest.fn(), | ||
| })); | ||
|
|
||
| const mockedHeaderProps = jest.fn(); | ||
| jest.mock('@edx/frontend-component-header', () => jest.fn((props) => { | ||
| mockedHeaderProps(props); | ||
| return <div>Header</div>; | ||
| })); | ||
|
|
||
| describe('CatalogHeader', () => { | ||
| const mockMenuItems = { | ||
| mainMenu: [ | ||
| { | ||
| type: 'item', | ||
| href: `${getConfig().LMS_BASE_URL}/dashboard`, | ||
| content: messages.courses.defaultMessage, | ||
| }, | ||
| ], | ||
| secondaryMenu: [ | ||
| { | ||
| type: 'item', | ||
| href: getConfig().SUPPORT_URL, | ||
| content: messages.help.defaultMessage, | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| beforeEach(() => { | ||
| (useMenuItems as jest.Mock).mockReturnValue(mockMenuItems); | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('renders header component with correct props', () => { | ||
| render(<CatalogHeader />); | ||
|
|
||
| expect(screen.getByText('Header')).toBeInTheDocument(); | ||
| expect(useMenuItems).toHaveBeenCalled(); | ||
|
|
||
| const props = mockedHeaderProps.mock.calls[0][0]; | ||
| expect(props.mainMenuItems).toEqual(mockMenuItems.mainMenu); | ||
| expect(props.secondaryMenuItems).toEqual(mockMenuItems.secondaryMenu); | ||
| }); | ||
|
|
||
| it('passes correct main menu items to Header', () => { | ||
| render(<CatalogHeader />); | ||
|
|
||
| const props = mockedHeaderProps.mock.calls[0][0]; | ||
|
|
||
| expect(props.mainMenuItems).toHaveLength(1); | ||
| expect(props.mainMenuItems[0].href).toBe(`${getConfig().LMS_BASE_URL}/dashboard`); | ||
| expect(props.mainMenuItems[0].content).toBe(messages.courses.defaultMessage); | ||
| }); | ||
|
|
||
| it('passes correct props to Header component', () => { | ||
| const { mainMenu, secondaryMenu } = mockMenuItems; | ||
|
|
||
| render(<CatalogHeader />); | ||
|
|
||
| expect(useMenuItems).toHaveBeenCalled(); | ||
| const hookResult = (useMenuItems as jest.Mock).mock.results[0].value; | ||
| expect(hookResult.mainMenu).toEqual(mainMenu); | ||
| expect(hookResult.secondaryMenu).toEqual(secondaryMenu); | ||
| }); | ||
|
|
||
| it('handles different menu configurations', () => { | ||
| const mockMenuItemsWithPrograms = { | ||
| mainMenu: [ | ||
| ...mockMenuItems.mainMenu, | ||
| { | ||
| type: 'item', | ||
| href: `${getConfig().LMS_BASE_URL}/programs`, | ||
| content: messages.programs.defaultMessage, | ||
| }, | ||
| ], | ||
| secondaryMenu: mockMenuItems.secondaryMenu, | ||
| }; | ||
|
|
||
| (useMenuItems as jest.Mock).mockReturnValue(mockMenuItemsWithPrograms); | ||
|
|
||
| render(<CatalogHeader />); | ||
|
|
||
| const hookResult = (useMenuItems as jest.Mock).mock.results[0].value; | ||
| expect(hookResult.mainMenu).toHaveLength(2); | ||
| expect(hookResult.mainMenu[1].content).toBe(messages.programs.defaultMessage); | ||
brian-smith-tcril marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| it('handles empty menu items', () => { | ||
| const mockEmptyMenuItems = { | ||
| mainMenu: [], | ||
| secondaryMenu: [], | ||
| }; | ||
|
|
||
| (useMenuItems as jest.Mock).mockReturnValue(mockEmptyMenuItems); | ||
|
|
||
| render(<CatalogHeader />); | ||
|
|
||
| const hookResult = (useMenuItems as jest.Mock).mock.results[0].value; | ||
| expect(hookResult.mainMenu).toHaveLength(0); | ||
| expect(hookResult.secondaryMenu).toHaveLength(0); | ||
| }); | ||
|
|
||
| it('handles authenticated user menu', () => { | ||
| const mockAuthMenuItems = { | ||
| mainMenu: [ | ||
| { | ||
| type: 'item', | ||
| href: `${getConfig().LMS_BASE_URL}/dashboard`, | ||
| content: messages.courses.defaultMessage, | ||
| }, | ||
| { | ||
| type: 'item', | ||
| href: `${getConfig().LMS_BASE_URL}/programs`, | ||
| content: messages.programs.defaultMessage, | ||
| }, | ||
| ], | ||
| secondaryMenu: [ | ||
| { | ||
| type: 'item', | ||
| href: getConfig().SUPPORT_URL, | ||
| content: messages.help.defaultMessage, | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| (useMenuItems as jest.Mock).mockReturnValue(mockAuthMenuItems); | ||
|
|
||
| render(<CatalogHeader />); | ||
|
|
||
| const hookResult = (useMenuItems as jest.Mock).mock.results[0].value; | ||
| expect(hookResult.mainMenu).toHaveLength(2); | ||
| expect(hookResult.mainMenu[0].href).toContain('/dashboard'); | ||
| expect(hookResult.mainMenu[1].href).toContain('/programs'); | ||
| }); | ||
|
|
||
| it('handles non-authenticated user menu', () => { | ||
| const mockNonAuthMenuItems = { | ||
| mainMenu: [ | ||
| { | ||
| type: 'item', | ||
| href: `${getConfig().LMS_BASE_URL}${ROUTES.COURSES}`, | ||
| content: messages.exploreCourses.defaultMessage, | ||
| isActive: true, | ||
| }, | ||
| ], | ||
| secondaryMenu: [ | ||
| { | ||
| type: 'item', | ||
| href: getConfig().SUPPORT_URL, | ||
| content: messages.help.defaultMessage, | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| (useMenuItems as jest.Mock).mockReturnValue(mockNonAuthMenuItems); | ||
|
|
||
| render(<CatalogHeader />); | ||
|
|
||
| const hookResult = (useMenuItems as jest.Mock).mock.results[0].value; | ||
| expect(hookResult.mainMenu).toHaveLength(1); | ||
| expect(hookResult.mainMenu[0].href).toContain(ROUTES.COURSES); | ||
| expect(hookResult.mainMenu[0].isActive).toBe(true); | ||
| }); | ||
| }); | ||
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,16 @@ | ||
| import Header from '@edx/frontend-component-header'; | ||
|
|
||
| import { useMenuItems } from './hooks/useMenuItems'; | ||
|
|
||
| const CatalogHeader = () => { | ||
| const { mainMenu, secondaryMenu } = useMenuItems(); | ||
|
|
||
| return ( | ||
| <Header | ||
| mainMenuItems={mainMenu} | ||
| secondaryMenuItems={secondaryMenu} | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| export default CatalogHeader; |
Oops, something went wrong.
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.
[question] Let's add an empty
SUPPORT_URLtoprodanddevenv filesThere 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.
Added to 3559b0e#diff-e9cbb0224c4a3d23a6019ba557e0cd568c1ad5e1582ff1e335fb7d99b7a1055dR26