-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move orcid link render function to misc components module [URO-208]
- Loading branch information
Showing
3 changed files
with
91 additions
and
69 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,86 @@ | ||
import { render } from '@testing-library/react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import 'core-js/stable/structured-clone'; | ||
import { ORCIDProfile } from '../../../common/api/orcidLinkCommon'; | ||
import { PROFILE_1 } from '../test/data'; | ||
import { renderCreditName, renderRealname } from './misc'; | ||
import { renderCreditName, renderORCIDId, renderRealname } from './misc'; | ||
|
||
describe('The common module renderORCIDIcon function', () => { | ||
it('renders correct', () => { | ||
expect(true).toBe(true); | ||
}); | ||
}); | ||
describe('The miscellaneous shared components module', () => { | ||
describe('the renderRealName render function ', () => { | ||
it('renders correctly if not private', () => { | ||
const profile = structuredClone<ORCIDProfile>(PROFILE_1); | ||
|
||
describe('The common module renderRealName function', () => { | ||
it('renders correctly if not private', () => { | ||
const profile = structuredClone<ORCIDProfile>(PROFILE_1); | ||
const { container } = render(renderRealname(profile)); | ||
|
||
const { container } = render(renderRealname(profile)); | ||
expect(container).toHaveTextContent('Foo Bar'); | ||
}); | ||
|
||
expect(container).toHaveTextContent('Foo Bar'); | ||
}); | ||
it('renders just the first name if no last name', () => { | ||
const profile = structuredClone<ORCIDProfile>(PROFILE_1); | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
profile.nameGroup.fields!.lastName = null; | ||
|
||
const { container } = render(renderRealname(profile)); | ||
|
||
expect(container).toHaveTextContent('Foo'); | ||
}); | ||
|
||
it('renders just the first name if no last name', () => { | ||
const profile = structuredClone<ORCIDProfile>(PROFILE_1); | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
profile.nameGroup.fields!.lastName = null; | ||
it('renders a special string if it is private', () => { | ||
const profile = structuredClone<ORCIDProfile>(PROFILE_1); | ||
profile.nameGroup.private = true; | ||
|
||
const { container } = render(renderRealname(profile)); | ||
const { container } = render(renderRealname(profile)); | ||
|
||
expect(container).toHaveTextContent('Foo'); | ||
expect(container).toHaveTextContent('private'); | ||
}); | ||
}); | ||
|
||
it('renders a special string if it is private', () => { | ||
const profile = structuredClone<ORCIDProfile>(PROFILE_1); | ||
profile.nameGroup.private = true; | ||
describe('The renderCreditName render function', () => { | ||
it('renders correctly if not private', () => { | ||
const profile = structuredClone<ORCIDProfile>(PROFILE_1); | ||
|
||
const { container } = render(renderRealname(profile)); | ||
const { container } = render(renderCreditName(profile)); | ||
|
||
expect(container).toHaveTextContent('private'); | ||
}); | ||
}); | ||
expect(container).toHaveTextContent('Foo B. Bar'); | ||
}); | ||
|
||
describe('The common module renderCreditName function', () => { | ||
it('renders correctly if not private', () => { | ||
const profile = structuredClone<ORCIDProfile>(PROFILE_1); | ||
it('renders a special string if it is private', () => { | ||
const profile = structuredClone<ORCIDProfile>(PROFILE_1); | ||
|
||
const { container } = render(renderCreditName(profile)); | ||
profile.nameGroup.private = true; | ||
|
||
expect(container).toHaveTextContent('Foo B. Bar'); | ||
}); | ||
const { container } = render(renderCreditName(profile)); | ||
|
||
it('renders a special string if it is private', () => { | ||
const profile = structuredClone<ORCIDProfile>(PROFILE_1); | ||
expect(container).toHaveTextContent('private'); | ||
}); | ||
|
||
profile.nameGroup.private = true; | ||
it('renders a "not available" string if it is absent', () => { | ||
const profile = structuredClone<ORCIDProfile>(PROFILE_1); | ||
|
||
const { container } = render(renderCreditName(profile)); | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
profile.nameGroup.fields!.creditName = null; | ||
|
||
expect(container).toHaveTextContent('private'); | ||
const { container } = render(renderCreditName(profile)); | ||
|
||
expect(container).toHaveTextContent('n/a'); | ||
}); | ||
}); | ||
|
||
it('renders a "not available" string if it is absent', () => { | ||
const profile = structuredClone<ORCIDProfile>(PROFILE_1); | ||
describe('The renderORCIDId render function', () => { | ||
it('renders an orcid id link', async () => { | ||
const baseURL = 'http://example.com'; | ||
const orcidId = 'abc123'; | ||
const expectedURL = `${baseURL}/${orcidId}`; | ||
|
||
const { container } = render(renderORCIDId(baseURL, orcidId)); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
profile.nameGroup.fields!.creditName = null; | ||
expect(container).toHaveTextContent(orcidId); | ||
|
||
const { container } = render(renderCreditName(profile)); | ||
const link = await screen.findByText(expectedURL); | ||
expect(link).toHaveAttribute('href', expectedURL); | ||
|
||
expect(container).toHaveTextContent('n/a'); | ||
const image = await screen.findByAltText('ORCID Icon'); | ||
expect(image).toBeVisible(); | ||
expect(image.getAttribute('src')).toContain('ORCID-iD_icon-vector.svg'); | ||
}); | ||
}); | ||
}); |
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