-
Notifications
You must be signed in to change notification settings - Fork 6
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 #1626 from terrestris/displayfield-links
Create anchor elements for linklike values in DisplayField
- Loading branch information
Showing
2 changed files
with
76 additions
and
6 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,3 +1,10 @@ | ||
import React from 'react'; | ||
|
||
import { | ||
render, | ||
screen | ||
} from '@testing-library/react'; | ||
|
||
import DisplayField from '.'; | ||
|
||
describe('<DisplayField />', () => { | ||
|
@@ -6,4 +13,33 @@ describe('<DisplayField />', () => { | |
expect(DisplayField).toBeDefined(); | ||
}); | ||
|
||
it('renders urls as links', () => { | ||
const linkValues = [ | ||
'http://example.com', | ||
'https://example.com', | ||
'http://localhost:8080', | ||
'ftp://example.com', | ||
'H:\\special\\windäws\\with spaces\\and, tons of, commas and .dots\\file.txt', | ||
'file://///server/share/path/to/file.txt', | ||
'mailto:[email protected]' | ||
]; | ||
|
||
for (const linkValue of linkValues) { | ||
render(<DisplayField value={linkValue} />); | ||
const link = screen.getByText(linkValue); | ||
expect(link).toBeVisible(); | ||
expect(link).toBeInstanceOf(HTMLAnchorElement); | ||
expect(link).toHaveAttribute('href', linkValue); | ||
} | ||
|
||
const noneLinkValues = [ 'Peter', 123 ]; | ||
|
||
for (const noneLinkValue of noneLinkValues) { | ||
render(<DisplayField value={noneLinkValue} />); | ||
const noneLink = screen.queryByText(noneLinkValue); | ||
expect(noneLink).toBeVisible(); | ||
expect(noneLink).not.toBeInstanceOf(HTMLAnchorElement); | ||
} | ||
}); | ||
|
||
}); |
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