Skip to content
Snippets Groups Projects
Unverified Commit 67d8096d authored by Jack Reed's avatar Jack Reed Committed by GitHub
Browse files

Merge pull request #1923 from ProjectMirador/render-html-content-in-info-panel

Render HTML content in info panel. Closes #1854
parents d80e77b1 5d8e52b9
No related branches found
No related tags found
No related merge requests found
import React from 'react'; import React from 'react';
import { shallow } from 'enzyme'; import { shallow } from 'enzyme';
import SanitizedHtml from '../../../src/components/SanitizedHtml';
import LabelValueMetadata from '../../../src/components/LabelValueMetadata'; import LabelValueMetadata from '../../../src/components/LabelValueMetadata';
describe('LabelValueMetadata', () => { describe('LabelValueMetadata', () => {
...@@ -25,14 +26,23 @@ describe('LabelValueMetadata', () => { ...@@ -25,14 +26,23 @@ describe('LabelValueMetadata', () => {
it('renders a dt/dd for each label/value pair', () => { it('renders a dt/dd for each label/value pair', () => {
expect(wrapper.find('dl').length).toEqual(1); expect(wrapper.find('dl').length).toEqual(1);
expect(wrapper.find('dt').length).toEqual(2); expect(wrapper.find('dt').length).toEqual(2);
expect(wrapper.find('dd').length).toEqual(2);
});
it('renders correct labels in dt', () => {
expect(wrapper.find('dt').first().text()).toEqual('Label 1'); expect(wrapper.find('dt').first().text()).toEqual('Label 1');
expect(wrapper.find('dt').last().text()).toEqual('Label 2'); expect(wrapper.find('dt').last().text()).toEqual('Label 2');
});
expect(wrapper.find('dd').length).toEqual(2); it('renders SanitizedHtml component in dt for each value', () => {
expect(wrapper.find('dd').first().text()).toEqual('Value 1'); expect(wrapper.find('dd').first().find(SanitizedHtml).length).toBe(1);
expect(wrapper.find('dd').last().text()).toEqual('Value 2'); expect(wrapper.find('dd').last().find(SanitizedHtml).length).toBe(1);
});
it('passes value string to SanitizedHtml', () => {
expect(wrapper.find(SanitizedHtml).first().props().htmlString).toBe('Value 1');
expect(wrapper.find(SanitizedHtml).last().props().htmlString).toBe('Value 2');
}); });
}); });
......
...@@ -2,9 +2,11 @@ import React from 'react'; ...@@ -2,9 +2,11 @@ import React from 'react';
import { shallow } from 'enzyme'; import { shallow } from 'enzyme';
import Typography from '@material-ui/core/Typography'; import Typography from '@material-ui/core/Typography';
import WindowSideBarInfoPanel from '../../../src/components/WindowSideBarInfoPanel'; import WindowSideBarInfoPanel from '../../../src/components/WindowSideBarInfoPanel';
import SanitizedHtml from '../../../src/components/SanitizedHtml';
import LabelValueMetadata from '../../../src/components/LabelValueMetadata'; import LabelValueMetadata from '../../../src/components/LabelValueMetadata';
describe('WindowSideBarInfoPanel', () => { describe('WindowSideBarInfoPanel', () => {
const metadata = [{ label: {}, value: {} }];
let wrapper; let wrapper;
describe('when metadata is present', () => { describe('when metadata is present', () => {
...@@ -13,43 +15,73 @@ describe('WindowSideBarInfoPanel', () => { ...@@ -13,43 +15,73 @@ describe('WindowSideBarInfoPanel', () => {
<WindowSideBarInfoPanel <WindowSideBarInfoPanel
canvasLabel="The Canvas Label" canvasLabel="The Canvas Label"
canvasDescription="The Canvas Description" canvasDescription="The Canvas Description"
canvasMetadata={[{ label: {}, value: {} }]} canvasMetadata={metadata}
manifestLabel="The Manifest Label" manifestLabel="The Manifest Label"
manifestDescription="The Manifest Description" manifestDescription="The Manifest Description"
manifestMetadata={metadata}
t={str => str}
/>, />,
).dive(); ).dive();
}); });
it('renders canvas level label, description, and metadata', () => { it('renders header', () => {
expect( expect(
wrapper.find('WithStyles(Typography)[variant="h3"]').first().matchesElement( wrapper.find(Typography).at(0).matchesElement(
<Typography>aboutThisItem</Typography>,
),
).toBe(true);
});
it('renders canvas label', () => {
expect(
wrapper.find(Typography).at(1).matchesElement(
<Typography>The Canvas Label</Typography>, <Typography>The Canvas Label</Typography>,
), ),
).toBe(true); ).toBe(true);
});
it('renders canvas description in SanitizedHtml component', () => {
expect( expect(
wrapper.find('WithStyles(Typography)[variant="body2"]').first().matchesElement( wrapper.find(Typography).at(2).matchesElement(
<Typography>The Canvas Description</Typography>, <Typography>
<SanitizedHtml htmlString="The Canvas Description" ruleSet="iiif" />
</Typography>,
), ),
).toBe(true); ).toBe(true);
});
expect(wrapper.find(LabelValueMetadata).length).toBe(2); // one for canvas one for manifest it('renders canvas metadata in LabelValueMetadata component', () => {
expect(
wrapper.find(LabelValueMetadata).at(0).matchesElement(
<LabelValueMetadata labelValuePairs={metadata} />,
),
).toBe(true);
}); });
it('renders manifest level label, description, and metadata', () => { it('renders manifest label', () => {
expect( expect(
wrapper.find('WithStyles(Typography)[variant="h3"]').last().matchesElement( wrapper.find(Typography).at(3).matchesElement(
<Typography>The Manifest Label</Typography>, <Typography>The Manifest Label</Typography>,
), ),
).toBe(true); ).toBe(true);
});
it('renders manifest description in SanitizedHtml component', () => {
expect( expect(
wrapper.find('WithStyles(Typography)[variant="body2"]').last().matchesElement( wrapper.find(Typography).at(4).matchesElement(
<Typography>The Manifest Description</Typography>, <Typography>
<SanitizedHtml htmlString="The Manifest Description" ruleSet="iiif" />
</Typography>,
), ),
).toBe(true); ).toBe(true);
});
expect(wrapper.find(LabelValueMetadata).length).toBe(2); // one for canvas one for manifest it('renders manifest metadata in LabelValueMetadata component', () => {
expect(
wrapper.find(LabelValueMetadata).at(1).matchesElement(
<LabelValueMetadata labelValuePairs={metadata} />,
),
).toBe(true);
}); });
}); });
...@@ -60,15 +92,17 @@ describe('WindowSideBarInfoPanel', () => { ...@@ -60,15 +92,17 @@ describe('WindowSideBarInfoPanel', () => {
).dive(); ).dive();
}); });
it('does not render empty elements', () => { it('does render header', () => {
expect( expect(
wrapper.find('WithStyles(Typography)[variant="h2"]').first().matchesElement( wrapper.find(Typography).first().matchesElement(
<Typography>aboutThisItem</Typography>, <Typography>aboutThisItem</Typography>,
), ),
).toBe(true); ).toBe(true);
});
expect(wrapper.find('WithStyles(Typography)[variant="h3"]').length).toEqual(0); it('does not render empty elements elements', () => {
expect(wrapper.find('WithStyles(Typography)[variant="body2"]').length).toEqual(0); expect(wrapper.find(Typography).length).toBe(1); // only header element
expect(wrapper.find(LabelValueMetadata).length).toBe(0);
}); });
}); });
}); });
import React, { Component } from 'react'; import React, { Component } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import SanitizedHtml from './SanitizedHtml';
/** /**
* Renders label/value pair metadata in a dl * Renders label/value pair metadata in a dl
...@@ -24,8 +25,12 @@ class LabelValueMetadata extends Component { ...@@ -24,8 +25,12 @@ class LabelValueMetadata extends Component {
return ( return (
<dl> <dl>
{labelValuePairs.reduce((acc, labelValuePair, i) => acc.concat([ {labelValuePairs.reduce((acc, labelValuePair, i) => acc.concat([
<dt key={`label-${i}`}>{labelValuePair.label}</dt>, <dt key={`label-${i}`}>
<dd key={`value-${i}`}>{labelValuePair.value}</dd>, {labelValuePair.label}
</dt>,
<dd key={`value-${i}`}>
<SanitizedHtml htmlString={labelValuePair.value} ruleSet="iiif" />
</dd>,
]), [])} ]), [])}
</dl> </dl>
); );
......
...@@ -4,8 +4,10 @@ import Divider from '@material-ui/core/Divider'; ...@@ -4,8 +4,10 @@ import Divider from '@material-ui/core/Divider';
import Typography from '@material-ui/core/Typography'; import Typography from '@material-ui/core/Typography';
import { withStyles } from '@material-ui/core/styles'; import { withStyles } from '@material-ui/core/styles';
import LabelValueMetadata from './LabelValueMetadata'; import LabelValueMetadata from './LabelValueMetadata';
import SanitizedHtml from './SanitizedHtml';
import ns from '../config/css-ns'; import ns from '../config/css-ns';
/** /**
* WindowSideBarInfoPanel * WindowSideBarInfoPanel
*/ */
...@@ -25,16 +27,48 @@ class WindowSideBarInfoPanel extends Component { ...@@ -25,16 +27,48 @@ class WindowSideBarInfoPanel extends Component {
manifestMetadata, manifestMetadata,
t, t,
} = this.props; } = this.props;
return ( return (
<div className={ns('window-sidebar-info-panel')}> <div className={ns('window-sidebar-info-panel')}>
<Typography variant="h2" className={classes.windowSideBarH2}>{t('aboutThisItem')}</Typography>
{canvasLabel && <Typography variant="h3" className={classes.windowSideBarH3}>{canvasLabel}</Typography>} <Typography variant="h2" className={classes.windowSideBarH2}>
{canvasDescription && <Typography variant="body2">{canvasDescription}</Typography>} {t('aboutThisItem')}
{canvasMetadata && <LabelValueMetadata labelValuePairs={canvasMetadata} />} </Typography>
{canvasLabel && (
<Typography variant="h3" className={classes.windowSideBarH3}>
{canvasLabel}
</Typography>
)}
{canvasDescription && (
<Typography variant="body2">
<SanitizedHtml htmlString={canvasDescription} ruleSet="iiif" />
</Typography>
)}
{canvasMetadata.length > 0 && (
<LabelValueMetadata labelValuePairs={canvasMetadata} />
)}
<Divider /> <Divider />
{manifestLabel && <Typography variant="h3" className={classes.windowSideBarH3}>{manifestLabel}</Typography>}
{manifestDescription && <Typography variant="body2">{manifestDescription}</Typography>} {manifestLabel && (
{manifestMetadata && <LabelValueMetadata labelValuePairs={manifestMetadata} />} <Typography variant="h3" className={classes.windowSideBarH3}>
{manifestLabel}
</Typography>
)}
{manifestDescription && (
<Typography variant="body2">
<SanitizedHtml htmlString={manifestDescription} ruleSet="iiif" />
</Typography>
)}
{manifestMetadata.length > 0 && (
<LabelValueMetadata labelValuePairs={manifestMetadata} />
)}
</div> </div>
); );
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment