-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4568 from WiXSL/change-urlfield-from-a-to-muilink
UrlField renders a material-ui Link component instead of an anchor element
- Loading branch information
Showing
2 changed files
with
21 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,43 @@ | ||
import React from 'react'; | ||
import assert from 'assert'; | ||
import { render } from '@testing-library/react'; | ||
import expect from 'expect'; | ||
import { render, cleanup } from '@testing-library/react'; | ||
import UrlField from './UrlField'; | ||
|
||
const url = 'https://en.wikipedia.org/wiki/HAL_9000'; | ||
|
||
describe('<UrlField />', () => { | ||
it('should display a link', () => { | ||
const record = { website: 'https://en.wikipedia.org/wiki/HAL_9000' }; | ||
const { container } = render( | ||
afterEach(cleanup); | ||
|
||
it('should render a link', () => { | ||
const record = { website: url }; | ||
const { getByText } = render( | ||
<UrlField record={record} source="website" /> | ||
); | ||
assert.equal( | ||
container.innerHTML, | ||
'<a href="https://en.wikipedia.org/wiki/HAL_9000">https://en.wikipedia.org/wiki/HAL_9000</a>' | ||
); | ||
const link = getByText(url); | ||
expect(link.tagName).toEqual('A'); | ||
expect(link.href).toEqual(url); | ||
}); | ||
|
||
it('should handle deep fields', () => { | ||
const record = { | ||
foo: { website: 'https://en.wikipedia.org/wiki/HAL_9000' }, | ||
foo: { website: url }, | ||
}; | ||
const { container } = render( | ||
const { getByText } = render( | ||
<UrlField record={record} source="foo.website" /> | ||
); | ||
assert.equal( | ||
container.innerHTML, | ||
'<a href="https://en.wikipedia.org/wiki/HAL_9000">https://en.wikipedia.org/wiki/HAL_9000</a>' | ||
); | ||
const link = getByText(url); | ||
expect(link.href).toEqual(url); | ||
}); | ||
|
||
it('should render the emptyText when value is null', () => { | ||
const { queryByText } = render( | ||
const { getByText } = render( | ||
<UrlField | ||
record={{ url: null }} | ||
className="foo" | ||
source="url" | ||
emptyText="NA" | ||
/> | ||
); | ||
assert.notEqual(queryByText('NA'), null); | ||
expect(getByText('NA')).not.toEqual(null); | ||
}); | ||
}); |
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