Skip to content

Commit

Permalink
Support JSX/node as customSlotContent.
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-searle committed Jan 21, 2019
1 parent a3970be commit b923ae8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
41 changes: 28 additions & 13 deletions components/x-teaser-timeline/__tests__/TeaserTimeline.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,30 +91,45 @@ describe('x-teaser-timeline', () => {
describe('custom slot', () => {
let component;

describe('custom slot without latestArticlesTime set', () => {
beforeEach(() => {
props.customSlotContent = '<div class="custom-slot">Custom slot content</div>';
props.customSlotPosition = 3;
component = shallow(<TeaserTimeline {...props} />);
describe('custom slot content is a string', () => {
describe('without latestArticlesTime set', () => {
beforeEach(() => {
props.customSlotContent = '<div class="custom-slot">Custom slot content</div>';
props.customSlotPosition = 3;
component = shallow(<TeaserTimeline {...props} />);
});

it('has custom content in correct position', () => {
expect(component.render().find('.custom-slot')).toHaveLength(1);
expect(component.render().find('li').eq(3).find('.custom-slot')).toHaveLength(1);
});
});

it('has custom content in correct position', () => {
expect(component.render().find('.custom-slot')).toHaveLength(1);
expect(component.render().find('li').eq(3).find('.custom-slot')).toHaveLength(1);
describe('with latestArticlesTime set', () => {
beforeEach(() => {
props.customSlotContent = '<div class="custom-slot">Custom slot content</div>';
props.customSlotPosition = 2;
props.latestItemsTime = '2018-10-16T12:10:33.000Z';
component = shallow(<TeaserTimeline {...props} />);
});

it('has custom content in correct position', () => {
expect(component.render().find('.custom-slot')).toHaveLength(1);
expect(component.render().find('li').eq(2).find('.custom-slot')).toHaveLength(1);
});
});
});

describe('custom slot with latestArticlesTime set', () => {
describe('custom slot content is a node', () => {
beforeEach(() => {
props.customSlotContent = '<div class="custom-slot">Custom slot content</div>';
props.customSlotPosition = 2;
props.latestItemsTime = '2018-10-16T12:10:33.000Z';
props.customSlotContent = <div className="custom-slot">Custom slot content</div>;
props.customSlotPosition = 3;
component = shallow(<TeaserTimeline {...props} />);
});

it('has custom content in correct position', () => {
expect(component.render().find('.custom-slot')).toHaveLength(1);
expect(component.render().find('li').eq(2).find('.custom-slot')).toHaveLength(1);
expect(component.render().find('li').eq(3).find('.custom-slot')).toHaveLength(1);
});
});
});
Expand Down
5 changes: 3 additions & 2 deletions components/x-teaser-timeline/src/TeaserTimeline.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ const TeaserTimeline = props => {
</div>}
</li>
);
}
if (typeof item === 'string') {
} else if (typeof item === 'string') {
return (<li key="custom-slot" dangerouslySetInnerHTML={{ __html: item }} />);
}

return (<li key="custom-slot">{item}</li>);
})}
</ul>
</section>
Expand Down

0 comments on commit b923ae8

Please sign in to comment.