-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add source-info component to change-view which renders link to Waybac…
…k calendar view and page versions #196
- Loading branch information
Showing
5 changed files
with
180 additions
and
4 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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* eslint-env jest */ | ||
|
||
import React from 'react'; | ||
import {shallow} from 'enzyme'; | ||
import SourceInfo from '../source-info'; | ||
|
||
describe('source-info', () => { | ||
const noViewUrl = { | ||
source_type: 'versionista', | ||
source_metadata: { | ||
url: 'https://versionista.com/1111/2222/3333/', | ||
account: 'versionista1', | ||
page_id: '1234567', | ||
site_id: '8888888', | ||
version_id: '123456778', | ||
has_content: true | ||
} | ||
}; | ||
|
||
const withViewUrl1 = { | ||
source_type: 'internet_archive', | ||
source_metadata: { | ||
encoding: 'ISO-8859-1', | ||
view_url: 'http://web.archive.org/web/1111111/https://19january2017snapshot.epa.gov/test-url', | ||
mime_type: 'text/html', | ||
status_code: 200 | ||
} | ||
}; | ||
|
||
const withViewUrl2 = { | ||
source_type: 'internet_archive', | ||
source_metadata: { | ||
encoding: 'ISO-8859-1', | ||
view_url: 'http://web.archive.org/web/22222/https://19january2017snapshot.epa.gov/test-url', | ||
mime_type: 'text/html', | ||
status_code: 200 | ||
} | ||
}; | ||
|
||
const pageUrl = 'https://19january2017snapshot.epa.gov/test-url'; | ||
|
||
it('Renders only the Wayback calendar link if neither of the page versions have a view_url', () => { | ||
const sInfo = shallow(<SourceInfo from={noViewUrl} to={noViewUrl} pageUrl={pageUrl} />); | ||
expect(sInfo.text()).toBe('Wayback Machine calendar view'); | ||
const anchorTag = sInfo.find('a'); | ||
expect(anchorTag.length).toBe(1); | ||
const { props: { href } } = anchorTag.get(0); | ||
expect(href).toBe('https://web.archive.org/web/*/https://19january2017snapshot.epa.gov/test-url'); | ||
}); | ||
|
||
it('Renders the Wayback calendar link and previous/next versions with Wayback links if they are sourced from Wayback', () => { | ||
const sInfo = shallow(<SourceInfo from={withViewUrl1} to={withViewUrl2} pageUrl={pageUrl} />); | ||
expect(sInfo.text()).toBe('Wayback Machine calendar view | Wayback Machine previous page version | Wayback Machine next page version'); | ||
const anchorTags = sInfo.find('a'); | ||
expect(anchorTags.length).toBe(3); | ||
const { props: { href : href1 } } = anchorTags.get(1); | ||
const { props: { href: href2 } } = anchorTags.get(2); | ||
expect(href1).toBe('http://web.archive.org/web/1111111/https://19january2017snapshot.epa.gov/test-url'); | ||
expect(href2).toBe('http://web.archive.org/web/22222/https://19january2017snapshot.epa.gov/test-url'); | ||
}); | ||
}); |
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,87 @@ | ||
import React from 'react'; | ||
|
||
/** | ||
* @typedef SourceInfo | ||
* @property {Version} from | ||
* @property {Version} to | ||
* @property {String} pageUrl | ||
*/ | ||
|
||
/** | ||
* Renders link to see Wayback Machine calendar view of the page | ||
* If one or both of the versions were sourced from Wayback, this component renders links to the Wayback Machine source url(s) | ||
* | ||
* @class SourceInfo | ||
* @extends {React.Component} | ||
* @param {SourceInfoProps} props | ||
*/ | ||
|
||
const sourceTypeName = { | ||
internet_archive: 'Wayback Machine' | ||
}; | ||
|
||
export default class SourceInfo extends React.Component { | ||
render () { | ||
const waybackCalendarUrl = `https://web.archive.org/web/*/${this.props.pageUrl}`; | ||
const waybackCalendarLink = ( | ||
<li className="source-info__list-item" key={waybackCalendarUrl}> | ||
<a | ||
className="source-info__list-link" | ||
href={waybackCalendarUrl} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
<i className="fa fa-calendar fa--no-hover" aria-hidden="true" /> | ||
Wayback Machine calendar view | ||
</a> | ||
</li> | ||
); | ||
const links = [waybackCalendarLink]; | ||
|
||
if (this.props.from.source_metadata.view_url) { | ||
const fromLink = ( | ||
<li className="source-info__list-item" key={this.props.from.source_metadata.view_url}> | ||
<span aria-hidden="true"> | </span> | ||
<a | ||
className="source-info__list-link" | ||
href={this.props.from.source_metadata.view_url} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
<i className="fa fa-arrow-left fa--no-hover" aria-hidden="true" /> | ||
{sourceTypeName[this.props.from.source_type]} previous page version | ||
</a> | ||
</li> | ||
); | ||
|
||
links.push(fromLink); | ||
} | ||
|
||
if (this.props.to.source_metadata.view_url) { | ||
const toLink = ( | ||
<li className="source-info__list-item" key={this.props.to.source_metadata.view_url}> | ||
<span aria-hidden="true"> | </span> | ||
<a | ||
className="source-info__list-link" | ||
href={this.props.to.source_metadata.view_url} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
{sourceTypeName[this.props.to.source_type]} next page version | ||
<i className="fa fa-arrow-right fa--right-icon fa--no-hover" aria-hidden="true" /> | ||
</a> | ||
</li> | ||
); | ||
|
||
links.push(toLink); | ||
} | ||
|
||
return ( | ||
<aside> | ||
<ol className="source-info__list"> | ||
{links} | ||
</ol> | ||
</aside> | ||
); | ||
} | ||
} |
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