Skip to content

Commit db39548

Browse files
committed
renamed component and add tests
1 parent b668a83 commit db39548

File tree

5 files changed

+101
-11
lines changed

5 files changed

+101
-11
lines changed

src/components/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export SearchWidget from './theme/SearchWidget/SearchWidget';
2323
export Title from './theme/Title/Title';
2424
export App from './theme/App/App';
2525
export DocumentView from './theme/View/DocumentView';
26-
export ListView from './theme/View/ListView';
26+
export ListingView from './theme/View/ListingView';
2727
export Login from './theme/Login/Login';
2828
export Logout from './theme/Logout/Logout';
2929
export NotFound from './theme/NotFound/NotFound';

src/components/theme/View/ListView.jsx renamed to src/components/theme/View/ListingView.jsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* Document view component.
3-
* @module components/theme/View/ListView
3+
* @module components/theme/View/ListingView
44
*/
55

66
import React from 'react';
@@ -9,11 +9,11 @@ import Helmet from 'react-helmet';
99
import { Link } from 'react-router';
1010
/**
1111
* List view component class.
12-
* @function ListView
12+
* @function ListingView
1313
* @params {object} content Content object.
1414
* @returns {string} Markup of the component.
1515
*/
16-
const ListView = ({ content }) => (
16+
const ListingView = ({ content }) => (
1717
<div id="page-home">
1818
<Helmet title={content.title} />
1919
<section id="content-core">
@@ -36,7 +36,7 @@ const ListView = ({ content }) => (
3636
* @property {Object} propTypes Property types.
3737
* @static
3838
*/
39-
ListView.propTypes = {
39+
ListingView.propTypes = {
4040
content: PropTypes.shape({
4141
title: PropTypes.string,
4242
description: PropTypes.string,
@@ -47,10 +47,10 @@ ListView.propTypes = {
4747
description: PropTypes.string,
4848
review_state: PropTypes.string,
4949
title: PropTypes.string,
50-
url: PropTypes.string
51-
})
52-
)
50+
url: PropTypes.string,
51+
}),
52+
),
5353
}).isRequired,
5454
};
5555

56-
export default ListView;
56+
export default ListingView;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import React from 'react';
2+
import renderer from 'react-test-renderer';
3+
import configureStore from 'redux-mock-store';
4+
import { Provider } from 'react-intl-redux';
5+
6+
import ListingView from './ListingView';
7+
8+
const mockStore = configureStore();
9+
10+
describe('ListingView', () => {
11+
it('renders a listing_view component', () => {
12+
const store = mockStore({
13+
intl: {
14+
locale: 'en',
15+
messages: {},
16+
},
17+
});
18+
const component = renderer.create(
19+
<Provider store={store}>
20+
<ListingView
21+
content={{
22+
title: 'Hello World!',
23+
description: 'Hi',
24+
items: [
25+
{
26+
title: 'My item',
27+
description: 'My item description',
28+
url: 'http://item',
29+
'@type': 'Document',
30+
},
31+
{
32+
title: 'Second item',
33+
description: 'My second item description',
34+
url: 'http://item2',
35+
'@type': 'Document',
36+
},
37+
],
38+
}}
39+
/>
40+
</Provider>,
41+
);
42+
const json = component.toJSON();
43+
expect(json).toMatchSnapshot();
44+
});
45+
});

src/components/theme/View/View.jsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ import React, { Component } from 'react';
77
import PropTypes from 'prop-types';
88
import { connect } from 'react-redux';
99

10-
import { SummaryView, TabularView, DocumentView, ListView } from '../../../components';
10+
import {
11+
SummaryView,
12+
TabularView,
13+
DocumentView,
14+
ListingView,
15+
} from '../../../components';
1116
import { getContent } from '../../../actions';
1217

1318
/**
@@ -87,7 +92,7 @@ export default class View extends Component {
8792
case 'tabular_view':
8893
return <TabularView content={this.props.content} />;
8994
case 'listing_view':
90-
return <ListView content={this.props.content} />;
95+
return <ListingView content={this.props.content} />;
9196
default:
9297
return <DocumentView content={this.props.content} />;
9398
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`ListingView renders a listing_view component 1`] = `
4+
<div
5+
id="page-home"
6+
>
7+
<section
8+
id="content-core"
9+
>
10+
<article>
11+
<h2>
12+
<a
13+
onClick={[Function]}
14+
style={Object {}}
15+
title="Document"
16+
>
17+
My item
18+
</a>
19+
</h2>
20+
<p>
21+
My item description
22+
</p>
23+
</article>
24+
<article>
25+
<h2>
26+
<a
27+
onClick={[Function]}
28+
style={Object {}}
29+
title="Document"
30+
>
31+
Second item
32+
</a>
33+
</h2>
34+
<p>
35+
My second item description
36+
</p>
37+
</article>
38+
</section>
39+
</div>
40+
`;

0 commit comments

Comments
 (0)