forked from edgi-govdata-archiving/web-monitoring-ui
-
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.
Add source-info component to change-view which renders link to Waybac…
…k calendar view and page versions edgi-govdata-archiving#196
- Loading branch information
Showing
5 changed files
with
113 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,58 @@ | ||
/* eslint-env jest */ | ||
|
||
import React from 'react'; | ||
import {render} 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('Only renders the Wayback calendar link if neither of the page versions have a view_url', () => { | ||
const sInfo = render(<SourceInfo from={noViewUrl} to={noViewUrl} pageUrl={pageUrl} />); | ||
expect(sInfo.text()).toBe('Wayback Machine calendar view'); | ||
const { attribs: { href } } = sInfo.find('a')[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 = render(<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'); | ||
const { attribs: { href : href1 } } = anchorTags[1]; | ||
const { attribs: { href: href2 } } = anchorTags[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,36 @@ | ||
import React from 'react'; | ||
|
||
/** | ||
* @typedef SourceInfo | ||
* @property {Object} from | ||
* @property {Object} to | ||
* @property {String} pageUrl | ||
*/ | ||
|
||
/** | ||
* Renders link to see Wayback Machine calendar view of the page | ||
* If one or both of the page diffs 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}`; | ||
|
||
return ( | ||
<div> | ||
<i className="fa fa-calendar" aria-hidden="true" /> | ||
<a href={waybackCalendarUrl} className="source-info-link" target="_blank" rel="noopener noreferrer">Wayback Machine calendar view</a> | ||
{this.props.from.source_metadata.view_url ? <span> | <i className="fa fa-arrow-left" aria-hidden="true" /><a href={this.props.from.source_metadata.view_url} className="source-info-link" target="_blank" rel="noopener noreferrer">{sourceTypeName[this.props.from.source_type]} previous page version</a></span> : ''} | ||
{this.props.to.source_metadata.view_url ? <span> | <a href={this.props.to.source_metadata.view_url} className="source-info-link" target="_blank" rel="noopener noreferrer">{sourceTypeName[this.props.to.source_type]} next page version</a><i className="fa fa-arrow-right fa--right-icon" aria-hidden="true" /></span> : ''} | ||
</div> | ||
); | ||
} | ||
} |
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