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 (#151)
* feat: [FC-0006] add Verifiable Credentials optional feature --------- Co-authored-by: Jason Wesson <[email protected]>
- Loading branch information
1 parent
ef037a5
commit f8e71a3
Showing
31 changed files
with
7,909 additions
and
8,110 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
Large diffs are not rendered by default.
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('does not render the component with Verifiable Credentials functionality when flag is disabled', () => { | ||
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'); | ||
}); | ||
}); |
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,89 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import { | ||
FormattedDate, | ||
injectIntl, | ||
intlShape, | ||
} from '@edx/frontend-platform/i18n'; | ||
import { Hyperlink, DropdownButton, Dropdown } from '@edx/paragon'; | ||
import messages from './messages'; | ||
|
||
function ProgramCertificate({ | ||
intl, | ||
program_title: programTitle, | ||
program_org: programOrg, | ||
modified_date: modifiedDate, | ||
uuid, | ||
handleCreate, | ||
storages = [], | ||
}) { | ||
const showSingleAction = storages.length === 1; | ||
|
||
const renderCreationButtons = () => ( | ||
<div> | ||
{showSingleAction && ( | ||
<Hyperlink | ||
className="btn btn-outline-primary" | ||
onClick={() => handleCreate(uuid, storages[0].id)} | ||
> | ||
{intl.formatMessage(messages.certificateCardActionLabel)} | ||
</Hyperlink> | ||
)} | ||
{!showSingleAction && ( | ||
<DropdownButton id="dropdown-storages" title={intl.formatMessage(messages.certificateCardMultiActionLabel)}> | ||
{storages.map(({ id, name }) => ( | ||
<Dropdown.Item key={id} onClick={() => handleCreate(uuid, id)}> | ||
{name} | ||
</Dropdown.Item> | ||
))} | ||
</DropdownButton> | ||
)} | ||
</div> | ||
); | ||
|
||
return ( | ||
<div className="col-12 col-sm-6 col-md-4 d-flex align-items-stretch"> | ||
<div className="card mb-4 certificate flex-grow-1"> | ||
<div className="card-body d-flex flex-column"> | ||
<div className="card-title"> | ||
<p className="small mb-0"> | ||
{intl.formatMessage(messages.certificateCardName)} | ||
</p> | ||
<h4 className="certificate-title">{programTitle}</h4> | ||
</div> | ||
<p className="small mb-0"> | ||
{intl.formatMessage(messages.certificateCardOrgLabel)} | ||
</p> | ||
<p className="h6 mb-4"> | ||
{programOrg | ||
|| intl.formatMessage(messages.certificateCardNoOrgText)} | ||
</p> | ||
<p className="small mb-2"> | ||
{intl.formatMessage(messages.certificateCardDateLabel, { | ||
date: <FormattedDate value={new Date(modifiedDate)} />, | ||
})} | ||
</p> | ||
{renderCreationButtons()} | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
ProgramCertificate.propTypes = { | ||
intl: intlShape.isRequired, | ||
program_title: PropTypes.string.isRequired, | ||
program_org: PropTypes.string.isRequired, | ||
modified_date: PropTypes.string.isRequired, | ||
uuid: PropTypes.string.isRequired, | ||
handleCreate: PropTypes.func.isRequired, | ||
storages: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
id: PropTypes.string.isRequired, | ||
name: PropTypes.string.isRequired, | ||
}), | ||
).isRequired, | ||
}; | ||
|
||
export default injectIntl(ProgramCertificate); |
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 './ProgramCertificate'; |
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,36 @@ | ||
import { defineMessages } from '@edx/frontend-platform/i18n'; | ||
|
||
const messages = defineMessages({ | ||
certificateCardName: { | ||
id: 'certificate.card.name', | ||
defaultMessage: 'Program Certificate', | ||
description: 'A title text of the available program certificate item.', | ||
}, | ||
certificateCardOrgLabel: { | ||
id: 'certificate.card.organization.label', | ||
defaultMessage: 'From', | ||
description: '', | ||
}, | ||
certificateCardNoOrgText: { | ||
id: 'certificate.card.noOrg.text', | ||
defaultMessage: 'No organization', | ||
description: '', | ||
}, | ||
certificateCardDateLabel: { | ||
id: 'certificate.card.date.label', | ||
defaultMessage: 'Awarded on {date}', | ||
description: '', | ||
}, | ||
certificateCardActionLabel: { | ||
id: 'certificate.card.action.label', | ||
defaultMessage: 'Create', | ||
description: 'A text on single action button', | ||
}, | ||
certificateCardMultiActionLabel: { | ||
id: 'certificate.card.multiAction.label', | ||
defaultMessage: 'Create with', | ||
description: 'A text on a dropdown with multiple action options', | ||
}, | ||
}); | ||
|
||
export default messages; |
47 changes: 47 additions & 0 deletions
47
src/components/ProgramCertificate/test/ProgramCertificate.test.jsx
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,47 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
import React from 'react'; | ||
import { | ||
render, screen, cleanup, initializeMockApp, fireEvent, | ||
} from '../../../setupTest'; | ||
import ProgramCertificate from '..'; | ||
|
||
describe('program-certificate', () => { | ||
beforeAll(async () => { | ||
await initializeMockApp(); | ||
}); | ||
beforeEach(() => jest.resetModules); | ||
afterEach(cleanup); | ||
|
||
const props = { | ||
program_title: 'Program name', | ||
program_org: 'Test org', | ||
modified_date: '2023-02-02', | ||
storages: [{ id: 'storageId', name: 'storageName' }], | ||
handleCreate: jest.fn(), | ||
}; | ||
|
||
it('renders the component', () => { | ||
render(<ProgramCertificate {...props} />); | ||
|
||
expect(screen.getByText('Program Certificate')).toBeTruthy(); | ||
expect(screen.getByText(props.program_title)).toBeTruthy(); | ||
expect(screen.getByText(props.program_org)).toBeTruthy(); | ||
expect(screen.getByText('Awarded on 2/2/2023')).toBeTruthy(); | ||
}); | ||
|
||
it('should display "No organization" if Program Organization wasn\'t set', () => { | ||
render(<ProgramCertificate {...props} program_org="" />); | ||
|
||
expect(screen.getByText('No organization')).toBeTruthy(); | ||
}); | ||
|
||
it('renders modal by clicking on a create button', () => { | ||
render(<ProgramCertificate {...props} />); | ||
fireEvent.click(screen.getByText('Create')); | ||
|
||
expect(screen.findByTitle('Verifiable credential')).toBeTruthy(); | ||
expect(screen.findByLabelText('Close')).toBeTruthy(); | ||
}); | ||
}); |
Oops, something went wrong.