generated from openedx/frontend-template-application
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [FC-0006] add Verifiable Credentials optional feature
- Loading branch information
1 parent
48973fe
commit f2b7990
Showing
30 changed files
with
1,104 additions
and
9 deletions.
There are no files selected for viewing
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,50 @@ | ||
import React from 'react'; | ||
import { useHistory, useLocation } from 'react-router-dom'; | ||
|
||
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n'; | ||
import { Tabs, Tab } from '@edx/paragon'; | ||
import { getConfig } from '@edx/frontend-platform'; | ||
import { ROUTES } from '../../constants'; | ||
|
||
import messages from './messages'; | ||
|
||
function NavigationBar({ intl }) { | ||
const NavigationTabs = [ | ||
{ | ||
id: 'learnerRecords', | ||
path: ROUTES.PROGRAM_RECORDS, | ||
}, | ||
]; | ||
|
||
if (getConfig().ENABLE_VERIFIABLE_CREDENTIALS) { | ||
NavigationTabs.push({ | ||
id: 'verifiableCredentials', | ||
path: ROUTES.VERIFIABLE_CREDENTIALS, | ||
}); | ||
} | ||
|
||
const history = useHistory(); | ||
const location = useLocation(); | ||
|
||
return NavigationTabs.length > 1 ? ( | ||
<Tabs | ||
className="mt-1 mb-5" | ||
defaultActiveKey={location.pathname} | ||
onSelect={path => history.push(path)} | ||
> | ||
{NavigationTabs.map(tab => ( | ||
<Tab | ||
key={tab.id} | ||
eventKey={tab.path} | ||
title={intl.formatMessage(messages[tab.id])} | ||
/> | ||
))} | ||
</Tabs> | ||
) : null; | ||
} | ||
|
||
NavigationBar.propTypes = { | ||
intl: intlShape.isRequired, | ||
}; | ||
|
||
export default injectIntl(NavigationBar); |
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,2 @@ | ||
// eslint-disable-next-line no-restricted-exports | ||
export { default } from './NavigationBar'; |
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,16 @@ | ||
import { defineMessages } from '@edx/frontend-platform/i18n'; | ||
|
||
const messages = defineMessages({ | ||
learnerRecords: { | ||
id: 'learnerRecords', | ||
defaultMessage: 'My Learner Records', | ||
description: 'A message of Learner Records navigation tab', | ||
}, | ||
verifiableCredentials: { | ||
id: 'verifiableCredentials', | ||
defaultMessage: 'Verifiable Credentials', | ||
description: 'A message of Verifiable Credentials navigation tab', | ||
}, | ||
}); | ||
|
||
export default messages; |
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,48 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
import React from 'react'; | ||
import { mergeConfig } from '@edx/frontend-platform'; | ||
import { | ||
render, screen, cleanup, initializeMockApp, fireEvent, | ||
} from '../../../setupTest'; | ||
import NavigationBar from '..'; | ||
|
||
const mockHistoryPush = jest.fn(); | ||
global.ResizeObserver = require('resize-observer-polyfill'); | ||
|
||
jest.mock('react-router-dom', () => ({ | ||
...jest.requireActual('react-router-dom'), | ||
useHistory: () => ({ | ||
push: mockHistoryPush, | ||
}), | ||
})); | ||
|
||
describe('navigation-bar', () => { | ||
beforeAll(async () => { | ||
await initializeMockApp(); | ||
}); | ||
beforeEach(() => { | ||
mergeConfig({ ENABLE_VERIFIABLE_CREDENTIALS: 'true' }); | ||
return jest.resetModules; | ||
}); | ||
afterEach(cleanup); | ||
|
||
it('not renders the component with disabled the Verifiable Credentials functionality', () => { | ||
mergeConfig({ ENABLE_VERIFIABLE_CREDENTIALS: false }); | ||
const { container } = render(<NavigationBar />); | ||
expect(container.innerHTML).toHaveLength(0); | ||
}); | ||
|
||
it('renders the component with enabled the Verifiable Credentials functionality', () => { | ||
render(<NavigationBar />); | ||
expect(screen.getByText('My Learner Records')).toBeTruthy(); | ||
expect(screen.getByText('Verifiable Credentials')).toBeTruthy(); | ||
}); | ||
|
||
it('redirects the appropriate route on tab click', () => { | ||
render(<NavigationBar />); | ||
fireEvent.click(screen.getByText('Verifiable Credentials')); | ||
expect(mockHistoryPush).toHaveBeenCalledWith('/verifiable-credentials'); | ||
}); | ||
}); |
Oops, something went wrong.