-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
24 changed files
with
627 additions
and
150 deletions.
There are no files selected for viewing
Binary file not shown.
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,8 +1,10 @@ | ||
import React from 'react'; | ||
import { format, parseISO } from 'date-fns'; | ||
|
||
export default function FormattedDate ({ date, time = false }) { | ||
export function FormattedDate ({ date, time = false }) { | ||
const formatted = React.useMemo(() => format(parseISO(date), `MMM d, Y${time ? ' HH:mm:ss' : ''}`), [date, time]); | ||
|
||
return (<>{ formatted }</>); | ||
} | ||
} | ||
|
||
export default FormattedDate; |
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,9 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
|
||
import { FormattedDate } from './FormattedDate'; | ||
|
||
it('should display a formatted date', () => { | ||
render(<FormattedDate date={ '2021-06-10T12:28:52.514342' } />); | ||
expect(screen.getByText('Jun 10, 2021')).toBeInTheDocument(); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React from 'react'; | ||
|
||
import { render, screen } from '@testing-library/react'; | ||
|
||
import { VersionInfo } from './VersionInfo'; | ||
|
||
const data = { "git": { "branch": "react", "commit": { "id": "634f1a4", "time": "2021-06-10T19:00:29Z" } }, "build": { "artifact": "shibui", "name": "backend", "time": "2021-06-10T19:26:14.478Z", "version": "2.0.0-SNAPSHOT", "group": "edu.internet2.tier.shibboleth.admin.ui" } }; | ||
|
||
jest.mock('../../i18n/components/translate', () => { | ||
return 'span'; | ||
}) | ||
|
||
jest.mock('use-http', () => { | ||
return () => ({ data }); | ||
}); | ||
|
||
it('should display formatted version information', () => { | ||
|
||
render(<VersionInfo />); | ||
expect(screen.getByText('2.0.0-SNAPSHOT-634f1a4', { exact: false })).toBeInTheDocument(); | ||
}); |
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 was deleted.
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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import React from 'react'; | ||
|
||
import { translate, getMessage, useTranslation, useTranslator } from './hooks'; | ||
|
||
const msgs = { foo: 'bar { baz }' }; | ||
|
||
describe('getMessage', () => { | ||
it('should return the expected message based on the key', () => { | ||
expect(getMessage('foo', msgs)).toEqual('bar { baz }'); | ||
}); | ||
}) | ||
|
||
describe('translate', () => { | ||
it('should translate the provided message', () => { | ||
const msg = getMessage('foo', msgs); | ||
expect(translate(msg, { baz: 'baz' })).toEqual('bar baz'); | ||
}); | ||
|
||
it('should return provided value if no interpolation strings are passed', () => { | ||
expect(translate('foo', {})).toEqual('foo'); | ||
}); | ||
|
||
it('should return an empty string if messages are empty', () => { | ||
expect(getMessage('foo', {})).toEqual(''); | ||
}); | ||
}); | ||
|
||
describe('useTranslation hook', () => { | ||
let realUseContext; | ||
let useContextMock; | ||
beforeEach(() => { | ||
realUseContext = React.useContext; | ||
useContextMock = React.useContext = jest.fn(); | ||
}); | ||
// Cleanup mock | ||
afterEach(() => { | ||
React.useContext = realUseContext; | ||
}); | ||
|
||
test("mock hook", () => { | ||
useContextMock.mockReturnValue(msgs); | ||
|
||
expect(useTranslation('foo', { baz: 'baz' })).toBe('bar baz'); | ||
}); | ||
//jest.mock('useContext') | ||
|
||
it('should translate the provided message', () => { | ||
const msg = getMessage('foo', { foo: 'bar { baz }' }); | ||
expect(translate(msg, { baz: 'baz' })).toEqual('bar baz'); | ||
}); | ||
}); | ||
|
||
describe('useTranslator hook', () => { | ||
let realUseContext; | ||
let useContextMock; | ||
beforeEach(() => { | ||
realUseContext = React.useContext; | ||
useContextMock = React.useContext = jest.fn(); | ||
}); | ||
// Cleanup mock | ||
afterEach(() => { | ||
React.useContext = realUseContext; | ||
}); | ||
|
||
test("mock hook", () => { | ||
useContextMock.mockReturnValue(msgs); | ||
const translator = useTranslator(); | ||
|
||
expect(translator('foo', { baz: 'baz' })).toBe('bar baz'); | ||
}); | ||
}); |
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,12 @@ | ||
import { NameIDFilterEditor } from './filter/NameIdFilterDefinition'; | ||
import { getDefinition } from './index'; | ||
import { FileSystemMetadataProviderEditor } from './provider/FileSystemMetadataProviderDefinition'; | ||
import { SourceEditor } from './source/SourceDefinition'; | ||
|
||
describe('getDefinitions method', () => { | ||
it('should retrieve the definition', () => { | ||
expect(getDefinition('source')).toBe(SourceEditor); | ||
expect(getDefinition('NameIDFormat')).toBe(NameIDFilterEditor); | ||
expect(getDefinition('FilesystemMetadataResolver')).toBe(FileSystemMetadataProviderEditor); | ||
}); | ||
}); |
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 was deleted.
Oops, something went wrong.
Empty file.
Oops, something went wrong.