Skip to content

Commit

Permalink
feat(talk-title): formatted markdown content in the title
Browse files Browse the repository at this point in the history
for #806
  • Loading branch information
travi committed Jun 18, 2020
1 parent 46cdcda commit 07d08a4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
19 changes: 17 additions & 2 deletions src/molecules/talk/presentational-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,37 @@ import React from 'react';
import {shallow} from 'enzyme';
import {assert} from 'chai';
import any from '@travi/any';
import sinon from 'sinon';
import * as formatters from '../../formatters';
import Talk from '.';

suite('talk', () => {
let sandbox;

setup(() => {
sandbox = sinon.createSandbox();

sandbox.stub(formatters, 'markdown');
});

teardown(() => sandbox.restore());

test('that the title and speaker details are displayed', () => {
const speakerName = any.string();
const github = any.word();
const twitter = any.word();
const talk = {title: any.sentence(), speaker: {frontmatter: {name: speakerName, github, twitter}}};
const talkTitle = any.sentence();
const formattedTitle = any.sentence();
const talk = {title: talkTitle, speaker: {frontmatter: {name: speakerName, github, twitter}}};
formatters.markdown.withArgs(talkTitle).returns(formattedTitle);

const htmlContent = any.string();

const wrapper = shallow(<Talk talk={talk} content={htmlContent} />);
const speaker = wrapper.find('h3');
const speakerSocialIcons = speaker.find('SpeakerSocialIcons');

assert.equal(wrapper.find('h1').text(), talk.title);
assert.equal(wrapper.find('h1').text(), formattedTitle);
assert.equal(speaker.find('span').text(), speakerName);
assert.equal(speakerSocialIcons.prop('twitter'), twitter);
assert.equal(speakerSocialIcons.prop('github'), github);
Expand Down
3 changes: 2 additions & 1 deletion src/molecules/talk/presentational.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React from 'react';
import {string, shape} from 'prop-types';
import SpeakerSocialIcons from '../../atoms/social/speaker';
import {markdown} from '../../formatters';

export default function Talk({talk, content}) {
const {github, twitter, name: speakerName} = talk.speaker.frontmatter;

return (
<>
<h1 css={{color: '#AD5472'}}>{talk.title}</h1>
<h1 css={{color: '#AD5472'}}>{markdown(talk.title)}</h1>
<h3 css={{display: 'flex', alignItems: 'center'}}>
<span>{speakerName}</span>
<small><SpeakerSocialIcons github={github} twitter={twitter} /></small>
Expand Down
8 changes: 8 additions & 0 deletions src/molecules/talk/stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ Default.story = {
name: 'default'
};

export const WithMarkdownInTitle = () => (
<Talk talk={{...talk, title: 'This is a `title` with _markdown_'}} content={talkContent} />
);

WithMarkdownInTitle.story = {
name: 'w/ markdown in title'
};

export const NoTwitter = () => <Talk talk={talkNoTwitter} content={talkContent} />;

NoTwitter.story = {
Expand Down

0 comments on commit 07d08a4

Please sign in to comment.