-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
12b9eac
commit d5745e2
Showing
17 changed files
with
132 additions
and
242 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,25 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Hyperlink } from '@openedx/paragon'; | ||
|
||
import { navigateToUrl } from './utils'; | ||
import { Link } from 'react-router-dom'; | ||
|
||
const BrandNav = ({ | ||
studioBaseUrl, | ||
logo, | ||
logoAltText, | ||
onNavigate, | ||
}) => ( | ||
<Hyperlink destination={studioBaseUrl} onClick={(e) => navigateToUrl(e, studioBaseUrl, onNavigate)}> | ||
<Link to={studioBaseUrl}> | ||
<img | ||
src={logo} | ||
alt={logoAltText} | ||
className="d-block logo" | ||
/> | ||
</Hyperlink> | ||
</Link> | ||
); | ||
|
||
BrandNav.propTypes = { | ||
studioBaseUrl: PropTypes.string.isRequired, | ||
logo: PropTypes.string.isRequired, | ||
logoAltText: PropTypes.string.isRequired, | ||
onNavigate: PropTypes.func.isRequired, | ||
}; | ||
|
||
export default BrandNav; |
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 |
---|---|---|
@@ -1,68 +1,40 @@ | ||
import React from 'react'; | ||
import { render, fireEvent, screen } from '@testing-library/react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
|
||
import BrandNav from './BrandNav'; | ||
|
||
describe('BrandNav Component', () => { | ||
const mockOnNavigate = jest.fn(); | ||
const studioBaseUrl = 'https://example.com'; | ||
const logo = 'logo.png'; | ||
const logoAltText = 'Example Logo'; | ||
const studioBaseUrl = 'https://example.com/'; | ||
const logo = 'logo.png'; | ||
const logoAltText = 'Example Logo'; | ||
|
||
const RootWrapper = () => ( | ||
<MemoryRouter> | ||
<BrandNav | ||
studioBaseUrl={studioBaseUrl} | ||
logo={logo} | ||
logoAltText={logoAltText} | ||
/> | ||
</MemoryRouter> | ||
); | ||
|
||
describe('BrandNav Component', () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('renders the logo with the correct alt text', () => { | ||
render( | ||
<BrandNav | ||
studioBaseUrl={studioBaseUrl} | ||
logo={logo} | ||
logoAltText={logoAltText} | ||
onNavigate={mockOnNavigate} | ||
/>, | ||
); | ||
render(<RootWrapper />); | ||
|
||
const img = screen.getByAltText(logoAltText); | ||
expect(img).toBeInTheDocument(); | ||
expect(img).toHaveAttribute('src', logo); | ||
}); | ||
|
||
it('navigates to an absolute URL by changing window location', () => { | ||
// Mock window.location.href | ||
delete window.location; | ||
window.location = { href: '' }; | ||
|
||
render( | ||
<BrandNav | ||
studioBaseUrl={studioBaseUrl} | ||
logo={logo} | ||
logoAltText={logoAltText} | ||
onNavigate={mockOnNavigate} | ||
/>, | ||
); | ||
|
||
const link = screen.getByRole('link'); | ||
fireEvent.click(link); | ||
|
||
expect(window.location.href).toBe(studioBaseUrl); | ||
}); | ||
|
||
it('calls onNavigate for relative URLs', () => { | ||
const relativeUrl = '/studio/dashboard'; | ||
|
||
render( | ||
<BrandNav | ||
studioBaseUrl={relativeUrl} | ||
logo={logo} | ||
logoAltText={logoAltText} | ||
onNavigate={mockOnNavigate} | ||
/>, | ||
); | ||
it('displays a link that navigates to studioBaseUrl', () => { | ||
render(<RootWrapper />); | ||
|
||
const link = screen.getByRole('link'); | ||
fireEvent.click(link); | ||
|
||
expect(mockOnNavigate).toHaveBeenCalledWith(relativeUrl); | ||
expect(link.href).toBe(studioBaseUrl); | ||
}); | ||
}); |
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
Oops, something went wrong.